react-native-update-cli 2.9.7 → 2.10.1
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 +6 -9
- package/README.zh-CN.md +6 -9
- package/cli.json +0 -27
- package/lib/app.d.ts +7 -6
- package/lib/app.js +23 -22
- package/lib/diff.d.ts +0 -4
- package/lib/diff.js +10 -55
- package/lib/locales/en.d.ts +0 -1
- package/lib/locales/en.js +0 -1
- package/lib/locales/zh.d.ts +0 -1
- package/lib/locales/zh.js +0 -1
- package/lib/utils/check-plugin.js +22 -10
- package/package.json +4 -4
- package/src/app.ts +39 -40
- package/src/diff.ts +7 -58
- package/src/locales/en.ts +0 -2
- package/src/locales/zh.ts +0 -2
- package/src/utils/check-plugin.ts +18 -11
package/README.md
CHANGED
|
@@ -197,12 +197,9 @@ Each workflow step contains:
|
|
|
197
197
|
### Bundle Module (`bundle`)
|
|
198
198
|
|
|
199
199
|
- `bundle`: Bundle JavaScript code and optionally publish
|
|
200
|
-
- `diff`: Generate differences between two PPK files
|
|
201
200
|
- `hdiff`: Generate hdiff between two PPK files
|
|
202
|
-
- `diffFromApk`: Generate differences from APK files
|
|
203
201
|
- `hdiffFromApk`: Generate hdiff from APK files
|
|
204
202
|
- `hdiffFromApp`: Generate hdiff from APP files
|
|
205
|
-
- `diffFromIpa`: Generate differences from IPA files
|
|
206
203
|
- `hdiffFromIpa`: Generate hdiff from IPA files
|
|
207
204
|
|
|
208
205
|
### Version Module (`version`)
|
|
@@ -300,23 +297,23 @@ const bundleResult = await moduleManager.executeCommand('custom-bundle', {
|
|
|
300
297
|
},
|
|
301
298
|
});
|
|
302
299
|
|
|
303
|
-
// Generate
|
|
304
|
-
const diffResult = await moduleManager.executeCommand('
|
|
300
|
+
// Generate hdiff file
|
|
301
|
+
const diffResult = await moduleManager.executeCommand('hdiff', {
|
|
305
302
|
args: [],
|
|
306
303
|
options: {
|
|
307
304
|
origin: './build/v1.0.0.ppk',
|
|
308
305
|
next: './build/v1.1.0.ppk',
|
|
309
|
-
output: './build/
|
|
306
|
+
output: './build/hdiff.patch',
|
|
310
307
|
},
|
|
311
308
|
});
|
|
312
309
|
|
|
313
|
-
// Generate
|
|
314
|
-
const apkDiffResult = await moduleManager.executeCommand('
|
|
310
|
+
// Generate hdiff from APK files
|
|
311
|
+
const apkDiffResult = await moduleManager.executeCommand('hdiffFromApk', {
|
|
315
312
|
args: [],
|
|
316
313
|
options: {
|
|
317
314
|
origin: './build/app-v1.0.0.apk',
|
|
318
315
|
next: './build/app-v1.1.0.apk',
|
|
319
|
-
output: './build/apk-
|
|
316
|
+
output: './build/apk-hdiff.patch',
|
|
320
317
|
},
|
|
321
318
|
});
|
|
322
319
|
```
|
package/README.zh-CN.md
CHANGED
|
@@ -195,12 +195,9 @@ const workflowResult = await moduleManager.executeWorkflow('my-workflow', {
|
|
|
195
195
|
### Bundle 模块 (`bundle`)
|
|
196
196
|
|
|
197
197
|
- `bundle`: 打包 JavaScript 代码并可选发布
|
|
198
|
-
- `diff`: 生成两个 PPK 文件之间的差异
|
|
199
198
|
- `hdiff`: 生成两个 PPK 文件之间的 hdiff
|
|
200
|
-
- `diffFromApk`: 从 APK 文件生成差异
|
|
201
199
|
- `hdiffFromApk`: 从 APK 文件生成 hdiff
|
|
202
200
|
- `hdiffFromApp`: 从 APP 文件生成 hdiff
|
|
203
|
-
- `diffFromIpa`: 从 IPA 文件生成差异
|
|
204
201
|
- `hdiffFromIpa`: 从 IPA 文件生成 hdiff
|
|
205
202
|
|
|
206
203
|
### Version 模块 (`version`)
|
|
@@ -298,23 +295,23 @@ const bundleResult = await moduleManager.executeCommand('custom-bundle', {
|
|
|
298
295
|
},
|
|
299
296
|
});
|
|
300
297
|
|
|
301
|
-
//
|
|
302
|
-
const diffResult = await moduleManager.executeCommand('
|
|
298
|
+
// 生成 hdiff 文件
|
|
299
|
+
const diffResult = await moduleManager.executeCommand('hdiff', {
|
|
303
300
|
args: [],
|
|
304
301
|
options: {
|
|
305
302
|
origin: './build/v1.0.0.ppk',
|
|
306
303
|
next: './build/v1.1.0.ppk',
|
|
307
|
-
output: './build/
|
|
304
|
+
output: './build/hdiff.patch',
|
|
308
305
|
},
|
|
309
306
|
});
|
|
310
307
|
|
|
311
|
-
// 从APK
|
|
312
|
-
const apkDiffResult = await moduleManager.executeCommand('
|
|
308
|
+
// 从 APK 文件生成 hdiff
|
|
309
|
+
const apkDiffResult = await moduleManager.executeCommand('hdiffFromApk', {
|
|
313
310
|
args: [],
|
|
314
311
|
options: {
|
|
315
312
|
origin: './build/app-v1.0.0.apk',
|
|
316
313
|
next: './build/app-v1.1.0.apk',
|
|
317
|
-
output: './build/apk-
|
|
314
|
+
output: './build/apk-hdiff.patch',
|
|
318
315
|
},
|
|
319
316
|
});
|
|
320
317
|
```
|
package/cli.json
CHANGED
|
@@ -294,33 +294,6 @@
|
|
|
294
294
|
"release": {
|
|
295
295
|
"description": "Push builded file to server."
|
|
296
296
|
},
|
|
297
|
-
"diff": {
|
|
298
|
-
"description": "Create diff patch",
|
|
299
|
-
"options": {
|
|
300
|
-
"output": {
|
|
301
|
-
"default": "${tempDir}/output/diff",
|
|
302
|
-
"hasValue": true
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
"diffFromApk": {
|
|
307
|
-
"description": "Create diff patch from a Android package(.apk)",
|
|
308
|
-
"options": {
|
|
309
|
-
"output": {
|
|
310
|
-
"default": "${tempDir}/output/diff-${time}.apk-patch",
|
|
311
|
-
"hasValue": true
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
"diffFromIpa": {
|
|
316
|
-
"description": "Create diff patch from a iOS package(.ipa)",
|
|
317
|
-
"options": {
|
|
318
|
-
"output": {
|
|
319
|
-
"default": "${tempDir}/output/diff-${time}.ipa-patch",
|
|
320
|
-
"hasValue": true
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
297
|
"hdiff": {
|
|
325
298
|
"description": "Create hdiff patch",
|
|
326
299
|
"options": {
|
package/lib/app.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ export declare function getSelectedApp(platform: Platform): Promise<{
|
|
|
13
13
|
}>;
|
|
14
14
|
export declare function listApp(platform?: Platform | ''): Promise<AppSummary[]>;
|
|
15
15
|
export declare function chooseApp(platform: Platform): Promise<AppSummary>;
|
|
16
|
+
declare function selectApp({ args, options, }: {
|
|
17
|
+
args: string[];
|
|
18
|
+
options: {
|
|
19
|
+
platform?: Platform | '';
|
|
20
|
+
};
|
|
21
|
+
}): Promise<void>;
|
|
16
22
|
export declare const appCommands: {
|
|
17
23
|
createApp: ({ options, }: {
|
|
18
24
|
options: {
|
|
@@ -32,11 +38,6 @@ export declare const appCommands: {
|
|
|
32
38
|
platform?: Platform | "";
|
|
33
39
|
};
|
|
34
40
|
}) => Promise<void>;
|
|
35
|
-
selectApp:
|
|
36
|
-
args: string[];
|
|
37
|
-
options: {
|
|
38
|
-
platform?: Platform | "";
|
|
39
|
-
};
|
|
40
|
-
}) => Promise<void>;
|
|
41
|
+
selectApp: typeof selectApp;
|
|
41
42
|
};
|
|
42
43
|
export {};
|
package/lib/app.js
CHANGED
|
@@ -119,8 +119,27 @@ async function chooseApp(platform) {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
+
async function selectApp({ args, options }) {
|
|
123
|
+
const platform = await getPlatform(options.platform);
|
|
124
|
+
const id = args[0] ? Number.parseInt(args[0], 10) : (await chooseApp(platform)).id;
|
|
125
|
+
let updateInfo = {};
|
|
126
|
+
try {
|
|
127
|
+
updateInfo = JSON.parse(await _fs.default.promises.readFile('update.json', 'utf8'));
|
|
128
|
+
} catch (e) {
|
|
129
|
+
if (e.code !== 'ENOENT') {
|
|
130
|
+
console.error((0, _i18n.t)('failedToParseUpdateJson'));
|
|
131
|
+
throw e;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const { appKey } = await (0, _api.get)(`/app/${id}`);
|
|
135
|
+
updateInfo[platform] = {
|
|
136
|
+
appId: id,
|
|
137
|
+
appKey
|
|
138
|
+
};
|
|
139
|
+
await _fs.default.promises.writeFile('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
|
140
|
+
}
|
|
122
141
|
const appCommands = {
|
|
123
|
-
createApp: async
|
|
142
|
+
createApp: async ({ options })=>{
|
|
124
143
|
const name = options.name || await (0, _utils.question)((0, _i18n.t)('appNameQuestion'));
|
|
125
144
|
const { downloadUrl } = options;
|
|
126
145
|
const platform = await getPlatform(options.platform);
|
|
@@ -132,9 +151,9 @@ const appCommands = {
|
|
|
132
151
|
console.log((0, _i18n.t)('createAppSuccess', {
|
|
133
152
|
id
|
|
134
153
|
}));
|
|
135
|
-
await
|
|
154
|
+
await selectApp({
|
|
136
155
|
args: [
|
|
137
|
-
id
|
|
156
|
+
String(id)
|
|
138
157
|
],
|
|
139
158
|
options: {
|
|
140
159
|
platform
|
|
@@ -154,23 +173,5 @@ const appCommands = {
|
|
|
154
173
|
const { platform = '' } = options;
|
|
155
174
|
await listApp(platform);
|
|
156
175
|
},
|
|
157
|
-
selectApp
|
|
158
|
-
const platform = await getPlatform(options.platform);
|
|
159
|
-
const id = args[0] ? Number.parseInt(args[0]) : (await chooseApp(platform)).id;
|
|
160
|
-
let updateInfo = {};
|
|
161
|
-
try {
|
|
162
|
-
updateInfo = JSON.parse(await _fs.default.promises.readFile('update.json', 'utf8'));
|
|
163
|
-
} catch (e) {
|
|
164
|
-
if (e.code !== 'ENOENT') {
|
|
165
|
-
console.error((0, _i18n.t)('failedToParseUpdateJson'));
|
|
166
|
-
throw e;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const { appKey } = await (0, _api.get)(`/app/${id}`);
|
|
170
|
-
updateInfo[platform] = {
|
|
171
|
-
appId: id,
|
|
172
|
-
appKey
|
|
173
|
-
};
|
|
174
|
-
await _fs.default.promises.writeFile('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
|
175
|
-
}
|
|
176
|
+
selectApp
|
|
176
177
|
};
|
package/lib/diff.d.ts
CHANGED
|
@@ -2,12 +2,8 @@ import type { CommandContext } from './types';
|
|
|
2
2
|
import { enumZipEntries, readEntry } from './utils/zip-entries';
|
|
3
3
|
export { enumZipEntries, readEntry };
|
|
4
4
|
export declare const diffCommands: {
|
|
5
|
-
diff: ({ args, options }: CommandContext) => Promise<void>;
|
|
6
5
|
hdiff: ({ args, options }: CommandContext) => Promise<void>;
|
|
7
|
-
diffFromApk: ({ args, options }: CommandContext) => Promise<void>;
|
|
8
6
|
hdiffFromApk: ({ args, options }: CommandContext) => Promise<void>;
|
|
9
|
-
diffFromApp: ({ args, options }: CommandContext) => Promise<void>;
|
|
10
7
|
hdiffFromApp: ({ args, options }: CommandContext) => Promise<void>;
|
|
11
|
-
diffFromIpa: ({ args, options }: CommandContext) => Promise<void>;
|
|
12
8
|
hdiffFromIpa: ({ args, options }: CommandContext) => Promise<void>;
|
|
13
9
|
};
|
package/lib/diff.js
CHANGED
|
@@ -89,7 +89,6 @@ const loadModule = (pkgName)=>{
|
|
|
89
89
|
return undefined;
|
|
90
90
|
};
|
|
91
91
|
const hdiff = loadModule('node-hdiffpatch');
|
|
92
|
-
const bsdiff = loadModule('node-bsdiff');
|
|
93
92
|
function basename(fn) {
|
|
94
93
|
const m = /^(.+\/)[^/]+\/?$/.exec(fn);
|
|
95
94
|
return m == null ? void 0 : m[1];
|
|
@@ -285,35 +284,27 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
|
|
|
285
284
|
zipfile.end();
|
|
286
285
|
await writePromise;
|
|
287
286
|
}
|
|
288
|
-
function resolveDiffImplementation(
|
|
287
|
+
function resolveDiffImplementation(options) {
|
|
288
|
+
var _options_customHdiffModule;
|
|
289
289
|
if (options.customDiff) {
|
|
290
290
|
return options.customDiff;
|
|
291
291
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (!(hdiffModule == null ? void 0 : hdiffModule.diff)) {
|
|
296
|
-
throw new Error((0, _i18n.t)('nodeHdiffpatchRequired', {
|
|
297
|
-
scriptName: _constants.scriptName
|
|
298
|
-
}));
|
|
299
|
-
}
|
|
300
|
-
return hdiffModule.diff;
|
|
301
|
-
}
|
|
302
|
-
if (!(bsdiff == null ? void 0 : bsdiff.diff)) {
|
|
303
|
-
throw new Error((0, _i18n.t)('nodeBsdiffRequired', {
|
|
292
|
+
const hdiffModule = (_options_customHdiffModule = options.customHdiffModule) != null ? _options_customHdiffModule : hdiff;
|
|
293
|
+
if (!(hdiffModule == null ? void 0 : hdiffModule.diff)) {
|
|
294
|
+
throw new Error((0, _i18n.t)('nodeHdiffpatchRequired', {
|
|
304
295
|
scriptName: _constants.scriptName
|
|
305
296
|
}));
|
|
306
297
|
}
|
|
307
|
-
return
|
|
298
|
+
return hdiffModule.diff;
|
|
308
299
|
}
|
|
309
|
-
function diffArgsCheck(args, options, diffFnName
|
|
300
|
+
function diffArgsCheck(args, options, diffFnName) {
|
|
310
301
|
const [origin, next] = args;
|
|
311
302
|
if (!origin || !next) {
|
|
312
303
|
throw new Error((0, _i18n.t)('usageDiff', {
|
|
313
304
|
command: diffFnName
|
|
314
305
|
}));
|
|
315
306
|
}
|
|
316
|
-
const diffFn = resolveDiffImplementation(
|
|
307
|
+
const diffFn = resolveDiffImplementation(options);
|
|
317
308
|
const { output } = (0, _utils.translateOptions)({
|
|
318
309
|
...options,
|
|
319
310
|
tempDir: _constants.tempDir
|
|
@@ -332,8 +323,8 @@ const transformIpaPackagePath = (v)=>{
|
|
|
332
323
|
const match = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
|
333
324
|
return match == null ? void 0 : match[1];
|
|
334
325
|
};
|
|
335
|
-
const createDiffCommand = ({ diffFnName,
|
|
336
|
-
const { origin, next, realOutput, diffFn } = diffArgsCheck(args, options, diffFnName
|
|
326
|
+
const createDiffCommand = ({ diffFnName, target })=>async ({ args, options })=>{
|
|
327
|
+
const { origin, next, realOutput, diffFn } = diffArgsCheck(args, options, diffFnName);
|
|
337
328
|
if (target.kind === 'ppk') {
|
|
338
329
|
await diffFromPPK(origin, next, realOutput, diffFn);
|
|
339
330
|
} else {
|
|
@@ -344,64 +335,28 @@ const createDiffCommand = ({ diffFnName, useHdiff, target })=>async ({ args, opt
|
|
|
344
335
|
}));
|
|
345
336
|
};
|
|
346
337
|
const diffCommands = {
|
|
347
|
-
diff: createDiffCommand({
|
|
348
|
-
diffFnName: 'diff',
|
|
349
|
-
useHdiff: false,
|
|
350
|
-
target: {
|
|
351
|
-
kind: 'ppk'
|
|
352
|
-
}
|
|
353
|
-
}),
|
|
354
338
|
hdiff: createDiffCommand({
|
|
355
339
|
diffFnName: 'hdiff',
|
|
356
|
-
useHdiff: true,
|
|
357
340
|
target: {
|
|
358
341
|
kind: 'ppk'
|
|
359
342
|
}
|
|
360
343
|
}),
|
|
361
|
-
diffFromApk: createDiffCommand({
|
|
362
|
-
diffFnName: 'diffFromApk',
|
|
363
|
-
useHdiff: false,
|
|
364
|
-
target: {
|
|
365
|
-
kind: 'package',
|
|
366
|
-
originBundleName: 'assets/index.android.bundle'
|
|
367
|
-
}
|
|
368
|
-
}),
|
|
369
344
|
hdiffFromApk: createDiffCommand({
|
|
370
345
|
diffFnName: 'hdiffFromApk',
|
|
371
|
-
useHdiff: true,
|
|
372
346
|
target: {
|
|
373
347
|
kind: 'package',
|
|
374
348
|
originBundleName: 'assets/index.android.bundle'
|
|
375
349
|
}
|
|
376
350
|
}),
|
|
377
|
-
diffFromApp: createDiffCommand({
|
|
378
|
-
diffFnName: 'diffFromApp',
|
|
379
|
-
useHdiff: false,
|
|
380
|
-
target: {
|
|
381
|
-
kind: 'package',
|
|
382
|
-
originBundleName: 'resources/rawfile/bundle.harmony.js'
|
|
383
|
-
}
|
|
384
|
-
}),
|
|
385
351
|
hdiffFromApp: createDiffCommand({
|
|
386
352
|
diffFnName: 'hdiffFromApp',
|
|
387
|
-
useHdiff: true,
|
|
388
353
|
target: {
|
|
389
354
|
kind: 'package',
|
|
390
355
|
originBundleName: 'resources/rawfile/bundle.harmony.js'
|
|
391
356
|
}
|
|
392
357
|
}),
|
|
393
|
-
diffFromIpa: createDiffCommand({
|
|
394
|
-
diffFnName: 'diffFromIpa',
|
|
395
|
-
useHdiff: false,
|
|
396
|
-
target: {
|
|
397
|
-
kind: 'package',
|
|
398
|
-
originBundleName: 'main.jsbundle',
|
|
399
|
-
transformPackagePath: transformIpaPackagePath
|
|
400
|
-
}
|
|
401
|
-
}),
|
|
402
358
|
hdiffFromIpa: createDiffCommand({
|
|
403
359
|
diffFnName: 'hdiffFromIpa',
|
|
404
|
-
useHdiff: true,
|
|
405
360
|
target: {
|
|
406
361
|
kind: 'package',
|
|
407
362
|
originBundleName: 'main.jsbundle',
|
package/lib/locales/en.d.ts
CHANGED
package/lib/locales/en.js
CHANGED
|
@@ -146,7 +146,6 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
146
146
|
deleteVersionError: 'Failed to delete version {{versionId}}: {{error}}',
|
|
147
147
|
bundleFileNotFound: 'Bundle file not found! Please use default bundle file name and path.',
|
|
148
148
|
diffPackageGenerated: '{{- output}} generated.',
|
|
149
|
-
nodeBsdiffRequired: 'This function needs "node-bsdiff". Please run "{{scriptName}} install node-bsdiff" to install',
|
|
150
149
|
nodeHdiffpatchRequired: 'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
|
|
151
150
|
apkExtracted: 'APK extracted to {{output}}'
|
|
152
151
|
};
|
package/lib/locales/zh.d.ts
CHANGED
package/lib/locales/zh.js
CHANGED
|
@@ -145,7 +145,6 @@ const _default = {
|
|
|
145
145
|
deleteVersionError: '删除热更包 {{versionId}} 失败: {{error}}',
|
|
146
146
|
bundleFileNotFound: '未找到 bundle 文件!请使用默认的 bundle 文件名和路径。',
|
|
147
147
|
diffPackageGenerated: '{{- output}} 已生成。',
|
|
148
|
-
nodeBsdiffRequired: '此功能需要 "node-bsdiff"。请运行 "{{scriptName}} install node-bsdiff" 来安装',
|
|
149
148
|
nodeHdiffpatchRequired: '此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
|
|
150
149
|
apkExtracted: 'APK 已提取到 {{output}}'
|
|
151
150
|
};
|
|
@@ -15,21 +15,33 @@ async function checkPlugins() {
|
|
|
15
15
|
sentry: false,
|
|
16
16
|
sourcemap: false
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
const results = await Promise.all(_pluginconfig.plugins.map(async (plugin)=>{
|
|
19
19
|
try {
|
|
20
20
|
const isEnabled = await plugin.detect();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
return {
|
|
22
|
+
isEnabled,
|
|
23
|
+
error: null
|
|
24
|
+
};
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
isEnabled: false,
|
|
28
|
+
error
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
results.forEach(({ isEnabled, error }, index)=>{
|
|
33
|
+
const plugin = _pluginconfig.plugins[index];
|
|
34
|
+
if (error) {
|
|
28
35
|
console.warn((0, _i18n.t)('pluginDetectionError', {
|
|
29
36
|
name: plugin.name,
|
|
30
|
-
error
|
|
37
|
+
error
|
|
38
|
+
}));
|
|
39
|
+
} else if (isEnabled && plugin.bundleParams) {
|
|
40
|
+
Object.assign(params, plugin.bundleParams);
|
|
41
|
+
console.log((0, _i18n.t)('pluginDetected', {
|
|
42
|
+
name: plugin.name
|
|
31
43
|
}));
|
|
32
44
|
}
|
|
33
|
-
}
|
|
45
|
+
});
|
|
34
46
|
return params;
|
|
35
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"description": "command line tool for react-native-update (remote updates for react native)",
|
|
5
5
|
"main": "lib/exports.js",
|
|
6
6
|
"types": "lib/exports.d.ts",
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
"yazl": "3.3.1"
|
|
95
95
|
},
|
|
96
96
|
"engines": {
|
|
97
|
-
"node": ">=
|
|
97
|
+
"node": ">= 16.6.0"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
|
-
"@biomejs/biome": "^2.4.
|
|
100
|
+
"@biomejs/biome": "^2.4.12",
|
|
101
101
|
"@swc/cli": "0.8.1",
|
|
102
|
-
"@swc/core": "^1.15.
|
|
102
|
+
"@swc/core": "^1.15.26",
|
|
103
103
|
"@types/bun": "^1.3.12",
|
|
104
104
|
"@types/filesize-parser": "^1.5.3",
|
|
105
105
|
"@types/fs-extra": "^11.0.4",
|
package/src/app.ts
CHANGED
|
@@ -87,19 +87,53 @@ export async function chooseApp(platform: Platform) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
async function selectApp({
|
|
91
|
+
args,
|
|
92
|
+
options,
|
|
93
|
+
}: {
|
|
94
|
+
args: string[];
|
|
95
|
+
options: { platform?: Platform | '' };
|
|
96
|
+
}) {
|
|
97
|
+
const platform = await getPlatform(options.platform);
|
|
98
|
+
const id = args[0]
|
|
99
|
+
? Number.parseInt(args[0], 10)
|
|
100
|
+
: (await chooseApp(platform)).id;
|
|
101
|
+
|
|
102
|
+
let updateInfo: Partial<Record<Platform, { appId: number; appKey: string }>> =
|
|
103
|
+
{};
|
|
104
|
+
try {
|
|
105
|
+
updateInfo = JSON.parse(await fs.promises.readFile('update.json', 'utf8'));
|
|
106
|
+
} catch (e: any) {
|
|
107
|
+
if (e.code !== 'ENOENT') {
|
|
108
|
+
console.error(t('failedToParseUpdateJson'));
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const { appKey } = await get(`/app/${id}`);
|
|
113
|
+
updateInfo[platform] = {
|
|
114
|
+
appId: id,
|
|
115
|
+
appKey,
|
|
116
|
+
};
|
|
117
|
+
await fs.promises.writeFile(
|
|
118
|
+
'update.json',
|
|
119
|
+
JSON.stringify(updateInfo, null, 4),
|
|
120
|
+
'utf8',
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
90
124
|
export const appCommands = {
|
|
91
|
-
createApp: async
|
|
125
|
+
createApp: async ({
|
|
92
126
|
options,
|
|
93
127
|
}: {
|
|
94
128
|
options: { name: string; downloadUrl: string; platform?: Platform | '' };
|
|
95
|
-
}) {
|
|
129
|
+
}) => {
|
|
96
130
|
const name = options.name || (await question(t('appNameQuestion')));
|
|
97
131
|
const { downloadUrl } = options;
|
|
98
132
|
const platform = await getPlatform(options.platform);
|
|
99
133
|
const { id } = await post('/app/create', { name, platform, downloadUrl });
|
|
100
134
|
console.log(t('createAppSuccess', { id }));
|
|
101
|
-
await
|
|
102
|
-
args: [id],
|
|
135
|
+
await selectApp({
|
|
136
|
+
args: [String(id)],
|
|
103
137
|
options: { platform },
|
|
104
138
|
});
|
|
105
139
|
},
|
|
@@ -122,40 +156,5 @@ export const appCommands = {
|
|
|
122
156
|
const { platform = '' } = options;
|
|
123
157
|
await listApp(platform);
|
|
124
158
|
},
|
|
125
|
-
selectApp
|
|
126
|
-
args,
|
|
127
|
-
options,
|
|
128
|
-
}: {
|
|
129
|
-
args: string[];
|
|
130
|
-
options: { platform?: Platform | '' };
|
|
131
|
-
}) => {
|
|
132
|
-
const platform = await getPlatform(options.platform);
|
|
133
|
-
const id = args[0]
|
|
134
|
-
? Number.parseInt(args[0])
|
|
135
|
-
: (await chooseApp(platform)).id;
|
|
136
|
-
|
|
137
|
-
let updateInfo: Partial<
|
|
138
|
-
Record<Platform, { appId: number; appKey: string }>
|
|
139
|
-
> = {};
|
|
140
|
-
try {
|
|
141
|
-
updateInfo = JSON.parse(
|
|
142
|
-
await fs.promises.readFile('update.json', 'utf8'),
|
|
143
|
-
);
|
|
144
|
-
} catch (e: any) {
|
|
145
|
-
if (e.code !== 'ENOENT') {
|
|
146
|
-
console.error(t('failedToParseUpdateJson'));
|
|
147
|
-
throw e;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const { appKey } = await get(`/app/${id}`);
|
|
151
|
-
updateInfo[platform] = {
|
|
152
|
-
appId: id,
|
|
153
|
-
appKey,
|
|
154
|
-
};
|
|
155
|
-
await fs.promises.writeFile(
|
|
156
|
-
'update.json',
|
|
157
|
-
JSON.stringify(updateInfo, null, 4),
|
|
158
|
-
'utf8',
|
|
159
|
-
);
|
|
160
|
-
},
|
|
159
|
+
selectApp,
|
|
161
160
|
};
|
package/src/diff.ts
CHANGED
|
@@ -22,9 +22,6 @@ type Diff = (oldSource?: Buffer, newSource?: Buffer) => Buffer;
|
|
|
22
22
|
type HdiffModule = {
|
|
23
23
|
diff?: Diff;
|
|
24
24
|
};
|
|
25
|
-
type BsdiffModule = {
|
|
26
|
-
diff?: Diff;
|
|
27
|
-
};
|
|
28
25
|
type EntryMap = Record<string, { crc32: number; fileName: string }>;
|
|
29
26
|
type CrcMap = Record<number, string>;
|
|
30
27
|
type CopyMap = Record<string, string>;
|
|
@@ -38,7 +35,6 @@ type DiffTarget =
|
|
|
38
35
|
};
|
|
39
36
|
type DiffCommandConfig = {
|
|
40
37
|
diffFnName: string;
|
|
41
|
-
useHdiff: boolean;
|
|
42
38
|
target: DiffTarget;
|
|
43
39
|
};
|
|
44
40
|
|
|
@@ -56,7 +52,6 @@ const loadModule = <T>(pkgName: string): T | undefined => {
|
|
|
56
52
|
};
|
|
57
53
|
|
|
58
54
|
const hdiff = loadModule<HdiffModule>('node-hdiffpatch');
|
|
59
|
-
const bsdiff = loadModule<BsdiffModule>('node-bsdiff');
|
|
60
55
|
|
|
61
56
|
function basename(fn: string): string | undefined {
|
|
62
57
|
const m = /^(.+\/)[^/]+\/?$/.exec(fn);
|
|
@@ -334,33 +329,22 @@ type DiffCommandOptions = {
|
|
|
334
329
|
[key: string]: any;
|
|
335
330
|
};
|
|
336
331
|
|
|
337
|
-
function resolveDiffImplementation(
|
|
338
|
-
useHdiff: boolean,
|
|
339
|
-
options: DiffCommandOptions,
|
|
340
|
-
): Diff {
|
|
332
|
+
function resolveDiffImplementation(options: DiffCommandOptions): Diff {
|
|
341
333
|
if (options.customDiff) {
|
|
342
334
|
return options.customDiff;
|
|
343
335
|
}
|
|
344
336
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
throw new Error(t('nodeHdiffpatchRequired', { scriptName }));
|
|
349
|
-
}
|
|
350
|
-
return hdiffModule.diff;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (!bsdiff?.diff) {
|
|
354
|
-
throw new Error(t('nodeBsdiffRequired', { scriptName }));
|
|
337
|
+
const hdiffModule = options.customHdiffModule ?? hdiff;
|
|
338
|
+
if (!hdiffModule?.diff) {
|
|
339
|
+
throw new Error(t('nodeHdiffpatchRequired', { scriptName }));
|
|
355
340
|
}
|
|
356
|
-
return
|
|
341
|
+
return hdiffModule.diff;
|
|
357
342
|
}
|
|
358
343
|
|
|
359
344
|
function diffArgsCheck(
|
|
360
345
|
args: string[],
|
|
361
346
|
options: DiffCommandOptions,
|
|
362
347
|
diffFnName: string,
|
|
363
|
-
useHdiff: boolean,
|
|
364
348
|
) {
|
|
365
349
|
const [origin, next] = args;
|
|
366
350
|
|
|
@@ -368,7 +352,7 @@ function diffArgsCheck(
|
|
|
368
352
|
throw new Error(t('usageDiff', { command: diffFnName }));
|
|
369
353
|
}
|
|
370
354
|
|
|
371
|
-
const diffFn = resolveDiffImplementation(
|
|
355
|
+
const diffFn = resolveDiffImplementation(options);
|
|
372
356
|
const { output } = translateOptions({
|
|
373
357
|
...options,
|
|
374
358
|
tempDir,
|
|
@@ -391,13 +375,12 @@ const transformIpaPackagePath: PackagePathTransform = (v) => {
|
|
|
391
375
|
};
|
|
392
376
|
|
|
393
377
|
const createDiffCommand =
|
|
394
|
-
({ diffFnName,
|
|
378
|
+
({ diffFnName, target }: DiffCommandConfig) =>
|
|
395
379
|
async ({ args, options }: CommandContext) => {
|
|
396
380
|
const { origin, next, realOutput, diffFn } = diffArgsCheck(
|
|
397
381
|
args,
|
|
398
382
|
options as DiffCommandOptions,
|
|
399
383
|
diffFnName,
|
|
400
|
-
useHdiff,
|
|
401
384
|
);
|
|
402
385
|
|
|
403
386
|
if (target.kind === 'ppk') {
|
|
@@ -417,60 +400,26 @@ const createDiffCommand =
|
|
|
417
400
|
};
|
|
418
401
|
|
|
419
402
|
export const diffCommands = {
|
|
420
|
-
diff: createDiffCommand({
|
|
421
|
-
diffFnName: 'diff',
|
|
422
|
-
useHdiff: false,
|
|
423
|
-
target: { kind: 'ppk' },
|
|
424
|
-
}),
|
|
425
403
|
hdiff: createDiffCommand({
|
|
426
404
|
diffFnName: 'hdiff',
|
|
427
|
-
useHdiff: true,
|
|
428
405
|
target: { kind: 'ppk' },
|
|
429
406
|
}),
|
|
430
|
-
diffFromApk: createDiffCommand({
|
|
431
|
-
diffFnName: 'diffFromApk',
|
|
432
|
-
useHdiff: false,
|
|
433
|
-
target: {
|
|
434
|
-
kind: 'package',
|
|
435
|
-
originBundleName: 'assets/index.android.bundle',
|
|
436
|
-
},
|
|
437
|
-
}),
|
|
438
407
|
hdiffFromApk: createDiffCommand({
|
|
439
408
|
diffFnName: 'hdiffFromApk',
|
|
440
|
-
useHdiff: true,
|
|
441
409
|
target: {
|
|
442
410
|
kind: 'package',
|
|
443
411
|
originBundleName: 'assets/index.android.bundle',
|
|
444
412
|
},
|
|
445
413
|
}),
|
|
446
|
-
diffFromApp: createDiffCommand({
|
|
447
|
-
diffFnName: 'diffFromApp',
|
|
448
|
-
useHdiff: false,
|
|
449
|
-
target: {
|
|
450
|
-
kind: 'package',
|
|
451
|
-
originBundleName: 'resources/rawfile/bundle.harmony.js',
|
|
452
|
-
},
|
|
453
|
-
}),
|
|
454
414
|
hdiffFromApp: createDiffCommand({
|
|
455
415
|
diffFnName: 'hdiffFromApp',
|
|
456
|
-
useHdiff: true,
|
|
457
416
|
target: {
|
|
458
417
|
kind: 'package',
|
|
459
418
|
originBundleName: 'resources/rawfile/bundle.harmony.js',
|
|
460
419
|
},
|
|
461
420
|
}),
|
|
462
|
-
diffFromIpa: createDiffCommand({
|
|
463
|
-
diffFnName: 'diffFromIpa',
|
|
464
|
-
useHdiff: false,
|
|
465
|
-
target: {
|
|
466
|
-
kind: 'package',
|
|
467
|
-
originBundleName: 'main.jsbundle',
|
|
468
|
-
transformPackagePath: transformIpaPackagePath,
|
|
469
|
-
},
|
|
470
|
-
}),
|
|
471
421
|
hdiffFromIpa: createDiffCommand({
|
|
472
422
|
diffFnName: 'hdiffFromIpa',
|
|
473
|
-
useHdiff: true,
|
|
474
423
|
target: {
|
|
475
424
|
kind: 'package',
|
|
476
425
|
originBundleName: 'main.jsbundle',
|
package/src/locales/en.ts
CHANGED
|
@@ -174,8 +174,6 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
174
174
|
bundleFileNotFound:
|
|
175
175
|
'Bundle file not found! Please use default bundle file name and path.',
|
|
176
176
|
diffPackageGenerated: '{{- output}} generated.',
|
|
177
|
-
nodeBsdiffRequired:
|
|
178
|
-
'This function needs "node-bsdiff". Please run "{{scriptName}} install node-bsdiff" to install',
|
|
179
177
|
nodeHdiffpatchRequired:
|
|
180
178
|
'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
|
|
181
179
|
apkExtracted: 'APK extracted to {{output}}',
|
package/src/locales/zh.ts
CHANGED
|
@@ -161,8 +161,6 @@ export default {
|
|
|
161
161
|
deleteVersionError: '删除热更包 {{versionId}} 失败: {{error}}',
|
|
162
162
|
bundleFileNotFound: '未找到 bundle 文件!请使用默认的 bundle 文件名和路径。',
|
|
163
163
|
diffPackageGenerated: '{{- output}} 已生成。',
|
|
164
|
-
nodeBsdiffRequired:
|
|
165
|
-
'此功能需要 "node-bsdiff"。请运行 "{{scriptName}} install node-bsdiff" 来安装',
|
|
166
164
|
nodeHdiffpatchRequired:
|
|
167
165
|
'此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
|
|
168
166
|
apkExtracted: 'APK 已提取到 {{output}}',
|
|
@@ -13,19 +13,26 @@ export async function checkPlugins(): Promise<BundleParams> {
|
|
|
13
13
|
sourcemap: false,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const results = await Promise.all(
|
|
17
|
+
plugins.map(async (plugin) => {
|
|
18
|
+
try {
|
|
19
|
+
const isEnabled = await plugin.detect();
|
|
20
|
+
return { isEnabled, error: null };
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return { isEnabled: false, error };
|
|
22
23
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
results.forEach(({ isEnabled, error }, index) => {
|
|
28
|
+
const plugin = plugins[index];
|
|
29
|
+
if (error) {
|
|
30
|
+
console.warn(t('pluginDetectionError', { name: plugin.name, error }));
|
|
31
|
+
} else if (isEnabled && plugin.bundleParams) {
|
|
32
|
+
Object.assign(params, plugin.bundleParams);
|
|
33
|
+
console.log(t('pluginDetected', { name: plugin.name }));
|
|
27
34
|
}
|
|
28
|
-
}
|
|
35
|
+
});
|
|
29
36
|
|
|
30
37
|
return params;
|
|
31
38
|
}
|