mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-11-22 16:26:10 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c633af549d | ||
|
|
78159f362b | ||
|
|
b76440d018 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update-cli",
|
||||
"version": "2.2.0",
|
||||
"version": "2.2.3",
|
||||
"description": "command line tool for react-native-update (remote updates for react native)",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
||||
108
src/bundle.ts
108
src/bundle.ts
@@ -75,15 +75,12 @@ async function runReactNativeBundleCommand({
|
||||
const envArgs = process.env.PUSHY_ENV_ARGS;
|
||||
|
||||
if (envArgs) {
|
||||
Array.prototype.push.apply(
|
||||
reactNativeBundleArgs,
|
||||
envArgs.trim().split(/\s+/),
|
||||
);
|
||||
reactNativeBundleArgs.push(...envArgs.trim().split(/\s+/));
|
||||
}
|
||||
|
||||
fs.emptyDirSync(outputFolder);
|
||||
|
||||
let cliPath: string | undefined;
|
||||
let cliPath = '';
|
||||
let usingExpo = false;
|
||||
|
||||
const getExpoCli = () => {
|
||||
@@ -104,7 +101,7 @@ async function runReactNativeBundleCommand({
|
||||
if (satisfies(expoCliVersion, '>= 0.10.17')) {
|
||||
usingExpo = true;
|
||||
} else {
|
||||
cliPath = undefined;
|
||||
cliPath = '';
|
||||
}
|
||||
} catch (e) {}
|
||||
};
|
||||
@@ -166,49 +163,32 @@ async function runReactNativeBundleCommand({
|
||||
bundleCommand = 'build';
|
||||
}
|
||||
|
||||
if (platform === 'harmony') {
|
||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||
cliPath,
|
||||
bundleCommand,
|
||||
'--dev',
|
||||
dev,
|
||||
'--entry-file',
|
||||
entryFile,
|
||||
]);
|
||||
reactNativeBundleArgs.push(cliPath, bundleCommand);
|
||||
|
||||
if (sourcemapOutput) {
|
||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||
}
|
||||
|
||||
if (config) {
|
||||
reactNativeBundleArgs.push('--config', config);
|
||||
}
|
||||
} else {
|
||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||
cliPath,
|
||||
bundleCommand,
|
||||
if (platform !== 'harmony') {
|
||||
reactNativeBundleArgs.push(
|
||||
'--platform',
|
||||
platform,
|
||||
'--assets-dest',
|
||||
outputFolder,
|
||||
'--bundle-output',
|
||||
path.join(outputFolder, bundleName),
|
||||
'--platform',
|
||||
platform,
|
||||
'--reset-cache',
|
||||
]);
|
||||
);
|
||||
}
|
||||
|
||||
if (cli.taro) {
|
||||
reactNativeBundleArgs.push(...['--type', 'rn']);
|
||||
} else {
|
||||
reactNativeBundleArgs.push(...['--dev', dev, '--entry-file', entryFile]);
|
||||
}
|
||||
if (cli.taro) {
|
||||
reactNativeBundleArgs.push('--type', 'rn');
|
||||
} else {
|
||||
reactNativeBundleArgs.push('--dev', dev, '--entry-file', entryFile);
|
||||
}
|
||||
|
||||
if (sourcemapOutput) {
|
||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||
}
|
||||
if (sourcemapOutput) {
|
||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||
}
|
||||
|
||||
if (config) {
|
||||
reactNativeBundleArgs.push('--config', config);
|
||||
}
|
||||
if (config) {
|
||||
reactNativeBundleArgs.push('--config', config);
|
||||
}
|
||||
|
||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
||||
@@ -290,20 +270,47 @@ async function copyHarmonyBundle(outputFolder: string) {
|
||||
await fs.copy('update.json', path.join(harmonyRawPath, 'update.json'));
|
||||
await fs.ensureDir(outputFolder);
|
||||
|
||||
const files = await fs.readdir(harmonyRawPath);
|
||||
for (const file of files) {
|
||||
if (file !== 'update.json' && file !== 'meta.json') {
|
||||
const sourcePath = path.join(harmonyRawPath, file);
|
||||
const destPath = path.join(outputFolder, file);
|
||||
const stat = await fs.stat(sourcePath);
|
||||
// Recursively copy files with special handling for assets directory
|
||||
async function copyFilesRecursively(
|
||||
srcDir: string,
|
||||
destDir: string,
|
||||
relativePath = '',
|
||||
) {
|
||||
const fullSrcPath = path.join(srcDir, relativePath);
|
||||
const items = await fs.readdir(fullSrcPath);
|
||||
|
||||
for (const item of items) {
|
||||
const itemRelativePath = path.join(relativePath, item);
|
||||
const itemSrcPath = path.join(srcDir, itemRelativePath);
|
||||
|
||||
// Skip update.json and meta.json at root level
|
||||
if (!relativePath && (item === 'update.json' || item === 'meta.json')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const stat = await fs.stat(itemSrcPath);
|
||||
|
||||
if (stat.isFile()) {
|
||||
await fs.copy(sourcePath, destPath);
|
||||
// Special handling: remove 'assets/' prefix to move files up one level
|
||||
let itemDestPath = itemRelativePath;
|
||||
if (
|
||||
itemDestPath.startsWith('assets/') ||
|
||||
itemDestPath.startsWith('assets\\')
|
||||
) {
|
||||
itemDestPath = itemDestPath.replace(/^assets[\\/]/, '');
|
||||
}
|
||||
|
||||
const fullDestPath = path.join(destDir, itemDestPath);
|
||||
await fs.ensureDir(path.dirname(fullDestPath));
|
||||
await fs.copy(itemSrcPath, fullDestPath);
|
||||
} else if (stat.isDirectory()) {
|
||||
await fs.copy(sourcePath, destPath);
|
||||
// Recursively process subdirectories
|
||||
await copyFilesRecursively(srcDir, destDir, itemRelativePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await copyFilesRecursively(harmonyRawPath, outputFolder);
|
||||
} catch (error: any) {
|
||||
console.error(t('copyHarmonyBundleError', { error }));
|
||||
throw new Error(t('copyFileFailed', { error: error.message }));
|
||||
@@ -814,7 +821,10 @@ async function diffFromPackage(
|
||||
}
|
||||
});
|
||||
|
||||
zipfile.addBuffer(Buffer.from(JSON.stringify({ copies, copiesv2 })), '__diff.json');
|
||||
zipfile.addBuffer(
|
||||
Buffer.from(JSON.stringify({ copies, copiesv2 })),
|
||||
'__diff.json',
|
||||
);
|
||||
zipfile.end();
|
||||
await writePromise;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user