Skip to content

Commit e81744b

Browse files
committed
Refactor bundle file handling by introducing isPPKBundleFileName utility; streamline diff logic for bundle files in bundle.ts.
1 parent 89da1e5 commit e81744b

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

src/bundle.ts

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import os from 'os';
1616
const properties = require('properties');
1717
import { addGitIgnore } from './utils/add-gitignore';
1818
import { checkLockFiles } from './utils/check-lockfile';
19-
import { scriptName, tempDir } from './utils/constants';
19+
import { isPPKBundleFileName, scriptName, tempDir } from './utils/constants';
2020
import { depVersions } from './utils/dep-versions';
2121
import { t } from './utils/i18n';
2222
import { versionCommands } from './versions';
@@ -537,10 +537,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
537537
// isFile
538538
originMap[entry.crc32] = entry.fileName;
539539

540-
if (
541-
entry.fileName === 'index.bundlejs' ||
542-
entry.fileName === 'bundle.harmony.js'
543-
) {
540+
if (isPPKBundleFileName(entry.fileName)) {
544541
// This is source.
545542
return readEntry(entry, zipFile).then((v) => (originSource = v));
546543
}
@@ -589,23 +586,13 @@ async function diffFromPPK(origin: string, next: string, output: string) {
589586
if (!originEntries[entry.fileName]) {
590587
addEntry(entry.fileName);
591588
}
592-
} else if (entry.fileName === 'index.bundlejs') {
589+
} else if (isPPKBundleFileName(entry.fileName)) {
593590
//console.log('Found bundle');
594591
return readEntry(entry, nextZipfile).then((newSource) => {
595592
//console.log('Begin diff');
596593
zipfile.addBuffer(
597594
diff(originSource, newSource),
598-
'index.bundlejs.patch',
599-
);
600-
//console.log('End diff');
601-
});
602-
} else if (entry.fileName === 'bundle.harmony.js') {
603-
//console.log('Found bundle');
604-
return readEntry(entry, nextZipfile).then((newSource) => {
605-
//console.log('Begin diff');
606-
zipfile.addBuffer(
607-
diff(originSource, newSource),
608-
'bundle.harmony.js.patch',
595+
`${entry.fileName}.patch`,
609596
);
610597
//console.log('End diff');
611598
});
@@ -719,23 +706,13 @@ async function diffFromPackage(
719706
if (/\/$/.test(entry.fileName)) {
720707
// Directory
721708
zipfile.addEmptyDirectory(entry.fileName);
722-
} else if (entry.fileName === 'index.bundlejs') {
723-
//console.log('Found bundle');
724-
return readEntry(entry, nextZipfile).then((newSource) => {
725-
//console.log('Begin diff');
726-
zipfile.addBuffer(
727-
diff(originSource, newSource),
728-
'index.bundlejs.patch',
729-
);
730-
//console.log('End diff');
731-
});
732-
} else if (entry.fileName === 'bundle.harmony.js') {
709+
} else if (isPPKBundleFileName(entry.fileName)) {
733710
//console.log('Found bundle');
734711
return readEntry(entry, nextZipfile).then((newSource) => {
735712
//console.log('Begin diff');
736713
zipfile.addBuffer(
737714
diff(originSource, newSource),
738-
'bundle.harmony.js.patch',
715+
`${entry.fileName}.patch`,
739716
);
740717
//console.log('End diff');
741718
});

src/utils/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import path from 'path';
33
export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
44
export const IS_CRESC = scriptName === 'cresc';
55

6+
export const ppkBundleFileNames = ['index.bundlejs', 'bundle.harmony.js'];
7+
export const isPPKBundleFileName = (fileName: string) =>
8+
ppkBundleFileNames.includes(fileName);
9+
610
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
711
export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
812
export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';

0 commit comments

Comments
 (0)