react-native-update-cli 1.10.0 → 1.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/cli.json +3 -1
- package/lib/api.js +1 -1
- package/lib/bundle.js +33 -10
- package/package.json +2 -1
- package/src/api.js +1 -1
- package/src/bundle.js +54 -21
package/cli.json
CHANGED
package/lib/api.js
CHANGED
|
@@ -17,7 +17,7 @@ var _utils = require('./utils');
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
19
|
const fetch = require('node-fetch');
|
|
20
|
-
const defaultEndpoint = '
|
|
20
|
+
const defaultEndpoint = 'https://update.reactnative.cn/api';
|
|
21
21
|
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
|
22
22
|
const fs = require('fs');
|
|
23
23
|
|
package/lib/bundle.js
CHANGED
|
@@ -26,6 +26,7 @@ const path = require('path');
|
|
|
26
26
|
const { spawn, spawnSync } = require('child_process');
|
|
27
27
|
const g2js = require('gradle-to-js/lib/parser');
|
|
28
28
|
const os = require('os');
|
|
29
|
+
const properties = require('properties');
|
|
29
30
|
|
|
30
31
|
var bsdiff, hdiff, diff;
|
|
31
32
|
try {
|
|
@@ -55,7 +56,6 @@ async function runReactNativeBundleCommand(bundleName, development, entryFile, o
|
|
|
55
56
|
|
|
56
57
|
fs.emptyDirSync(outputFolder);
|
|
57
58
|
|
|
58
|
-
// TODO sourcemap
|
|
59
59
|
Array.prototype.push.apply(reactNativeBundleArgs, [path.join('node_modules', 'react-native', 'local-cli', 'cli.js'), 'bundle', '--assets-dest', outputFolder, '--bundle-output', path.join(outputFolder, bundleName), '--dev', development, '--entry-file', entryFile, '--platform', platform, '--reset-cache']);
|
|
60
60
|
|
|
61
61
|
if (sourcemapOutput) {
|
|
@@ -82,8 +82,27 @@ async function runReactNativeBundleCommand(bundleName, development, entryFile, o
|
|
|
82
82
|
if (exitCode) {
|
|
83
83
|
reject(new Error(`"react-native bundle" command exited with code ${exitCode}.`));
|
|
84
84
|
} else {
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
let hermesEnabled = false;
|
|
86
|
+
|
|
87
|
+
if (platform === 'android') {
|
|
88
|
+
const gradlePropeties = await new Promise(resolve => {
|
|
89
|
+
properties.parse('./android/gradle.properties', { path: true }, function (error, props) {
|
|
90
|
+
if (error) {
|
|
91
|
+
console.error(error);
|
|
92
|
+
resolve(null);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
resolve(props);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
hermesEnabled = gradlePropeties.hermesEnabled;
|
|
99
|
+
|
|
100
|
+
if (typeof hermesEnabled !== 'boolean') hermesEnabled = gradleConfig.enableHermes;
|
|
101
|
+
} else if (platform === 'ios' && fs.existsSync('ios/Pods/hermes-engine')) {
|
|
102
|
+
hermesEnabled = true;
|
|
103
|
+
}
|
|
104
|
+
if (hermesEnabled) {
|
|
105
|
+
await compileHermesByteCode(bundleName, outputFolder, sourcemapOutput);
|
|
87
106
|
}
|
|
88
107
|
resolve(null);
|
|
89
108
|
}
|
|
@@ -117,7 +136,7 @@ async function checkGradleConfig() {
|
|
|
117
136
|
};
|
|
118
137
|
}
|
|
119
138
|
|
|
120
|
-
async function compileHermesByteCode(bundleName, outputFolder) {
|
|
139
|
+
async function compileHermesByteCode(bundleName, outputFolder, sourcemapOutput) {
|
|
121
140
|
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
|
122
141
|
// >= rn 0.69
|
|
123
142
|
let hermesCommand = `node_modules/react-native/sdks/hermesc/${getHermesOSBin()}/hermesc`;
|
|
@@ -130,9 +149,13 @@ async function compileHermesByteCode(bundleName, outputFolder) {
|
|
|
130
149
|
hermesCommand = fs.existsSync(`${hermesPath}/hermesc`) ? `${hermesPath}/hermesc` // 0.5+
|
|
131
150
|
: `${hermesPath}/hermes`; // < 0.5
|
|
132
151
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
const args = ['-emit-binary', '-out', path.join(outputFolder, bundleName), path.join(outputFolder, bundleName), '-O'];
|
|
153
|
+
if (sourcemapOutput) {
|
|
154
|
+
args.push('-output-source-map');
|
|
155
|
+
}
|
|
156
|
+
spawnSync(path.join.apply(null, hermesCommand.split('/')), args, {
|
|
157
|
+
stdio: 'ignore'
|
|
158
|
+
});
|
|
136
159
|
}
|
|
137
160
|
|
|
138
161
|
async function pack(dir, output) {
|
|
@@ -462,11 +485,11 @@ const commands = exports.commands = {
|
|
|
462
485
|
bundle: async function ({ options }) {
|
|
463
486
|
const platform = (0, _app.checkPlatform)(options.platform || (await (0, _utils.question)('平台(ios/android):')));
|
|
464
487
|
|
|
465
|
-
let { bundleName, entryFile, intermediaDir, output, dev,
|
|
488
|
+
let { bundleName, entryFile, intermediaDir, output, dev, sourcemap } = (0, _utils.translateOptions)(_extends({}, options, {
|
|
466
489
|
platform
|
|
467
490
|
}));
|
|
468
491
|
|
|
469
|
-
|
|
492
|
+
const sourcemapOutput = path.join(intermediaDir, bundleName + '.map');
|
|
470
493
|
|
|
471
494
|
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
|
472
495
|
|
|
@@ -479,7 +502,7 @@ const commands = exports.commands = {
|
|
|
479
502
|
console.log('Bundling with react-native: ', version);
|
|
480
503
|
(0, _utils.printVersionCommand)();
|
|
481
504
|
|
|
482
|
-
await runReactNativeBundleCommand(bundleName, dev, entryFile, intermediaDir, platform);
|
|
505
|
+
await runReactNativeBundleCommand(bundleName, dev, entryFile, intermediaDir, platform, sourcemap ? sourcemapOutput : '');
|
|
483
506
|
|
|
484
507
|
await pack(path.resolve(intermediaDir), realOutput);
|
|
485
508
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"gradle-to-js": "^2.0.1",
|
|
40
40
|
"node-fetch": "^2.6.1",
|
|
41
41
|
"progress": "^2.0.3",
|
|
42
|
+
"properties": "^1.2.1",
|
|
42
43
|
"read": "^1.0.7",
|
|
43
44
|
"request": "^2.88.2",
|
|
44
45
|
"tcp-ping": "^0.1.1",
|
package/src/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const fetch = require('node-fetch');
|
|
2
|
-
const defaultEndpoint = '
|
|
2
|
+
const defaultEndpoint = 'https://update.reactnative.cn/api';
|
|
3
3
|
let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
import request from 'request';
|
package/src/bundle.js
CHANGED
|
@@ -8,6 +8,7 @@ import { checkPlatform } from './app';
|
|
|
8
8
|
const { spawn, spawnSync } = require('child_process');
|
|
9
9
|
const g2js = require('gradle-to-js/lib/parser');
|
|
10
10
|
const os = require('os');
|
|
11
|
+
const properties = require('properties');
|
|
11
12
|
|
|
12
13
|
var bsdiff, hdiff, diff;
|
|
13
14
|
try {
|
|
@@ -48,7 +49,6 @@ async function runReactNativeBundleCommand(
|
|
|
48
49
|
|
|
49
50
|
fs.emptyDirSync(outputFolder);
|
|
50
51
|
|
|
51
|
-
// TODO sourcemap
|
|
52
52
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
|
53
53
|
path.join('node_modules', 'react-native', 'local-cli', 'cli.js'),
|
|
54
54
|
'bundle',
|
|
@@ -95,11 +95,39 @@ async function runReactNativeBundleCommand(
|
|
|
95
95
|
),
|
|
96
96
|
);
|
|
97
97
|
} else {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
let hermesEnabled = false;
|
|
99
|
+
|
|
100
|
+
if (platform === 'android') {
|
|
101
|
+
const gradlePropeties = await new Promise((resolve) => {
|
|
102
|
+
properties.parse(
|
|
103
|
+
'./android/gradle.properties',
|
|
104
|
+
{ path: true },
|
|
105
|
+
function (error, props) {
|
|
106
|
+
if (error) {
|
|
107
|
+
console.error(error);
|
|
108
|
+
resolve(null);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
resolve(props);
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
hermesEnabled = gradlePropeties.hermesEnabled;
|
|
116
|
+
|
|
117
|
+
if (typeof hermesEnabled !== 'boolean')
|
|
118
|
+
hermesEnabled = gradleConfig.enableHermes;
|
|
119
|
+
} else if (
|
|
120
|
+
platform === 'ios' &&
|
|
121
|
+
fs.existsSync('ios/Pods/hermes-engine')
|
|
101
122
|
) {
|
|
102
|
-
|
|
123
|
+
hermesEnabled = true;
|
|
124
|
+
}
|
|
125
|
+
if (hermesEnabled) {
|
|
126
|
+
await compileHermesByteCode(
|
|
127
|
+
bundleName,
|
|
128
|
+
outputFolder,
|
|
129
|
+
sourcemapOutput,
|
|
130
|
+
);
|
|
103
131
|
}
|
|
104
132
|
resolve(null);
|
|
105
133
|
}
|
|
@@ -136,7 +164,11 @@ async function checkGradleConfig() {
|
|
|
136
164
|
};
|
|
137
165
|
}
|
|
138
166
|
|
|
139
|
-
async function compileHermesByteCode(
|
|
167
|
+
async function compileHermesByteCode(
|
|
168
|
+
bundleName,
|
|
169
|
+
outputFolder,
|
|
170
|
+
sourcemapOutput,
|
|
171
|
+
) {
|
|
140
172
|
console.log(`Hermes enabled, now compiling to hermes bytecode:\n`);
|
|
141
173
|
// >= rn 0.69
|
|
142
174
|
let hermesCommand = `node_modules/react-native/sdks/hermesc/${getHermesOSBin()}/hermesc`;
|
|
@@ -151,19 +183,19 @@ async function compileHermesByteCode(bundleName, outputFolder) {
|
|
|
151
183
|
? `${hermesPath}/hermesc` // 0.5+
|
|
152
184
|
: `${hermesPath}/hermes`; // < 0.5
|
|
153
185
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
path.join
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
);
|
|
186
|
+
const args = [
|
|
187
|
+
'-emit-binary',
|
|
188
|
+
'-out',
|
|
189
|
+
path.join(outputFolder, bundleName),
|
|
190
|
+
path.join(outputFolder, bundleName),
|
|
191
|
+
'-O',
|
|
192
|
+
];
|
|
193
|
+
if (sourcemapOutput) {
|
|
194
|
+
args.push('-output-source-map');
|
|
195
|
+
}
|
|
196
|
+
spawnSync(path.join.apply(null, hermesCommand.split('/')), args, {
|
|
197
|
+
stdio: 'ignore',
|
|
198
|
+
});
|
|
167
199
|
}
|
|
168
200
|
|
|
169
201
|
async function pack(dir, output) {
|
|
@@ -524,13 +556,13 @@ export const commands = {
|
|
|
524
556
|
options.platform || (await question('平台(ios/android):')),
|
|
525
557
|
);
|
|
526
558
|
|
|
527
|
-
let { bundleName, entryFile, intermediaDir, output, dev,
|
|
559
|
+
let { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
|
|
528
560
|
translateOptions({
|
|
529
561
|
...options,
|
|
530
562
|
platform,
|
|
531
563
|
});
|
|
532
564
|
|
|
533
|
-
|
|
565
|
+
const sourcemapOutput = path.join(intermediaDir, bundleName + '.map');
|
|
534
566
|
|
|
535
567
|
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
|
|
536
568
|
|
|
@@ -549,6 +581,7 @@ export const commands = {
|
|
|
549
581
|
entryFile,
|
|
550
582
|
intermediaDir,
|
|
551
583
|
platform,
|
|
584
|
+
sourcemap ? sourcemapOutput : '',
|
|
552
585
|
);
|
|
553
586
|
|
|
554
587
|
await pack(path.resolve(intermediaDir), realOutput);
|