mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-11-08 18:25:48 +08:00
add i18n
This commit is contained in:
@@ -92,7 +92,7 @@ function queryWithoutBody(method: string) {
|
||||
}
|
||||
|
||||
function queryWithBody(method: string) {
|
||||
return (api: string, body: Record<string, any>) =>
|
||||
return (api: string, body?: Record<string, any>) =>
|
||||
query(host + api, {
|
||||
method,
|
||||
headers: {
|
||||
|
||||
18
src/app.ts
18
src/app.ts
@@ -72,20 +72,24 @@ export async function chooseApp(platform: Platform) {
|
||||
}
|
||||
|
||||
export const commands = {
|
||||
createApp: async function ({ options }) {
|
||||
createApp: async function ({
|
||||
options,
|
||||
}: {
|
||||
options: { name: string; downloadUrl: string; platform: Platform };
|
||||
}) {
|
||||
const name = options.name || (await question('应用名称:'));
|
||||
const { downloadUrl } = options;
|
||||
const platform = checkPlatform(
|
||||
options.platform || (await question('平台(ios/android/harmony):')),
|
||||
);
|
||||
const { id } = await post('/app/create', { name, platform });
|
||||
const { id } = await post('/app/create', { name, platform, downloadUrl });
|
||||
console.log(`已成功创建应用(id: ${id})`);
|
||||
await this.selectApp({
|
||||
args: [id],
|
||||
options: { platform, downloadUrl },
|
||||
options: { platform },
|
||||
});
|
||||
},
|
||||
deleteApp: async ({ args, options }) => {
|
||||
deleteApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
|
||||
const { platform } = options;
|
||||
const id = args[0] || chooseApp(platform);
|
||||
if (!id) {
|
||||
@@ -94,11 +98,11 @@ export const commands = {
|
||||
await doDelete(`/app/${id}`);
|
||||
console.log('操作成功');
|
||||
},
|
||||
apps: async ({ options }) => {
|
||||
apps: async ({ options }: { options: { platform: Platform } }) => {
|
||||
const { platform } = options;
|
||||
listApp(platform);
|
||||
},
|
||||
selectApp: async ({ args, options }) => {
|
||||
selectApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
|
||||
const platform = checkPlatform(
|
||||
options.platform || (await question('平台(ios/android/harmony):')),
|
||||
);
|
||||
@@ -106,7 +110,7 @@ export const commands = {
|
||||
? Number.parseInt(args[0])
|
||||
: (await chooseApp(platform)).id;
|
||||
|
||||
let updateInfo = {};
|
||||
let updateInfo: Partial<Record<Platform, { appId: number; appKey: string }>> = {};
|
||||
if (fs.existsSync('update.json')) {
|
||||
try {
|
||||
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||
|
||||
21
src/index.ts
21
src/index.ts
@@ -4,24 +4,11 @@ import { loadSession } from './api';
|
||||
import updateNotifier from 'update-notifier';
|
||||
import { printVersionCommand } from './utils';
|
||||
import pkg from '../package.json';
|
||||
import i18next from 'i18next';
|
||||
import en from './locales/en';
|
||||
import zh from './locales/zh';
|
||||
import { IS_CRESC } from './utils/constants';
|
||||
|
||||
i18next.init({
|
||||
lng: IS_CRESC ? 'en' : 'zh',
|
||||
// debug: process.env.NODE_ENV !== 'production',
|
||||
resources: {
|
||||
en,
|
||||
zh,
|
||||
},
|
||||
});
|
||||
import { t } from './utils/i18n';
|
||||
|
||||
updateNotifier({ pkg }).notify({
|
||||
isGlobal: true,
|
||||
message:
|
||||
'建议运行 `{updateCommand}` 来更新命令行工具以获得功能、性能和安全性的持续改进',
|
||||
message: t('updateNotifier'),
|
||||
});
|
||||
|
||||
function printUsage() {
|
||||
@@ -30,7 +17,7 @@ function printUsage() {
|
||||
|
||||
console.log('Usage is under development now.');
|
||||
console.log(
|
||||
'Visit `https://github.com/reactnativecn/react-native-pushy` for early document.',
|
||||
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -58,7 +45,7 @@ async function run() {
|
||||
.then(() => commands[argv.command](argv))
|
||||
.catch((err) => {
|
||||
if (err.status === 401) {
|
||||
console.log('尚未登录。\n请在项目目录中运行`pushy login`命令来登录');
|
||||
console.log(t('loginFirst'));
|
||||
return;
|
||||
}
|
||||
console.error(err.stack);
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
export default {};
|
||||
export default {
|
||||
updateNotifier:
|
||||
'Run `{updateCommand}` to update the CLI to get continuous improvements in features, performance, and security.',
|
||||
loginFirst: 'Not logged in.\nPlease run `cresc login` in the project directory to login.',
|
||||
};
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
export default {};
|
||||
export default {
|
||||
updateNotifier:
|
||||
'建议运行 `{updateCommand}` 来更新命令行工具以获得功能、性能和安全性的持续改进',
|
||||
loginFirst: '尚未登录。\n请在项目目录中运行`pushy login`命令来登录',
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ function mapInfoResource (apkInfo, resourceMap) {
|
||||
iteratorObj(apkInfo)
|
||||
return apkInfo
|
||||
function iteratorObj (obj) {
|
||||
for (var i in obj) {
|
||||
for (const i in obj) {
|
||||
if (isArray(obj[i])) {
|
||||
iteratorArray(obj[i])
|
||||
} else if (isObject(obj[i])) {
|
||||
|
||||
28
src/utils/i18n.ts
Normal file
28
src/utils/i18n.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import i18next from 'i18next';
|
||||
import en from '../locales/en';
|
||||
import zh from '../locales/zh';
|
||||
import { IS_CRESC } from './constants';
|
||||
i18next.init({
|
||||
lng: IS_CRESC ? 'en' : 'zh',
|
||||
// debug: process.env.NODE_ENV !== 'production',
|
||||
resources: {
|
||||
en,
|
||||
zh,
|
||||
},
|
||||
});
|
||||
|
||||
declare module 'i18next' {
|
||||
// Extend CustomTypeOptions
|
||||
interface CustomTypeOptions {
|
||||
// custom namespace type, if you changed it
|
||||
defaultNS: 'en';
|
||||
// custom resources type
|
||||
resources: {
|
||||
en: typeof en;
|
||||
zh: typeof zh;
|
||||
};
|
||||
// other
|
||||
}
|
||||
}
|
||||
|
||||
export const t = i18next.t;
|
||||
@@ -11,6 +11,7 @@ import { checkPlugins } from './check-plugin';
|
||||
import { read } from 'read';
|
||||
import { tempDir } from './constants';
|
||||
import { depVersions } from './dep-versions';
|
||||
import { getCommitInfo } from './git';
|
||||
|
||||
export async function question(query: string, password?: boolean) {
|
||||
if (NO_INTERACTIVE) {
|
||||
@@ -168,6 +169,8 @@ async function getLatestVersion(pkgNames: string[]) {
|
||||
}
|
||||
|
||||
export async function printVersionCommand() {
|
||||
const result = await getCommitInfo();
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
|
||||
'react-native-update-cli',
|
||||
'react-native-update',
|
||||
|
||||
Reference in New Issue
Block a user