Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
"defaultCommand": "help",
"commands": {
"help": {},

"login": {},
"logout": {},
"me": {},

"createApp": {
"options": {
"name": {
Expand All @@ -33,7 +31,6 @@
}
}
},

"uploadIpa": {},
"uploadApk": {},
"parseIpa": {},
Expand All @@ -45,7 +42,6 @@
}
}
},

"publish": {
"options": {
"platform": {
Expand All @@ -69,7 +65,6 @@
}
}
},

"update": {
"options": {
"platform": {
Expand All @@ -95,7 +90,6 @@
}
}
},

"updateVersionInfo": {
"options": {
"platform": {
Expand All @@ -118,7 +112,6 @@
}
}
},

"build": {
"description": "Bundle javascript and copy assets."
},
Expand Down Expand Up @@ -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": {
Expand All @@ -216,4 +227,4 @@
"default": false
}
}
}
}
169 changes: 136 additions & 33 deletions src/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -72,32 +73,51 @@ async function runReactNativeBundleCommand(
});
}
}
const bundleCommand = usingExpo ? 'export:embed' : 'bundle';

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',
]);
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,
]);

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(' ')}`,
Expand Down Expand Up @@ -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(
Expand All @@ -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';
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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] = '';
Expand Down Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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,
Expand Down
Loading