react-native-update-cli 2.10.2 → 2.12.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 +4 -0
- package/README.zh-CN.md +4 -0
- package/cli.json +6 -0
- package/lib/api.js +10 -12
- package/lib/app.d.ts +2 -2
- package/lib/app.js +42 -45
- package/lib/bin.d.ts +2 -0
- package/lib/bin.js +73 -0
- package/lib/bundle-runner.d.ts +1 -0
- package/lib/bundle-runner.js +68 -22
- package/lib/exports.d.ts +2 -9
- package/lib/exports.js +0 -31
- package/lib/index.d.ts +1 -4
- package/lib/index.js +12 -80
- package/lib/install.js +3 -4
- package/lib/locales/en.d.ts +1 -0
- package/lib/locales/en.js +1 -0
- package/lib/locales/zh.d.ts +1 -0
- package/lib/locales/zh.js +1 -0
- package/lib/package.d.ts +3 -0
- package/lib/package.js +50 -6
- package/lib/provider.d.ts +2 -2
- package/lib/provider.js +26 -25
- package/lib/types.d.ts +17 -21
- package/lib/utils/app-info-parser/aab.js +45 -4
- package/lib/utils/app-info-parser/zip.d.ts +3 -3
- package/lib/utils/app-info-parser/zip.js +33 -19
- package/lib/utils/http-helper.js +2 -7
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +9 -14
- package/lib/utils/plugin-config.js +42 -6
- package/lib/utils/runtime.d.ts +28 -0
- package/lib/utils/runtime.js +185 -0
- package/lib/versions.d.ts +6 -3
- package/lib/versions.js +80 -25
- package/package.json +8 -15
- package/src/api.ts +23 -15
- package/src/app.ts +40 -40
- package/src/bin.ts +93 -0
- package/src/bundle-runner.ts +161 -62
- package/src/exports.ts +1 -10
- package/src/index.ts +1 -94
- package/src/install.ts +3 -1
- package/src/locales/en.ts +1 -0
- package/src/locales/zh.ts +1 -0
- package/src/package.ts +12 -5
- package/src/provider.ts +49 -40
- package/src/types.ts +18 -26
- package/src/utils/app-info-parser/aab.ts +1 -1
- package/src/utils/app-info-parser/zip.ts +41 -24
- package/src/utils/http-helper.ts +2 -2
- package/src/utils/index.ts +9 -13
- package/src/utils/plugin-config.ts +1 -1
- package/src/utils/runtime.ts +190 -0
- package/src/versions.ts +105 -34
- package/lib/module-manager.d.ts +0 -16
- package/lib/module-manager.js +0 -90
- package/lib/modules/app-module.d.ts +0 -2
- package/lib/modules/app-module.js +0 -15
- package/lib/modules/bundle-module.d.ts +0 -2
- package/lib/modules/bundle-module.js +0 -15
- package/lib/modules/index.d.ts +0 -6
- package/lib/modules/index.js +0 -42
- package/lib/modules/package-module.d.ts +0 -2
- package/lib/modules/package-module.js +0 -15
- package/lib/modules/user-module.d.ts +0 -2
- package/lib/modules/user-module.js +0 -15
- package/lib/modules/version-module.d.ts +0 -2
- package/lib/modules/version-module.js +0 -15
- package/lib/utils/latest-version/cli.d.ts +0 -1
- package/lib/utils/latest-version/cli.js +0 -308
- package/src/module-manager.ts +0 -105
- package/src/modules/app-module.ts +0 -7
- package/src/modules/bundle-module.ts +0 -7
- package/src/modules/index.ts +0 -19
- package/src/modules/package-module.ts +0 -7
- package/src/modules/user-module.ts +0 -7
- package/src/modules/version-module.ts +0 -7
- package/src/utils/latest-version/cli.ts +0 -445
package/src/index.ts
CHANGED
|
@@ -1,94 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { loadSession } from './api';
|
|
4
|
-
import { appCommands } from './app';
|
|
5
|
-
import { bundleCommands } from './bundle';
|
|
6
|
-
import { diffCommands } from './diff';
|
|
7
|
-
import { installCommands } from './install';
|
|
8
|
-
import { packageCommands } from './package';
|
|
9
|
-
import { userCommands } from './user';
|
|
10
|
-
import { printVersionCommand } from './utils';
|
|
11
|
-
import { t } from './utils/i18n';
|
|
12
|
-
import { versionCommands } from './versions';
|
|
13
|
-
|
|
14
|
-
type CliCommandHandler = (argv: any) => Promise<unknown> | unknown;
|
|
15
|
-
|
|
16
|
-
interface CliArgv {
|
|
17
|
-
command: string;
|
|
18
|
-
args: string[];
|
|
19
|
-
options: Record<string, any>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function printUsage(exitCode = 1) {
|
|
23
|
-
console.log('React Native Update CLI');
|
|
24
|
-
console.log('');
|
|
25
|
-
console.log('Commands:');
|
|
26
|
-
for (const name of Object.keys(commandHandlers)) {
|
|
27
|
-
console.log(` ${name}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
console.log('');
|
|
31
|
-
console.log('Special commands:');
|
|
32
|
-
console.log(' list: List all available commands');
|
|
33
|
-
console.log(' help: Show this help message');
|
|
34
|
-
|
|
35
|
-
console.log('');
|
|
36
|
-
console.log(
|
|
37
|
-
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
|
|
38
|
-
);
|
|
39
|
-
process.exit(exitCode);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const commandHandlers: Record<string, CliCommandHandler> = {
|
|
43
|
-
...userCommands,
|
|
44
|
-
...bundleCommands,
|
|
45
|
-
...diffCommands,
|
|
46
|
-
...appCommands,
|
|
47
|
-
...packageCommands,
|
|
48
|
-
...versionCommands,
|
|
49
|
-
...installCommands,
|
|
50
|
-
help: printUsage,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
async function run() {
|
|
54
|
-
await printVersionCommand();
|
|
55
|
-
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
|
|
56
|
-
process.exit();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const argv: CliArgv = require('cli-arguments').parse(require('../cli.json'));
|
|
60
|
-
global.NO_INTERACTIVE = argv.options['no-interactive'];
|
|
61
|
-
global.USE_ACC_OSS = argv.options.acc;
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
await loadSession();
|
|
65
|
-
|
|
66
|
-
if (argv.command === 'help') {
|
|
67
|
-
printUsage(0);
|
|
68
|
-
} else if (argv.command === 'list') {
|
|
69
|
-
printUsage(0);
|
|
70
|
-
} else if (commandHandlers[argv.command]) {
|
|
71
|
-
const handler = commandHandlers[argv.command];
|
|
72
|
-
await handler(argv);
|
|
73
|
-
} else {
|
|
74
|
-
throw new Error(`Unknown command: ${argv.command}`);
|
|
75
|
-
}
|
|
76
|
-
} catch (err: any) {
|
|
77
|
-
if (err.status === 401) {
|
|
78
|
-
console.log(t('loginFirst'));
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
console.error(err.stack);
|
|
82
|
-
process.exit(-1);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { moduleManager } from './module-manager';
|
|
87
|
-
export { CLIProviderImpl } from './provider';
|
|
88
|
-
export type {
|
|
89
|
-
CLIModule,
|
|
90
|
-
CLIProvider,
|
|
91
|
-
CommandDefinition,
|
|
92
|
-
} from './types';
|
|
93
|
-
|
|
94
|
-
run();
|
|
1
|
+
export * from './exports';
|
package/src/install.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from 'child_process';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import type { CommandContext } from './types';
|
|
4
|
+
import { getInstallCommand } from './utils/runtime';
|
|
4
5
|
|
|
5
6
|
export const installCommands = {
|
|
6
7
|
install: async ({ args }: CommandContext) => {
|
|
@@ -9,8 +10,9 @@ export const installCommands = {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
const cliDir = path.resolve(__dirname, '..');
|
|
13
|
+
const installCommand = getInstallCommand(args, cliDir);
|
|
12
14
|
|
|
13
|
-
spawnSync(
|
|
15
|
+
spawnSync(installCommand.command, installCommand.args, {
|
|
14
16
|
cwd: cliDir,
|
|
15
17
|
stdio: 'inherit',
|
|
16
18
|
shell: true,
|
package/src/locales/en.ts
CHANGED
|
@@ -156,6 +156,7 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
156
156
|
usageUploadIpa: 'Usage: cresc uploadIpa <ipa file>',
|
|
157
157
|
versionBind:
|
|
158
158
|
'Bound hot update {{version}} to native version {{nativeVersion}} (id: {{id}})',
|
|
159
|
+
versionIdRequired: 'Please provide versionId in non-interactive mode.',
|
|
159
160
|
welcomeMessage: 'Welcome to Cresc hot update service, {{name}}.',
|
|
160
161
|
versionNameQuestion: 'Enter OTA update name:',
|
|
161
162
|
versionDescriptionQuestion: 'Enter OTA update description:',
|
package/src/locales/zh.ts
CHANGED
|
@@ -145,6 +145,7 @@ export default {
|
|
|
145
145
|
usageUploadIpa: '使用方法: pushy uploadIpa ipa后缀文件',
|
|
146
146
|
versionBind:
|
|
147
147
|
'已将热更包 {{version}} 绑定到原生版本 {{nativeVersion}} (id: {{id}})',
|
|
148
|
+
versionIdRequired: '非交互模式下请提供 versionId。',
|
|
148
149
|
welcomeMessage: '欢迎使用 pushy 热更新服务,{{name}}。',
|
|
149
150
|
versionNameQuestion: '输入版本名称:',
|
|
150
151
|
versionDescriptionQuestion: '输入版本描述:',
|
package/src/package.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
1
|
+
import * as fs from 'fs-extra';
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import Table from 'tty-table';
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
getAppInfo,
|
|
12
12
|
getIpaInfo,
|
|
13
13
|
question,
|
|
14
|
-
saveToLocal,
|
|
15
14
|
} from './utils';
|
|
16
15
|
import { AabParser } from './utils/app-info-parser/aab';
|
|
17
16
|
import { depVersions } from './utils/dep-versions';
|
|
@@ -19,6 +18,9 @@ import { getCommitInfo } from './utils/git';
|
|
|
19
18
|
import { t } from './utils/i18n';
|
|
20
19
|
|
|
21
20
|
type PackageCommandOptions = Record<string, unknown> & {
|
|
21
|
+
appId?: string;
|
|
22
|
+
appKey?: string;
|
|
23
|
+
platform?: Platform;
|
|
22
24
|
version?: string;
|
|
23
25
|
includeAllSplits?: boolean | string;
|
|
24
26
|
splits?: string;
|
|
@@ -97,13 +99,19 @@ async function uploadNativePackage(
|
|
|
97
99
|
const info = await config.getInfo(filePath);
|
|
98
100
|
const { versionName: extractedVersionName, buildTime } = info;
|
|
99
101
|
const { appId: appIdInPkg, appKey: appKeyInPkg } = info;
|
|
100
|
-
const
|
|
102
|
+
const selectedApp = options.appId
|
|
103
|
+
? {
|
|
104
|
+
appId: String(options.appId),
|
|
105
|
+
appKey: typeof options.appKey === 'string' ? options.appKey : undefined,
|
|
106
|
+
}
|
|
107
|
+
: await getSelectedApp(config.platform);
|
|
108
|
+
const { appId, appKey } = selectedApp;
|
|
101
109
|
|
|
102
110
|
if (appIdInPkg && String(appIdInPkg) !== appId) {
|
|
103
111
|
throw new Error(t(config.appIdMismatchKey, { appIdInPkg, appId }));
|
|
104
112
|
}
|
|
105
113
|
|
|
106
|
-
if (appKeyInPkg && appKeyInPkg !== appKey) {
|
|
114
|
+
if (appKeyInPkg && appKey && appKeyInPkg !== appKey) {
|
|
107
115
|
throw new Error(t(config.appKeyMismatchKey, { appKeyInPkg, appKey }));
|
|
108
116
|
}
|
|
109
117
|
|
|
@@ -129,7 +137,6 @@ async function uploadNativePackage(
|
|
|
129
137
|
deps: depVersions,
|
|
130
138
|
commit: await getCommitInfo(),
|
|
131
139
|
});
|
|
132
|
-
saveToLocal(filePath, `${appId}/package/${id}${config.extension}`);
|
|
133
140
|
console.log(
|
|
134
141
|
t(config.successKey, {
|
|
135
142
|
id,
|
package/src/provider.ts
CHANGED
|
@@ -8,8 +8,8 @@ import type {
|
|
|
8
8
|
Platform,
|
|
9
9
|
PublishOptions,
|
|
10
10
|
Session,
|
|
11
|
+
UpdateVersionOptions,
|
|
11
12
|
UploadOptions,
|
|
12
|
-
Version,
|
|
13
13
|
} from './types';
|
|
14
14
|
import { runAsCommandResult } from './utils/command-result';
|
|
15
15
|
|
|
@@ -84,6 +84,7 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
84
84
|
bundleName: options.bundleName || 'index.bundlejs',
|
|
85
85
|
entryFile: options.entryFile || 'index.js',
|
|
86
86
|
output: options.output || DEFAULT_BUNDLE_OUTPUT,
|
|
87
|
+
'no-interactive': true,
|
|
87
88
|
sourcemap: options.sourcemap || false,
|
|
88
89
|
taro: options.taro || false,
|
|
89
90
|
expo: options.expo || false,
|
|
@@ -103,18 +104,26 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
103
104
|
async publish(options: PublishOptions): Promise<CommandResult> {
|
|
104
105
|
return this.runMessageCommand(
|
|
105
106
|
async () => {
|
|
106
|
-
const context = this.createContext(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
const context = this.createContext(
|
|
108
|
+
{
|
|
109
|
+
name: options.name,
|
|
110
|
+
description: options.description,
|
|
111
|
+
metaInfo: options.metaInfo,
|
|
112
|
+
packageId: options.packageId,
|
|
113
|
+
packageVersion: options.packageVersion,
|
|
114
|
+
minPackageVersion: options.minPackageVersion,
|
|
115
|
+
maxPackageVersion: options.maxPackageVersion,
|
|
116
|
+
packageVersionRange: options.packageVersionRange,
|
|
117
|
+
platform: options.platform,
|
|
118
|
+
'no-interactive': true,
|
|
119
|
+
rollout:
|
|
120
|
+
options.rollout === undefined
|
|
121
|
+
? undefined
|
|
122
|
+
: String(options.rollout),
|
|
123
|
+
dryRun: options.dryRun || false,
|
|
124
|
+
},
|
|
125
|
+
options.filePath ? [options.filePath] : [],
|
|
126
|
+
);
|
|
118
127
|
|
|
119
128
|
const { versionCommands } = await import('./versions');
|
|
120
129
|
await versionCommands.publish(context);
|
|
@@ -127,14 +136,16 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
127
136
|
async upload(options: UploadOptions): Promise<CommandResult> {
|
|
128
137
|
return this.runMessageCommand(
|
|
129
138
|
async () => {
|
|
130
|
-
const platform = await this.getPlatform(options.platform);
|
|
131
|
-
const { appId } = await this.getSelectedApp(platform);
|
|
132
|
-
|
|
133
139
|
const filePath = options.filePath;
|
|
134
140
|
const fileType = filePath.split('.').pop()?.toLowerCase();
|
|
135
141
|
|
|
136
142
|
const context = this.createContext(
|
|
137
|
-
{
|
|
143
|
+
{
|
|
144
|
+
platform: options.platform,
|
|
145
|
+
appId: options.appId,
|
|
146
|
+
appKey: options.appKey,
|
|
147
|
+
version: options.version,
|
|
148
|
+
},
|
|
138
149
|
[filePath],
|
|
139
150
|
);
|
|
140
151
|
|
|
@@ -168,22 +179,19 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
async listApps(platform?: Platform): Promise<CommandResult> {
|
|
171
|
-
return this.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
'Unknown error listing apps',
|
|
178
|
-
'Apps listed successfully',
|
|
179
|
-
);
|
|
182
|
+
return this.runDataCommand(async () => {
|
|
183
|
+
const { getAppCommands } = await import('./app');
|
|
184
|
+
return getAppCommands().apps({
|
|
185
|
+
options: { platform: platform ?? '' },
|
|
186
|
+
});
|
|
187
|
+
}, 'Unknown error listing apps');
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
async createApp(name: string, platform: Platform): Promise<CommandResult> {
|
|
183
191
|
return this.runMessageCommand(
|
|
184
192
|
async () => {
|
|
185
|
-
const {
|
|
186
|
-
await
|
|
193
|
+
const { getAppCommands } = await import('./app');
|
|
194
|
+
await getAppCommands().createApp({
|
|
187
195
|
options: {
|
|
188
196
|
name,
|
|
189
197
|
platform,
|
|
@@ -197,26 +205,27 @@ export class CLIProviderImpl implements CLIProvider {
|
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
async listVersions(appId: string): Promise<CommandResult> {
|
|
200
|
-
return this.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const { versionCommands } = await import('./versions');
|
|
205
|
-
await versionCommands.versions(context);
|
|
206
|
-
},
|
|
207
|
-
'Unknown error listing versions',
|
|
208
|
-
'Versions listed successfully',
|
|
209
|
-
);
|
|
208
|
+
return this.runDataCommand(async () => {
|
|
209
|
+
const { fetchVersions } = await import('./versions');
|
|
210
|
+
return fetchVersions(appId);
|
|
211
|
+
}, 'Unknown error listing versions');
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
async updateVersion(
|
|
213
215
|
appId: string,
|
|
214
216
|
versionId: string,
|
|
215
|
-
updates:
|
|
217
|
+
updates: UpdateVersionOptions,
|
|
216
218
|
): Promise<CommandResult> {
|
|
217
219
|
return this.runMessageCommand(
|
|
218
220
|
async () => {
|
|
219
|
-
const context = this.createContext({
|
|
221
|
+
const context = this.createContext({
|
|
222
|
+
appId,
|
|
223
|
+
versionId,
|
|
224
|
+
...updates,
|
|
225
|
+
'no-interactive': true,
|
|
226
|
+
rollout:
|
|
227
|
+
updates.rollout === undefined ? undefined : String(updates.rollout),
|
|
228
|
+
});
|
|
220
229
|
|
|
221
230
|
const { versionCommands } = await import('./versions');
|
|
222
231
|
await versionCommands.update(context);
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare global {
|
|
2
|
-
var NO_INTERACTIVE: boolean;
|
|
3
|
-
var USE_ACC_OSS: boolean;
|
|
2
|
+
var NO_INTERACTIVE: boolean | undefined;
|
|
3
|
+
var USE_ACC_OSS: boolean | undefined;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export interface Session {
|
|
@@ -45,20 +45,6 @@ export interface CommandResult {
|
|
|
45
45
|
error?: string;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export interface CommandDefinition {
|
|
49
|
-
name: string;
|
|
50
|
-
description?: string;
|
|
51
|
-
handler: (context: CommandContext) => Promise<CommandResult>;
|
|
52
|
-
options?: Record<
|
|
53
|
-
string,
|
|
54
|
-
{
|
|
55
|
-
hasValue?: boolean;
|
|
56
|
-
default?: unknown;
|
|
57
|
-
description?: string;
|
|
58
|
-
}
|
|
59
|
-
>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
48
|
export interface BundleOptions {
|
|
63
49
|
dev?: boolean;
|
|
64
50
|
platform?: Platform;
|
|
@@ -73,6 +59,8 @@ export interface BundleOptions {
|
|
|
73
59
|
}
|
|
74
60
|
|
|
75
61
|
export interface PublishOptions {
|
|
62
|
+
filePath?: string;
|
|
63
|
+
platform?: Platform;
|
|
76
64
|
name?: string;
|
|
77
65
|
description?: string;
|
|
78
66
|
metaInfo?: string;
|
|
@@ -81,7 +69,7 @@ export interface PublishOptions {
|
|
|
81
69
|
minPackageVersion?: string;
|
|
82
70
|
maxPackageVersion?: string;
|
|
83
71
|
packageVersionRange?: string;
|
|
84
|
-
rollout?: number;
|
|
72
|
+
rollout?: number | string;
|
|
85
73
|
dryRun?: boolean;
|
|
86
74
|
}
|
|
87
75
|
|
|
@@ -89,9 +77,21 @@ export interface UploadOptions {
|
|
|
89
77
|
platform?: Platform;
|
|
90
78
|
filePath: string;
|
|
91
79
|
appId?: string;
|
|
80
|
+
appKey?: string;
|
|
92
81
|
version?: string;
|
|
93
82
|
}
|
|
94
83
|
|
|
84
|
+
export interface UpdateVersionOptions {
|
|
85
|
+
platform?: Platform;
|
|
86
|
+
packageId?: string;
|
|
87
|
+
packageVersion?: string;
|
|
88
|
+
minPackageVersion?: string;
|
|
89
|
+
maxPackageVersion?: string;
|
|
90
|
+
packageVersionRange?: string;
|
|
91
|
+
rollout?: number | string;
|
|
92
|
+
dryRun?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
95
|
export interface CLIProvider {
|
|
96
96
|
bundle: (options: BundleOptions) => Promise<CommandResult>;
|
|
97
97
|
publish: (options: PublishOptions) => Promise<CommandResult>;
|
|
@@ -107,17 +107,9 @@ export interface CLIProvider {
|
|
|
107
107
|
updateVersion: (
|
|
108
108
|
appId: string,
|
|
109
109
|
versionId: string,
|
|
110
|
-
updates:
|
|
110
|
+
updates: UpdateVersionOptions,
|
|
111
111
|
) => Promise<CommandResult>;
|
|
112
112
|
|
|
113
113
|
getPlatform: (platform?: Platform) => Promise<Platform>;
|
|
114
114
|
loadSession: () => Promise<Session>;
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
export interface CLIModule {
|
|
118
|
-
name: string;
|
|
119
|
-
version: string;
|
|
120
|
-
commands?: CommandDefinition[];
|
|
121
|
-
init?: (provider: CLIProvider) => void;
|
|
122
|
-
cleanup?: () => void;
|
|
123
|
-
}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { decodeNullUnicode } from './utils';
|
|
3
|
-
|
|
4
|
-
const Unzip = require('isomorphic-unzip');
|
|
5
|
-
|
|
6
2
|
import { enumZipEntries, readEntry } from '../zip-entries';
|
|
3
|
+
import { decodeNullUnicode } from './utils';
|
|
7
4
|
|
|
8
5
|
export class Zip {
|
|
9
6
|
file: string | File;
|
|
10
|
-
unzip: any;
|
|
11
7
|
|
|
12
8
|
constructor(file: string | File) {
|
|
13
9
|
this.file = typeof file === 'string' ? path.resolve(file) : file;
|
|
14
|
-
this.unzip = new Unzip(this.file);
|
|
15
10
|
}
|
|
16
11
|
|
|
17
12
|
/**
|
|
@@ -24,15 +19,7 @@ export class Zip {
|
|
|
24
19
|
type: 'buffer' | 'blob' = 'buffer',
|
|
25
20
|
) {
|
|
26
21
|
const decoded = regexps.map((regex) => decodeNullUnicode(regex));
|
|
27
|
-
return
|
|
28
|
-
this.unzip.getBuffer(
|
|
29
|
-
decoded,
|
|
30
|
-
{ type },
|
|
31
|
-
(err: Error | null, buffers: Record<string, Buffer | Blob>) => {
|
|
32
|
-
err ? reject(err) : resolve(buffers);
|
|
33
|
-
},
|
|
34
|
-
);
|
|
35
|
-
});
|
|
22
|
+
return this.readEntries(decoded, type);
|
|
36
23
|
}
|
|
37
24
|
|
|
38
25
|
/**
|
|
@@ -42,15 +29,9 @@ export class Zip {
|
|
|
42
29
|
*/
|
|
43
30
|
getEntry(regex: RegExp | string, type: 'buffer' | 'blob' = 'buffer') {
|
|
44
31
|
const decoded = decodeNullUnicode(regex);
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
{ type },
|
|
49
|
-
(err: Error | null, buffers: Record<string, Buffer | Blob>) => {
|
|
50
|
-
err ? reject(err) : resolve(buffers[decoded as any]);
|
|
51
|
-
},
|
|
52
|
-
);
|
|
53
|
-
});
|
|
32
|
+
return this.readEntries([decoded], type).then(
|
|
33
|
+
(buffers) => buffers[decoded as any],
|
|
34
|
+
);
|
|
54
35
|
}
|
|
55
36
|
|
|
56
37
|
async getEntryFromHarmonyApp(
|
|
@@ -71,4 +52,40 @@ export class Zip {
|
|
|
71
52
|
console.error('Error in getEntryFromHarmonyApp:', error);
|
|
72
53
|
}
|
|
73
54
|
}
|
|
55
|
+
|
|
56
|
+
private async readEntries(
|
|
57
|
+
decoded: Array<RegExp | string>,
|
|
58
|
+
type: 'buffer' | 'blob',
|
|
59
|
+
): Promise<Record<string, Buffer | Blob>> {
|
|
60
|
+
if (typeof this.file !== 'string') {
|
|
61
|
+
throw new Error('Param error: [file] must be file path in Node.');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const buffers: Record<string, Buffer | Blob> = {};
|
|
65
|
+
await enumZipEntries(this.file, async (entry, zipFile) => {
|
|
66
|
+
if (entry.fileName.endsWith('/')) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const entryName = decodeNullUnicode(entry.fileName).toString();
|
|
71
|
+
const lowerEntryName = entryName.toLowerCase();
|
|
72
|
+
const matched = decoded.find((pattern) => {
|
|
73
|
+
if (typeof pattern === 'string') {
|
|
74
|
+
return pattern === entryName || pattern === lowerEntryName;
|
|
75
|
+
}
|
|
76
|
+
pattern.lastIndex = 0;
|
|
77
|
+
return pattern.test(lowerEntryName);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (!matched) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const buffer = await readEntry(entry, zipFile);
|
|
85
|
+
buffers[matched as any] =
|
|
86
|
+
type === 'blob' ? new Blob([buffer as any]) : buffer;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return buffers;
|
|
90
|
+
}
|
|
74
91
|
}
|
package/src/utils/http-helper.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fetch from 'node-fetch';
|
|
2
1
|
import { defaultEndpoints } from './constants';
|
|
2
|
+
import { runtimeFetch } from './runtime';
|
|
3
3
|
|
|
4
4
|
// const baseUrl = `http://localhost:9000`;
|
|
5
5
|
// let baseUrl = SERVER.main[0];
|
|
@@ -25,7 +25,7 @@ export function promiseAny<T>(promises: Promise<T>[]) {
|
|
|
25
25
|
export const ping = async (url: string) => {
|
|
26
26
|
let pingFinished = false;
|
|
27
27
|
return Promise.race([
|
|
28
|
-
|
|
28
|
+
runtimeFetch(url, {
|
|
29
29
|
method: 'HEAD',
|
|
30
30
|
})
|
|
31
31
|
.then(({ status }) => {
|
package/src/utils/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { satisfies } from 'compare-versions';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import os from 'os';
|
|
5
3
|
import path from 'path';
|
|
6
4
|
import type { Root as ProtobufRoot } from 'protobufjs';
|
|
7
5
|
import { read } from 'read';
|
|
@@ -10,7 +8,7 @@ import pkg from '../../package.json';
|
|
|
10
8
|
import latestVersion from '../utils/latest-version';
|
|
11
9
|
import AppInfoParser from './app-info-parser';
|
|
12
10
|
import { checkPlugins } from './check-plugin';
|
|
13
|
-
import { IS_CRESC
|
|
11
|
+
import { IS_CRESC } from './constants';
|
|
14
12
|
import { depVersions } from './dep-versions';
|
|
15
13
|
import { t } from './i18n';
|
|
16
14
|
|
|
@@ -85,8 +83,15 @@ type AabResourceTableObject = {
|
|
|
85
83
|
package: AabResourcePackage[];
|
|
86
84
|
};
|
|
87
85
|
|
|
86
|
+
export function isNonInteractive() {
|
|
87
|
+
const envValue = process.env.NO_INTERACTIVE?.toLowerCase();
|
|
88
|
+
return (
|
|
89
|
+
global.NO_INTERACTIVE === true || envValue === 'true' || envValue === '1'
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
export async function question(query: string, password?: boolean) {
|
|
89
|
-
if (
|
|
94
|
+
if (isNonInteractive()) {
|
|
90
95
|
return '';
|
|
91
96
|
}
|
|
92
97
|
return read({
|
|
@@ -401,15 +406,6 @@ async function resolveResource(
|
|
|
401
406
|
return null;
|
|
402
407
|
}
|
|
403
408
|
|
|
404
|
-
const localDir = path.resolve(os.homedir(), tempDir);
|
|
405
|
-
fs.ensureDirSync(localDir);
|
|
406
|
-
export function saveToLocal(_originPath: string, _destName: string) {
|
|
407
|
-
// TODO
|
|
408
|
-
// const destPath = path.join(localDir, destName);
|
|
409
|
-
// fs.ensureDirSync(path.dirname(destPath));
|
|
410
|
-
// fs.copyFileSync(originPath, destPath);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
409
|
async function getLatestVersion(pkgNames: string[]) {
|
|
414
410
|
return latestVersion(pkgNames, {
|
|
415
411
|
// useCache: true,
|