mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-10-29 05:43:11 +08:00
Refactor bundle file handling by introducing isPPKBundleFileName utility; streamline diff logic for bundle files in bundle.ts.
This commit is contained in:
@@ -16,7 +16,7 @@ import os from 'os';
|
|||||||
const properties = require('properties');
|
const properties = require('properties');
|
||||||
import { addGitIgnore } from './utils/add-gitignore';
|
import { addGitIgnore } from './utils/add-gitignore';
|
||||||
import { checkLockFiles } from './utils/check-lockfile';
|
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 { depVersions } from './utils/dep-versions';
|
||||||
import { t } from './utils/i18n';
|
import { t } from './utils/i18n';
|
||||||
import { versionCommands } from './versions';
|
import { versionCommands } from './versions';
|
||||||
@@ -537,10 +537,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
|
|||||||
// isFile
|
// isFile
|
||||||
originMap[entry.crc32] = entry.fileName;
|
originMap[entry.crc32] = entry.fileName;
|
||||||
|
|
||||||
if (
|
if (isPPKBundleFileName(entry.fileName)) {
|
||||||
entry.fileName === 'index.bundlejs' ||
|
|
||||||
entry.fileName === 'bundle.harmony.js'
|
|
||||||
) {
|
|
||||||
// This is source.
|
// This is source.
|
||||||
return readEntry(entry, zipFile).then((v) => (originSource = v));
|
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]) {
|
if (!originEntries[entry.fileName]) {
|
||||||
addEntry(entry.fileName);
|
addEntry(entry.fileName);
|
||||||
}
|
}
|
||||||
} else if (entry.fileName === 'index.bundlejs') {
|
} else if (isPPKBundleFileName(entry.fileName)) {
|
||||||
//console.log('Found bundle');
|
//console.log('Found bundle');
|
||||||
return readEntry(entry, nextZipfile).then((newSource) => {
|
return readEntry(entry, nextZipfile).then((newSource) => {
|
||||||
//console.log('Begin diff');
|
//console.log('Begin diff');
|
||||||
zipfile.addBuffer(
|
zipfile.addBuffer(
|
||||||
diff(originSource, newSource),
|
diff(originSource, newSource),
|
||||||
'index.bundlejs.patch',
|
`${entry.fileName}.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',
|
|
||||||
);
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
@@ -719,23 +706,13 @@ async function diffFromPackage(
|
|||||||
if (/\/$/.test(entry.fileName)) {
|
if (/\/$/.test(entry.fileName)) {
|
||||||
// Directory
|
// Directory
|
||||||
zipfile.addEmptyDirectory(entry.fileName);
|
zipfile.addEmptyDirectory(entry.fileName);
|
||||||
} else if (entry.fileName === 'index.bundlejs') {
|
} else if (isPPKBundleFileName(entry.fileName)) {
|
||||||
//console.log('Found bundle');
|
//console.log('Found bundle');
|
||||||
return readEntry(entry, nextZipfile).then((newSource) => {
|
return readEntry(entry, nextZipfile).then((newSource) => {
|
||||||
//console.log('Begin diff');
|
//console.log('Begin diff');
|
||||||
zipfile.addBuffer(
|
zipfile.addBuffer(
|
||||||
diff(originSource, newSource),
|
diff(originSource, newSource),
|
||||||
'index.bundlejs.patch',
|
`${entry.fileName}.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',
|
|
||||||
);
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ import path from 'path';
|
|||||||
export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
|
export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
|
||||||
export const IS_CRESC = scriptName === 'cresc';
|
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 credentialFile = IS_CRESC ? '.cresc.token' : '.update';
|
||||||
export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
|
export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
|
||||||
export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
|
export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
|
||||||
|
|||||||
Reference in New Issue
Block a user