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

Compare commits

..

12 Commits

Author SHA1 Message Date
Sunny Luo
3987a5191f Update publish.yml 2024-12-26 15:41:57 +08:00
Sunny Luo
9903fb97e4 bump 2024-12-26 15:40:05 +08:00
Sunny Luo
834c0bb351 Create lint.yml 2024-12-26 14:57:21 +08:00
Sunny Luo
fa8ba44bfa Create publish.yml 2024-12-26 14:56:49 +08:00
Sunny Luo
6e4e89428c Merge pull request #5 from bozaigao/master
适配鸿蒙
2024-12-26 12:14:14 +08:00
HeYanbo
e018761fc8 init 2024-12-25 23:38:29 +08:00
sunny.luo
6534379d81 use expo cli if available 2024-12-11 17:23:28 +08:00
sunny.luo
bb777bf973 update 2024-12-02 16:32:34 +08:00
sunny.luo
ea05d4ab66 fix chalk 2024-11-25 10:51:35 +08:00
sunny.luo
a259ff671d check latest version 2024-11-24 11:51:55 +08:00
sunny.luo
3f68fa0f11 compose sourcemap 2024-11-19 23:28:54 +08:00
sunnylqm
fa750ba157 update 2024-11-16 18:54:34 +08:00
10 changed files with 313 additions and 2839 deletions

47
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
name: lint
on:
pull_request:
branches:
- master
push:
branches:
- master
# Cancel a currently running workflow from the same PR/branch/tag
# when a new workflow is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Install Dependency
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: '--max_old_space_size=4096'
run: bun install --frozen-lockfile
- name: Run lint
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_OPTIONS: '--max_old_space_size=4096'
run: bun lint

22
.github/workflows/publish.yml vendored Normal file
View File

@@ -0,0 +1,22 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: bun install --frozen-lockfile
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
registry = "https://registry.npmjs.org"

BIN
bun.lockb

Binary file not shown.

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

@@ -1,6 +1,6 @@
{
"name": "react-native-update-cli",
"version": "1.32.3",
"version": "1.36.0",
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
"main": "index.js",
"bin": {
@@ -32,9 +32,11 @@
},
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
"dependencies": {
"@badisi/latest-version": "^7.0.10",
"bplist-parser": "^0.3.2",
"bytebuffer": "^5.0.1",
"cgbi-to-png": "^1.0.7",
"chalk": "4",
"cli-arguments": "^0.2.1",
"commander": "^12.1.0",
"compare-versions": "^6.1.1",
@@ -53,17 +55,17 @@
"tty-table": "4.2",
"update-notifier": "^5.1.0",
"yauzl": "^3.2.0",
"yazl": "3.3.0"
"yazl": "3.3.1"
},
"engines": {
"node": ">= 10"
},
"devDependencies": {
"@swc/cli": "^0.5.0",
"@swc/core": "^1.9.2",
"@types/node": "^22.9.0",
"oxlint": "^0.11.1",
"typescript": "^5.6.3"
"@swc/cli": "^0.5.1",
"@swc/core": "^1.9.3",
"@types/node": "^22.9.3",
"oxlint": "^0.13.1",
"typescript": "^5.7.2"
},
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
"packageManager": "yarn@1.22.22"
}

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 {
@@ -53,57 +54,70 @@ async function runReactNativeBundleCommand(
let cliPath;
try {
// rn >= 0.75
cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
paths: [process.cwd()],
});
} catch (e) {
// rn < 0.75
cliPath = require.resolve('react-native/local-cli/cli.js', {
paths: [process.cwd()],
});
}
let usingExpo = false;
try {
require.resolve('expo-router', {
paths: [process.cwd()],
});
console.log(`expo-router detected, will use @expo/cli to bundle.\n`);
// if using expo-router, use expo-cli
cliPath = require.resolve('@expo/cli', {
paths: [process.cwd()],
});
usingExpo = true;
} catch (e) {}
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',
]);
if (sourcemapOutput) {
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
} catch (e) {
try {
// rn >= 0.75
cliPath = require.resolve('@react-native-community/cli/build/bin.js', {
paths: [process.cwd()],
});
} catch (e) {
// rn < 0.75
cliPath = require.resolve('react-native/local-cli/cli.js', {
paths: [process.cwd()],
});
}
}
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 (config) {
reactNativeBundleArgs.push('--config', config);
if (sourcemapOutput) {
reactNativeBundleArgs.push('--sourcemap-output', sourcemapOutput);
}
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(' ')}`,
@@ -152,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(
@@ -166,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';
@@ -226,6 +257,10 @@ async function compileHermesByteCode(
'-O',
];
if (sourcemapOutput) {
fs.copyFileSync(
sourcemapOutput,
path.join(outputFolder, bundleName + '.txt.map'),
);
args.push('-output-source-map');
}
console.log(
@@ -234,6 +269,28 @@ async function compileHermesByteCode(
spawnSync(hermesCommand, args, {
stdio: 'ignore',
});
if (sourcemapOutput) {
const composerPath =
'node_modules/react-native/scripts/compose-source-maps.js';
if (!fs.existsSync(composerPath)) {
return;
}
console.log(`Composing source map`);
spawnSync(
'node',
[
composerPath,
path.join(outputFolder, bundleName + '.txt.map'),
path.join(outputFolder, bundleName + '.map'),
'-o',
sourcemapOutput,
],
{
stdio: 'ignore',
},
);
}
fs.removeSync(path.join(outputFolder, bundleName + '.txt.map'));
}
async function pack(dir, output) {
@@ -315,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));
}
@@ -377,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];
@@ -499,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] = '';
@@ -531,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();
});
});
@@ -680,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,

View File

@@ -5,9 +5,13 @@ import updateNotifier from 'update-notifier';
import { printVersionCommand } from './utils/index.js';
import pkg from '../package.json';
updateNotifier({ pkg }).notify({ isGlobal: true });
updateNotifier({ pkg }).notify({
isGlobal: true,
message:
'建议运行 `{updateCommand}` 来更新命令行工具以获得功能、性能和安全性的持续改进',
});
function printUsage({ args }) {
function printUsage() {
// const commandName = args[0];
// TODO: print usage of commandName, or print global usage.
@@ -27,8 +31,8 @@ const commands = {
help: printUsage,
};
function run() {
printVersionCommand();
async function run() {
await printVersionCommand();
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
process.exit();
}

View File

@@ -4,6 +4,8 @@ import path from 'node:path';
import pkg from '../../package.json';
import AppInfoParser from './app-info-parser';
import semverSatisfies from 'semver/functions/satisfies';
import chalk from 'chalk';
import latestVersion from '@badisi/latest-version';
import { read } from 'read';
@@ -131,8 +133,23 @@ export function saveToLocal(originPath, destName) {
// fs.copyFileSync(originPath, destPath);
}
export function printVersionCommand() {
console.log('react-native-update-cli: ' + pkg.version);
async function getLatestVersion(pkgName) {
return Promise.race([
latestVersion(pkgName)
.then((p) => p.latest)
.catch(() => ''),
new Promise((resolve) => setTimeout(() => resolve(''), 2000)),
]);
}
export async function printVersionCommand() {
let latestPushyCliVersion = await getLatestVersion('react-native-update-cli');
latestPushyCliVersion = latestPushyCliVersion
? ` (最新:${chalk.green(latestPushyCliVersion)}`
: '';
console.log(
`react-native-update-cli: ${pkg.version}${latestPushyCliVersion}`,
);
let pushyVersion = '';
try {
const PACKAGE_JSON_PATH = require.resolve(
@@ -142,21 +159,29 @@ export function printVersionCommand() {
},
);
pushyVersion = require(PACKAGE_JSON_PATH).version;
console.log('react-native-update: ' + pushyVersion);
let latestPushyVersion = await getLatestVersion('react-native-update');
latestPushyVersion = latestPushyVersion
? ` (最新:${chalk.green(latestPushyVersion)}`
: '';
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
} catch (e) {
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
}
if (pushyVersion) {
if (semverSatisfies(pushyVersion, '<8.5.1')) {
if (semverSatisfies(pushyVersion, '<8.5.2')) {
console.warn(
`当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
);
} else if (semverSatisfies(pushyVersion, '9.0.0 - 9.2.0')) {
} else if (semverSatisfies(pushyVersion, '9.0.0 - 9.2.1')) {
console.warn(
`当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动): npm i react-native-update@9 .
`当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更: npm i react-native-update@9 .
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
);
} else if (semverSatisfies(pushyVersion, '10.0.0 - 10.17.0')) {
console.warn(
`当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10`,
);
}
}
}

2761
yarn.lock

File diff suppressed because it is too large Load Diff