react-native-update-cli 1.46.1 → 2.0.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.
Files changed (64) hide show
  1. package/README.md +578 -1
  2. package/README.zh-CN.md +576 -0
  3. package/cli.json +18 -0
  4. package/lib/api.js +5 -5
  5. package/lib/app.js +1 -1
  6. package/lib/bundle.js +43 -29
  7. package/lib/exports.js +65 -0
  8. package/lib/index.js +100 -9
  9. package/lib/module-manager.js +125 -0
  10. package/lib/modules/app-module.js +223 -0
  11. package/lib/modules/bundle-module.js +188 -0
  12. package/lib/modules/index.js +42 -0
  13. package/lib/modules/package-module.js +16 -0
  14. package/lib/modules/user-module.js +402 -0
  15. package/lib/modules/version-module.js +16 -0
  16. package/lib/package.js +16 -6
  17. package/lib/provider.js +340 -0
  18. package/lib/user.js +3 -3
  19. package/lib/utils/app-info-parser/apk.js +1 -1
  20. package/lib/utils/app-info-parser/ipa.js +2 -2
  21. package/lib/utils/app-info-parser/resource-finder.js +35 -35
  22. package/lib/utils/app-info-parser/xml-parser/manifest.js +2 -2
  23. package/lib/utils/app-info-parser/zip.js +3 -6
  24. package/lib/utils/check-plugin.js +1 -1
  25. package/lib/utils/git.js +1 -1
  26. package/lib/utils/i18n.js +3 -1
  27. package/lib/utils/index.js +4 -4
  28. package/lib/utils/latest-version/cli.js +3 -3
  29. package/lib/utils/latest-version/index.js +4 -4
  30. package/lib/versions.js +2 -2
  31. package/package.json +4 -4
  32. package/src/api.ts +7 -7
  33. package/src/app.ts +2 -2
  34. package/src/bundle.ts +57 -32
  35. package/src/exports.ts +30 -0
  36. package/src/index.ts +118 -16
  37. package/src/module-manager.ts +149 -0
  38. package/src/modules/app-module.ts +205 -0
  39. package/src/modules/bundle-module.ts +202 -0
  40. package/src/modules/index.ts +19 -0
  41. package/src/modules/package-module.ts +11 -0
  42. package/src/modules/user-module.ts +406 -0
  43. package/src/modules/version-module.ts +8 -0
  44. package/src/package.ts +29 -16
  45. package/src/provider.ts +341 -0
  46. package/src/types.ts +125 -0
  47. package/src/user.ts +4 -3
  48. package/src/utils/app-info-parser/apk.js +62 -52
  49. package/src/utils/app-info-parser/app.js +5 -5
  50. package/src/utils/app-info-parser/ipa.js +69 -57
  51. package/src/utils/app-info-parser/resource-finder.js +50 -54
  52. package/src/utils/app-info-parser/utils.js +59 -54
  53. package/src/utils/app-info-parser/xml-parser/binary.js +366 -354
  54. package/src/utils/app-info-parser/xml-parser/manifest.js +145 -137
  55. package/src/utils/app-info-parser/zip.js +1 -1
  56. package/src/utils/check-plugin.ts +4 -2
  57. package/src/utils/dep-versions.ts +13 -6
  58. package/src/utils/git.ts +1 -1
  59. package/src/utils/i18n.ts +3 -1
  60. package/src/utils/index.ts +8 -10
  61. package/src/utils/latest-version/cli.ts +4 -4
  62. package/src/utils/latest-version/index.ts +17 -17
  63. package/src/utils/plugin-config.ts +3 -3
  64. package/src/versions.ts +3 -3
package/lib/bundle.js CHANGED
@@ -19,20 +19,20 @@ _export(exports, {
19
19
  return readEntry;
20
20
  }
21
21
  });
22
+ const _child_process = require("child_process");
22
23
  const _path = /*#__PURE__*/ _interop_require_default(require("path"));
23
- const _utils = require("./utils");
24
+ const _compareversions = require("compare-versions");
24
25
  const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
25
- const _yazl = require("yazl");
26
26
  const _yauzl = require("yauzl");
27
+ const _yazl = require("yazl");
27
28
  const _app = require("./app");
28
- const _child_process = require("child_process");
29
- const _compareversions = require("compare-versions");
29
+ const _utils = require("./utils");
30
30
  const _os = /*#__PURE__*/ _interop_require_default(require("os"));
31
+ const _addgitignore = require("./utils/add-gitignore");
32
+ const _checklockfile = require("./utils/check-lockfile");
33
+ const _constants = require("./utils/constants");
31
34
  const _depversions = require("./utils/dep-versions");
32
35
  const _i18n = require("./utils/i18n");
33
- const _constants = require("./utils/constants");
34
- const _checklockfile = require("./utils/check-lockfile");
35
- const _addgitignore = require("./utils/add-gitignore");
36
36
  const _versions = require("./versions");
37
37
  function _interop_require_default(obj) {
38
38
  return obj && obj.__esModule ? obj : {
@@ -288,7 +288,19 @@ async function copyHarmonyBundle(outputFolder) {
288
288
  await _fsextra.remove(_path.default.join(harmonyRawPath, 'update.json'));
289
289
  await _fsextra.copy('update.json', _path.default.join(harmonyRawPath, 'update.json'));
290
290
  await _fsextra.ensureDir(outputFolder);
291
- await _fsextra.copy(harmonyRawPath, outputFolder);
291
+ const files = await _fsextra.readdir(harmonyRawPath);
292
+ for (const file of files){
293
+ if (file !== 'update.json' && file !== 'meta.json') {
294
+ const sourcePath = _path.default.join(harmonyRawPath, file);
295
+ const destPath = _path.default.join(outputFolder, file);
296
+ const stat = await _fsextra.stat(sourcePath);
297
+ if (stat.isFile()) {
298
+ await _fsextra.copy(sourcePath, destPath);
299
+ } else if (stat.isDirectory()) {
300
+ await _fsextra.copy(sourcePath, destPath);
301
+ }
302
+ }
303
+ }
292
304
  } catch (error) {
293
305
  console.error((0, _i18n.t)('copyHarmonyBundleError', {
294
306
  error
@@ -484,7 +496,7 @@ async function pack(dir, output) {
484
496
  addDirectory(dir, '');
485
497
  zipfile.outputStream.on('error', (err)=>reject(err));
486
498
  zipfile.outputStream.pipe(_fsextra.createWriteStream(output)).on('close', ()=>{
487
- resolve();
499
+ resolve(void 0);
488
500
  });
489
501
  zipfile.end();
490
502
  });
@@ -496,17 +508,14 @@ function readEntry(entry, zipFile) {
496
508
  const buffers = [];
497
509
  return new Promise((resolve, reject)=>{
498
510
  zipFile.openReadStream(entry, (err, stream)=>{
499
- stream.pipe({
500
- write (chunk) {
501
- buffers.push(chunk);
502
- },
503
- end () {
504
- resolve(Buffer.concat(buffers));
505
- },
506
- prependListener () {},
507
- on () {},
508
- once () {},
509
- emit () {}
511
+ stream.on('data', (chunk)=>{
512
+ buffers.push(chunk);
513
+ });
514
+ stream.on('end', ()=>{
515
+ resolve(Buffer.concat(buffers));
516
+ });
517
+ stream.on('error', (err)=>{
518
+ reject(err);
510
519
  });
511
520
  });
512
521
  });
@@ -541,7 +550,7 @@ async function diffFromPPK(origin, next, output) {
541
550
  throw err;
542
551
  });
543
552
  zipfile.outputStream.pipe(_fsextra.createWriteStream(output)).on('close', ()=>{
544
- resolve();
553
+ resolve(void 0);
545
554
  });
546
555
  });
547
556
  const addedEntry = {};
@@ -604,7 +613,7 @@ async function diffFromPPK(origin, next, output) {
604
613
  zipfile.addReadStream(readStream, entry.fileName);
605
614
  readStream.on('end', ()=>{
606
615
  //console.log('add finished');
607
- resolve();
616
+ resolve(void 0);
608
617
  });
609
618
  });
610
619
  });
@@ -658,7 +667,7 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
658
667
  throw err;
659
668
  });
660
669
  zipfile.outputStream.pipe(_fsextra.createWriteStream(output)).on('close', ()=>{
661
- resolve();
670
+ resolve(void 0);
662
671
  });
663
672
  });
664
673
  await enumZipEntries(next, (entry, nextZipfile)=>{
@@ -698,7 +707,7 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
698
707
  zipfile.addReadStream(readStream, entry.fileName);
699
708
  readStream.on('end', ()=>{
700
709
  //console.log('add finished');
701
- resolve();
710
+ resolve(void 0);
702
711
  });
703
712
  });
704
713
  });
@@ -732,7 +741,7 @@ async function enumZipEntries(zipFn, callback, nestedPath = '') {
732
741
  if (err) return rej(err);
733
742
  const writeStream = _fsextra.createWriteStream(tempZipPath);
734
743
  readStream.pipe(writeStream);
735
- writeStream.on('finish', res);
744
+ writeStream.on('finish', ()=>res(void 0));
736
745
  writeStream.on('error', rej);
737
746
  });
738
747
  });
@@ -810,11 +819,11 @@ const bundleCommands = {
810
819
  outputFolder: intermediaDir,
811
820
  platform,
812
821
  sourcemapOutput: sourcemap || sourcemapPlugin ? sourcemapOutput : '',
813
- disableHermes,
822
+ disableHermes: !!disableHermes,
814
823
  cli: {
815
- taro,
816
- expo,
817
- rncli
824
+ taro: !!taro,
825
+ expo: !!expo,
826
+ rncli: !!rncli
818
827
  }
819
828
  });
820
829
  await pack(_path.default.resolve(intermediaDir), realOutput);
@@ -879,6 +888,11 @@ const bundleCommands = {
879
888
  await diffFromPackage(origin, next, realOutput, 'assets/index.android.bundle');
880
889
  console.log(`${realOutput} generated.`);
881
890
  },
891
+ async diffFromApp ({ args, options }) {
892
+ const { origin, next, realOutput } = diffArgsCheck(args, options, 'diffFromApp');
893
+ await diffFromPackage(origin, next, realOutput, 'resources/rawfile/bundle.harmony.js');
894
+ console.log(`${realOutput} generated.`);
895
+ },
882
896
  async hdiffFromApp ({ args, options }) {
883
897
  const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiffFromApp');
884
898
  await diffFromPackage(origin, next, realOutput, 'resources/rawfile/bundle.harmony.js');
package/lib/exports.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ CLIProviderImpl: function() {
13
+ return _provider.CLIProviderImpl;
14
+ },
15
+ appModule: function() {
16
+ return _appmodule.appModule;
17
+ },
18
+ builtinModules: function() {
19
+ return _modules.builtinModules;
20
+ },
21
+ bundleModule: function() {
22
+ return _bundlemodule.bundleModule;
23
+ },
24
+ getPlatform: function() {
25
+ return _app.getPlatform;
26
+ },
27
+ getSelectedApp: function() {
28
+ return _app.getSelectedApp;
29
+ },
30
+ getSession: function() {
31
+ return _api.getSession;
32
+ },
33
+ loadSession: function() {
34
+ return _api.loadSession;
35
+ },
36
+ moduleManager: function() {
37
+ return _modulemanager.moduleManager;
38
+ },
39
+ packageModule: function() {
40
+ return _packagemodule.packageModule;
41
+ },
42
+ question: function() {
43
+ return _utils.question;
44
+ },
45
+ saveToLocal: function() {
46
+ return _utils.saveToLocal;
47
+ },
48
+ userModule: function() {
49
+ return _usermodule.userModule;
50
+ },
51
+ versionModule: function() {
52
+ return _versionmodule.versionModule;
53
+ }
54
+ });
55
+ const _modulemanager = require("./module-manager");
56
+ const _provider = require("./provider");
57
+ const _modules = require("./modules");
58
+ const _bundlemodule = require("./modules/bundle-module");
59
+ const _versionmodule = require("./modules/version-module");
60
+ const _appmodule = require("./modules/app-module");
61
+ const _usermodule = require("./modules/user-module");
62
+ const _packagemodule = require("./modules/package-module");
63
+ const _api = require("./api");
64
+ const _app = require("./app");
65
+ const _utils = require("./utils");
package/lib/index.js CHANGED
@@ -3,21 +3,76 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ CLIProviderImpl: function() {
14
+ return _provider.CLIProviderImpl;
15
+ },
16
+ moduleManager: function() {
17
+ return _modulemanager.moduleManager;
18
+ }
19
+ });
6
20
  const _api = require("./api");
21
+ const _app = require("./app");
22
+ const _bundle = require("./bundle");
23
+ const _modulemanager = require("./module-manager");
24
+ const _modules = require("./modules");
25
+ const _package = require("./package");
26
+ const _user = require("./user");
7
27
  const _utils = require("./utils");
8
28
  const _i18n = require("./utils/i18n");
9
- const _bundle = require("./bundle");
10
29
  const _versions = require("./versions");
11
- const _user = require("./user");
12
- const _app = require("./app");
13
- const _package = require("./package");
30
+ const _provider = require("./provider");
31
+ function registerBuiltinModules() {
32
+ for (const module of _modules.builtinModules){
33
+ try {
34
+ _modulemanager.moduleManager.registerModule(module);
35
+ } catch (error) {
36
+ console.error(`Failed to register module ${module.name}:`, error);
37
+ }
38
+ }
39
+ }
14
40
  function printUsage() {
15
- // const commandName = args[0];
16
- // TODO: print usage of commandName, or print global usage.
41
+ console.log('React Native Update CLI');
42
+ console.log('');
43
+ console.log('Traditional commands:');
44
+ const legacyCommands = {
45
+ ..._user.userCommands,
46
+ ..._bundle.bundleCommands,
47
+ ..._app.appCommands,
48
+ ..._package.packageCommands,
49
+ ..._versions.versionCommands
50
+ };
51
+ for (const [name, handler] of Object.entries(legacyCommands)){
52
+ console.log(` ${name}: Legacy command`);
53
+ }
54
+ console.log('');
55
+ console.log('Modular commands:');
56
+ const commands = _modulemanager.moduleManager.getRegisteredCommands();
57
+ for (const command of commands){
58
+ console.log(` ${command.name}: ${command.description || 'No description'}`);
59
+ }
60
+ console.log('');
61
+ console.log('Available workflows:');
62
+ const workflows = _modulemanager.moduleManager.getRegisteredWorkflows();
63
+ for (const workflow of workflows){
64
+ console.log(` ${workflow.name}: ${workflow.description || 'No description'}`);
65
+ }
66
+ console.log('');
67
+ console.log('Special commands:');
68
+ console.log(' list: List all available commands and workflows');
69
+ console.log(' workflow <name>: Execute a specific workflow');
70
+ console.log(' help: Show this help message');
71
+ console.log('');
17
72
  console.log('Visit `https://github.com/reactnativecn/react-native-update` for document.');
18
73
  process.exit(1);
19
74
  }
20
- const commands = {
75
+ const legacyCommands = {
21
76
  ..._user.userCommands,
22
77
  ..._bundle.bundleCommands,
23
78
  ..._app.appCommands,
@@ -30,16 +85,52 @@ async function run() {
30
85
  if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
31
86
  process.exit();
32
87
  }
88
+ // Register builtin modules for modular functionality
89
+ registerBuiltinModules();
33
90
  const argv = require('cli-arguments').parse(require('../cli.json'));
34
91
  global.NO_INTERACTIVE = argv.options['no-interactive'];
35
92
  global.USE_ACC_OSS = argv.options.acc;
36
- (0, _api.loadSession)().then(()=>commands[argv.command](argv)).catch((err)=>{
93
+ const context = {
94
+ args: argv.args || [],
95
+ options: argv.options || {}
96
+ };
97
+ try {
98
+ await (0, _api.loadSession)();
99
+ context.session = require('./api').getSession();
100
+ // Handle special modular commands first
101
+ if (argv.command === 'help') {
102
+ printUsage();
103
+ } else if (argv.command === 'list') {
104
+ _modulemanager.moduleManager.listAll();
105
+ } else if (argv.command === 'workflow') {
106
+ const workflowName = argv.args[0];
107
+ if (!workflowName) {
108
+ console.error('Workflow name is required');
109
+ process.exit(1);
110
+ }
111
+ const result = await _modulemanager.moduleManager.executeWorkflow(workflowName, context);
112
+ if (!result.success) {
113
+ console.error('Workflow execution failed:', result.error);
114
+ process.exit(1);
115
+ }
116
+ console.log('Workflow completed successfully:', result.data);
117
+ } else if (legacyCommands[argv.command]) {
118
+ await legacyCommands[argv.command](argv);
119
+ } else {
120
+ const result = await _modulemanager.moduleManager.executeCommand(argv.command, context);
121
+ if (!result.success) {
122
+ console.error('Command execution failed:', result.error);
123
+ process.exit(1);
124
+ }
125
+ console.log('Command completed successfully:', result.data);
126
+ }
127
+ } catch (err) {
37
128
  if (err.status === 401) {
38
129
  console.log((0, _i18n.t)('loginFirst'));
39
130
  return;
40
131
  }
41
132
  console.error(err.stack);
42
133
  process.exit(-1);
43
- });
134
+ }
44
135
  }
45
136
  run();
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ ModuleManager: function() {
13
+ return ModuleManager;
14
+ },
15
+ moduleManager: function() {
16
+ return moduleManager;
17
+ }
18
+ });
19
+ const _provider = require("./provider");
20
+ class ModuleManager {
21
+ registerModule(module) {
22
+ if (this.modules.has(module.name)) {
23
+ throw new Error(`Module '${module.name}' is already registered`);
24
+ }
25
+ this.modules.set(module.name, module);
26
+ if (module.commands) {
27
+ for (const command of module.commands){
28
+ this.registerCommand(command);
29
+ }
30
+ }
31
+ if (module.workflows) {
32
+ for (const workflow of module.workflows){
33
+ this.registerWorkflow(workflow);
34
+ }
35
+ }
36
+ if (module.init) {
37
+ module.init(this.provider);
38
+ }
39
+ console.log(`Module '${module.name}' (v${module.version}) registered successfully`);
40
+ }
41
+ unregisterModule(moduleName) {
42
+ const module = this.modules.get(moduleName);
43
+ if (!module) {
44
+ throw new Error(`Module '${moduleName}' is not registered`);
45
+ }
46
+ if (module.commands) {
47
+ for (const command of module.commands){
48
+ this.commands.delete(command.name);
49
+ }
50
+ }
51
+ if (module.workflows) {
52
+ for (const workflow of module.workflows){
53
+ this.workflows.delete(workflow.name);
54
+ }
55
+ }
56
+ if (module.cleanup) {
57
+ module.cleanup();
58
+ }
59
+ this.modules.delete(moduleName);
60
+ console.log(`Module '${moduleName}' unregistered successfully`);
61
+ }
62
+ registerCommand(command) {
63
+ if (this.commands.has(command.name)) {
64
+ throw new Error(`Command '${command.name}' is already registered`);
65
+ }
66
+ this.commands.set(command.name, command);
67
+ }
68
+ registerWorkflow(workflow) {
69
+ if (this.workflows.has(workflow.name)) {
70
+ throw new Error(`Workflow '${workflow.name}' is already registered`);
71
+ }
72
+ this.workflows.set(workflow.name, workflow);
73
+ this.provider.registerWorkflow(workflow);
74
+ }
75
+ getRegisteredCommands() {
76
+ return Array.from(this.commands.values());
77
+ }
78
+ getRegisteredWorkflows() {
79
+ return Array.from(this.workflows.values());
80
+ }
81
+ getRegisteredModules() {
82
+ return Array.from(this.modules.values());
83
+ }
84
+ async executeCommand(commandName, context) {
85
+ const command = this.commands.get(commandName);
86
+ if (!command) {
87
+ throw new Error(`Command '${commandName}' not found`);
88
+ }
89
+ return await command.handler(context);
90
+ }
91
+ async executeWorkflow(workflowName, context) {
92
+ return await this.provider.executeWorkflow(workflowName, context);
93
+ }
94
+ getProvider() {
95
+ return this.provider;
96
+ }
97
+ listCommands() {
98
+ return Array.from(this.commands.values());
99
+ }
100
+ listWorkflows() {
101
+ return Array.from(this.workflows.values());
102
+ }
103
+ listAll() {
104
+ console.log('\n=== Registered Commands ===');
105
+ for (const command of this.commands.values()){
106
+ console.log(` ${command.name}: ${command.description || 'No description'}`);
107
+ }
108
+ console.log('\n=== Registered Workflows ===');
109
+ for (const workflow of this.workflows.values()){
110
+ console.log(` ${workflow.name}: ${workflow.description || 'No description'}`);
111
+ }
112
+ console.log('\n=== Registered Modules ===');
113
+ for (const module of this.modules.values()){
114
+ var _module_commands, _module_workflows;
115
+ console.log(` ${module.name} (v${module.version}): ${((_module_commands = module.commands) == null ? void 0 : _module_commands.length) || 0} commands, ${((_module_workflows = module.workflows) == null ? void 0 : _module_workflows.length) || 0} workflows`);
116
+ }
117
+ }
118
+ constructor(){
119
+ this.modules = new Map();
120
+ this.commands = new Map();
121
+ this.workflows = new Map();
122
+ this.provider = new _provider.CLIProviderImpl();
123
+ }
124
+ }
125
+ const moduleManager = new ModuleManager();