react-native-update-cli 2.23.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/README.zh-CN.md +8 -0
- package/lib/app.d.ts +28 -0
- package/lib/app.js +71 -9
- package/lib/auto-update.d.ts +30 -0
- package/lib/auto-update.js +502 -0
- package/lib/bin.js +3 -0
- package/lib/bundle.d.ts +4 -0
- package/lib/bundle.js +48 -23
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +10 -7
- package/lib/locales/zh.d.ts +3 -0
- package/lib/locales/zh.js +10 -7
- package/lib/package.d.ts +1 -0
- package/lib/package.js +7 -13
- package/lib/provider.d.ts +1 -1
- package/lib/provider.js +4 -2
- package/lib/types.d.ts +5 -1
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +3 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +33 -1
- package/lib/versions.js +18 -43
- package/package.json +1 -1
- package/src/app.ts +89 -16
- package/src/auto-update.ts +647 -0
- package/src/bin.ts +3 -0
- package/src/bundle.ts +54 -28
- package/src/locales/en.ts +13 -7
- package/src/locales/zh.ts +12 -7
- package/src/package.ts +12 -23
- package/src/provider.ts +4 -1
- package/src/types.ts +5 -0
- package/src/utils/constants.ts +3 -1
- package/src/utils/index.ts +39 -1
- package/src/versions.ts +19 -52
package/README.md
CHANGED
|
@@ -19,6 +19,23 @@ npm install -g react-native-update-cli
|
|
|
19
19
|
|
|
20
20
|
The command-line tool is installed globally. Invoke `pushy` or `cresc` directly; do not use a project-local CLI or prefix commands with `npx`.
|
|
21
21
|
|
|
22
|
+
### Background CLI updates
|
|
23
|
+
|
|
24
|
+
Global installations update themselves in a detached background process after
|
|
25
|
+
a successful command. The foreground command is never held open for the
|
|
26
|
+
install. The CLI reuses the package manager that owns the global installation
|
|
27
|
+
(`npm`, `pnpm`, Yarn Classic, or Bun) and the registry configured in the current
|
|
28
|
+
`.npmrc`/environment, so private mirrors, credentials, proxies, and custom
|
|
29
|
+
global prefixes keep working.
|
|
30
|
+
|
|
31
|
+
Network failures are silent and retried after a cooldown. Concurrent commands
|
|
32
|
+
share a lock. A non-writable global directory is never escalated with `sudo`;
|
|
33
|
+
the next invocation prints the exact manual command after the permission issue
|
|
34
|
+
has been fixed. Project-local/npx installations and CI are not modified.
|
|
35
|
+
|
|
36
|
+
Set `RNU_AUTO_UPDATE=0` (or `RNU_DISABLE_AUTO_UPDATE=1`) to disable the feature.
|
|
37
|
+
`RNU_AUTO_UPDATE_PACKAGE_MANAGER=npm|pnpm|yarn|bun` overrides manager detection.
|
|
38
|
+
|
|
22
39
|
## Basic Usage
|
|
23
40
|
|
|
24
41
|
```bash
|
package/README.zh-CN.md
CHANGED
|
@@ -19,6 +19,14 @@ npm install -g react-native-update-cli
|
|
|
19
19
|
|
|
20
20
|
命令行工具始终全局安装,直接调用 `pushy` 或 `cresc`;不要使用项目本地 CLI,也不要给命令添加 `npx` 前缀。
|
|
21
21
|
|
|
22
|
+
### CLI 后台自动更新
|
|
23
|
+
|
|
24
|
+
全局安装的 CLI 会在命令成功结束后启动独立后台进程完成自更新,不会让当前命令等待安装。更新会沿用这份全局安装实际所属的包管理器(`npm`、`pnpm`、Yarn Classic 或 Bun),并使用当前 `.npmrc` / 环境中的 registry 配置,因此私有镜像、认证、代理和自定义全局目录均可继续生效。
|
|
25
|
+
|
|
26
|
+
网络失败会静默降级并在冷却期后重试;并发命令通过锁避免重复安装。全局目录不可写时不会自动调用 `sudo`,下次运行会给出修复权限后可执行的准确命令。本地依赖、npx 临时安装和 CI 环境不会被修改。
|
|
27
|
+
|
|
28
|
+
设置 `RNU_AUTO_UPDATE=0`(或 `RNU_DISABLE_AUTO_UPDATE=1`)可关闭;`RNU_AUTO_UPDATE_PACKAGE_MANAGER=npm|pnpm|yarn|bun` 可覆盖包管理器识别结果。
|
|
29
|
+
|
|
22
30
|
## 基础用法
|
|
23
31
|
|
|
24
32
|
```bash
|
package/lib/app.d.ts
CHANGED
|
@@ -4,35 +4,63 @@ interface AppSummary {
|
|
|
4
4
|
name: string;
|
|
5
5
|
platform: Platform;
|
|
6
6
|
}
|
|
7
|
+
export interface AppTargetOptions {
|
|
8
|
+
appId?: string;
|
|
9
|
+
config?: string;
|
|
10
|
+
platform?: Platform | '';
|
|
11
|
+
}
|
|
12
|
+
/** The selected-app config file was missing or has no entry for the platform. */
|
|
13
|
+
export declare class AppNotSelectedError extends Error {
|
|
14
|
+
readonly code = "APP_NOT_SELECTED";
|
|
15
|
+
constructor(platform: Platform);
|
|
16
|
+
}
|
|
17
|
+
/** Resolve an explicit platform or prompt for one interactively. */
|
|
7
18
|
export declare function getPlatform(platform?: string): Promise<Platform>;
|
|
19
|
+
/** Validate that a string names a platform supported by the update service. */
|
|
8
20
|
export declare function assertPlatform(platform: string): Platform;
|
|
21
|
+
/** Read the selected app for a platform from the requested config file. */
|
|
9
22
|
export declare function getSelectedApp(platform: Platform, configPath?: string): Promise<{
|
|
10
23
|
appId: string;
|
|
11
24
|
appKey: string;
|
|
12
25
|
platform: Platform;
|
|
13
26
|
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the app an operation targets: an explicit `--appId` wins, otherwise
|
|
29
|
+
* the app selected for the platform in `--config` (default: update.json).
|
|
30
|
+
* Prompts for the platform only when it is needed and not given.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveAppId(options?: AppTargetOptions): Promise<string>;
|
|
33
|
+
/** List apps, optionally filtering them to one platform. */
|
|
14
34
|
export declare function listApp(platform?: Platform | ''): Promise<AppSummary[]>;
|
|
35
|
+
/** Prompt until the user chooses an app belonging to the target platform. */
|
|
15
36
|
export declare function chooseApp(platform: Platform): Promise<AppSummary>;
|
|
37
|
+
/** Persist an app selection in the requested brand-aware config file. */
|
|
16
38
|
declare function selectApp({ args, options, }: {
|
|
17
39
|
args: string[];
|
|
18
40
|
options: {
|
|
19
41
|
platform?: Platform | '';
|
|
42
|
+
config?: string;
|
|
20
43
|
};
|
|
21
44
|
}): Promise<void>;
|
|
45
|
+
/** Build the application-management command handlers used by the CLI. */
|
|
22
46
|
export declare function getAppCommands(): {
|
|
47
|
+
/** Create an app and select it in the same configuration file. */
|
|
23
48
|
createApp: ({ options, }: {
|
|
24
49
|
options: {
|
|
25
50
|
name: string;
|
|
26
51
|
downloadUrl: string;
|
|
27
52
|
platform?: Platform | '';
|
|
53
|
+
config?: string;
|
|
28
54
|
};
|
|
29
55
|
}) => Promise<void>;
|
|
56
|
+
/** Delete the specified app, or prompt for one when no ID is supplied. */
|
|
30
57
|
deleteApp: ({ args, options, }: {
|
|
31
58
|
args: string[];
|
|
32
59
|
options: {
|
|
33
60
|
platform: Platform;
|
|
34
61
|
};
|
|
35
62
|
}) => Promise<void>;
|
|
63
|
+
/** List apps through the command interface. */
|
|
36
64
|
apps: ({ options }: {
|
|
37
65
|
options: {
|
|
38
66
|
platform?: Platform | '';
|
package/lib/app.js
CHANGED
|
@@ -3,40 +3,63 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AppNotSelectedError = void 0;
|
|
6
7
|
exports.getPlatform = getPlatform;
|
|
7
8
|
exports.assertPlatform = assertPlatform;
|
|
8
9
|
exports.getSelectedApp = getSelectedApp;
|
|
10
|
+
exports.resolveAppId = resolveAppId;
|
|
9
11
|
exports.listApp = listApp;
|
|
10
12
|
exports.chooseApp = chooseApp;
|
|
11
13
|
exports.getAppCommands = getAppCommands;
|
|
12
14
|
const fs_1 = __importDefault(require("fs"));
|
|
13
15
|
const api_1 = require("./api");
|
|
14
16
|
const utils_1 = require("./utils");
|
|
17
|
+
const constants_1 = require("./utils/constants");
|
|
15
18
|
const i18n_1 = require("./utils/i18n");
|
|
19
|
+
/** The selected-app config file was missing or has no entry for the platform. */
|
|
20
|
+
class AppNotSelectedError extends Error {
|
|
21
|
+
code = 'APP_NOT_SELECTED';
|
|
22
|
+
constructor(platform) {
|
|
23
|
+
super((0, i18n_1.t)('appNotSelected', { platform }));
|
|
24
|
+
this.name = 'AppNotSelectedError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AppNotSelectedError = AppNotSelectedError;
|
|
28
|
+
/** Resolve an explicit platform or prompt for one interactively. */
|
|
16
29
|
async function getPlatform(platform) {
|
|
17
30
|
return assertPlatform(platform || (await (0, utils_1.question)((0, i18n_1.t)('platformQuestion'))));
|
|
18
31
|
}
|
|
32
|
+
/** Validate that a string names a platform supported by the update service. */
|
|
19
33
|
function assertPlatform(platform) {
|
|
20
34
|
if (platform !== 'ios' && platform !== 'android' && platform !== 'harmony') {
|
|
21
35
|
throw new Error((0, i18n_1.t)('unsupportedPlatform', { platform }));
|
|
22
36
|
}
|
|
23
37
|
return platform;
|
|
24
38
|
}
|
|
39
|
+
/** Read the selected app for a platform from the requested config file. */
|
|
25
40
|
async function getSelectedApp(platform, configPath) {
|
|
26
41
|
assertPlatform(platform);
|
|
27
|
-
|
|
42
|
+
const resolvedConfigPath = configPath || constants_1.updateJson;
|
|
43
|
+
let raw;
|
|
28
44
|
try {
|
|
29
|
-
|
|
45
|
+
raw = await fs_1.default.promises.readFile(resolvedConfigPath, 'utf8');
|
|
30
46
|
}
|
|
31
47
|
catch (e) {
|
|
32
48
|
if (e.code === 'ENOENT') {
|
|
33
|
-
throw new
|
|
49
|
+
throw new AppNotSelectedError(platform);
|
|
34
50
|
}
|
|
35
51
|
throw e;
|
|
36
52
|
}
|
|
53
|
+
let updateInfo;
|
|
54
|
+
try {
|
|
55
|
+
updateInfo = JSON.parse(raw);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
throw new Error((0, i18n_1.t)('failedToParseUpdateJson', { configPath: resolvedConfigPath }));
|
|
59
|
+
}
|
|
37
60
|
const info = updateInfo[platform];
|
|
38
61
|
if (!info) {
|
|
39
|
-
throw new
|
|
62
|
+
throw new AppNotSelectedError(platform);
|
|
40
63
|
}
|
|
41
64
|
return {
|
|
42
65
|
appId: String(info.appId),
|
|
@@ -44,6 +67,39 @@ async function getSelectedApp(platform, configPath) {
|
|
|
44
67
|
platform,
|
|
45
68
|
};
|
|
46
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Fail fast when an explicit `--appId` names an app of another platform.
|
|
72
|
+
* The server accepts a bundle for any app the account owns and never sees
|
|
73
|
+
* the platform it was built for, so this is the only place the mistake can
|
|
74
|
+
* be caught before it reaches devices. A missing or foreign app fails here
|
|
75
|
+
* too (403/404) instead of after the expensive work.
|
|
76
|
+
*/
|
|
77
|
+
async function assertAppPlatform(appId, platform) {
|
|
78
|
+
const app = (await (0, api_1.get)(`/app/${appId}`));
|
|
79
|
+
if (app.platform && app.platform !== platform) {
|
|
80
|
+
throw new Error((0, i18n_1.t)('appPlatformMismatch', { appId, appPlatform: app.platform, platform }));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolve the app an operation targets: an explicit `--appId` wins, otherwise
|
|
85
|
+
* the app selected for the platform in `--config` (default: update.json).
|
|
86
|
+
* Prompts for the platform only when it is needed and not given.
|
|
87
|
+
*/
|
|
88
|
+
async function resolveAppId(options = {}) {
|
|
89
|
+
if (options.platform) {
|
|
90
|
+
assertPlatform(options.platform);
|
|
91
|
+
}
|
|
92
|
+
if (options.appId) {
|
|
93
|
+
const appId = String(options.appId);
|
|
94
|
+
if (options.platform) {
|
|
95
|
+
await assertAppPlatform(appId, options.platform);
|
|
96
|
+
}
|
|
97
|
+
return appId;
|
|
98
|
+
}
|
|
99
|
+
const platform = await getPlatform(options.platform || undefined);
|
|
100
|
+
return (await getSelectedApp(platform, options.config)).appId;
|
|
101
|
+
}
|
|
102
|
+
/** List apps, optionally filtering them to one platform. */
|
|
47
103
|
async function listApp(platform = '') {
|
|
48
104
|
const { data } = await (0, api_1.get)('/app/list');
|
|
49
105
|
const allApps = data;
|
|
@@ -65,6 +121,7 @@ async function listApp(platform = '') {
|
|
|
65
121
|
console.log(`\n${(0, i18n_1.t)('totalApps', { count: list.length, platform })}`);
|
|
66
122
|
return list;
|
|
67
123
|
}
|
|
124
|
+
/** Prompt until the user chooses an app belonging to the target platform. */
|
|
68
125
|
async function chooseApp(platform) {
|
|
69
126
|
const list = await listApp(platform);
|
|
70
127
|
while (true) {
|
|
@@ -75,19 +132,20 @@ async function chooseApp(platform) {
|
|
|
75
132
|
}
|
|
76
133
|
}
|
|
77
134
|
}
|
|
135
|
+
/** Persist an app selection in the requested brand-aware config file. */
|
|
78
136
|
async function selectApp({ args, options, }) {
|
|
79
137
|
const platform = await getPlatform(options.platform);
|
|
80
138
|
const id = args[0]
|
|
81
139
|
? Number.parseInt(args[0], 10)
|
|
82
140
|
: (await chooseApp(platform)).id;
|
|
83
|
-
const configPath = options.config;
|
|
141
|
+
const configPath = options.config || constants_1.updateJson;
|
|
84
142
|
let updateInfo = {};
|
|
85
143
|
try {
|
|
86
|
-
updateInfo = JSON.parse(await fs_1.default.promises.readFile(configPath
|
|
144
|
+
updateInfo = JSON.parse(await fs_1.default.promises.readFile(configPath, 'utf8'));
|
|
87
145
|
}
|
|
88
146
|
catch (e) {
|
|
89
147
|
if (e.code !== 'ENOENT') {
|
|
90
|
-
console.error((0, i18n_1.t)('failedToParseUpdateJson'));
|
|
148
|
+
console.error((0, i18n_1.t)('failedToParseUpdateJson', { configPath }));
|
|
91
149
|
throw e;
|
|
92
150
|
}
|
|
93
151
|
}
|
|
@@ -96,10 +154,12 @@ async function selectApp({ args, options, }) {
|
|
|
96
154
|
appId: id,
|
|
97
155
|
appKey,
|
|
98
156
|
};
|
|
99
|
-
await fs_1.default.promises.writeFile(configPath
|
|
157
|
+
await fs_1.default.promises.writeFile(configPath, JSON.stringify(updateInfo, null, 4), 'utf8');
|
|
100
158
|
}
|
|
159
|
+
/** Build the application-management command handlers used by the CLI. */
|
|
101
160
|
function getAppCommands() {
|
|
102
161
|
return {
|
|
162
|
+
/** Create an app and select it in the same configuration file. */
|
|
103
163
|
createApp: async ({ options, }) => {
|
|
104
164
|
const name = options.name || (await (0, utils_1.question)((0, i18n_1.t)('appNameQuestion')));
|
|
105
165
|
const { downloadUrl } = options;
|
|
@@ -108,9 +168,10 @@ function getAppCommands() {
|
|
|
108
168
|
console.log((0, i18n_1.t)('createAppSuccess', { id }));
|
|
109
169
|
await selectApp({
|
|
110
170
|
args: [String(id)],
|
|
111
|
-
options: { platform },
|
|
171
|
+
options: { platform, config: options.config },
|
|
112
172
|
});
|
|
113
173
|
},
|
|
174
|
+
/** Delete the specified app, or prompt for one when no ID is supplied. */
|
|
114
175
|
deleteApp: async ({ args, options, }) => {
|
|
115
176
|
const { platform } = options;
|
|
116
177
|
const id = args[0] || (await chooseApp(platform)).id;
|
|
@@ -121,6 +182,7 @@ function getAppCommands() {
|
|
|
121
182
|
await (0, api_1.doDelete)(`/app/${id}`);
|
|
122
183
|
console.log((0, i18n_1.t)('operationSuccess'));
|
|
123
184
|
},
|
|
185
|
+
/** List apps through the command interface. */
|
|
124
186
|
apps: async ({ options }) => {
|
|
125
187
|
const { platform = '' } = options;
|
|
126
188
|
return listApp(platform);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
2
|
+
export interface AutoUpdateNotice {
|
|
3
|
+
kind: 'updated' | 'permission';
|
|
4
|
+
currentVersion: string;
|
|
5
|
+
targetVersion: string;
|
|
6
|
+
command?: string;
|
|
7
|
+
}
|
|
8
|
+
interface PackageManagerDetectionOptions {
|
|
9
|
+
packageRoot: string;
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
npmGlobalDir?: string;
|
|
12
|
+
yarnGlobalDir?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Identify the package manager that owns this global installation. Project
|
|
16
|
+
* lockfiles are deliberately ignored: they say how the app is installed, not
|
|
17
|
+
* how this CLI was installed.
|
|
18
|
+
*/
|
|
19
|
+
export declare function detectGlobalPackageManager({ packageRoot, env, npmGlobalDir, yarnGlobalDir, }: PackageManagerDetectionOptions): PackageManager | undefined;
|
|
20
|
+
export declare function buildUpdateCommand(manager: PackageManager, targetVersion: string, registryUrl: string, installPrefix?: string): {
|
|
21
|
+
command: string;
|
|
22
|
+
args: string[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Start a detached updater after the foreground command has completed. This
|
|
26
|
+
* function is synchronous on purpose: it is safe to call from process.exit.
|
|
27
|
+
*/
|
|
28
|
+
export declare function launchAutoUpdate(currentVersion: string, targetVersion: string | undefined, env?: NodeJS.ProcessEnv): boolean;
|
|
29
|
+
export declare function consumeAutoUpdateNotice(currentVersion: string): AutoUpdateNotice | undefined;
|
|
30
|
+
export {};
|