mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 09:41:38 +08:00
update i18n
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-update-cli",
|
"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.",
|
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
52
src/app.ts
52
src/app.ts
@@ -4,16 +4,14 @@ import Table from 'tty-table';
|
|||||||
|
|
||||||
import { post, get, doDelete } from './api';
|
import { post, get, doDelete } from './api';
|
||||||
import type { Platform } from './types';
|
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) {
|
export function checkPlatform(platform: Platform) {
|
||||||
if (!validPlatforms[platform]) {
|
if (!validPlatforms.includes(platform)) {
|
||||||
throw new Error(`无法识别的平台 '${platform}'`);
|
throw new Error(t('unsupportedPlatform', { platform }));
|
||||||
}
|
}
|
||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
@@ -22,27 +20,23 @@ export function getSelectedApp(platform: Platform) {
|
|||||||
checkPlatform(platform);
|
checkPlatform(platform);
|
||||||
|
|
||||||
if (!fs.existsSync('update.json')) {
|
if (!fs.existsSync('update.json')) {
|
||||||
throw new Error(
|
throw new Error(t('appNotSelected', { platform }));
|
||||||
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||||
if (!updateInfo[platform]) {
|
if (!updateInfo[platform]) {
|
||||||
throw new Error(
|
throw new Error(t('appNotSelected', { platform }));
|
||||||
`App not selected. run 'pushy selectApp --platform ${platform}' first!`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return updateInfo[platform];
|
return updateInfo[platform];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listApp(platform: Platform) {
|
export async function listApp(platform: Platform | '' = '') {
|
||||||
const { data } = await get('/app/list');
|
const { data } = await get('/app/list');
|
||||||
const list = platform ? data.filter((v) => v.platform === platform) : data;
|
const list = platform ? data.filter((v) => v.platform === platform) : data;
|
||||||
|
|
||||||
const header = [
|
const header = [
|
||||||
{ value: '应用 id' },
|
{ value: t('appId') },
|
||||||
{ value: '应用名称' },
|
{ value: t('appName') },
|
||||||
{ value: '平台' },
|
{ value: t('platform') },
|
||||||
];
|
];
|
||||||
const rows = [];
|
const rows = [];
|
||||||
for (const app of list) {
|
for (const app of list) {
|
||||||
@@ -51,11 +45,7 @@ export async function listApp(platform: Platform) {
|
|||||||
|
|
||||||
console.log(Table(header, rows).render());
|
console.log(Table(header, rows).render());
|
||||||
|
|
||||||
if (platform) {
|
console.log(`\n${t('totalApps', { count: list.length, platform })}`);
|
||||||
console.log(`\共 ${list.length} ${platform} 个应用`);
|
|
||||||
} else {
|
|
||||||
console.log(`\共 ${list.length} 个应用`);
|
|
||||||
}
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +53,7 @@ export async function chooseApp(platform: Platform) {
|
|||||||
const list = await listApp(platform);
|
const list = await listApp(platform);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const id = await question('输入应用 id:');
|
const id = await question(t('enterAppIdQuestion'));
|
||||||
const app = list.find((v) => v.id === Number(id));
|
const app = list.find((v) => v.id === Number(id));
|
||||||
if (app) {
|
if (app) {
|
||||||
return app;
|
return app;
|
||||||
@@ -77,13 +67,13 @@ export const commands = {
|
|||||||
}: {
|
}: {
|
||||||
options: { name: string; downloadUrl: string; platform: Platform };
|
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 { downloadUrl } = options;
|
||||||
const platform = checkPlatform(
|
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 });
|
const { id } = await post('/app/create', { name, platform, downloadUrl });
|
||||||
console.log(`已成功创建应用(id: ${id})`);
|
console.log(t('createAppSuccess', { id }));
|
||||||
await this.selectApp({
|
await this.selectApp({
|
||||||
args: [id],
|
args: [id],
|
||||||
options: { platform },
|
options: { platform },
|
||||||
@@ -93,10 +83,10 @@ export const commands = {
|
|||||||
const { platform } = options;
|
const { platform } = options;
|
||||||
const id = args[0] || chooseApp(platform);
|
const id = args[0] || chooseApp(platform);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
console.log('已取消');
|
console.log(t('cancelled'));
|
||||||
}
|
}
|
||||||
await doDelete(`/app/${id}`);
|
await doDelete(`/app/${id}`);
|
||||||
console.log('操作成功');
|
console.log(t('operationSuccess'));
|
||||||
},
|
},
|
||||||
apps: async ({ options }: { options: { platform: Platform } }) => {
|
apps: async ({ options }: { options: { platform: Platform } }) => {
|
||||||
const { platform } = options;
|
const { platform } = options;
|
||||||
@@ -104,7 +94,7 @@ export const commands = {
|
|||||||
},
|
},
|
||||||
selectApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
|
selectApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
|
||||||
const platform = checkPlatform(
|
const platform = checkPlatform(
|
||||||
options.platform || (await question('平台(ios/android/harmony):')),
|
options.platform || (await question(t('platformQuestion'))),
|
||||||
);
|
);
|
||||||
const id = args[0]
|
const id = args[0]
|
||||||
? Number.parseInt(args[0])
|
? Number.parseInt(args[0])
|
||||||
@@ -115,9 +105,7 @@ export const commands = {
|
|||||||
try {
|
try {
|
||||||
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(
|
console.error(t('failedToParseUpdateJson'));
|
||||||
'Failed to parse file `update.json`. Try to remove it manually.',
|
|
||||||
);
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,4 +25,18 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|||||||
latestVersionTag: '(latest: {{version}})',
|
latestVersionTag: '(latest: {{version}})',
|
||||||
rnuVersionNotFound:
|
rnuVersionNotFound:
|
||||||
'react-native-update: Cannot get the version number. Please run the command in the project directory',
|
'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.',
|
||||||
};
|
};
|
||||||
|
@@ -23,4 +23,18 @@ export default {
|
|||||||
latestVersionTag: '(最新:{{version}})',
|
latestVersionTag: '(最新:{{version}})',
|
||||||
rnuVersionNotFound:
|
rnuVersionNotFound:
|
||||||
'react-native-update: 无法获取版本号。请在项目目录中运行命令',
|
'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`。请手动删除它。',
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user