1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-09-16 01:41:37 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Merge pull request #5 from bozaigao/master

适配鸿蒙
This commit is contained in:
Sunny Luo
2024-12-26 12:14:14 +08:00
committed by GitHub
3 changed files with 154 additions and 2801 deletions

View File

@@ -3,11 +3,9 @@
"defaultCommand": "help",
"commands": {
"help": {},
"login": {},
"logout": {},
"me": {},
"createApp": {
"options": {
"name": {
@@ -33,7 +31,6 @@
}
}
},
"uploadIpa": {},
"uploadApk": {},
"parseIpa": {},
@@ -45,7 +42,6 @@
}
}
},
"publish": {
"options": {
"platform": {
@@ -69,7 +65,6 @@
}
}
},
"update": {
"options": {
"platform": {
@@ -95,7 +90,6 @@
}
}
},
"updateVersionInfo": {
"options": {
"platform": {
@@ -118,7 +112,6 @@
}
}
},
"build": {
"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": {
"description": "Create hdiff patch from a iOS package(.ipa)",
"options": {
@@ -216,4 +227,4 @@
"default": false
}
}
}
}

View File

@@ -9,6 +9,7 @@ import { spawn, spawnSync } from 'node:child_process';
const g2js = require('gradle-to-js/lib/parser');
import os from 'os';
const properties = require('properties');
const path = require('path');
let bsdiff, hdiff, diff;
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, [
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 (sourcemapOutput) {
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
if (config) {
reactNativeBundleArgs.push('--config', config);
}
}
if (config) {
reactNativeBundleArgs.push('--config', config);
else{
Array.prototype.push.apply(reactNativeBundleArgs, [
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);
console.log(
`Running bundle command: node ${reactNativeBundleArgs.join(' ')}`,
@@ -146,6 +166,8 @@ async function runReactNativeBundleCommand(
fs.existsSync('ios/Pods/hermes-engine')
) {
hermesEnabled = true;
}else if (platform === 'harmony') {
await copyHarmonyBundle(outputFolder);
}
if (hermesEnabled) {
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() {
if (os.platform() === 'win32') return 'win64-bin';
if (os.platform() === 'darwin') return 'osx-bin';
@@ -335,7 +372,7 @@ async function diffFromPPK(origin, next, output) {
// isFile
originMap[entry.crc32] = entry.fileName;
if (entry.fileName === 'index.bundlejs') {
if (entry.fileName === 'index.bundlejs' || entry.fileName === 'bundle.harmony.js') {
// This is source.
return readEntire(entry, zipFile).then((v) => (originSource = v));
}
@@ -397,6 +434,16 @@ async function diffFromPPK(origin, next, output) {
);
//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 {
// If same file.
const originEntry = originEntries[entry.fileName];
@@ -519,7 +566,17 @@ async function diffFromPackage(
);
//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 (originEntries[entry.fileName] === entry.crc32) {
copies[entry.fileName] = '';
@@ -551,22 +608,53 @@ async function diffFromPackage(
await writePromise;
}
function enumZipEntries(zipFn, callback) {
async function enumZipEntries(zipFn, callback, nestedPath = '') {
return new Promise((resolve, reject) => {
openZipFile(zipFn, { lazyEntries: true }, (err, zipfile) => {
openZipFile(zipFn, { lazyEntries: true }, async (err, zipfile) => {
if (err) {
return reject(err);
}
zipfile.on('end', resolve);
zipfile.on('error', reject);
zipfile.on('entry', (entry) => {
const result = callback(entry, zipfile);
if (result && typeof result.then === 'function') {
result.then(() => zipfile.readEntry());
} else {
zipfile.readEntry();
zipfile.on('entry', async (entry) => {
const fullPath = nestedPath + entry.fileName;
try {
if (
!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();
});
});
@@ -700,6 +788,21 @@ export const commands = {
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 }) {
const { origin, next, realOutput } = diffArgsCheck(
args,

2761
yarn.lock

File diff suppressed because it is too large Load Diff