diff --git a/local-cli/cli.json b/local-cli/cli.json index de2e1be..865905f 100644 --- a/local-cli/cli.json +++ b/local-cli/cli.json @@ -70,6 +70,15 @@ "hasValue": true } } + }, + "diffWithIpa": { + "description": "Create diff patch from a iOS package(.ipa)", + "options": { + "output": { + "default": "build/output/diff-${time}.ipa-patch", + "hasValue": true + } + } } }, "globalOptions":{ diff --git a/local-cli/src/bundle.js b/local-cli/src/bundle.js index ea78a21..9ab7673 100644 --- a/local-cli/src/bundle.js +++ b/local-cli/src/bundle.js @@ -207,7 +207,7 @@ async function diffWithPPK(origin, next, output) { await writePromise; } -async function diffWithPackage(origin, next, output, originBundleName) { +async function diffWithPackage(origin, next, output, originBundleName, transformPackagePath = v=>v) { const originEntries = {}; const originMap = {}; @@ -215,11 +215,16 @@ async function diffWithPackage(origin, next, output, originBundleName) { await enumZipEntries(origin, (entry, zipFile) => { if (!/\/$/.test(entry.fileName)) { - // isFile - originEntries[entry.fileName] = entry.crc32; - originMap[entry.crc32] = entry.fileName; + const fn = transformPackagePath(entry.filename); + if (!fn) { + return; + } - if (entry.fileName === originBundleName) { + // isFile + originEntries[fn] = entry.crc32; + originMap[entry.crc32] = fn; + + if (fn === originBundleName) { // This is source. return readEntire(entry, zipFile).then(v=>originSource = v); } @@ -381,6 +386,26 @@ export const commands = { process.exit(1); } - await diffWithPackage(origin, next, realOutput, 'assets/index.android.bundle'); + await diffWithPackage(origin, next, realOutput, 'assets/index.android.bundle', v=>{ + const m = /^res\/(.+)$/.exec(v); + return m && m[1]; + }); + }, + + async diffWithIpa({args, options}) { + const [origin, next] = args; + const {output} = options; + + const realOutput = output.replace(/\$\{time\}/g, '' + Date.now()); + + if (!origin || !next) { + console.error('pushy diffWithIpa '); + process.exit(1); + } + + await diffWithPackage(origin, next, realOutput, 'index.ios.bundle', v=>{ + const m = /^Payload\/[^/]+\/(.+)$/.exec(v); + return m && m[1]; + }); }, };