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

Revert fs-extra

This commit is contained in:
sunnylqm
2020-05-30 12:58:34 +08:00
parent aa5fd4b4b1
commit 3a9bf67703
4 changed files with 59 additions and 221 deletions

View File

@@ -4,7 +4,7 @@
const path = require('path');
import { getRNVersion, translateOptions } from './utils';
import fs from 'fs';
import * as fs from 'fs-extra';
import { ZipFile } from 'yazl';
import { open as openZipFile } from 'yauzl';
import { question, printVersionCommand } from './utils';
@@ -18,7 +18,7 @@ try {
var bsdiff = require('node-bsdiff');
diff = typeof bsdiff != 'function' ? bsdiff.diff : bsdiff;
} catch (e) {
diff = function () {
diff = function() {
console.warn(
'This function needs "node-bsdiff". Please run "npm i node-bsdiff" from your project directory first!',
);
@@ -37,13 +37,6 @@ function exec(command) {
throw commandResult.error;
}
}
function emptyDir(dir) {
return new Promise((resolve) => {
fs.rmdir(dir, { recursive: true }, () => {
fs.mkdir(dir, resolve);
});
});
}
async function runReactNativeBundleCommand(
bundleName,
@@ -54,7 +47,6 @@ async function runReactNativeBundleCommand(
sourcemapOutput,
config,
) {
await emptyDir(outputFolder);
let reactNativeBundleArgs = [];
let envArgs = process.env.PUSHY_ENV_ARGS;
@@ -66,6 +58,8 @@ async function runReactNativeBundleCommand(
);
}
fs.emptyDirSync(outputFolder);
Array.prototype.push.apply(reactNativeBundleArgs, [
path.join('node_modules', 'react-native', 'local-cli', 'cli.js'),
'bundle',
@@ -96,15 +90,15 @@ async function runReactNativeBundleCommand(
);
return new Promise((resolve, reject) => {
reactNativeBundleProcess.stdout.on('data', (data) => {
reactNativeBundleProcess.stdout.on('data', data => {
console.log(data.toString().trim());
});
reactNativeBundleProcess.stderr.on('data', (data) => {
reactNativeBundleProcess.stderr.on('data', data => {
console.error(data.toString().trim());
});
reactNativeBundleProcess.on('close', async (exitCode) => {
reactNativeBundleProcess.on('close', async exitCode => {
if (exitCode) {
reject(
new Error(
@@ -148,10 +142,10 @@ async function compileHermesByteCode(bundleName, outputFolder) {
? 'node_modules/hermes-engine' // 0.2+
: 'node_modules/hermesvm'; // < 0.2
const hermesPath = `${hermesPackage}/${getHermesOSBin()}`;
const hermesCommand = fs.existsSync(`${hermesPath}/hermesc`)
? `${hermesPath}/hermesc` // 0.5+
: `${hermesPath}/hermes`; // < 0.5
? `${hermesPath}/hermesc` // 0.5+
: `${hermesPath}/hermes`; // < 0.5
execSync(
`${hermesCommand} -emit-binary -out ${outputFolder}/${bundleName} ${outputFolder}/${bundleName} -O`,
@@ -189,10 +183,10 @@ async function pack(dir, output) {
addDirectory(dir, '');
zipfile.outputStream.on('error', (err) => reject(err));
zipfile.outputStream.on('error', err => reject(err));
zipfile.outputStream
.pipe(fs.createWriteStream(output))
.on('close', function () {
.on('close', function() {
resolve();
});
zipfile.end();
@@ -241,7 +235,7 @@ async function diffFromPPK(origin, next, output) {
if (entry.fileName === 'index.bundlejs') {
// This is source.
return readEntire(entry, zipFile).then((v) => (originSource = v));
return readEntire(entry, zipFile).then(v => (originSource = v));
}
}
});
@@ -257,12 +251,12 @@ async function diffFromPPK(origin, next, output) {
var zipfile = new ZipFile();
const writePromise = new Promise((resolve, reject) => {
zipfile.outputStream.on('error', (err) => {
zipfile.outputStream.on('error', err => {
throw err;
});
zipfile.outputStream
.pipe(fs.createWriteStream(output))
.on('close', function () {
.on('close', function() {
resolve();
});
});
@@ -293,7 +287,7 @@ async function diffFromPPK(origin, next, output) {
}
} else if (entry.fileName === 'index.bundlejs') {
//console.log('Found bundle');
return readEntire(entry, nextZipfile).then((newSource) => {
return readEntire(entry, nextZipfile).then(newSource => {
//console.log('Begin diff');
zipfile.addBuffer(
diff(originSource, newSource),
@@ -323,7 +317,7 @@ async function diffFromPPK(origin, next, output) {
addEntry(basename(entry.fileName));
return new Promise((resolve, reject) => {
nextZipfile.openReadStream(entry, function (err, readStream) {
nextZipfile.openReadStream(entry, function(err, readStream) {
if (err) {
return reject(err);
}
@@ -360,7 +354,7 @@ async function diffFromPackage(
next,
output,
originBundleName,
transformPackagePath = (v) => v,
transformPackagePath = v => v,
) {
fs.ensureDirSync(path.dirname(output));
@@ -383,7 +377,7 @@ async function diffFromPackage(
if (fn === originBundleName) {
// This is source.
return readEntire(entry, zipFile).then((v) => (originSource = v));
return readEntire(entry, zipFile).then(v => (originSource = v));
}
}
});
@@ -399,12 +393,12 @@ async function diffFromPackage(
var zipfile = new ZipFile();
const writePromise = new Promise((resolve, reject) => {
zipfile.outputStream.on('error', (err) => {
zipfile.outputStream.on('error', err => {
throw err;
});
zipfile.outputStream
.pipe(fs.createWriteStream(output))
.on('close', function () {
.on('close', function() {
resolve();
});
});
@@ -415,7 +409,7 @@ async function diffFromPackage(
zipfile.addEmptyDirectory(entry.fileName);
} else if (entry.fileName === 'index.bundlejs') {
//console.log('Found bundle');
return readEntire(entry, nextZipfile).then((newSource) => {
return readEntire(entry, nextZipfile).then(newSource => {
//console.log('Begin diff');
zipfile.addBuffer(
diff(originSource, newSource),
@@ -436,7 +430,7 @@ async function diffFromPackage(
}
return new Promise((resolve, reject) => {
nextZipfile.openReadStream(entry, function (err, readStream) {
nextZipfile.openReadStream(entry, function(err, readStream) {
if (err) {
return reject(err);
}
@@ -463,7 +457,7 @@ function enumZipEntries(zipFn, callback) {
}
zipfile.on('end', resolve);
zipfile.on('error', reject);
zipfile.on('entry', (entry) => {
zipfile.on('entry', entry => {
const result = callback(entry, zipfile);
if (result && typeof result.then === 'function') {
result.then(() => zipfile.readEntry());
@@ -477,7 +471,7 @@ function enumZipEntries(zipFn, callback) {
}
export const commands = {
bundle: async function ({ options }) {
bundle: async function({ options }) {
const platform = checkPlatform(
options.platform || (await question('Platform(ios/android):')),
);
@@ -574,7 +568,7 @@ export const commands = {
process.exit(1);
}
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v) => {
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', v => {
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
return m && m[1];
});

View File

@@ -2,7 +2,7 @@
* Created by tdzl2003 on 2/13/16.
*/
import fs from 'fs';
import fs from 'fs-extra';
import os from 'os';
import path from 'path';
const pkg = require('../../package.json');
@@ -114,7 +114,7 @@ export async function getIpaInfo(fn) {
}
const localDir = path.resolve(os.homedir(), '.pushy');
fs.mkdir(localDir, () => {});
fs.ensureDirSync(localDir);
export function saveToLocal(originPath, destName) {
// TODO
// const destPath = path.join(localDir, destName);