1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-11-22 16:26:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Fix windows bundle command

This commit is contained in:
sunnylqm
2020-06-22 18:26:18 +08:00
parent 233e661f17
commit 62a37a955b

View File

@@ -9,7 +9,7 @@ import { ZipFile } from 'yazl';
import { open as openZipFile } from 'yauzl'; import { open as openZipFile } from 'yauzl';
import { question, printVersionCommand } from './utils'; import { question, printVersionCommand } from './utils';
import { checkPlatform } from './app'; import { checkPlatform } from './app';
const { spawn, spawnSync, execSync } = require('child_process'); const { spawn, spawnSync } = require('child_process');
const g2js = require('gradle-to-js/lib/parser'); const g2js = require('gradle-to-js/lib/parser');
const os = require('os'); const os = require('os');
@@ -18,7 +18,7 @@ try {
var bsdiff = require('node-bsdiff'); var bsdiff = require('node-bsdiff');
diff = typeof bsdiff != 'function' ? bsdiff.diff : bsdiff; diff = typeof bsdiff != 'function' ? bsdiff.diff : bsdiff;
} catch (e) { } catch (e) {
diff = function() { diff = function () {
console.warn( console.warn(
'This function needs "node-bsdiff". Please run "npm i node-bsdiff" from your project directory first!', 'This function needs "node-bsdiff". Please run "npm i node-bsdiff" from your project directory first!',
); );
@@ -28,16 +28,6 @@ try {
}; };
} }
function exec(command) {
const commandResult = spawnSync(command, {
shell: true,
stdio: 'inherit',
});
if (commandResult.error) {
throw commandResult.error;
}
}
async function runReactNativeBundleCommand( async function runReactNativeBundleCommand(
bundleName, bundleName,
development, development,
@@ -90,15 +80,15 @@ async function runReactNativeBundleCommand(
); );
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
reactNativeBundleProcess.stdout.on('data', data => { reactNativeBundleProcess.stdout.on('data', (data) => {
console.log(data.toString().trim()); console.log(data.toString().trim());
}); });
reactNativeBundleProcess.stderr.on('data', data => { reactNativeBundleProcess.stderr.on('data', (data) => {
console.error(data.toString().trim()); console.error(data.toString().trim());
}); });
reactNativeBundleProcess.on('close', async exitCode => { reactNativeBundleProcess.on('close', async (exitCode) => {
if (exitCode) { if (exitCode) {
reject( reject(
new Error( new Error(
@@ -142,13 +132,20 @@ async function compileHermesByteCode(bundleName, outputFolder) {
? 'node_modules/hermes-engine' // 0.2+ ? 'node_modules/hermes-engine' // 0.2+
: 'node_modules/hermesvm'; // < 0.2 : 'node_modules/hermesvm'; // < 0.2
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`; const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
const hermesCommand = fs.existsSync(`${hermesPath}/hermesc`)
? `${hermesPath}/hermesc` // 0.5+
: `${hermesPath}/hermes`; // < 0.5
execSync( const hermesCommand = fs.existsSync(`${hermesPath}/hermesc`)
`${hermesCommand} -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O`, ? `${hermesPath}/hermesc` // 0.5+
: `${hermesPath}/hermes`; // < 0.5
spawnSync(
path.join.apply(null, hermesCommand.split('/')),
[
'-emit-binary',
'-out',
path.join(outputFolder, bundleName),
path.join(outputFolder, bundleName),
'-O',
],
{ stdio: 'ignore' }, { stdio: 'ignore' },
); );
} }
@@ -183,10 +180,10 @@ async function pack(dir, output) {
addDirectory(dir, ''); addDirectory(dir, '');
zipfile.outputStream.on('error', err => reject(err)); zipfile.outputStream.on('error', (err) => reject(err));
zipfile.outputStream zipfile.outputStream
.pipe(fs.createWriteStream(output)) .pipe(fs.createWriteStream(output))
.on('close', function() { .on('close', function () {
resolve(); resolve();
}); });
zipfile.end(); zipfile.end();
@@ -235,7 +232,7 @@ async function diffFromPPK(origin, next, output) {
if (entry.fileName === 'index.bundlejs') { if (entry.fileName === 'index.bundlejs') {
// This is source. // This is source.
return readEntire(entry, zipFile).then(v => (originSource = v)); return readEntire(entry, zipFile).then((v) => (originSource = v));
} }
} }
}); });
@@ -251,12 +248,12 @@ async function diffFromPPK(origin, next, output) {
var zipfile = new ZipFile(); var zipfile = new ZipFile();
const writePromise = new Promise((resolve, reject) => { const writePromise = new Promise((resolve, reject) => {
zipfile.outputStream.on('error', err => { zipfile.outputStream.on('error', (err) => {
throw err; throw err;
}); });
zipfile.outputStream zipfile.outputStream
.pipe(fs.createWriteStream(output)) .pipe(fs.createWriteStream(output))
.on('close', function() { .on('close', function () {
resolve(); resolve();
}); });
}); });
@@ -287,7 +284,7 @@ async function diffFromPPK(origin, next, output) {
} }
} else if (entry.fileName === 'index.bundlejs') { } else if (entry.fileName === 'index.bundlejs') {
//console.log('Found bundle'); //console.log('Found bundle');
return readEntire(entry, nextZipfile).then(newSource => { return readEntire(entry, nextZipfile).then((newSource) => {
//console.log('Begin diff'); //console.log('Begin diff');
zipfile.addBuffer( zipfile.addBuffer(
diff(originSource, newSource), diff(originSource, newSource),
@@ -317,7 +314,7 @@ async function diffFromPPK(origin, next, output) {
addEntry(basename(entry.fileName)); addEntry(basename(entry.fileName));
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
nextZipfile.openReadStream(entry, function(err, readStream) { nextZipfile.openReadStream(entry, function (err, readStream) {
if (err) { if (err) {
return reject(err); return reject(err);
} }
@@ -354,7 +351,7 @@ async function diffFromPackage(
next, next,
output, output,
originBundleName, originBundleName,
transformPackagePath = v => v, transformPackagePath = (v) => v,
) { ) {
fs.ensureDirSync(path.dirname(output)); fs.ensureDirSync(path.dirname(output));
@@ -377,7 +374,7 @@ async function diffFromPackage(
if (fn === originBundleName) { if (fn === originBundleName) {
// This is source. // This is source.
return readEntire(entry, zipFile).then(v => (originSource = v)); return readEntire(entry, zipFile).then((v) => (originSource = v));
} }
} }
}); });
@@ -393,12 +390,12 @@ async function diffFromPackage(
var zipfile = new ZipFile(); var zipfile = new ZipFile();
const writePromise = new Promise((resolve, reject) => { const writePromise = new Promise((resolve, reject) => {
zipfile.outputStream.on('error', err => { zipfile.outputStream.on('error', (err) => {
throw err; throw err;
}); });
zipfile.outputStream zipfile.outputStream
.pipe(fs.createWriteStream(output)) .pipe(fs.createWriteStream(output))
.on('close', function() { .on('close', function () {
resolve(); resolve();
}); });
}); });
@@ -409,7 +406,7 @@ async function diffFromPackage(
zipfile.addEmptyDirectory(entry.fileName); zipfile.addEmptyDirectory(entry.fileName);
} else if (entry.fileName === 'index.bundlejs') { } else if (entry.fileName === 'index.bundlejs') {
//console.log('Found bundle'); //console.log('Found bundle');
return readEntire(entry, nextZipfile).then(newSource => { return readEntire(entry, nextZipfile).then((newSource) => {
//console.log('Begin diff'); //console.log('Begin diff');
zipfile.addBuffer( zipfile.addBuffer(
diff(originSource, newSource), diff(originSource, newSource),
@@ -430,7 +427,7 @@ async function diffFromPackage(
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
nextZipfile.openReadStream(entry, function(err, readStream) { nextZipfile.openReadStream(entry, function (err, readStream) {
if (err) { if (err) {
return reject(err); return reject(err);
} }
@@ -457,7 +454,7 @@ function enumZipEntries(zipFn, callback) {
} }
zipfile.on('end', resolve); zipfile.on('end', resolve);
zipfile.on('error', reject); zipfile.on('error', reject);
zipfile.on('entry', entry => { zipfile.on('entry', (entry) => {
const result = callback(entry, zipfile); const result = callback(entry, zipfile);
if (result && typeof result.then === 'function') { if (result && typeof result.then === 'function') {
result.then(() => zipfile.readEntry()); result.then(() => zipfile.readEntry());
@@ -471,7 +468,7 @@ function enumZipEntries(zipFn, callback) {
} }
export const commands = { export const commands = {
bundle: async function({ options }) { bundle: async function ({ options }) {
const platform = checkPlatform( const platform = checkPlatform(
options.platform || (await question('Platform(ios/android):')), options.platform || (await question('Platform(ios/android):')),
); );
@@ -568,7 +565,7 @@ export const commands = {
process.exit(1); process.exit(1);
} }
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', v => { await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
const m = /^Payload\/[^/]+\/(.+)$/.exec(v); const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
return m && m[1]; return m && m[1];
}); });