From 19b2b5918ec138ab55c6d92c48c0ec9842cd7010 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Thu, 25 Aug 2016 14:08:47 +0800 Subject: [PATCH] remove node-bsdiff. prompt to install when needed. --- local-cli/src/bundle.js | 28 +++++++++++++++++++--------- package.json | 1 - 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/local-cli/src/bundle.js b/local-cli/src/bundle.js index 0979963..2d5af37 100644 --- a/local-cli/src/bundle.js +++ b/local-cli/src/bundle.js @@ -12,11 +12,21 @@ import { import * as fs from 'fs'; import {ZipFile} from 'yazl'; import {open as openZipFile} from 'yauzl'; -import {diff} from 'node-bsdiff'; +// import {diff} from 'node-bsdiff'; import { question } from './utils'; import {checkPlatform} from './app'; import crypto from 'crypto'; +var diff; +try { + diff = require('node-bsdiff'); +} catch(e) { + diff = function() { + console.warn('This function needs "node-bsdiff". Please run "npm i node-bsdiff -S" from your project directory first!'); + throw new Error('This function needs module "node-bsdiff". Please install it first.') + } +} + function mkdir(dir){ return new Promise((resolve, reject) => { mkdirRecurisve(dir, err => { @@ -106,7 +116,7 @@ function basename(fn) { return m && m[1]; } -async function diffWithPPK(origin, next, output) { +async function diffFromPPK(origin, next, output) { await mkdir(path.dirname(output)); const originEntries = {}; @@ -223,7 +233,7 @@ async function diffWithPPK(origin, next, output) { await writePromise; } -async function diffWithPackage(origin, next, output, originBundleName, transformPackagePath = v=>v) { +async function diffFromPackage(origin, next, output, originBundleName, transformPackagePath = v=>v) { await mkdir(path.dirname(output)); const originEntries = {}; @@ -419,11 +429,11 @@ export const commands = { const realOutput = output.replace(/\$\{time\}/g, '' + Date.now()); if (!origin || !next) { - console.error('pushy diffWithApk '); + console.error('pushy diff '); process.exit(1); } - await diffWithPPK(origin, next, realOutput, 'index.bundlejs'); + await diffFromPPK(origin, next, realOutput, 'index.bundlejs'); console.log(`${realOutput} generated.`); }, @@ -434,11 +444,11 @@ export const commands = { const realOutput = output.replace(/\$\{time\}/g, '' + Date.now()); if (!origin || !next) { - console.error('pushy diffWithApk '); + console.error('pushy diffFromApk '); process.exit(1); } - await diffWithPackage(origin, next, realOutput, 'assets/index.android.bundle'); + await diffFromPackage(origin, next, realOutput, 'assets/index.android.bundle'); console.log(`${realOutput} generated.`); }, @@ -449,11 +459,11 @@ export const commands = { const realOutput = output.replace(/\$\{time\}/g, '' + Date.now()); if (!origin || !next) { - console.error('pushy diffWithIpa '); + console.error('pushy diffFromIpa '); process.exit(1); } - await diffWithPackage(origin, next, realOutput, 'main.jsbundle', v=>{ + await diffFromPackage(origin, next, realOutput, 'main.jsbundle', v=>{ const m = /^Payload\/[^/]+\/(.+)$/.exec(v); return m && m[1]; }); diff --git a/package.json b/package.json index 2bbc4d5..759c775 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "isomorphic-fetch": "^2.2.1", "mkdir-recursive": "^0.2.1", "node-apk-parser": "^0.2.3", - "node-bsdiff": "^0.1.4", "progress": "^1.1.8", "read": "^1.0.7", "request": "^2.69.0",