mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-11-23 00:36:11 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c633af549d | ||
|
|
78159f362b | ||
|
|
b76440d018 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"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)",
|
"description": "command line tool for react-native-update (remote updates for react native)",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
108
src/bundle.ts
108
src/bundle.ts
@@ -75,15 +75,12 @@ async function runReactNativeBundleCommand({
|
|||||||
const envArgs = process.env.PUSHY_ENV_ARGS;
|
const envArgs = process.env.PUSHY_ENV_ARGS;
|
||||||
|
|
||||||
if (envArgs) {
|
if (envArgs) {
|
||||||
Array.prototype.push.apply(
|
reactNativeBundleArgs.push(...envArgs.trim().split(/\s+/));
|
||||||
reactNativeBundleArgs,
|
|
||||||
envArgs.trim().split(/\s+/),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.emptyDirSync(outputFolder);
|
fs.emptyDirSync(outputFolder);
|
||||||
|
|
||||||
let cliPath: string | undefined;
|
let cliPath = '';
|
||||||
let usingExpo = false;
|
let usingExpo = false;
|
||||||
|
|
||||||
const getExpoCli = () => {
|
const getExpoCli = () => {
|
||||||
@@ -104,7 +101,7 @@ async function runReactNativeBundleCommand({
|
|||||||
if (satisfies(expoCliVersion, '>= 0.10.17')) {
|
if (satisfies(expoCliVersion, '>= 0.10.17')) {
|
||||||
usingExpo = true;
|
usingExpo = true;
|
||||||
} else {
|
} else {
|
||||||
cliPath = undefined;
|
cliPath = '';
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
};
|
};
|
||||||
@@ -166,49 +163,32 @@ async function runReactNativeBundleCommand({
|
|||||||
bundleCommand = 'build';
|
bundleCommand = 'build';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platform === 'harmony') {
|
reactNativeBundleArgs.push(cliPath, bundleCommand);
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
|
||||||
cliPath,
|
|
||||||
bundleCommand,
|
|
||||||
'--dev',
|
|
||||||
dev,
|
|
||||||
'--entry-file',
|
|
||||||
entryFile,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (sourcemapOutput) {
|
if (platform !== 'harmony') {
|
||||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
reactNativeBundleArgs.push(
|
||||||
}
|
'--platform',
|
||||||
|
platform,
|
||||||
if (config) {
|
|
||||||
reactNativeBundleArgs.push('--config', config);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
|
||||||
cliPath,
|
|
||||||
bundleCommand,
|
|
||||||
'--assets-dest',
|
'--assets-dest',
|
||||||
outputFolder,
|
outputFolder,
|
||||||
'--bundle-output',
|
'--bundle-output',
|
||||||
path.join(outputFolder, bundleName),
|
path.join(outputFolder, bundleName),
|
||||||
'--platform',
|
|
||||||
platform,
|
|
||||||
'--reset-cache',
|
'--reset-cache',
|
||||||
]);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (cli.taro) {
|
if (cli.taro) {
|
||||||
reactNativeBundleArgs.push(...['--type', 'rn']);
|
reactNativeBundleArgs.push('--type', 'rn');
|
||||||
} else {
|
} else {
|
||||||
reactNativeBundleArgs.push(...['--dev', dev, '--entry-file', entryFile]);
|
reactNativeBundleArgs.push('--dev', dev, '--entry-file', entryFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourcemapOutput) {
|
if (sourcemapOutput) {
|
||||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config) {
|
if (config) {
|
||||||
reactNativeBundleArgs.push('--config', config);
|
reactNativeBundleArgs.push('--config', config);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
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.copy('update.json', path.join(harmonyRawPath, 'update.json'));
|
||||||
await fs.ensureDir(outputFolder);
|
await fs.ensureDir(outputFolder);
|
||||||
|
|
||||||
const files = await fs.readdir(harmonyRawPath);
|
// Recursively copy files with special handling for assets directory
|
||||||
for (const file of files) {
|
async function copyFilesRecursively(
|
||||||
if (file !== 'update.json' && file !== 'meta.json') {
|
srcDir: string,
|
||||||
const sourcePath = path.join(harmonyRawPath, file);
|
destDir: string,
|
||||||
const destPath = path.join(outputFolder, file);
|
relativePath = '',
|
||||||
const stat = await fs.stat(sourcePath);
|
) {
|
||||||
|
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()) {
|
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()) {
|
} else if (stat.isDirectory()) {
|
||||||
await fs.copy(sourcePath, destPath);
|
// Recursively process subdirectories
|
||||||
|
await copyFilesRecursively(srcDir, destDir, itemRelativePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await copyFilesRecursively(harmonyRawPath, outputFolder);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(t('copyHarmonyBundleError', { error }));
|
console.error(t('copyHarmonyBundleError', { error }));
|
||||||
throw new Error(t('copyFileFailed', { error: error.message }));
|
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();
|
zipfile.end();
|
||||||
await writePromise;
|
await writePromise;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user