mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-18 18:30:39 +08:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e713f4bbd1 | ||
![]() |
5a6463de33 | ||
![]() |
1fb308af94 | ||
![]() |
f10d4d3004 | ||
![]() |
0f44de772f | ||
![]() |
814a9d10fb | ||
![]() |
c08c5c0b07 | ||
![]() |
dc8c134ff0 | ||
![]() |
1d1e6cde0f | ||
![]() |
f16aff5674 |
9
bun.lock
Executable file → Normal file
9
bun.lock
Executable file → Normal file
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"lockfileVersion": 0,
|
"lockfileVersion": 1,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
"form-data": "^4.0.1",
|
"form-data": "^4.0.1",
|
||||||
"fs-extra": "8",
|
"fs-extra": "8",
|
||||||
"gradle-to-js": "^2.0.1",
|
"gradle-to-js": "^2.0.1",
|
||||||
|
"i18next": "^24.2.2",
|
||||||
"isomorphic-unzip": "^1.1.5",
|
"isomorphic-unzip": "^1.1.5",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"plist": "^3.1.0",
|
"plist": "^3.1.0",
|
||||||
@@ -38,6 +39,8 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
|
"@babel/runtime": ["@babel/runtime@7.26.9", "", { "dependencies": { "regenerator-runtime": "^0.14.0" } }, "sha512-aA63XwOkcl4xxQa3HjPMqOP6LiK0ZDv3mUPYEFXkpHbaFjtGggE1A61FjFzJnB+p7/oy2gA8E+rcBNl/zC1tMg=="],
|
||||||
|
|
||||||
"@badisi/latest-version": ["@badisi/latest-version@7.0.10", "", { "dependencies": { "@colors/colors": "^1.6.0", "global-dirs": "3.0.1", "ora": "^8.1.0", "registry-auth-token": "^5.0.2", "semver": "^7.6.3" }, "bin": { "latest-version": "bin/latest-version", "lv": "bin/latest-version" } }, "sha512-1lX9wvXiJC552C+rrwwjEbpvvuDwYTU3OLFwFA1pTVYTnJGUkbBkfqz1MuTIPP1fL2LCvjd21ri/u39sSIcMTg=="],
|
"@badisi/latest-version": ["@badisi/latest-version@7.0.10", "", { "dependencies": { "@colors/colors": "^1.6.0", "global-dirs": "3.0.1", "ora": "^8.1.0", "registry-auth-token": "^5.0.2", "semver": "^7.6.3" }, "bin": { "latest-version": "bin/latest-version", "lv": "bin/latest-version" } }, "sha512-1lX9wvXiJC552C+rrwwjEbpvvuDwYTU3OLFwFA1pTVYTnJGUkbBkfqz1MuTIPP1fL2LCvjd21ri/u39sSIcMTg=="],
|
||||||
|
|
||||||
"@biomejs/biome": ["@biomejs/biome@1.9.4", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "1.9.4", "@biomejs/cli-darwin-x64": "1.9.4", "@biomejs/cli-linux-arm64": "1.9.4", "@biomejs/cli-linux-arm64-musl": "1.9.4", "@biomejs/cli-linux-x64": "1.9.4", "@biomejs/cli-linux-x64-musl": "1.9.4", "@biomejs/cli-win32-arm64": "1.9.4", "@biomejs/cli-win32-x64": "1.9.4" }, "bin": { "biome": "bin/biome" } }, "sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog=="],
|
"@biomejs/biome": ["@biomejs/biome@1.9.4", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "1.9.4", "@biomejs/cli-darwin-x64": "1.9.4", "@biomejs/cli-linux-arm64": "1.9.4", "@biomejs/cli-linux-arm64-musl": "1.9.4", "@biomejs/cli-linux-x64": "1.9.4", "@biomejs/cli-linux-x64-musl": "1.9.4", "@biomejs/cli-win32-arm64": "1.9.4", "@biomejs/cli-win32-x64": "1.9.4" }, "bin": { "biome": "bin/biome" } }, "sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog=="],
|
||||||
@@ -414,6 +417,8 @@
|
|||||||
|
|
||||||
"human-signals": ["human-signals@2.1.0", "", {}, "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw=="],
|
"human-signals": ["human-signals@2.1.0", "", {}, "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw=="],
|
||||||
|
|
||||||
|
"i18next": ["i18next@24.2.2", "", { "dependencies": { "@babel/runtime": "^7.23.2" }, "peerDependencies": { "typescript": "^5" }, "optionalPeers": ["typescript"] }, "sha512-NE6i86lBCKRYZa5TaUDkU5S4HFgLIEJRLr3Whf2psgaxBleQ2LC1YW1Vc+SCgkAW7VEzndT6al6+CzegSUHcTQ=="],
|
||||||
|
|
||||||
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
||||||
|
|
||||||
"import-lazy": ["import-lazy@2.1.0", "", {}, "sha512-m7ZEHgtw69qOGw+jwxXkHlrlIPdTGkyh66zXZ1ajZbxkDBNjSY/LGbmjc7h0s2ELsUDTAhFr55TrPSSqJGPG0A=="],
|
"import-lazy": ["import-lazy@2.1.0", "", {}, "sha512-m7ZEHgtw69qOGw+jwxXkHlrlIPdTGkyh66zXZ1ajZbxkDBNjSY/LGbmjc7h0s2ELsUDTAhFr55TrPSSqJGPG0A=="],
|
||||||
@@ -604,6 +609,8 @@
|
|||||||
|
|
||||||
"read": ["read@4.0.0", "", { "dependencies": { "mute-stream": "^2.0.0" } }, "sha512-nbYGT3cec3J5NPUeJia7l72I3oIzMIB6yeNyDqi8CVHr3WftwjrCUqR0j13daoHEMVaZ/rxCpmHKrbods3hI2g=="],
|
"read": ["read@4.0.0", "", { "dependencies": { "mute-stream": "^2.0.0" } }, "sha512-nbYGT3cec3J5NPUeJia7l72I3oIzMIB6yeNyDqi8CVHr3WftwjrCUqR0j13daoHEMVaZ/rxCpmHKrbods3hI2g=="],
|
||||||
|
|
||||||
|
"regenerator-runtime": ["regenerator-runtime@0.14.1", "", {}, "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw=="],
|
||||||
|
|
||||||
"regexp.prototype.flags": ["regexp.prototype.flags@1.5.3", "", { "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1", "es-errors": "^1.3.0", "set-function-name": "^2.0.2" } }, "sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ=="],
|
"regexp.prototype.flags": ["regexp.prototype.flags@1.5.3", "", { "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1", "es-errors": "^1.3.0", "set-function-name": "^2.0.2" } }, "sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ=="],
|
||||||
|
|
||||||
"registry-auth-token": ["registry-auth-token@5.0.2", "", { "dependencies": { "@pnpm/npm-conf": "^2.1.0" } }, "sha512-o/3ikDxtXaA59BmZuZrJZDJv8NMDGSj+6j6XaeBmHw8eY1i1qd9+6H+LjVvQXx3HN6aRCGa1cUdJ9RaJZUugnQ=="],
|
"registry-auth-token": ["registry-auth-token@5.0.2", "", { "dependencies": { "@pnpm/npm-conf": "^2.1.0" } }, "sha512-o/3ikDxtXaA59BmZuZrJZDJv8NMDGSj+6j6XaeBmHw8eY1i1qd9+6H+LjVvQXx3HN6aRCGa1cUdJ9RaJZUugnQ=="],
|
||||||
|
12
cli.json
12
cli.json
@@ -145,6 +145,18 @@
|
|||||||
},
|
},
|
||||||
"sourcemap": {
|
"sourcemap": {
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"taro": {
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"expo": {
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"rncli": {
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
|
"disableHermes": {
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"name": "react-native-update-cli",
|
||||||
"version": "1.39.1",
|
"version": "1.40.1",
|
||||||
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"pushy": "lib/index.js"
|
"pushy": "lib/index.js",
|
||||||
|
"cresc": "lib/index.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
@@ -46,6 +47,7 @@
|
|||||||
"form-data": "^4.0.1",
|
"form-data": "^4.0.1",
|
||||||
"fs-extra": "8",
|
"fs-extra": "8",
|
||||||
"gradle-to-js": "^2.0.1",
|
"gradle-to-js": "^2.0.1",
|
||||||
|
"i18next": "^24.2.2",
|
||||||
"isomorphic-unzip": "^1.1.5",
|
"isomorphic-unzip": "^1.1.5",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"plist": "^3.1.0",
|
"plist": "^3.1.0",
|
||||||
|
@@ -121,7 +121,7 @@ export async function uploadFile(fn: string, key?: string) {
|
|||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
});
|
});
|
||||||
// console.log({pingResult});
|
// console.log({pingResult});
|
||||||
if (isNaN(pingResult.avg) || pingResult.avg > 150) {
|
if (Number.isNaN(pingResult.avg) || pingResult.avg > 150) {
|
||||||
realUrl = backupUrl;
|
realUrl = backupUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,16 +22,35 @@ try {
|
|||||||
hdiff = require('node-hdiffpatch').diff;
|
hdiff = require('node-hdiffpatch').diff;
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
async function runReactNativeBundleCommand(
|
async function runReactNativeBundleCommand({
|
||||||
bundleName,
|
bundleName,
|
||||||
development,
|
dev,
|
||||||
entryFile,
|
entryFile,
|
||||||
outputFolder,
|
outputFolder,
|
||||||
platform,
|
platform,
|
||||||
sourcemapOutput,
|
sourcemapOutput,
|
||||||
config,
|
config,
|
||||||
) {
|
disableHermes,
|
||||||
let gradleConfig = {};
|
cli,
|
||||||
|
}: {
|
||||||
|
bundleName: string;
|
||||||
|
dev: string;
|
||||||
|
entryFile: string;
|
||||||
|
outputFolder: string;
|
||||||
|
platform: string;
|
||||||
|
sourcemapOutput: string;
|
||||||
|
config?: string;
|
||||||
|
disableHermes?: boolean;
|
||||||
|
cli: {
|
||||||
|
taro?: boolean;
|
||||||
|
expo?: boolean;
|
||||||
|
rncli?: boolean;
|
||||||
|
};
|
||||||
|
}) {
|
||||||
|
let gradleConfig: {
|
||||||
|
crunchPngs?: boolean;
|
||||||
|
enableHermes?: boolean;
|
||||||
|
} = {};
|
||||||
if (platform === 'android') {
|
if (platform === 'android') {
|
||||||
gradleConfig = await checkGradleConfig();
|
gradleConfig = await checkGradleConfig();
|
||||||
if (gradleConfig.crunchPngs !== false) {
|
if (gradleConfig.crunchPngs !== false) {
|
||||||
@@ -41,7 +60,7 @@ async function runReactNativeBundleCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactNativeBundleArgs = [];
|
const reactNativeBundleArgs: string[] = [];
|
||||||
|
|
||||||
const envArgs = process.env.PUSHY_ENV_ARGS;
|
const envArgs = process.env.PUSHY_ENV_ARGS;
|
||||||
|
|
||||||
@@ -54,9 +73,10 @@ async function runReactNativeBundleCommand(
|
|||||||
|
|
||||||
fs.emptyDirSync(outputFolder);
|
fs.emptyDirSync(outputFolder);
|
||||||
|
|
||||||
let cliPath;
|
let cliPath: string | undefined;
|
||||||
|
|
||||||
let usingExpo = false;
|
let usingExpo = false;
|
||||||
|
|
||||||
|
const getExpoCli = () => {
|
||||||
try {
|
try {
|
||||||
cliPath = require.resolve('@expo/cli', {
|
cliPath = require.resolve('@expo/cli', {
|
||||||
paths: [process.cwd()],
|
paths: [process.cwd()],
|
||||||
@@ -66,14 +86,18 @@ async function runReactNativeBundleCommand(
|
|||||||
require.resolve('@expo/cli/package.json', {
|
require.resolve('@expo/cli/package.json', {
|
||||||
paths: [process.cwd()],
|
paths: [process.cwd()],
|
||||||
}),
|
}),
|
||||||
),
|
).toString(),
|
||||||
).version;
|
).version;
|
||||||
// expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
|
// expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
|
||||||
if (semverSatisfies(expoCliVersion, '>= 0.10.17')) {
|
if (semverSatisfies(expoCliVersion, '>= 0.10.17')) {
|
||||||
usingExpo = true;
|
usingExpo = true;
|
||||||
|
} else {
|
||||||
|
cliPath = undefined;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
if (!usingExpo) {
|
};
|
||||||
|
|
||||||
|
const getRnCli = () => {
|
||||||
try {
|
try {
|
||||||
// rn >= 0.75
|
// rn >= 0.75
|
||||||
cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
|
cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
|
||||||
@@ -85,20 +109,49 @@ async function runReactNativeBundleCommand(
|
|||||||
paths: [process.cwd()],
|
paths: [process.cwd()],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTaroCli = () => {
|
||||||
|
try {
|
||||||
|
cliPath = require.resolve('@tarojs/cli/bin/taro', {
|
||||||
|
paths: [process.cwd()],
|
||||||
|
});
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (cli.expo) {
|
||||||
|
getExpoCli();
|
||||||
|
} else if (cli.taro) {
|
||||||
|
getTaroCli();
|
||||||
|
} else if (cli.rncli) {
|
||||||
|
getRnCli();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cliPath) {
|
||||||
|
getExpoCli();
|
||||||
|
if (!usingExpo) {
|
||||||
|
getRnCli();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const bundleParams = await checkPlugins();
|
const bundleParams = await checkPlugins();
|
||||||
const isSentry = bundleParams.sentry;
|
const isSentry = bundleParams.sentry;
|
||||||
const bundleCommand = usingExpo
|
|
||||||
? 'export:embed'
|
let bundleCommand = 'bundle';
|
||||||
: platform === 'harmony'
|
if (usingExpo) {
|
||||||
? 'bundle-harmony'
|
bundleCommand = 'export:embed';
|
||||||
: 'bundle';
|
} else if (platform === 'harmony') {
|
||||||
|
bundleCommand = 'bundle-harmony';
|
||||||
|
} else if (cli.taro) {
|
||||||
|
bundleCommand = 'build';
|
||||||
|
}
|
||||||
|
|
||||||
if (platform === 'harmony') {
|
if (platform === 'harmony') {
|
||||||
Array.prototype.push.apply(reactNativeBundleArgs, [
|
Array.prototype.push.apply(reactNativeBundleArgs, [
|
||||||
cliPath,
|
cliPath,
|
||||||
bundleCommand,
|
bundleCommand,
|
||||||
'--dev',
|
'--dev',
|
||||||
development,
|
dev,
|
||||||
'--entry-file',
|
'--entry-file',
|
||||||
entryFile,
|
entryFile,
|
||||||
]);
|
]);
|
||||||
@@ -118,15 +171,25 @@ async function runReactNativeBundleCommand(
|
|||||||
outputFolder,
|
outputFolder,
|
||||||
'--bundle-output',
|
'--bundle-output',
|
||||||
path.join(outputFolder, bundleName),
|
path.join(outputFolder, bundleName),
|
||||||
'--dev',
|
|
||||||
development,
|
|
||||||
'--entry-file',
|
|
||||||
entryFile,
|
|
||||||
'--platform',
|
'--platform',
|
||||||
platform,
|
platform,
|
||||||
'--reset-cache',
|
'--reset-cache',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (cli.taro) {
|
||||||
|
reactNativeBundleArgs.push(...[
|
||||||
|
'--type',
|
||||||
|
'rn',
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
reactNativeBundleArgs.push(...[
|
||||||
|
'--dev',
|
||||||
|
dev,
|
||||||
|
'--entry-file',
|
||||||
|
entryFile,
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
if (sourcemapOutput) {
|
if (sourcemapOutput) {
|
||||||
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
|
||||||
}
|
}
|
||||||
@@ -158,17 +221,22 @@ async function runReactNativeBundleCommand(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let hermesEnabled = false;
|
let hermesEnabled: boolean | undefined = false;
|
||||||
|
|
||||||
if (platform === 'android') {
|
if (disableHermes) {
|
||||||
const gradlePropeties = await new Promise((resolve) => {
|
hermesEnabled = false;
|
||||||
|
console.log('Hermes disabled');
|
||||||
|
} else if (platform === 'android') {
|
||||||
|
const gradlePropeties = await new Promise<{
|
||||||
|
hermesEnabled?: boolean;
|
||||||
|
}>((resolve) => {
|
||||||
properties.parse(
|
properties.parse(
|
||||||
'./android/gradle.properties',
|
'./android/gradle.properties',
|
||||||
{ path: true },
|
{ path: true },
|
||||||
(error, props) => {
|
(error: any, props: { hermesEnabled?: boolean }) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
resolve(null);
|
resolve({});
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(props);
|
resolve(props);
|
||||||
@@ -201,7 +269,7 @@ async function runReactNativeBundleCommand(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyHarmonyBundle(outputFolder) {
|
async function copyHarmonyBundle(outputFolder: string) {
|
||||||
const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile';
|
const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile';
|
||||||
try {
|
try {
|
||||||
await fs.ensureDir(harmonyRawPath);
|
await fs.ensureDir(harmonyRawPath);
|
||||||
@@ -215,7 +283,7 @@ async function copyHarmonyBundle(outputFolder) {
|
|||||||
|
|
||||||
await fs.ensureDir(outputFolder);
|
await fs.ensureDir(outputFolder);
|
||||||
await fs.copy(harmonyRawPath, outputFolder);
|
await fs.copy(harmonyRawPath, outputFolder);
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('copyHarmonyBundle 错误:', error);
|
console.error('copyHarmonyBundle 错误:', error);
|
||||||
throw new Error(`复制文件失败: ${error.message}`);
|
throw new Error(`复制文件失败: ${error.message}`);
|
||||||
}
|
}
|
||||||
@@ -253,10 +321,10 @@ async function checkGradleConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function compileHermesByteCode(
|
async function compileHermesByteCode(
|
||||||
bundleName,
|
bundleName: string,
|
||||||
outputFolder,
|
outputFolder: string,
|
||||||
sourcemapOutput,
|
sourcemapOutput: string,
|
||||||
shouldCleanSourcemap,
|
shouldCleanSourcemap: boolean,
|
||||||
) {
|
) {
|
||||||
console.log('Hermes enabled, now compiling to hermes bytecode:\n');
|
console.log('Hermes enabled, now compiling to hermes bytecode:\n');
|
||||||
// >= rn 0.69
|
// >= rn 0.69
|
||||||
@@ -318,7 +386,11 @@ async function compileHermesByteCode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
|
async function copyDebugidForSentry(
|
||||||
|
bundleName: string,
|
||||||
|
outputFolder: string,
|
||||||
|
sourcemapOutput: string,
|
||||||
|
) {
|
||||||
if (sourcemapOutput) {
|
if (sourcemapOutput) {
|
||||||
let copyDebugidPath;
|
let copyDebugidPath;
|
||||||
try {
|
try {
|
||||||
@@ -355,10 +427,10 @@ async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function uploadSourcemapForSentry(
|
async function uploadSourcemapForSentry(
|
||||||
bundleName,
|
bundleName: string,
|
||||||
outputFolder,
|
outputFolder: string,
|
||||||
sourcemapOutput,
|
sourcemapOutput: string,
|
||||||
version,
|
version: string,
|
||||||
) {
|
) {
|
||||||
if (sourcemapOutput) {
|
if (sourcemapOutput) {
|
||||||
let sentryCliPath;
|
let sentryCliPath;
|
||||||
@@ -405,19 +477,24 @@ async function uploadSourcemapForSentry(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pack(dir, output) {
|
const ignorePackingFileNames = ['.', '..', 'index.bundlejs.map'];
|
||||||
|
const ignorePackingExtensions = ['DS_Store'];
|
||||||
|
async function pack(dir: string, output: string) {
|
||||||
console.log('Packing');
|
console.log('Packing');
|
||||||
fs.ensureDirSync(path.dirname(output));
|
fs.ensureDirSync(path.dirname(output));
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const zipfile = new ZipFile();
|
const zipfile = new ZipFile();
|
||||||
|
|
||||||
function addDirectory(root, rel) {
|
function addDirectory(root: string, rel: string) {
|
||||||
if (rel) {
|
if (rel) {
|
||||||
zipfile.addEmptyDirectory(rel);
|
zipfile.addEmptyDirectory(rel);
|
||||||
}
|
}
|
||||||
const childs = fs.readdirSync(root);
|
const childs = fs.readdirSync(root);
|
||||||
for (const name of childs) {
|
for (const name of childs) {
|
||||||
if (name === '.' || name === '..' || name === 'index.bundlejs.map' || name === 'index.bundlejs.txt.map') {
|
if (
|
||||||
|
ignorePackingFileNames.includes(name) ||
|
||||||
|
ignorePackingExtensions.some((ext) => name.endsWith(`.${ext}`))
|
||||||
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const fullPath = path.join(root, name);
|
const fullPath = path.join(root, name);
|
||||||
@@ -434,7 +511,7 @@ async function pack(dir, output) {
|
|||||||
|
|
||||||
addDirectory(dir, '');
|
addDirectory(dir, '');
|
||||||
|
|
||||||
zipfile.outputStream.on('error', (err) => reject(err));
|
zipfile.outputStream.on('error', (err: any) => reject(err));
|
||||||
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
|
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@@ -443,12 +520,12 @@ async function pack(dir, output) {
|
|||||||
console.log(`ppk热更包已生成并保存到: ${output}`);
|
console.log(`ppk热更包已生成并保存到: ${output}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readEntire(entry, zipFile) {
|
export function readEntire(entry: string, zipFile: ZipFile) {
|
||||||
const buffers = [];
|
const buffers: Buffer[] = [];
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
zipFile.openReadStream(entry, (err, stream) => {
|
zipFile.openReadStream(entry, (err: any, stream: any) => {
|
||||||
stream.pipe({
|
stream.pipe({
|
||||||
write(chunk) {
|
write(chunk: Buffer) {
|
||||||
buffers.push(chunk);
|
buffers.push(chunk);
|
||||||
},
|
},
|
||||||
end() {
|
end() {
|
||||||
@@ -463,12 +540,12 @@ export function readEntire(entry, zipFile) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function basename(fn) {
|
function basename(fn: string) {
|
||||||
const m = /^(.+\/)[^\/]+\/?$/.exec(fn);
|
const m = /^(.+\/)[^\/]+\/?$/.exec(fn);
|
||||||
return m?.[1];
|
return m?.[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function diffFromPPK(origin, next, output) {
|
async function diffFromPPK(origin: string, next: string, output: string) {
|
||||||
fs.ensureDirSync(path.dirname(output));
|
fs.ensureDirSync(path.dirname(output));
|
||||||
|
|
||||||
const originEntries = {};
|
const originEntries = {};
|
||||||
@@ -513,7 +590,7 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
|
|
||||||
const addedEntry = {};
|
const addedEntry = {};
|
||||||
|
|
||||||
function addEntry(fn) {
|
function addEntry(fn: string) {
|
||||||
//console.log(fn);
|
//console.log(fn);
|
||||||
if (!fn || addedEntry[fn]) {
|
if (!fn || addedEntry[fn]) {
|
||||||
return;
|
return;
|
||||||
@@ -610,11 +687,11 @@ async function diffFromPPK(origin, next, output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function diffFromPackage(
|
async function diffFromPackage(
|
||||||
origin,
|
origin: string,
|
||||||
next,
|
next: string,
|
||||||
output,
|
output: string,
|
||||||
originBundleName,
|
originBundleName: string,
|
||||||
transformPackagePath = (v) => v,
|
transformPackagePath = (v: string) => v,
|
||||||
) {
|
) {
|
||||||
fs.ensureDirSync(path.dirname(output));
|
fs.ensureDirSync(path.dirname(output));
|
||||||
|
|
||||||
@@ -623,7 +700,7 @@ async function diffFromPackage(
|
|||||||
|
|
||||||
let originSource;
|
let originSource;
|
||||||
|
|
||||||
await enumZipEntries(origin, (entry, zipFile) => {
|
await enumZipEntries(origin, (entry: any, zipFile: any) => {
|
||||||
if (!/\/$/.test(entry.fileName)) {
|
if (!/\/$/.test(entry.fileName)) {
|
||||||
const fn = transformPackagePath(entry.fileName);
|
const fn = transformPackagePath(entry.fileName);
|
||||||
if (!fn) {
|
if (!fn) {
|
||||||
@@ -717,9 +794,16 @@ async function diffFromPackage(
|
|||||||
await writePromise;
|
await writePromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
export async function enumZipEntries(
|
||||||
|
zipFn: string,
|
||||||
|
callback: (entry: any, zipFile: any) => void,
|
||||||
|
nestedPath = '',
|
||||||
|
) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
openZipFile(zipFn, { lazyEntries: true }, async (err, zipfile) => {
|
openZipFile(
|
||||||
|
zipFn,
|
||||||
|
{ lazyEntries: true },
|
||||||
|
async (err: any, zipfile: ZipFile) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
@@ -734,7 +818,10 @@ export async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
|||||||
!entry.fileName.endsWith('/') &&
|
!entry.fileName.endsWith('/') &&
|
||||||
entry.fileName.toLowerCase().endsWith('.hap')
|
entry.fileName.toLowerCase().endsWith('.hap')
|
||||||
) {
|
) {
|
||||||
const tempDir = path.join(os.tmpdir(), `nested_zip_${Date.now()}`);
|
const tempDir = path.join(
|
||||||
|
os.tmpdir(),
|
||||||
|
`nested_zip_${Date.now()}`,
|
||||||
|
);
|
||||||
await fs.ensureDir(tempDir);
|
await fs.ensureDir(tempDir);
|
||||||
const tempZipPath = path.join(tempDir, 'temp.zip');
|
const tempZipPath = path.join(tempDir, 'temp.zip');
|
||||||
|
|
||||||
@@ -765,7 +852,8 @@ export async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
|||||||
});
|
});
|
||||||
|
|
||||||
zipfile.readEntry();
|
zipfile.readEntry();
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,8 +899,18 @@ export const commands = {
|
|||||||
options.platform || (await question('平台(ios/android/harmony):')),
|
options.platform || (await question('平台(ios/android/harmony):')),
|
||||||
);
|
);
|
||||||
|
|
||||||
const { bundleName, entryFile, intermediaDir, output, dev, sourcemap } =
|
const {
|
||||||
translateOptions({
|
bundleName,
|
||||||
|
entryFile,
|
||||||
|
intermediaDir,
|
||||||
|
output,
|
||||||
|
dev,
|
||||||
|
sourcemap,
|
||||||
|
taro,
|
||||||
|
expo,
|
||||||
|
rncli,
|
||||||
|
disableHermes,
|
||||||
|
} = translateOptions({
|
||||||
...options,
|
...options,
|
||||||
platform,
|
platform,
|
||||||
});
|
});
|
||||||
@@ -833,14 +931,20 @@ export const commands = {
|
|||||||
|
|
||||||
console.log(`Bundling with react-native: ${version}`);
|
console.log(`Bundling with react-native: ${version}`);
|
||||||
|
|
||||||
await runReactNativeBundleCommand(
|
await runReactNativeBundleCommand({
|
||||||
bundleName,
|
bundleName,
|
||||||
dev,
|
dev,
|
||||||
entryFile,
|
entryFile,
|
||||||
intermediaDir,
|
outputFolder: intermediaDir,
|
||||||
platform,
|
platform,
|
||||||
sourcemap || sourcemapPlugin ? sourcemapOutput : '',
|
sourcemapOutput: sourcemap || sourcemapPlugin ? sourcemapOutput : '',
|
||||||
);
|
disableHermes,
|
||||||
|
cli: {
|
||||||
|
taro,
|
||||||
|
expo,
|
||||||
|
rncli,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await pack(path.resolve(intermediaDir), realOutput);
|
await pack(path.resolve(intermediaDir), realOutput);
|
||||||
|
|
20
src/index.ts
20
src/index.ts
@@ -2,8 +2,26 @@
|
|||||||
|
|
||||||
import { loadSession } from './api';
|
import { loadSession } from './api';
|
||||||
import updateNotifier from 'update-notifier';
|
import updateNotifier from 'update-notifier';
|
||||||
import { printVersionCommand } from './utils/index.js';
|
import { printVersionCommand } from './utils';
|
||||||
import pkg from '../package.json';
|
import pkg from '../package.json';
|
||||||
|
import path from 'node:path';
|
||||||
|
import i18next from 'i18next';
|
||||||
|
import en from './locales/en';
|
||||||
|
import zh from './locales/zh';
|
||||||
|
|
||||||
|
const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
|
||||||
|
| 'cresc'
|
||||||
|
| 'pushy';
|
||||||
|
global.IS_CRESC = scriptName === 'cresc';
|
||||||
|
|
||||||
|
i18next.init({
|
||||||
|
lng: global.IS_CRESC ? 'en' : 'zh',
|
||||||
|
// debug: process.env.NODE_ENV !== 'production',
|
||||||
|
resources: {
|
||||||
|
en,
|
||||||
|
zh,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
updateNotifier({ pkg }).notify({
|
updateNotifier({ pkg }).notify({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
|
1
src/locales/en.ts
Normal file
1
src/locales/en.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export default {};
|
1
src/locales/zh.ts
Normal file
1
src/locales/zh.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export default {};
|
@@ -1,6 +1,7 @@
|
|||||||
declare global {
|
declare global {
|
||||||
var NO_INTERACTIVE: boolean;
|
var NO_INTERACTIVE: boolean;
|
||||||
var USE_ACC_OSS: boolean;
|
var USE_ACC_OSS: boolean;
|
||||||
|
var IS_CRESC: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Session {
|
export interface Session {
|
||||||
|
@@ -42,7 +42,7 @@ class Zip {
|
|||||||
regex = decodeNullUnicode(regex);
|
regex = decodeNullUnicode(regex);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.unzip.getBuffer([regex], { type }, (err, buffers) => {
|
this.unzip.getBuffer([regex], { type }, (err, buffers) => {
|
||||||
console.log(buffers);
|
// console.log(buffers);
|
||||||
err ? reject(err) : resolve(buffers[regex]);
|
err ? reject(err) : resolve(buffers[regex]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -55,7 +55,7 @@ export function getRNVersion() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getApkInfo(fn) {
|
export async function getApkInfo(fn: string) {
|
||||||
const appInfoParser = new AppInfoParser(fn);
|
const appInfoParser = new AppInfoParser(fn);
|
||||||
const bundleFile = await appInfoParser.parser.getEntry(
|
const bundleFile = await appInfoParser.parser.getEntry(
|
||||||
/assets\/index.android.bundle/,
|
/assets\/index.android.bundle/,
|
||||||
|
Reference in New Issue
Block a user