mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 09:41:38 +08:00
27
cli.json
27
cli.json
@@ -3,11 +3,9 @@
|
|||||||
"defaultCommand": "help",
|
"defaultCommand": "help",
|
||||||
"commands": {
|
"commands": {
|
||||||
"help": {},
|
"help": {},
|
||||||
|
|
||||||
"login": {},
|
"login": {},
|
||||||
"logout": {},
|
"logout": {},
|
||||||
"me": {},
|
"me": {},
|
||||||
|
|
||||||
"createApp": {
|
"createApp": {
|
||||||
"options": {
|
"options": {
|
||||||
"name": {
|
"name": {
|
||||||
@@ -33,7 +31,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"uploadIpa": {},
|
"uploadIpa": {},
|
||||||
"uploadApk": {},
|
"uploadApk": {},
|
||||||
"parseIpa": {},
|
"parseIpa": {},
|
||||||
@@ -45,7 +42,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"publish": {
|
"publish": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -69,7 +65,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"update": {
|
"update": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -95,7 +90,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"updateVersionInfo": {
|
"updateVersionInfo": {
|
||||||
"options": {
|
"options": {
|
||||||
"platform": {
|
"platform": {
|
||||||
@@ -118,7 +112,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"build": {
|
"build": {
|
||||||
"description": "Bundle javascript and copy assets."
|
"description": "Bundle javascript and copy assets."
|
||||||
},
|
},
|
||||||
@@ -201,6 +194,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"hdiffFromPPK": {
|
||||||
|
"description": "Create hdiff patch from a Prepare package(.ppk)",
|
||||||
|
"options": {
|
||||||
|
"output": {
|
||||||
|
"default": ".pushy/output/hdiff-${time}.ppk-patch",
|
||||||
|
"hasValue": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"hdiffFromApp": {
|
||||||
|
"description": "Create hdiff patch from a Harmony package(.app)",
|
||||||
|
"options": {
|
||||||
|
"output": {
|
||||||
|
"default": ".pushy/output/hdiff-${time}.app-patch",
|
||||||
|
"hasValue": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"hdiffFromIpa": {
|
"hdiffFromIpa": {
|
||||||
"description": "Create hdiff patch from a iOS package(.ipa)",
|
"description": "Create hdiff patch from a iOS package(.ipa)",
|
||||||
"options": {
|
"options": {
|
||||||
@@ -216,4 +227,4 @@
|
|||||||
"default": false
|
"default": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
167
src/bundle.js
167
src/bundle.js
@@ -9,6 +9,7 @@ import { spawn, spawnSync } from 'node:child_process';
|
|||||||
const g2js = require('gradle-to-js/lib/parser');
|
const g2js = require('gradle-to-js/lib/parser');
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
const properties = require('properties');
|
const properties = require('properties');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
let bsdiff, hdiff, diff;
|
let bsdiff, hdiff, diff;
|
||||||
try {
|
try {
|
||||||
@@ -72,32 +73,51 @@ async function runReactNativeBundleCommand(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const bundleCommand = usingExpo ? 'export:embed' : 'bundle';
|
const bundleCommand = usingExpo ? 'export:embed' : platform === 'harmony' ? 'bundle-harmony' : 'bundle';
|
||||||
|
if (platform == 'harmony') {
|
||||||
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
|
cliPath,
|
||||||
|
bundleCommand,
|
||||||
|
'--dev',
|
||||||
|
development,
|
||||||
|
'--entry-file',
|
||||||
|
entryFile,
|
||||||
|
]);
|
||||||
|
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
if (sourcemapOutput) {
|
||||||
cliPath,
|
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||||
bundleCommand,
|
}
|
||||||
'--assets-dest',
|
|
||||||
outputFolder,
|
|
||||||
'--bundle-output',
|
|
||||||
path.join(outputFolder, bundleName),
|
|
||||||
'--dev',
|
|
||||||
development,
|
|
||||||
'--entry-file',
|
|
||||||
entryFile,
|
|
||||||
'--platform',
|
|
||||||
platform,
|
|
||||||
'--reset-cache',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (sourcemapOutput) {
|
if (config) {
|
||||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
reactNativeBundleArgs.push('--config', config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
if (config) {
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
reactNativeBundleArgs.push('--config', config);
|
cliPath,
|
||||||
|
bundleCommand,
|
||||||
|
'--assets-dest',
|
||||||
|
outputFolder,
|
||||||
|
'--bundle-output',
|
||||||
|
path.join(outputFolder, bundleName),
|
||||||
|
'--dev',
|
||||||
|
development,
|
||||||
|
'--entry-file',
|
||||||
|
entryFile,
|
||||||
|
'--platform',
|
||||||
|
platform,
|
||||||
|
'--reset-cache',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (sourcemapOutput) {
|
||||||
|
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config) {
|
||||||
|
reactNativeBundleArgs.push('--config', config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
const reactNativeBundleProcess = spawn('node', reactNativeBundleArgs);
|
||||||
console.log(
|
console.log(
|
||||||
`Running bundle command: node ${reactNativeBundleArgs.join(' ')}`,
|
`Running bundle command: node ${reactNativeBundleArgs.join(' ')}`,
|
||||||
@@ -146,6 +166,8 @@ async function runReactNativeBundleCommand(
|
|||||||
fs.existsSync('ios/Pods/hermes-engine')
|
fs.existsSync('ios/Pods/hermes-engine')
|
||||||
) {
|
) {
|
||||||
hermesEnabled = true;
|
hermesEnabled = true;
|
||||||
|
}else if (platform === 'harmony') {
|
||||||
|
await copyHarmonyBundle(outputFolder);
|
||||||
}
|
}
|
||||||
if (hermesEnabled) {
|
if (hermesEnabled) {
|
||||||
await compileHermesByteCode(
|
await compileHermesByteCode(
|
||||||
@@ -160,6 +182,21 @@ async function runReactNativeBundleCommand(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function copyHarmonyBundle(outputFolder) {
|
||||||
|
const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile';
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.ensureDir(outputFolder);
|
||||||
|
await fs.copy(harmonyRawPath, outputFolder);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Successfully copied from ${harmonyRawPath} to ${outputFolder}`,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in copyHarmonyBundle:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getHermesOSBin() {
|
function getHermesOSBin() {
|
||||||
if (os.platform() === 'win32') return 'win64-bin';
|
if (os.platform() === 'win32') return 'win64-bin';
|
||||||
if (os.platform() === 'darwin') return 'osx-bin';
|
if (os.platform() === 'darwin') return 'osx-bin';
|
||||||
@@ -335,7 +372,7 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
// isFile
|
// isFile
|
||||||
originMap[entry.crc32] = entry.fileName;
|
originMap[entry.crc32] = entry.fileName;
|
||||||
|
|
||||||
if (entry.fileName === 'index.bundlejs') {
|
if (entry.fileName === 'index.bundlejs' || entry.fileName === 'bundle.harmony.js') {
|
||||||
// This is source.
|
// This is source.
|
||||||
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
return readEntire(entry, zipFile).then((v) => (originSource = v));
|
||||||
}
|
}
|
||||||
@@ -397,6 +434,16 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
);
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
|
}else if (entry.fileName === 'bundle.harmony.js') {
|
||||||
|
//console.log('Found bundle');
|
||||||
|
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||||
|
//console.log('Begin diff');
|
||||||
|
zipfile.addBuffer(
|
||||||
|
diff(originSource, newSource),
|
||||||
|
'bundle.harmony.js.patch',
|
||||||
|
);
|
||||||
|
//console.log('End diff');
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// If same file.
|
// If same file.
|
||||||
const originEntry = originEntries[entry.fileName];
|
const originEntry = originEntries[entry.fileName];
|
||||||
@@ -519,7 +566,17 @@ async function diffFromPackage(
|
|||||||
);
|
);
|
||||||
//console.log('End diff');
|
//console.log('End diff');
|
||||||
});
|
});
|
||||||
} else {
|
} else if (entry.fileName === 'bundle.harmony.js') {
|
||||||
|
//console.log('Found bundle');
|
||||||
|
return readEntire(entry, nextZipfile).then((newSource) => {
|
||||||
|
//console.log('Begin diff');
|
||||||
|
zipfile.addBuffer(
|
||||||
|
diff(originSource, newSource),
|
||||||
|
'bundle.harmony.js.patch',
|
||||||
|
);
|
||||||
|
//console.log('End diff');
|
||||||
|
});
|
||||||
|
}else {
|
||||||
// If same file.
|
// If same file.
|
||||||
if (originEntries[entry.fileName] === entry.crc32) {
|
if (originEntries[entry.fileName] === entry.crc32) {
|
||||||
copies[entry.fileName] = '';
|
copies[entry.fileName] = '';
|
||||||
@@ -551,22 +608,53 @@ async function diffFromPackage(
|
|||||||
await writePromise;
|
await writePromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function enumZipEntries(zipFn, callback) {
|
async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
openZipFile(zipFn, { lazyEntries: true }, (err, zipfile) => {
|
openZipFile(zipFn, { lazyEntries: true }, async (err, zipfile) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
zipfile.on('end', resolve);
|
zipfile.on('end', resolve);
|
||||||
zipfile.on('error', reject);
|
zipfile.on('error', reject);
|
||||||
zipfile.on('entry', (entry) => {
|
zipfile.on('entry', async (entry) => {
|
||||||
const result = callback(entry, zipfile);
|
const fullPath = nestedPath + entry.fileName;
|
||||||
if (result && typeof result.then === 'function') {
|
|
||||||
result.then(() => zipfile.readEntry());
|
try {
|
||||||
} else {
|
if (
|
||||||
zipfile.readEntry();
|
!entry.fileName.endsWith('/') &&
|
||||||
|
entry.fileName.toLowerCase().endsWith('.hap')
|
||||||
|
) {
|
||||||
|
const tempDir = path.join(os.tmpdir(), 'nested_zip_' + Date.now());
|
||||||
|
await fs.ensureDir(tempDir);
|
||||||
|
const tempZipPath = path.join(tempDir, 'temp.zip');
|
||||||
|
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
zipfile.openReadStream(entry, async (err, readStream) => {
|
||||||
|
if (err) return rej(err);
|
||||||
|
const writeStream = fs.createWriteStream(tempZipPath);
|
||||||
|
readStream.pipe(writeStream);
|
||||||
|
writeStream.on('finish', res);
|
||||||
|
writeStream.on('error', rej);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await enumZipEntries(tempZipPath, callback, fullPath + '/');
|
||||||
|
|
||||||
|
await fs.remove(tempDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = callback(entry, zipfile, fullPath);
|
||||||
|
if (result && typeof result.then === 'function') {
|
||||||
|
await result;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('处理文件时出错:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zipfile.readEntry();
|
||||||
});
|
});
|
||||||
|
|
||||||
zipfile.readEntry();
|
zipfile.readEntry();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -700,6 +788,21 @@ export const commands = {
|
|||||||
console.log(`${realOutput} generated.`);
|
console.log(`${realOutput} generated.`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async hdiffFromApp({ args, options }) {
|
||||||
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
|
args,
|
||||||
|
options,
|
||||||
|
'hdiffFromApp',
|
||||||
|
);
|
||||||
|
await diffFromPackage(
|
||||||
|
origin,
|
||||||
|
next,
|
||||||
|
realOutput,
|
||||||
|
'resources/rawfile/bundle.harmony.js',
|
||||||
|
);
|
||||||
|
console.log(`${realOutput} generated.`);
|
||||||
|
},
|
||||||
|
|
||||||
async diffFromIpa({ args, options }) {
|
async diffFromIpa({ args, options }) {
|
||||||
const { origin, next, realOutput } = diffArgsCheck(
|
const { origin, next, realOutput } = diffArgsCheck(
|
||||||
args,
|
args,
|
||||||
|
Reference in New Issue
Block a user