From fbad603d05b5520690d128e1b917fd83cb9a356f Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Mon, 10 Mar 2025 22:56:58 +0800 Subject: [PATCH] sort key --- package.json | 2 +- src/package.ts | 2 +- src/utils/dep-versions.ts | 15 ++++++++++++--- src/versions.ts | 14 +++++++------- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 866d75a..c976426 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update-cli", - "version": "1.41.0", + "version": "1.42.0", "description": "Command tools for javaScript updater with `pushy` service for react native apps.", "main": "index.js", "bin": { diff --git a/src/package.ts b/src/package.ts index 6da2b30..7fe7408 100644 --- a/src/package.ts +++ b/src/package.ts @@ -5,7 +5,7 @@ import { checkPlatform, getSelectedApp } from './app'; import { getApkInfo, getIpaInfo, getAppInfo } from './utils'; import Table from 'tty-table'; -import { depVersions } from 'utils/dep-versions'; +import { depVersions } from './utils/dep-versions'; export async function listPackage(appId: string) { const { data } = await get(`/app/${appId}/package/list?limit=1000`); diff --git a/src/utils/dep-versions.ts b/src/utils/dep-versions.ts index c5c186e..7cf7c1a 100644 --- a/src/utils/dep-versions.ts +++ b/src/utils/dep-versions.ts @@ -1,10 +1,10 @@ -import currentPackage from '../../package.json'; +const currentPackage = require(`${process.cwd()}/package.json`); const depKeys = Object.keys(currentPackage.dependencies); const devDepKeys = Object.keys(currentPackage.devDependencies); const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])]; -export const depVersions: Record = {}; +const _depVersions: Record = {}; for (const dep of dedupedDeps) { try { @@ -12,6 +12,15 @@ for (const dep of dedupedDeps) { paths: [process.cwd()], }); const version = require(packageJsonPath).version; - depVersions[dep] = version; + _depVersions[dep] = version; } catch (e) {} } + +export const depVersions = Object.keys(_depVersions) + .sort() // Sort the keys alphabetically + .reduce((obj, key) => { + obj[key] = _depVersions[key]; // Rebuild the object with sorted keys + return obj; + }, {} as Record); + +// console.log({ depVersions }); diff --git a/src/versions.ts b/src/versions.ts index 0b5f14c..f36b672 100644 --- a/src/versions.ts +++ b/src/versions.ts @@ -4,7 +4,7 @@ import { question, saveToLocal } from './utils'; import { checkPlatform, getSelectedApp } from './app'; import { choosePackage } from './package'; import { compare } from 'compare-versions'; -import { depVersions } from 'utils/dep-versions'; +import { depVersions } from './utils/dep-versions'; async function showVersion(appId: string, offset: number) { const { data, count } = await get(`/app/${appId}/version/list`); @@ -14,11 +14,11 @@ async function showVersion(appId: string, offset: number) { .slice(0, 3) .map((v) => v.name) .join(', '); - const count = version.packages.length; - if (count > 3) { - packageInfo += `...and ${count - 3} more`; + const pkgCount = version.packages.length; + if (pkgCount > 3) { + packageInfo += `...and ${pkgCount - 3} more`; } - if (count === 0) { + if (pkgCount === 0) { packageInfo = 'no package'; } else { packageInfo = `[${packageInfo}]`; @@ -32,7 +32,7 @@ async function showVersion(appId: string, offset: number) { return data; } -async function listVersions(appId) { +async function listVersions(appId: string) { let offset = 0; while (true) { await showVersion(appId, offset); @@ -53,7 +53,7 @@ async function listVersions(appId) { } } -async function chooseVersion(appId) { +async function chooseVersion(appId: string) { let offset = 0; while (true) { const data = await showVersion(appId, offset);