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

update i18n

This commit is contained in:
sunnylqm
2025-03-25 09:36:58 +08:00
parent 328b1f5447
commit 3f1b43e38e
4 changed files with 49 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update-cli",
"version": "1.42.1",
"version": "1.42.2",
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
"main": "index.js",
"bin": {

View File

@@ -4,16 +4,14 @@ import Table from 'tty-table';
import { post, get, doDelete } from './api';
import type { Platform } from './types';
import { t } from './utils/i18n';
const validPlatforms = ['ios', 'android', 'harmony'];
const validPlatforms = {
ios: 1,
android: 1,
harmony: 1,
};
export function checkPlatform(platform: Platform) {
if (!validPlatforms[platform]) {
throw new Error(`无法识别的平台 '${platform}'`);
if (!validPlatforms.includes(platform)) {
throw new Error(t('unsupportedPlatform', { platform }));
}
return platform;
}
@@ -22,27 +20,23 @@ export function getSelectedApp(platform: Platform) {
checkPlatform(platform);
if (!fs.existsSync('update.json')) {
throw new Error(
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
);
throw new Error(t('appNotSelected', { platform }));
}
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
if (!updateInfo[platform]) {
throw new Error(
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
);
throw new Error(t('appNotSelected', { platform }));
}
return updateInfo[platform];
}
export async function listApp(platform: Platform) {
export async function listApp(platform: Platform | '' = '') {
const { data } = await get('/app/list');
const list = platform ? data.filter((v) => v.platform === platform) : data;
const header = [
{ value: '应用 id' },
{ value: '应用名称' },
{ value: '平台' },
{ value: t('appId') },
{ value: t('appName') },
{ value: t('platform') },
];
const rows = [];
for (const app of list) {
@@ -51,11 +45,7 @@ export async function listApp(platform: Platform) {
console.log(Table(header, rows).render());
if (platform) {
console.log(`\${list.length} ${platform} 个应用`);
} else {
console.log(`\${list.length} 个应用`);
}
console.log(`\n${t('totalApps', { count: list.length, platform })}`);
return list;
}
@@ -63,7 +53,7 @@ export async function chooseApp(platform: Platform) {
const list = await listApp(platform);
while (true) {
const id = await question('输入应用 id:');
const id = await question(t('enterAppIdQuestion'));
const app = list.find((v) => v.id === Number(id));
if (app) {
return app;
@@ -77,13 +67,13 @@ export const commands = {
}: {
options: { name: string; downloadUrl: string; platform: Platform };
}) {
const name = options.name || (await question('应用名称:'));
const name = options.name || (await question(t('appNameQuestion')));
const { downloadUrl } = options;
const platform = checkPlatform(
options.platform || (await question('平台(ios/android/harmony):')),
options.platform || (await question(t('platformQuestion'))),
);
const { id } = await post('/app/create', { name, platform, downloadUrl });
console.log(`已成功创建应用id: ${id}`);
console.log(t('createAppSuccess', { id }));
await this.selectApp({
args: [id],
options: { platform },
@@ -93,10 +83,10 @@ export const commands = {
const { platform } = options;
const id = args[0] || chooseApp(platform);
if (!id) {
console.log('已取消');
console.log(t('cancelled'));
}
await doDelete(`/app/${id}`);
console.log('操作成功');
console.log(t('operationSuccess'));
},
apps: async ({ options }: { options: { platform: Platform } }) => {
const { platform } = options;
@@ -104,7 +94,7 @@ export const commands = {
},
selectApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
const platform = checkPlatform(
options.platform || (await question('平台(ios/android/harmony):')),
options.platform || (await question(t('platformQuestion'))),
);
const id = args[0]
? Number.parseInt(args[0])
@@ -115,9 +105,7 @@ export const commands = {
try {
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
} catch (e) {
console.error(
'Failed to parse file `update.json`. Try to remove it manually.',
);
console.error(t('failedToParseUpdateJson'));
throw e;
}
}

View File

@@ -25,4 +25,18 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
latestVersionTag: '(latest: {{version}})',
rnuVersionNotFound:
'react-native-update: Cannot get the version number. Please run the command in the project directory',
unsupportedPlatform: 'Unsupported platform `{{platform}}`',
appId: 'App ID',
appName: 'App Name',
platform: 'Platform',
totalApps: 'Total {{count}} apps',
appNotSelected:
'App not selected. run `cresc selectApp --platform {{platform}}` first!',
enterAppIdQuestion: 'Enter AppId:',
appNameQuestion: 'App Name:',
platformQuestion: 'Platform(ios/android/harmony):',
createAppSuccess: 'App created successfully (id: {{id}})',
cancelled: 'Cancelled',
operationSuccess: 'Operation successful',
failedToParseUpdateJson: 'Failed to parse file `update.json`. Try to remove it manually.',
};

View File

@@ -23,4 +23,18 @@ export default {
latestVersionTag: '(最新:{{version}}',
rnuVersionNotFound:
'react-native-update: 无法获取版本号。请在项目目录中运行命令',
unsupportedPlatform: '无法识别的平台 `{{platform}}`',
appId: '应用 id',
appName: '应用名称',
platform: '平台',
totalApps: '共 {{count}} 个{{platform}}应用',
appNotSelected:
'尚未选择应用。请先运行 `pushy selectApp --platform {{platform}}` 来选择应用',
enterAppIdQuestion: '输入应用 id:',
appNameQuestion: '应用名称:',
platformQuestion: '平台(ios/android/harmony):',
createAppSuccess: '已成功创建应用id: {{id}}',
cancelled: '已取消',
operationSuccess: '操作成功',
failedToParseUpdateJson: '无法解析文件 `update.json`。请手动删除它。',
};