mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-17 18:06:10 +08:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6db237fc8c | ||
![]() |
bd7d78e7ac | ||
![]() |
91a602979d | ||
![]() |
2cfe451db5 | ||
![]() |
c7d0aadbf2 | ||
![]() |
2e37d6f1c7 | ||
![]() |
6e7d5de82e | ||
![]() |
3266f09644 | ||
![]() |
848f528625 |
47
cli.json
47
cli.json
@@ -57,6 +57,27 @@
|
||||
},
|
||||
"metaInfo": {
|
||||
"hasValue": true
|
||||
},
|
||||
"packageId": {
|
||||
"hasValue": true
|
||||
},
|
||||
"packageVersion": {
|
||||
"hasValue": true
|
||||
},
|
||||
"minPackageVersion": {
|
||||
"hasValue": true
|
||||
},
|
||||
"maxPackageVersion": {
|
||||
"hasValue": true
|
||||
},
|
||||
"packageVersionRange": {
|
||||
"hasValue": true
|
||||
},
|
||||
"rollout": {
|
||||
"hasValue": true
|
||||
},
|
||||
"dryRun": {
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -87,11 +108,14 @@
|
||||
"maxPackageVersion": {
|
||||
"hasValue": true
|
||||
},
|
||||
"semverRange": {
|
||||
"packageVersionRange": {
|
||||
"hasValue": true
|
||||
},
|
||||
"rollout": {
|
||||
"hasValue": true
|
||||
},
|
||||
"dryRun": {
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -172,6 +196,27 @@
|
||||
"metaInfo": {
|
||||
"hasValue": true,
|
||||
"description": "Meta information for publishing"
|
||||
},
|
||||
"packageId": {
|
||||
"hasValue": true
|
||||
},
|
||||
"packageVersion": {
|
||||
"hasValue": true
|
||||
},
|
||||
"minPackageVersion": {
|
||||
"hasValue": true
|
||||
},
|
||||
"maxPackageVersion": {
|
||||
"hasValue": true
|
||||
},
|
||||
"packageVersionRange": {
|
||||
"hasValue": true
|
||||
},
|
||||
"rollout": {
|
||||
"hasValue": true
|
||||
},
|
||||
"dryRun": {
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update-cli",
|
||||
"version": "1.45.2",
|
||||
"version": "1.46.2",
|
||||
"description": "command line tool for react-native-update (remote updates for react native)",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
|
@@ -66,7 +66,7 @@ export async function chooseApp(platform: Platform) {
|
||||
}
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
export const appCommands = {
|
||||
createApp: async function ({
|
||||
options,
|
||||
}: {
|
||||
|
@@ -19,7 +19,7 @@ import { t } from './utils/i18n';
|
||||
import { tempDir } from './utils/constants';
|
||||
import { checkLockFiles } from './utils/check-lockfile';
|
||||
import { addGitIgnore } from './utils/add-gitignore';
|
||||
import { commands as versionCommands } from './versions';
|
||||
import { versionCommands } from './versions';
|
||||
|
||||
type Diff = (oldSource?: Buffer, newSource?: Buffer) => Buffer;
|
||||
|
||||
@@ -149,6 +149,14 @@ async function runReactNativeBundleCommand({
|
||||
const bundleParams = await checkPlugins();
|
||||
const isSentry = bundleParams.sentry;
|
||||
|
||||
if (isSentry) {
|
||||
if (platform === 'ios') {
|
||||
process.env.SENTRY_PROPERTIES = 'ios/sentry.properties';
|
||||
} else if (platform === 'android') {
|
||||
process.env.SENTRY_PROPERTIES = 'android/sentry.properties';
|
||||
}
|
||||
}
|
||||
|
||||
let bundleCommand = 'bundle';
|
||||
if (usingExpo) {
|
||||
bundleCommand = 'export:embed';
|
||||
@@ -280,9 +288,22 @@ async function copyHarmonyBundle(outputFolder: string) {
|
||||
}
|
||||
await fs.remove(path.join(harmonyRawPath, 'update.json'));
|
||||
await fs.copy('update.json', path.join(harmonyRawPath, 'update.json'));
|
||||
|
||||
await fs.ensureDir(outputFolder);
|
||||
await fs.copy(harmonyRawPath, outputFolder);
|
||||
|
||||
const files = await fs.readdir(harmonyRawPath);
|
||||
for (const file of files) {
|
||||
if (file !== 'update.json' && file !== 'meta.json') {
|
||||
const sourcePath = path.join(harmonyRawPath, file);
|
||||
const destPath = path.join(outputFolder, file);
|
||||
const stat = await fs.stat(sourcePath);
|
||||
|
||||
if (stat.isFile()) {
|
||||
await fs.copy(sourcePath, destPath);
|
||||
} else if (stat.isDirectory()) {
|
||||
await fs.copy(sourcePath, destPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error(t('copyHarmonyBundleError', { error }));
|
||||
throw new Error(t('copyFileFailed', { error: error.message }));
|
||||
@@ -900,7 +921,7 @@ function diffArgsCheck(args: string[], options: any, diffFn: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
export const bundleCommands = {
|
||||
bundle: async ({ options }) => {
|
||||
const platform = await getPlatform(options.platform);
|
||||
|
||||
@@ -918,6 +939,13 @@ export const commands = {
|
||||
name,
|
||||
description,
|
||||
metaInfo,
|
||||
packageId,
|
||||
packageVersion,
|
||||
minPackageVersion,
|
||||
maxPackageVersion,
|
||||
packageVersionRange,
|
||||
rollout,
|
||||
dryRun,
|
||||
} = translateOptions({
|
||||
...options,
|
||||
tempDir,
|
||||
@@ -966,6 +994,13 @@ export const commands = {
|
||||
name,
|
||||
description,
|
||||
metaInfo,
|
||||
packageId,
|
||||
packageVersion,
|
||||
minPackageVersion,
|
||||
maxPackageVersion,
|
||||
packageVersionRange,
|
||||
rollout,
|
||||
dryRun: Boolean(dryRun),
|
||||
},
|
||||
});
|
||||
|
||||
|
15
src/index.ts
15
src/index.ts
@@ -3,6 +3,11 @@
|
||||
import { loadSession } from './api';
|
||||
import { printVersionCommand } from './utils';
|
||||
import { t } from './utils/i18n';
|
||||
import { bundleCommands } from './bundle';
|
||||
import { versionCommands } from './versions';
|
||||
import { userCommands } from './user';
|
||||
import { appCommands } from './app';
|
||||
import { packageCommands } from './package';
|
||||
|
||||
function printUsage() {
|
||||
// const commandName = args[0];
|
||||
@@ -15,11 +20,11 @@ function printUsage() {
|
||||
}
|
||||
|
||||
const commands = {
|
||||
...require('./user').commands,
|
||||
...require('./bundle').commands,
|
||||
...require('./app').commands,
|
||||
...require('./package').commands,
|
||||
...require('./versions').commands,
|
||||
...userCommands,
|
||||
...bundleCommands,
|
||||
...appCommands,
|
||||
...packageCommands,
|
||||
...versionCommands,
|
||||
help: printUsage,
|
||||
};
|
||||
|
||||
|
@@ -101,7 +101,7 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
||||
rnuVersionNotFound:
|
||||
'react-native-update: Cannot get the version number. Please run the command in the project directory',
|
||||
rolloutConfigSet:
|
||||
'Set {{rollout}}% rollout for version {{version}} on native version(s) {{versions}}',
|
||||
'Set {{rollout}}% rollout for OTA update {{version}} on native version(s) {{versions}}',
|
||||
rolloutRangeError: 'rollout must be an integer between 1-100',
|
||||
runningHermesc: 'Running hermesc: {{- command}} {{- args}}',
|
||||
sentryCliNotFound:
|
||||
@@ -122,11 +122,12 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
||||
usageUploadApp: 'Usage: cresc uploadApp <app file>',
|
||||
usageUploadIpa: 'Usage: cresc uploadIpa <ipa file>',
|
||||
versionBind:
|
||||
'Bound version {{version}} to native version {{nativeVersion}} (id: {{id}})',
|
||||
'Bound hot update {{version}} to native version {{nativeVersion}} (id: {{id}})',
|
||||
welcomeMessage: 'Welcome to Cresc hot update service, {{name}}.',
|
||||
versionNameQuestion: 'Enter version name:',
|
||||
versionDescriptionQuestion: 'Enter version description:',
|
||||
versionNameQuestion: 'Enter OTA update name:',
|
||||
versionDescriptionQuestion: 'Enter OTA update description:',
|
||||
versionMetaInfoQuestion: 'Enter custom meta info:',
|
||||
updateNativePackageQuestion: 'Bind to native package now?(Y/N)',
|
||||
unnamed: '(Unnamed)',
|
||||
dryRun: 'Below is the dry-run result, no actual operation will be performed:',
|
||||
};
|
||||
|
@@ -96,7 +96,7 @@ export default {
|
||||
rnuVersionNotFound:
|
||||
'react-native-update: 无法获取版本号。请在项目目录中运行命令',
|
||||
rolloutConfigSet:
|
||||
'已在原生版本 {{versions}} 上设置灰度发布 {{rollout}}% 热更版本 {{version}}',
|
||||
'已在原生版本 {{versions}} 上设置灰度发布 {{rollout}}% 热更包 {{version}}',
|
||||
rolloutRangeError: 'rollout 必须是 1-100 的整数',
|
||||
runningHermesc: '运行 hermesc:{{- command}} {{- args}}',
|
||||
sentryCliNotFound: '无法找到 Sentry CLI 工具,请确保已正确安装 @sentry/cli',
|
||||
@@ -115,11 +115,12 @@ export default {
|
||||
usageUploadApp: '使用方法: pushy uploadApp app后缀文件',
|
||||
usageUploadIpa: '使用方法: pushy uploadIpa ipa后缀文件',
|
||||
versionBind:
|
||||
'已将热更版本 {{version}} 绑定到原生版本 {{nativeVersion}} (id: {{id}})',
|
||||
'已将热更包 {{version}} 绑定到原生版本 {{nativeVersion}} (id: {{id}})',
|
||||
welcomeMessage: '欢迎使用 pushy 热更新服务,{{name}}。',
|
||||
versionNameQuestion: '输入版本名称:',
|
||||
versionDescriptionQuestion: '输入版本描述:',
|
||||
versionMetaInfoQuestion: '输入自定义的 meta info:',
|
||||
updateNativePackageQuestion: '是否现在将此热更应用到原生包上?(Y/N)',
|
||||
unnamed: '(未命名)',
|
||||
dryRun: '以下是 dry-run 模拟运行结果,不会实际执行任何操作:',
|
||||
};
|
||||
|
@@ -2,7 +2,7 @@ import { get, getAllPackages, post, uploadFile } from './api';
|
||||
import { question, saveToLocal } from './utils';
|
||||
import { t } from './utils/i18n';
|
||||
|
||||
import { checkPlatform, getPlatform, getSelectedApp } from './app';
|
||||
import { getPlatform, getSelectedApp } from './app';
|
||||
|
||||
import { getApkInfo, getIpaInfo, getAppInfo } from './utils';
|
||||
import Table from 'tty-table';
|
||||
@@ -52,7 +52,7 @@ export async function choosePackage(appId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
export const packageCommands = {
|
||||
uploadIpa: async ({ args }: { args: string[] }) => {
|
||||
const fn = args[0];
|
||||
if (!fn || !fn.endsWith('.ipa')) {
|
||||
|
@@ -7,7 +7,7 @@ function md5(str: string) {
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
export const userCommands = {
|
||||
login: async ({ args }: { args: string[] }) => {
|
||||
const email = args[0] || (await question('email:'));
|
||||
const pwd = args[1] || (await question('password:', true));
|
||||
|
102
src/versions.ts
102
src/versions.ts
@@ -8,8 +8,10 @@ import { depVersions } from './utils/dep-versions';
|
||||
import { getCommitInfo } from './utils/git';
|
||||
import type { Package, Platform, Version } from 'types';
|
||||
import { satisfies } from 'compare-versions';
|
||||
import chalk from 'chalk';
|
||||
|
||||
interface CommandOptions {
|
||||
interface VersionCommandOptions {
|
||||
appId?: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
metaInfo?: string;
|
||||
@@ -19,8 +21,9 @@ interface CommandOptions {
|
||||
packageVersion?: string;
|
||||
minPackageVersion?: string;
|
||||
maxPackageVersion?: string;
|
||||
semverRange?: string;
|
||||
packageVersionRange?: string;
|
||||
rollout?: string;
|
||||
dryRun?: boolean;
|
||||
}
|
||||
|
||||
async function showVersion(appId: string, offset: number) {
|
||||
@@ -107,22 +110,29 @@ export const bindVersionToPackages = async ({
|
||||
versionId,
|
||||
pkgs,
|
||||
rollout,
|
||||
dryRun,
|
||||
}: {
|
||||
appId: string;
|
||||
versionId: string;
|
||||
pkgs: Package[];
|
||||
rollout?: number;
|
||||
dryRun?: boolean;
|
||||
}) => {
|
||||
if (dryRun) {
|
||||
console.log(chalk.yellow(t('dryRun')));
|
||||
}
|
||||
if (rollout !== undefined) {
|
||||
const rolloutConfig: Record<string, number> = {};
|
||||
for (const pkg of pkgs) {
|
||||
rolloutConfig[pkg.name] = rollout;
|
||||
}
|
||||
await put(`/app/${appId}/version/${versionId}`, {
|
||||
config: {
|
||||
rollout: rolloutConfig,
|
||||
},
|
||||
});
|
||||
if (!dryRun) {
|
||||
await put(`/app/${appId}/version/${versionId}`, {
|
||||
config: {
|
||||
rollout: rolloutConfig,
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log(
|
||||
`${t('rolloutConfigSet', {
|
||||
versions: pkgs.map((pkg: Package) => pkg.name).join(', '),
|
||||
@@ -131,9 +141,11 @@ export const bindVersionToPackages = async ({
|
||||
);
|
||||
}
|
||||
for (const pkg of pkgs) {
|
||||
await put(`/app/${appId}/package/${pkg.id}`, {
|
||||
versionId,
|
||||
});
|
||||
if (!dryRun) {
|
||||
await put(`/app/${appId}/package/${pkg.id}`, {
|
||||
versionId,
|
||||
});
|
||||
}
|
||||
console.log(
|
||||
`${t('versionBind', {
|
||||
version: versionId,
|
||||
@@ -145,13 +157,13 @@ export const bindVersionToPackages = async ({
|
||||
console.log(t('operationComplete', { count: pkgs.length }));
|
||||
};
|
||||
|
||||
export const commands = {
|
||||
export const versionCommands = {
|
||||
publish: async function ({
|
||||
args,
|
||||
options,
|
||||
}: {
|
||||
args: string[];
|
||||
options: CommandOptions;
|
||||
options: VersionCommandOptions;
|
||||
}) {
|
||||
const fn = args[0];
|
||||
const { name, description, metaInfo } = options;
|
||||
@@ -180,26 +192,52 @@ export const commands = {
|
||||
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
|
||||
console.log(t('packageUploadSuccess', { id }));
|
||||
|
||||
const v = await question(t('updateNativePackageQuestion'));
|
||||
if (v.toLowerCase() === 'y') {
|
||||
await this.update({ args: [], options: { versionId: id, platform } });
|
||||
const {
|
||||
packageId,
|
||||
packageVersion,
|
||||
packageVersionRange,
|
||||
minPackageVersion,
|
||||
maxPackageVersion,
|
||||
rollout,
|
||||
dryRun,
|
||||
} = options;
|
||||
|
||||
if (
|
||||
packageId ||
|
||||
packageVersion ||
|
||||
packageVersionRange ||
|
||||
minPackageVersion ||
|
||||
maxPackageVersion
|
||||
) {
|
||||
await this.update({
|
||||
options: {
|
||||
versionId: id,
|
||||
platform,
|
||||
packageId,
|
||||
packageVersion,
|
||||
packageVersionRange,
|
||||
minPackageVersion,
|
||||
maxPackageVersion,
|
||||
rollout,
|
||||
dryRun,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const q = await question(t('updateNativePackageQuestion'));
|
||||
if (q.toLowerCase() === 'y') {
|
||||
await this.update({ options: { versionId: id, platform } });
|
||||
}
|
||||
}
|
||||
return versionName;
|
||||
},
|
||||
versions: async ({ options }: { options: CommandOptions }) => {
|
||||
versions: async ({ options }: { options: VersionCommandOptions }) => {
|
||||
const platform = await getPlatform(options.platform);
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
await listVersions(appId);
|
||||
},
|
||||
update: async ({
|
||||
args,
|
||||
options,
|
||||
}: {
|
||||
args: string[];
|
||||
options: CommandOptions;
|
||||
}) => {
|
||||
update: async ({ options }: { options: VersionCommandOptions }) => {
|
||||
const platform = await getPlatform(options.platform);
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
const appId = options.appId || (await getSelectedApp(platform)).appId;
|
||||
let versionId = options.versionId || (await chooseVersion(appId)).id;
|
||||
if (versionId === 'null') {
|
||||
versionId = undefined;
|
||||
@@ -209,7 +247,7 @@ export const commands = {
|
||||
let pkgVersion = options.packageVersion;
|
||||
let minPkgVersion = options.minPackageVersion;
|
||||
let maxPkgVersion = options.maxPackageVersion;
|
||||
let semverRange = options.semverRange;
|
||||
let packageVersionRange = options.packageVersionRange;
|
||||
let rollout: number | undefined = undefined;
|
||||
|
||||
if (options.rollout !== undefined) {
|
||||
@@ -261,14 +299,14 @@ export const commands = {
|
||||
t('nativeVersionNotFoundMatch', { version: pkgVersion }),
|
||||
);
|
||||
}
|
||||
} else if (semverRange) {
|
||||
semverRange = semverRange.trim();
|
||||
} else if (packageVersionRange) {
|
||||
packageVersionRange = packageVersionRange.trim();
|
||||
pkgsToBind = allPkgs.filter((pkg: Package) =>
|
||||
satisfies(pkg.name, semverRange!),
|
||||
satisfies(pkg.name, packageVersionRange!),
|
||||
);
|
||||
if (pkgsToBind.length === 0) {
|
||||
throw new Error(
|
||||
t('nativeVersionNotFoundMatch', { version: semverRange }),
|
||||
t('nativeVersionNotFoundMatch', { version: packageVersionRange }),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -294,15 +332,13 @@ export const commands = {
|
||||
versionId,
|
||||
pkgs: pkgsToBind,
|
||||
rollout,
|
||||
dryRun: options.dryRun,
|
||||
});
|
||||
console.log(t('operationSuccess'));
|
||||
},
|
||||
updateVersionInfo: async ({
|
||||
args,
|
||||
options,
|
||||
}: {
|
||||
args: string[];
|
||||
options: CommandOptions;
|
||||
options: VersionCommandOptions;
|
||||
}) => {
|
||||
const platform = await getPlatform(options.platform);
|
||||
const { appId } = await getSelectedApp(platform);
|
||||
|
Reference in New Issue
Block a user