mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-11-22 16:26:10 +08:00
add deps
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { getRNVersion, translateOptions } from './utils';
|
import { translateOptions } from './utils';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
import { ZipFile } from 'yazl';
|
import { ZipFile } from 'yazl';
|
||||||
import { open as openZipFile } from 'yauzl';
|
import { open as openZipFile } from 'yauzl';
|
||||||
@@ -10,6 +10,7 @@ import semverSatisfies from 'semver/functions/satisfies';
|
|||||||
const g2js = require('gradle-to-js/lib/parser');
|
const g2js = require('gradle-to-js/lib/parser');
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
const properties = require('properties');
|
const properties = require('properties');
|
||||||
|
import { depVersions } from './utils/dep-versions';
|
||||||
|
|
||||||
let bsdiff;
|
let bsdiff;
|
||||||
let hdiff;
|
let hdiff;
|
||||||
@@ -82,11 +83,13 @@ async function runReactNativeBundleCommand({
|
|||||||
paths: [process.cwd()],
|
paths: [process.cwd()],
|
||||||
});
|
});
|
||||||
const expoCliVersion = JSON.parse(
|
const expoCliVersion = JSON.parse(
|
||||||
fs.readFileSync(
|
fs
|
||||||
require.resolve('@expo/cli/package.json', {
|
.readFileSync(
|
||||||
paths: [process.cwd()],
|
require.resolve('@expo/cli/package.json', {
|
||||||
}),
|
paths: [process.cwd()],
|
||||||
).toString(),
|
}),
|
||||||
|
)
|
||||||
|
.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')) {
|
||||||
@@ -177,17 +180,9 @@ async function runReactNativeBundleCommand({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (cli.taro) {
|
if (cli.taro) {
|
||||||
reactNativeBundleArgs.push(...[
|
reactNativeBundleArgs.push(...['--type', 'rn']);
|
||||||
'--type',
|
|
||||||
'rn',
|
|
||||||
])
|
|
||||||
} else {
|
} else {
|
||||||
reactNativeBundleArgs.push(...[
|
reactNativeBundleArgs.push(...['--dev', dev, '--entry-file', entryFile]);
|
||||||
'--dev',
|
|
||||||
dev,
|
|
||||||
'--entry-file',
|
|
||||||
entryFile,
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourcemapOutput) {
|
if (sourcemapOutput) {
|
||||||
@@ -927,9 +922,7 @@ export const commands = {
|
|||||||
throw new Error('Platform must be specified.');
|
throw new Error('Platform must be specified.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { version, major, minor } = getRNVersion();
|
console.log(`Bundling with react-native: ${depVersions['react-native']}`);
|
||||||
|
|
||||||
console.log(`Bundling with react-native: ${version}`);
|
|
||||||
|
|
||||||
await runReactNativeBundleCommand({
|
await runReactNativeBundleCommand({
|
||||||
bundleName,
|
bundleName,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { checkPlatform, getSelectedApp } from './app';
|
|||||||
|
|
||||||
import { getApkInfo, getIpaInfo, getAppInfo } from './utils';
|
import { getApkInfo, getIpaInfo, getAppInfo } from './utils';
|
||||||
import Table from 'tty-table';
|
import Table from 'tty-table';
|
||||||
|
import { depVersions } from 'utils/dep-versions';
|
||||||
|
|
||||||
export async function listPackage(appId: string) {
|
export async function listPackage(appId: string) {
|
||||||
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
const { data } = await get(`/app/${appId}/package/list?limit=1000`);
|
||||||
@@ -79,6 +80,7 @@ export const commands = {
|
|||||||
name: versionName,
|
name: versionName,
|
||||||
hash,
|
hash,
|
||||||
buildTime,
|
buildTime,
|
||||||
|
deps: depVersions,
|
||||||
});
|
});
|
||||||
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
saveToLocal(fn, `${appId}/package/${id}.ipa`);
|
||||||
console.log(
|
console.log(
|
||||||
@@ -116,6 +118,7 @@ export const commands = {
|
|||||||
name: versionName,
|
name: versionName,
|
||||||
hash,
|
hash,
|
||||||
buildTime,
|
buildTime,
|
||||||
|
deps: depVersions,
|
||||||
});
|
});
|
||||||
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
saveToLocal(fn, `${appId}/package/${id}.apk`);
|
||||||
console.log(
|
console.log(
|
||||||
@@ -153,6 +156,7 @@ export const commands = {
|
|||||||
name: versionName,
|
name: versionName,
|
||||||
hash,
|
hash,
|
||||||
buildTime,
|
buildTime,
|
||||||
|
deps: depVersions,
|
||||||
});
|
});
|
||||||
saveToLocal(fn, `${appId}/package/${id}.app`);
|
saveToLocal(fn, `${appId}/package/${id}.app`);
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@@ -1,34 +1,17 @@
|
|||||||
import fs from 'node:fs';
|
|
||||||
import path from 'node:path';
|
|
||||||
import currentPackage from '../../package.json';
|
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 depKeys = Object.keys(currentPackage.dependencies);
|
||||||
const devDepKeys = Object.keys(currentPackage.devDependencies);
|
const devDepKeys = Object.keys(currentPackage.devDependencies);
|
||||||
const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
|
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 {
|
try {
|
||||||
const packageDir = path.resolve(__dirname, 'node_modules', current);
|
const packageJsonPath = require.resolve(`${dep}/package.json`, {
|
||||||
const { name, version } = require(`${packageDir}/package.json`);
|
paths: [process.cwd()],
|
||||||
if (depKeys.includes(name)) {
|
});
|
||||||
return Object.assign(acc, {
|
const version = require(packageJsonPath).version;
|
||||||
dependencies: Object.assign(acc.dependencies, { [name]: version }),
|
depVersions[dep] = version;
|
||||||
});
|
} catch (e) {}
|
||||||
} else {
|
|
||||||
return Object.assign(acc, {
|
|
||||||
devDependencies: Object.assign(acc.devDependencies, {
|
|
||||||
[name]: version,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// noop
|
|
||||||
console.log(e);
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { checkPlugins } from './check-plugin';
|
|||||||
|
|
||||||
import { read } from 'read';
|
import { read } from 'read';
|
||||||
import { tempDir } from './constants';
|
import { tempDir } from './constants';
|
||||||
|
import { depVersions } from './dep-versions';
|
||||||
|
|
||||||
export async function question(query: string, password?: boolean) {
|
export async function question(query: string, password?: boolean) {
|
||||||
if (NO_INTERACTIVE) {
|
if (NO_INTERACTIVE) {
|
||||||
@@ -38,26 +39,6 @@ export function translateOptions(options: Record<string, string>) {
|
|||||||
return ret;
|
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) {
|
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(
|
||||||
@@ -198,21 +179,11 @@ export async function printVersionCommand() {
|
|||||||
`react-native-update-cli: ${pkg.version}${latestPushyCliVersion}`,
|
`react-native-update-cli: ${pkg.version}${latestPushyCliVersion}`,
|
||||||
);
|
);
|
||||||
let pushyVersion = '';
|
let pushyVersion = '';
|
||||||
try {
|
pushyVersion = depVersions['react-native-update'];
|
||||||
const PACKAGE_JSON_PATH = require.resolve(
|
latestPushyVersion = latestPushyVersion
|
||||||
'react-native-update/package.json',
|
? ` (最新:${chalk.green(latestPushyVersion)})`
|
||||||
{
|
: '';
|
||||||
paths: [process.cwd()],
|
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
|
||||||
},
|
|
||||||
);
|
|
||||||
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: 无法获取版本号,请在项目目录中运行命令');
|
|
||||||
}
|
|
||||||
if (pushyVersion) {
|
if (pushyVersion) {
|
||||||
if (semverSatisfies(pushyVersion, '<8.5.2')) {
|
if (semverSatisfies(pushyVersion, '<8.5.2')) {
|
||||||
console.warn(
|
console.warn(
|
||||||
@@ -229,6 +200,8 @@ export async function printVersionCommand() {
|
|||||||
'当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10',
|
'当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { question, saveToLocal } from './utils';
|
|||||||
import { checkPlatform, getSelectedApp } from './app';
|
import { checkPlatform, getSelectedApp } from './app';
|
||||||
import { choosePackage } from './package';
|
import { choosePackage } from './package';
|
||||||
import { compare } from 'compare-versions';
|
import { compare } from 'compare-versions';
|
||||||
|
import { depVersions } from 'utils/dep-versions';
|
||||||
|
|
||||||
async function showVersion(appId: string, offset: number) {
|
async function showVersion(appId: string, offset: number) {
|
||||||
const { data, count } = await get(`/app/${appId}/version/list`);
|
const { data, count } = await get(`/app/${appId}/version/list`);
|
||||||
@@ -103,6 +104,7 @@ export const commands = {
|
|||||||
hash,
|
hash,
|
||||||
description: description || (await question('输入版本描述:')),
|
description: description || (await question('输入版本描述:')),
|
||||||
metaInfo: metaInfo || (await question('输入自定义的 meta info:')),
|
metaInfo: metaInfo || (await question('输入自定义的 meta info:')),
|
||||||
|
deps: depVersions,
|
||||||
});
|
});
|
||||||
// TODO local diff
|
// TODO local diff
|
||||||
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
||||||
|
|||||||
Reference in New Issue
Block a user