Skip to content

Commit fbad603

Browse files
committed
sort key
1 parent a1231f6 commit fbad603

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update-cli",
3-
"version": "1.41.0",
3+
"version": "1.42.0",
44
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
55
"main": "index.js",
66
"bin": {

src/package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { checkPlatform, getSelectedApp } from './app';
55

66
import { getApkInfo, getIpaInfo, getAppInfo } from './utils';
77
import Table from 'tty-table';
8-
import { depVersions } from 'utils/dep-versions';
8+
import { depVersions } from './utils/dep-versions';
99

1010
export async function listPackage(appId: string) {
1111
const { data } = await get(`/app/${appId}/package/list?limit=1000`);

src/utils/dep-versions.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
import currentPackage from '../../package.json';
1+
const currentPackage = require(`${process.cwd()}/package.json`);
22

33
const depKeys = Object.keys(currentPackage.dependencies);
44
const devDepKeys = Object.keys(currentPackage.devDependencies);
55
const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
66

7-
export const depVersions: Record<string, string> = {};
7+
const _depVersions: Record<string, string> = {};
88

99
for (const dep of dedupedDeps) {
1010
try {
1111
const packageJsonPath = require.resolve(`${dep}/package.json`, {
1212
paths: [process.cwd()],
1313
});
1414
const version = require(packageJsonPath).version;
15-
depVersions[dep] = version;
15+
_depVersions[dep] = version;
1616
} catch (e) {}
1717
}
18+
19+
export const depVersions = Object.keys(_depVersions)
20+
.sort() // Sort the keys alphabetically
21+
.reduce((obj, key) => {
22+
obj[key] = _depVersions[key]; // Rebuild the object with sorted keys
23+
return obj;
24+
}, {} as Record<string, string>);
25+
26+
// console.log({ depVersions });

src/versions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { question, saveToLocal } from './utils';
44
import { checkPlatform, getSelectedApp } from './app';
55
import { choosePackage } from './package';
66
import { compare } from 'compare-versions';
7-
import { depVersions } from 'utils/dep-versions';
7+
import { depVersions } from './utils/dep-versions';
88

99
async function showVersion(appId: string, offset: number) {
1010
const { data, count } = await get(`/app/${appId}/version/list`);
@@ -14,11 +14,11 @@ async function showVersion(appId: string, offset: number) {
1414
.slice(0, 3)
1515
.map((v) => v.name)
1616
.join(', ');
17-
const count = version.packages.length;
18-
if (count > 3) {
19-
packageInfo += `...and ${count - 3} more`;
17+
const pkgCount = version.packages.length;
18+
if (pkgCount > 3) {
19+
packageInfo += `...and ${pkgCount - 3} more`;
2020
}
21-
if (count === 0) {
21+
if (pkgCount === 0) {
2222
packageInfo = 'no package';
2323
} else {
2424
packageInfo = `[${packageInfo}]`;
@@ -32,7 +32,7 @@ async function showVersion(appId: string, offset: number) {
3232
return data;
3333
}
3434

35-
async function listVersions(appId) {
35+
async function listVersions(appId: string) {
3636
let offset = 0;
3737
while (true) {
3838
await showVersion(appId, offset);
@@ -53,7 +53,7 @@ async function listVersions(appId) {
5353
}
5454
}
5555

56-
async function chooseVersion(appId) {
56+
async function chooseVersion(appId: string) {
5757
let offset = 0;
5858
while (true) {
5959
const data = await showVersion(appId, offset);

0 commit comments

Comments
 (0)