diff --git a/src/bundle.ts b/src/bundle.ts index ae1be2c..9b7677a 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -16,7 +16,7 @@ import os from 'os'; const properties = require('properties'); import { addGitIgnore } from './utils/add-gitignore'; import { checkLockFiles } from './utils/check-lockfile'; -import { scriptName, tempDir } from './utils/constants'; +import { isPPKBundleFileName, scriptName, tempDir } from './utils/constants'; import { depVersions } from './utils/dep-versions'; import { t } from './utils/i18n'; import { versionCommands } from './versions'; @@ -537,10 +537,7 @@ async function diffFromPPK(origin: string, next: string, output: string) { // isFile originMap[entry.crc32] = entry.fileName; - if ( - entry.fileName === 'index.bundlejs' || - entry.fileName === 'bundle.harmony.js' - ) { + if (isPPKBundleFileName(entry.fileName)) { // This is source. return readEntry(entry, zipFile).then((v) => (originSource = v)); } @@ -589,23 +586,13 @@ async function diffFromPPK(origin: string, next: string, output: string) { if (!originEntries[entry.fileName]) { addEntry(entry.fileName); } - } else if (entry.fileName === 'index.bundlejs') { + } else if (isPPKBundleFileName(entry.fileName)) { //console.log('Found bundle'); return readEntry(entry, nextZipfile).then((newSource) => { //console.log('Begin diff'); zipfile.addBuffer( diff(originSource, newSource), - 'index.bundlejs.patch', - ); - //console.log('End diff'); - }); - } else if (entry.fileName === 'bundle.harmony.js') { - //console.log('Found bundle'); - return readEntry(entry, nextZipfile).then((newSource) => { - //console.log('Begin diff'); - zipfile.addBuffer( - diff(originSource, newSource), - 'bundle.harmony.js.patch', + `${entry.fileName}.patch`, ); //console.log('End diff'); }); @@ -719,23 +706,13 @@ async function diffFromPackage( if (/\/$/.test(entry.fileName)) { // Directory zipfile.addEmptyDirectory(entry.fileName); - } else if (entry.fileName === 'index.bundlejs') { + } else if (isPPKBundleFileName(entry.fileName)) { //console.log('Found bundle'); return readEntry(entry, nextZipfile).then((newSource) => { //console.log('Begin diff'); zipfile.addBuffer( diff(originSource, newSource), - 'index.bundlejs.patch', - ); - //console.log('End diff'); - }); - } else if (entry.fileName === 'bundle.harmony.js') { - //console.log('Found bundle'); - return readEntry(entry, nextZipfile).then((newSource) => { - //console.log('Begin diff'); - zipfile.addBuffer( - diff(originSource, newSource), - 'bundle.harmony.js.patch', + `${entry.fileName}.patch`, ); //console.log('End diff'); }); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 05e9dbe..6b61b9f 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -3,6 +3,10 @@ import path from 'path'; export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy'; export const IS_CRESC = scriptName === 'cresc'; +export const ppkBundleFileNames = ['index.bundlejs', 'bundle.harmony.js']; +export const isPPKBundleFileName = (fileName: string) => + ppkBundleFileNames.includes(fileName); + export const credentialFile = IS_CRESC ? '.cresc.token' : '.update'; export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json'; export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';