1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-09-16 09:41:38 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
sunnylqm
2025-03-10 22:24:22 +08:00
parent f32b201778
commit a1231f6a73
5 changed files with 35 additions and 80 deletions

View File

@@ -1,5 +1,5 @@
import path from 'node:path';
import { getRNVersion, translateOptions } from './utils';
import { translateOptions } from './utils';
import * as fs from 'fs-extra';
import { ZipFile } from 'yazl';
import { open as openZipFile } from 'yauzl';
@@ -10,6 +10,7 @@ import semverSatisfies from 'semver/functions/satisfies';
const g2js = require('gradle-to-js/lib/parser');
import os from 'node:os';
const properties = require('properties');
import { depVersions } from './utils/dep-versions';
let bsdiff;
let hdiff;
@@ -82,11 +83,13 @@ async function runReactNativeBundleCommand({
paths: [process.cwd()],
});
const expoCliVersion = JSON.parse(
fs.readFileSync(
require.resolve('@expo/cli/package.json', {
paths: [process.cwd()],
}),
).toString(),
fs
.readFileSync(
require.resolve('@expo/cli/package.json', {
paths: [process.cwd()],
}),
)
.toString(),
).version;
// expo cli 0.10.17 (expo 49) 开始支持 bundle:embed
if (semverSatisfies(expoCliVersion, '>= 0.10.17')) {
@@ -175,19 +178,11 @@ async function runReactNativeBundleCommand({
platform,
'--reset-cache',
]);
if (cli.taro) {
reactNativeBundleArgs.push(...[
'--type',
'rn',
])
reactNativeBundleArgs.push(...['--type', 'rn']);
} else {
reactNativeBundleArgs.push(...[
'--dev',
dev,
'--entry-file',
entryFile,
])
reactNativeBundleArgs.push(...['--dev', dev, '--entry-file', entryFile]);
}
if (sourcemapOutput) {
@@ -927,9 +922,7 @@ export const commands = {
throw new Error('Platform must be specified.');
}
const { version, major, minor } = getRNVersion();
console.log(`Bundling with react-native: ${version}`);
console.log(`Bundling with react-native: ${depVersions['react-native']}`);
await runReactNativeBundleCommand({
bundleName,

View File

@@ -5,6 +5,7 @@ import { checkPlatform, getSelectedApp } from './app';
import { getApkInfo, getIpaInfo, getAppInfo } from './utils';
import Table from 'tty-table';
import { depVersions } from 'utils/dep-versions';
export async function listPackage(appId: string) {
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
@@ -79,6 +80,7 @@ export const commands = {
name: versionName,
hash,
buildTime,
deps: depVersions,
});
saveToLocal(fn, `${appId}/package/${id}.ipa`);
console.log(
@@ -116,6 +118,7 @@ export const commands = {
name: versionName,
hash,
buildTime,
deps: depVersions,
});
saveToLocal(fn, `${appId}/package/${id}.apk`);
console.log(
@@ -153,6 +156,7 @@ export const commands = {
name: versionName,
hash,
buildTime,
deps: depVersions,
});
saveToLocal(fn, `${appId}/package/${id}.app`);
console.log(

View File

@@ -1,34 +1,17 @@
import fs from 'node:fs';
import path from 'node:path';
import currentPackage from '../../package.json';
const packages = fs.readdirSync(path.join(__dirname, 'node_modules'));
const exclude = ['.bin', '.cache'];
const depKeys = Object.keys(currentPackage.dependencies);
const devDepKeys = Object.keys(currentPackage.devDependencies);
const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
const versions = {};
export const depVersions: Record<string, string> = {};
for (const package of dedupedDeps) {
for (const dep of dedupedDeps) {
try {
const packageDir = path.resolve(__dirname, 'node_modules', current);
const { name, version } = require(`${packageDir}/package.json`);
if (depKeys.includes(name)) {
return Object.assign(acc, {
dependencies: Object.assign(acc.dependencies, { [name]: version }),
});
} else {
return Object.assign(acc, {
devDependencies: Object.assign(acc.devDependencies, {
[name]: version,
}),
});
}
} catch (e) {
// noop
console.log(e);
return acc;
}
const packageJsonPath = require.resolve(`${dep}/package.json`, {
paths: [process.cwd()],
});
const version = require(packageJsonPath).version;
depVersions[dep] = version;
} catch (e) {}
}

View File

@@ -10,6 +10,7 @@ import { checkPlugins } from './check-plugin';
import { read } from 'read';
import { tempDir } from './constants';
import { depVersions } from './dep-versions';
export async function question(query: string, password?: boolean) {
if (NO_INTERACTIVE) {
@@ -38,26 +39,6 @@ export function translateOptions(options: Record<string, string>) {
return ret;
}
export function getRNVersion() {
const version = JSON.parse(
fs
.readFileSync(
require.resolve('react-native/package.json', {
paths: [process.cwd()],
}),
)
.toString(),
).version;
const [, major, minor] = /^(\d+)\.(\d+)\./.exec(version) || [];
return {
version,
major: Number(major),
minor: Number(minor),
};
}
export async function getApkInfo(fn: string) {
const appInfoParser = new AppInfoParser(fn);
const bundleFile = await appInfoParser.parser.getEntry(
@@ -198,21 +179,11 @@ export async function printVersionCommand() {
`react-native-update-cli: ${pkg.version}${latestPushyCliVersion}`,
);
let pushyVersion = '';
try {
const PACKAGE_JSON_PATH = require.resolve(
'react-native-update/package.json',
{
paths: [process.cwd()],
},
);
pushyVersion = require(PACKAGE_JSON_PATH).version;
latestPushyVersion = latestPushyVersion
? ` (最新:${chalk.green(latestPushyVersion)}`
: '';
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
} catch (e) {
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
}
pushyVersion = depVersions['react-native-update'];
latestPushyVersion = latestPushyVersion
? ` (最新:${chalk.green(latestPushyVersion)}`
: '';
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
if (pushyVersion) {
if (semverSatisfies(pushyVersion, '<8.5.2')) {
console.warn(
@@ -229,6 +200,8 @@ export async function printVersionCommand() {
'当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10',
);
}
} else {
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
}
}

View File

@@ -4,6 +4,7 @@ import { question, saveToLocal } from './utils';
import { checkPlatform, getSelectedApp } from './app';
import { choosePackage } from './package';
import { compare } from 'compare-versions';
import { depVersions } from 'utils/dep-versions';
async function showVersion(appId: string, offset: number) {
const { data, count } = await get(`/app/${appId}/version/list`);
@@ -103,6 +104,7 @@ export const commands = {
hash,
description: description || (await question('输入版本描述:')),
metaInfo: metaInfo || (await question('输入自定义的 meta info:')),
deps: depVersions,
});
// TODO local diff
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);