react-native-update-cli 1.39.2 → 1.40.0-beta.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/cli.json CHANGED
@@ -145,6 +145,15 @@
145
145
  },
146
146
  "sourcemap": {
147
147
  "default": false
148
+ },
149
+ "taro": {
150
+ "default": false
151
+ },
152
+ "expo": {
153
+ "default": false
154
+ },
155
+ "rncli": {
156
+ "default": false
148
157
  }
149
158
  }
150
159
  },
package/lib/bundle.js CHANGED
@@ -85,7 +85,7 @@ try {
85
85
  try {
86
86
  hdiff = require('node-hdiffpatch').diff;
87
87
  } catch (e) {}
88
- async function runReactNativeBundleCommand(bundleName, development, entryFile, outputFolder, platform, sourcemapOutput, config) {
88
+ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, cli }) {
89
89
  let gradleConfig = {};
90
90
  if (platform === 'android') {
91
91
  gradleConfig = await checkGradleConfig();
@@ -101,23 +101,27 @@ async function runReactNativeBundleCommand(bundleName, development, entryFile, o
101
101
  _fsextra.emptyDirSync(outputFolder);
102
102
  let cliPath;
103
103
  let usingExpo = false;
104
- try {
105
- cliPath = require.resolve('@expo/cli', {
106
- paths: [
107
- process.cwd()
108
- ]
109
- });
110
- const expoCliVersion = JSON.parse(_fsextra.readFileSync(require.resolve('@expo/cli/package.json', {
111
- paths: [
112
- process.cwd()
113
- ]
114
- }))).version;
115
- // expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
116
- if ((0, _satisfies.default)(expoCliVersion, '>= 0.10.17')) {
117
- usingExpo = true;
118
- }
119
- } catch (e) {}
120
- if (!usingExpo) {
104
+ const getExpoCli = ()=>{
105
+ try {
106
+ cliPath = require.resolve('@expo/cli', {
107
+ paths: [
108
+ process.cwd()
109
+ ]
110
+ });
111
+ const expoCliVersion = JSON.parse(_fsextra.readFileSync(require.resolve('@expo/cli/package.json', {
112
+ paths: [
113
+ process.cwd()
114
+ ]
115
+ }))).version;
116
+ // expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
117
+ if ((0, _satisfies.default)(expoCliVersion, '>= 0.10.17')) {
118
+ usingExpo = true;
119
+ } else {
120
+ cliPath = undefined;
121
+ }
122
+ } catch (e) {}
123
+ };
124
+ const getRnCli = ()=>{
121
125
  try {
122
126
  // rn >= 0.75
123
127
  cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
@@ -133,16 +137,45 @@ async function runReactNativeBundleCommand(bundleName, development, entryFile, o
133
137
  ]
134
138
  });
135
139
  }
140
+ };
141
+ const getTaroCli = ()=>{
142
+ try {
143
+ cliPath = require.resolve('@tarojs/cli/bin/taro.js', {
144
+ paths: [
145
+ process.cwd()
146
+ ]
147
+ });
148
+ } catch (e) {}
149
+ };
150
+ if (cli.expo) {
151
+ getExpoCli();
152
+ } else if (cli.taro) {
153
+ getTaroCli();
154
+ } else if (cli.rncli) {
155
+ getRnCli();
156
+ }
157
+ if (!cliPath) {
158
+ getExpoCli();
159
+ if (!usingExpo) {
160
+ getRnCli();
161
+ }
136
162
  }
137
163
  const bundleParams = await (0, _utils.checkPlugins)();
138
164
  const isSentry = bundleParams.sentry;
139
- const bundleCommand = usingExpo ? 'export:embed' : platform === 'harmony' ? 'bundle-harmony' : 'bundle';
165
+ let bundleCommand = 'bundle';
166
+ if (usingExpo) {
167
+ bundleCommand = 'export:embed';
168
+ } else if (platform === 'harmony') {
169
+ bundleCommand = 'bundle-harmony';
170
+ } else if (cli.taro) {
171
+ bundleCommand = 'build';
172
+ }
140
173
  if (platform === 'harmony') {
141
174
  Array.prototype.push.apply(reactNativeBundleArgs, [
142
175
  cliPath,
143
176
  bundleCommand,
144
177
  '--dev',
145
- development,
178
+ dev,
146
179
  '--entry-file',
147
180
  entryFile
148
181
  ]);
@@ -160,14 +193,23 @@ async function runReactNativeBundleCommand(bundleName, development, entryFile, o
160
193
  outputFolder,
161
194
  '--bundle-output',
162
195
  _nodepath.default.join(outputFolder, bundleName),
163
- '--dev',
164
- development,
165
- '--entry-file',
166
- entryFile,
167
196
  '--platform',
168
197
  platform,
169
198
  '--reset-cache'
170
199
  ]);
200
+ if (cli.taro) {
201
+ reactNativeBundleArgs.push(...[
202
+ '--type',
203
+ 'rn'
204
+ ]);
205
+ } else {
206
+ reactNativeBundleArgs.push(...[
207
+ '--dev',
208
+ dev,
209
+ '--entry-file',
210
+ entryFile
211
+ ]);
212
+ }
171
213
  if (sourcemapOutput) {
172
214
  reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
173
215
  }
@@ -709,7 +751,7 @@ function diffArgsCheck(args, options, diffFn) {
709
751
  const commands = {
710
752
  bundle: async function({ options }) {
711
753
  const platform = (0, _app.checkPlatform)(options.platform || await (0, _utils.question)('平台(ios/android/harmony):'));
712
- const { bundleName, entryFile, intermediaDir, output, dev, sourcemap } = (0, _utils.translateOptions)({
754
+ const { bundleName, entryFile, intermediaDir, output, dev, sourcemap, taro, expo, rncli } = (0, _utils.translateOptions)({
713
755
  ...options,
714
756
  platform
715
757
  });
@@ -723,7 +765,19 @@ const commands = {
723
765
  }
724
766
  const { version, major, minor } = (0, _utils.getRNVersion)();
725
767
  console.log(`Bundling with react-native: ${version}`);
726
- await runReactNativeBundleCommand(bundleName, dev, entryFile, intermediaDir, platform, sourcemap || sourcemapPlugin ? sourcemapOutput : '');
768
+ await runReactNativeBundleCommand({
769
+ bundleName,
770
+ dev,
771
+ entryFile,
772
+ outputFolder: intermediaDir,
773
+ platform,
774
+ sourcemapOutput: sourcemap || sourcemapPlugin ? sourcemapOutput : '',
775
+ cli: {
776
+ taro,
777
+ expo,
778
+ rncli
779
+ }
780
+ });
727
781
  await pack(_nodepath.default.resolve(intermediaDir), realOutput);
728
782
  const v = await (0, _utils.question)('是否现在上传此热更包?(Y/N)');
729
783
  if (v.toLowerCase() === 'y') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "1.39.2",
3
+ "version": "1.40.0-beta.0",
4
4
  "description": "Command tools for javaScript updater with `pushy` service for react native apps.",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/.DS_Store ADDED
Binary file
package/src/bundle.ts CHANGED
@@ -22,16 +22,29 @@ try {
22
22
  hdiff = require('node-hdiffpatch').diff;
23
23
  } catch (e) {}
24
24
 
25
-
26
- async function runReactNativeBundleCommand(
27
- bundleName: string,
28
- development: string,
29
- entryFile: string,
30
- outputFolder: string,
31
- platform: string,
32
- sourcemapOutput: string,
33
- config: string,
34
- ) {
25
+ async function runReactNativeBundleCommand({
26
+ bundleName,
27
+ dev,
28
+ entryFile,
29
+ outputFolder,
30
+ platform,
31
+ sourcemapOutput,
32
+ config,
33
+ cli,
34
+ }: {
35
+ bundleName: string;
36
+ dev: string;
37
+ entryFile: string;
38
+ outputFolder: string;
39
+ platform: string;
40
+ sourcemapOutput: string;
41
+ config?: string;
42
+ cli: {
43
+ taro?: boolean;
44
+ expo?: boolean;
45
+ rncli?: boolean;
46
+ };
47
+ }) {
35
48
  let gradleConfig: {
36
49
  crunchPngs?: boolean;
37
50
  enableHermes?: boolean;
@@ -58,26 +71,31 @@ async function runReactNativeBundleCommand(
58
71
 
59
72
  fs.emptyDirSync(outputFolder);
60
73
 
61
- let cliPath;
62
-
74
+ let cliPath: string | undefined;
63
75
  let usingExpo = false;
64
- try {
65
- cliPath = require.resolve('@expo/cli', {
66
- paths: [process.cwd()],
67
- });
68
- const expoCliVersion = JSON.parse(
69
- fs.readFileSync(
70
- require.resolve('@expo/cli/package.json', {
71
- paths: [process.cwd()],
72
- }),
73
- ),
74
- ).version;
75
- // expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
76
- if (semverSatisfies(expoCliVersion, '>= 0.10.17')) {
77
- usingExpo = true;
78
- }
79
- } catch (e) {}
80
- if (!usingExpo) {
76
+
77
+ const getExpoCli = () => {
78
+ try {
79
+ cliPath = require.resolve('@expo/cli', {
80
+ paths: [process.cwd()],
81
+ });
82
+ const expoCliVersion = JSON.parse(
83
+ fs.readFileSync(
84
+ require.resolve('@expo/cli/package.json', {
85
+ paths: [process.cwd()],
86
+ }),
87
+ ),
88
+ ).version;
89
+ // expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
90
+ if (semverSatisfies(expoCliVersion, '>= 0.10.17')) {
91
+ usingExpo = true;
92
+ } else {
93
+ cliPath = undefined;
94
+ }
95
+ } catch (e) {}
96
+ };
97
+
98
+ const getRnCli = () => {
81
99
  try {
82
100
  // rn >= 0.75
83
101
  cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
@@ -89,20 +107,49 @@ async function runReactNativeBundleCommand(
89
107
  paths: [process.cwd()],
90
108
  });
91
109
  }
110
+ };
111
+
112
+ const getTaroCli = () => {
113
+ try {
114
+ cliPath = require.resolve('@tarojs/cli/bin/taro.js', {
115
+ paths: [process.cwd()],
116
+ });
117
+ } catch (e) {}
118
+ };
119
+
120
+ if (cli.expo) {
121
+ getExpoCli();
122
+ } else if (cli.taro) {
123
+ getTaroCli();
124
+ } else if (cli.rncli) {
125
+ getRnCli();
126
+ }
127
+
128
+ if (!cliPath) {
129
+ getExpoCli();
130
+ if (!usingExpo) {
131
+ getRnCli();
132
+ }
92
133
  }
134
+
93
135
  const bundleParams = await checkPlugins();
94
136
  const isSentry = bundleParams.sentry;
95
- const bundleCommand = usingExpo
96
- ? 'export:embed'
97
- : platform === 'harmony'
98
- ? 'bundle-harmony'
99
- : 'bundle';
137
+
138
+ let bundleCommand = 'bundle';
139
+ if (usingExpo) {
140
+ bundleCommand = 'export:embed';
141
+ } else if (platform === 'harmony') {
142
+ bundleCommand = 'bundle-harmony';
143
+ } else if (cli.taro) {
144
+ bundleCommand = 'build';
145
+ }
146
+
100
147
  if (platform === 'harmony') {
101
148
  Array.prototype.push.apply(reactNativeBundleArgs, [
102
149
  cliPath,
103
150
  bundleCommand,
104
151
  '--dev',
105
- development,
152
+ dev,
106
153
  '--entry-file',
107
154
  entryFile,
108
155
  ]);
@@ -122,14 +169,24 @@ async function runReactNativeBundleCommand(
122
169
  outputFolder,
123
170
  '--bundle-output',
124
171
  path.join(outputFolder, bundleName),
125
- '--dev',
126
- development,
127
- '--entry-file',
128
- entryFile,
129
172
  '--platform',
130
173
  platform,
131
174
  '--reset-cache',
132
175
  ]);
176
+
177
+ if (cli.taro) {
178
+ reactNativeBundleArgs.push(...[
179
+ '--type',
180
+ 'rn',
181
+ ])
182
+ } else {
183
+ reactNativeBundleArgs.push(...[
184
+ '--dev',
185
+ dev,
186
+ '--entry-file',
187
+ entryFile,
188
+ ])
189
+ }
133
190
 
134
191
  if (sourcemapOutput) {
135
192
  reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
@@ -165,7 +222,9 @@ async function runReactNativeBundleCommand(
165
222
  let hermesEnabled: boolean | undefined = false;
166
223
 
167
224
  if (platform === 'android') {
168
- const gradlePropeties = await new Promise<{ hermesEnabled?: boolean }>((resolve) => {
225
+ const gradlePropeties = await new Promise<{
226
+ hermesEnabled?: boolean;
227
+ }>((resolve) => {
169
228
  properties.parse(
170
229
  './android/gradle.properties',
171
230
  { path: true },
@@ -322,7 +381,11 @@ async function compileHermesByteCode(
322
381
  }
323
382
  }
324
383
 
325
- async function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string) {
384
+ async function copyDebugidForSentry(
385
+ bundleName: string,
386
+ outputFolder: string,
387
+ sourcemapOutput: string,
388
+ ) {
326
389
  if (sourcemapOutput) {
327
390
  let copyDebugidPath;
328
391
  try {
@@ -423,7 +486,10 @@ async function pack(dir: string, output: string) {
423
486
  }
424
487
  const childs = fs.readdirSync(root);
425
488
  for (const name of childs) {
426
- if (ignorePackingFileNames.includes(name) || ignorePackingExtensions.some(ext => name.endsWith(`.${ext}`))) {
489
+ if (
490
+ ignorePackingFileNames.includes(name) ||
491
+ ignorePackingExtensions.some((ext) => name.endsWith(`.${ext}`))
492
+ ) {
427
493
  continue;
428
494
  }
429
495
  const fullPath = path.join(root, name);
@@ -723,55 +789,66 @@ async function diffFromPackage(
723
789
  await writePromise;
724
790
  }
725
791
 
726
- export async function enumZipEntries(zipFn: string, callback: (entry: any, zipFile: any) => void, nestedPath = '') {
792
+ export async function enumZipEntries(
793
+ zipFn: string,
794
+ callback: (entry: any, zipFile: any) => void,
795
+ nestedPath = '',
796
+ ) {
727
797
  return new Promise((resolve, reject) => {
728
- openZipFile(zipFn, { lazyEntries: true }, async (err: any, zipfile: ZipFile) => {
729
- if (err) {
730
- return reject(err);
731
- }
798
+ openZipFile(
799
+ zipFn,
800
+ { lazyEntries: true },
801
+ async (err: any, zipfile: ZipFile) => {
802
+ if (err) {
803
+ return reject(err);
804
+ }
732
805
 
733
- zipfile.on('end', resolve);
734
- zipfile.on('error', reject);
735
- zipfile.on('entry', async (entry) => {
736
- const fullPath = nestedPath + entry.fileName;
737
-
738
- try {
739
- if (
740
- !entry.fileName.endsWith('/') &&
741
- entry.fileName.toLowerCase().endsWith('.hap')
742
- ) {
743
- const tempDir = path.join(os.tmpdir(), `nested_zip_${Date.now()}`);
744
- await fs.ensureDir(tempDir);
745
- const tempZipPath = path.join(tempDir, 'temp.zip');
746
-
747
- await new Promise((res, rej) => {
748
- zipfile.openReadStream(entry, async (err, readStream) => {
749
- if (err) return rej(err);
750
- const writeStream = fs.createWriteStream(tempZipPath);
751
- readStream.pipe(writeStream);
752
- writeStream.on('finish', res);
753
- writeStream.on('error', rej);
806
+ zipfile.on('end', resolve);
807
+ zipfile.on('error', reject);
808
+ zipfile.on('entry', async (entry) => {
809
+ const fullPath = nestedPath + entry.fileName;
810
+
811
+ try {
812
+ if (
813
+ !entry.fileName.endsWith('/') &&
814
+ entry.fileName.toLowerCase().endsWith('.hap')
815
+ ) {
816
+ const tempDir = path.join(
817
+ os.tmpdir(),
818
+ `nested_zip_${Date.now()}`,
819
+ );
820
+ await fs.ensureDir(tempDir);
821
+ const tempZipPath = path.join(tempDir, 'temp.zip');
822
+
823
+ await new Promise((res, rej) => {
824
+ zipfile.openReadStream(entry, async (err, readStream) => {
825
+ if (err) return rej(err);
826
+ const writeStream = fs.createWriteStream(tempZipPath);
827
+ readStream.pipe(writeStream);
828
+ writeStream.on('finish', res);
829
+ writeStream.on('error', rej);
830
+ });
754
831
  });
755
- });
756
832
 
757
- await enumZipEntries(tempZipPath, callback, `${fullPath}/`);
833
+ await enumZipEntries(tempZipPath, callback, `${fullPath}/`);
758
834
 
759
- await fs.remove(tempDir);
760
- }
835
+ await fs.remove(tempDir);
836
+ }
761
837
 
762
- const result = callback(entry, zipfile, fullPath);
763
- if (result && typeof result.then === 'function') {
764
- await result;
838
+ const result = callback(entry, zipfile, fullPath);
839
+ if (result && typeof result.then === 'function') {
840
+ await result;
841
+ }
842
+ } catch (error) {
843
+ console.error('处理文件时出错:', error);
765
844
  }
766
- } catch (error) {
767
- console.error('处理文件时出错:', error);
768
- }
769
845
 
770
- zipfile.readEntry();
771
- });
846
+ zipfile.readEntry();
847
+ });
772
848
 
773
- zipfile.readEntry();
774
- });
849
+ zipfile.readEntry();
850
+ },
851
+ );
775
852
  });
776
853
  }
777
854
 
@@ -817,11 +894,20 @@ export const commands = {
817
894
  options.platform || (await question('平台(ios/android/harmony):')),
818
895
  );
819
896
 
820
- const { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
821
- translateOptions({
822
- ...options,
823
- platform,
824
- });
897
+ const {
898
+ bundleName,
899
+ entryFile,
900
+ intermediaDir,
901
+ output,
902
+ dev,
903
+ sourcemap,
904
+ taro,
905
+ expo,
906
+ rncli,
907
+ } = translateOptions({
908
+ ...options,
909
+ platform,
910
+ });
825
911
 
826
912
  const bundleParams = await checkPlugins();
827
913
  const sourcemapPlugin = bundleParams.sourcemap;
@@ -839,20 +925,25 @@ export const commands = {
839
925
 
840
926
  console.log(`Bundling with react-native: ${version}`);
841
927
 
842
- await runReactNativeBundleCommand(
928
+ await runReactNativeBundleCommand({
843
929
  bundleName,
844
930
  dev,
845
931
  entryFile,
846
- intermediaDir,
932
+ outputFolder: intermediaDir,
847
933
  platform,
848
- sourcemap || sourcemapPlugin ? sourcemapOutput : '',
849
- );
934
+ sourcemapOutput: sourcemap || sourcemapPlugin ? sourcemapOutput : '',
935
+ cli: {
936
+ taro,
937
+ expo,
938
+ rncli,
939
+ },
940
+ });
850
941
 
851
942
  await pack(path.resolve(intermediaDir), realOutput);
852
943
 
853
944
  const v = await question('是否现在上传此热更包?(Y/N)');
854
945
  if (v.toLowerCase() === 'y') {
855
- const versionName = await this.publish({
946
+ const versionName = await this.publish({
856
947
  args: [realOutput],
857
948
  options: {
858
949
  platform,
Binary file