From 3266f0964404d28ee5524b9c88de63d31b7a7c28 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Fri, 16 May 2025 09:32:46 +0800 Subject: [PATCH] Update version to 1.45.4, add dryRun option in cli.json and versions.ts, and enhance localization for dryRun messages --- cli.json | 3 +++ package.json | 2 +- src/locales/en.ts | 1 + src/locales/zh.ts | 1 + src/versions.ts | 28 ++++++++++++++++++++-------- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/cli.json b/cli.json index 52b90b2..f309961 100644 --- a/cli.json +++ b/cli.json @@ -92,6 +92,9 @@ }, "rollout": { "hasValue": true + }, + "dryRun": { + "default": false } } }, diff --git a/package.json b/package.json index eef5834..b7fa38c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update-cli", - "version": "1.45.3", + "version": "1.45.4", "description": "command line tool for react-native-update (remote updates for react native)", "main": "index.js", "bin": { diff --git a/src/locales/en.ts b/src/locales/en.ts index 0d4773f..5cc964b 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -129,4 +129,5 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks. versionMetaInfoQuestion: 'Enter custom meta info:', updateNativePackageQuestion: 'Bind to native package now?(Y/N)', unnamed: '(Unnamed)', + dryRun: 'Below is the dry-run result, no actual operation will be performed:', }; diff --git a/src/locales/zh.ts b/src/locales/zh.ts index 77782fb..96619d4 100644 --- a/src/locales/zh.ts +++ b/src/locales/zh.ts @@ -122,4 +122,5 @@ export default { versionMetaInfoQuestion: '输入自定义的 meta info:', updateNativePackageQuestion: '是否现在将此热更应用到原生包上?(Y/N)', unnamed: '(未命名)', + dryRun: '以下是 dry-run 模拟运行结果,不会实际执行任何操作:', }; diff --git a/src/versions.ts b/src/versions.ts index 5f858cb..b3a0d59 100644 --- a/src/versions.ts +++ b/src/versions.ts @@ -8,6 +8,7 @@ import { depVersions } from './utils/dep-versions'; import { getCommitInfo } from './utils/git'; import type { Package, Platform, Version } from 'types'; import { satisfies } from 'compare-versions'; +import chalk from 'chalk'; interface CommandOptions { name?: string; @@ -21,6 +22,7 @@ interface CommandOptions { maxPackageVersion?: string; packageVersionRange?: string; rollout?: string; + dryRun?: boolean; } async function showVersion(appId: string, offset: number) { @@ -107,22 +109,29 @@ export const bindVersionToPackages = async ({ versionId, pkgs, rollout, + dryRun, }: { appId: string; versionId: string; pkgs: Package[]; rollout?: number; + dryRun?: boolean; }) => { + if (dryRun) { + console.log(chalk.yellow(t('dryRun'))); + } if (rollout !== undefined) { const rolloutConfig: Record = {}; for (const pkg of pkgs) { rolloutConfig[pkg.name] = rollout; } - await put(`/app/${appId}/version/${versionId}`, { - config: { - rollout: rolloutConfig, - }, - }); + if (!dryRun) { + await put(`/app/${appId}/version/${versionId}`, { + config: { + rollout: rolloutConfig, + }, + }); + } console.log( `${t('rolloutConfigSet', { versions: pkgs.map((pkg: Package) => pkg.name).join(', '), @@ -131,9 +140,11 @@ export const bindVersionToPackages = async ({ ); } for (const pkg of pkgs) { - await put(`/app/${appId}/package/${pkg.id}`, { - versionId, - }); + if (!dryRun) { + await put(`/app/${appId}/package/${pkg.id}`, { + versionId, + }); + } console.log( `${t('versionBind', { version: versionId, @@ -294,6 +305,7 @@ export const commands = { versionId, pkgs: pkgsToBind, rollout, + dryRun: options.dryRun, }); console.log(t('operationSuccess')); },