Skip to content

Commit d974be6

Browse files
committed
add i18n
1 parent d0495fb commit d974be6

File tree

10 files changed

+257
-79
lines changed

10 files changed

+257
-79
lines changed

bun.lock

Lines changed: 189 additions & 41 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@
3535
},
3636
"homepage": "https://github.com/reactnativecn/react-native-pushy/tree/master/react-native-pushy-cli",
3737
"dependencies": {
38-
"@badisi/latest-version": "^7.0.10",
38+
"@badisi/latest-version": "^7.0.12",
3939
"bplist-parser": "^0.3.2",
4040
"bytebuffer": "^5.0.1",
4141
"cgbi-to-png": "^1.0.7",
4242
"chalk": "4",
4343
"cli-arguments": "^0.2.1",
44-
"commander": "^12.1.0",
44+
"commander": "^13.1.0",
4545
"compare-versions": "^6.1.1",
4646
"filesize-parser": "^1.5.1",
47-
"form-data": "^4.0.1",
47+
"form-data": "^4.0.2",
4848
"fs-extra": "8",
4949
"gradle-to-js": "^2.0.1",
50-
"i18next": "^24.2.2",
50+
"i18next": "^24.2.3",
5151
"isomorphic-git": "^1.29.0",
5252
"isomorphic-unzip": "^1.1.5",
5353
"node-fetch": "^2.6.1",
5454
"plist": "^3.1.0",
5555
"progress": "^2.0.3",
5656
"properties": "^1.2.1",
57-
"read": "^4.0.0",
58-
"semver": "^7.6.3",
57+
"read": "^4.1.0",
58+
"semver": "^7.7.1",
5959
"tcp-ping": "^0.1.1",
6060
"tty-table": "4.2",
6161
"update-notifier": "^5.1.0",
@@ -67,18 +67,18 @@
6767
},
6868
"devDependencies": {
6969
"@biomejs/biome": "^1.9.4",
70-
"@swc/cli": "^0.5.1",
71-
"@swc/core": "^1.9.3",
70+
"@swc/cli": "^0.6.0",
71+
"@swc/core": "^1.11.9",
7272
"@types/filesize-parser": "^1.5.3",
7373
"@types/fs-extra": "^11.0.4",
74-
"@types/node": "^22.9.3",
74+
"@types/node": "^22.13.10",
7575
"@types/node-fetch": "^2.6.12",
7676
"@types/progress": "^2.0.7",
7777
"@types/semver": "^7.5.8",
7878
"@types/tcp-ping": "^0.1.6",
7979
"@types/update-notifier": "^6.0.8",
8080
"@types/yauzl": "^2.10.3",
8181
"@types/yazl": "^2.4.6",
82-
"typescript": "^5.7.2"
82+
"typescript": "^5.8.2"
8383
}
8484
}

src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function queryWithoutBody(method: string) {
9292
}
9393

9494
function queryWithBody(method: string) {
95-
return (api: string, body: Record<string, any>) =>
95+
return (api: string, body?: Record<string, any>) =>
9696
query(host + api, {
9797
method,
9898
headers: {

src/app.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,24 @@ export async function chooseApp(platform: Platform) {
7272
}
7373

7474
export const commands = {
75-
createApp: async function ({ options }) {
75+
createApp: async function ({
76+
options,
77+
}: {
78+
options: { name: string; downloadUrl: string; platform: Platform };
79+
}) {
7680
const name = options.name || (await question('应用名称:'));
7781
const { downloadUrl } = options;
7882
const platform = checkPlatform(
7983
options.platform || (await question('平台(ios/android/harmony):')),
8084
);
81-
const { id } = await post('/app/create', { name, platform });
85+
const { id } = await post('/app/create', { name, platform, downloadUrl });
8286
console.log(`已成功创建应用(id: ${id})`);
8387
await this.selectApp({
8488
args: [id],
85-
options: { platform, downloadUrl },
89+
options: { platform },
8690
});
8791
},
88-
deleteApp: async ({ args, options }) => {
92+
deleteApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
8993
const { platform } = options;
9094
const id = args[0] || chooseApp(platform);
9195
if (!id) {
@@ -94,19 +98,19 @@ export const commands = {
9498
await doDelete(`/app/${id}`);
9599
console.log('操作成功');
96100
},
97-
apps: async ({ options }) => {
101+
apps: async ({ options }: { options: { platform: Platform } }) => {
98102
const { platform } = options;
99103
listApp(platform);
100104
},
101-
selectApp: async ({ args, options }) => {
105+
selectApp: async ({ args, options }: { args: string[]; options: { platform: Platform } }) => {
102106
const platform = checkPlatform(
103107
options.platform || (await question('平台(ios/android/harmony):')),
104108
);
105109
const id = args[0]
106110
? Number.parseInt(args[0])
107111
: (await chooseApp(platform)).id;
108112

109-
let updateInfo = {};
113+
let updateInfo: Partial<Record<Platform, { appId: number; appKey: string }>> = {};
110114
if (fs.existsSync('update.json')) {
111115
try {
112116
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));

src/index.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@ import { loadSession } from './api';
44
import updateNotifier from 'update-notifier';
55
import { printVersionCommand } from './utils';
66
import pkg from '../package.json';
7-
import i18next from 'i18next';
8-
import en from './locales/en';
9-
import zh from './locales/zh';
10-
import { IS_CRESC } from './utils/constants';
11-
12-
i18next.init({
13-
lng: IS_CRESC ? 'en' : 'zh',
14-
// debug: process.env.NODE_ENV !== 'production',
15-
resources: {
16-
en,
17-
zh,
18-
},
19-
});
7+
import { t } from './utils/i18n';
208

219
updateNotifier({ pkg }).notify({
2210
isGlobal: true,
23-
message:
24-
'建议运行 `{updateCommand}` 来更新命令行工具以获得功能、性能和安全性的持续改进',
11+
message: t('updateNotifier'),
2512
});
2613

2714
function printUsage() {
@@ -30,7 +17,7 @@ function printUsage() {
3017

3118
console.log('Usage is under development now.');
3219
console.log(
33-
'Visit `https://github.com/reactnativecn/react-native-pushy` for early document.',
20+
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
3421
);
3522
process.exit(1);
3623
}
@@ -58,7 +45,7 @@ async function run() {
5845
.then(() => commands[argv.command](argv))
5946
.catch((err) => {
6047
if (err.status === 401) {
61-
console.log('尚未登录。\n请在项目目录中运行`pushy login`命令来登录');
48+
console.log(t('loginFirst'));
6249
return;
6350
}
6451
console.error(err.stack);

src/locales/en.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export default {};
1+
export default {
2+
updateNotifier:
3+
'Run `{updateCommand}` to update the CLI to get continuous improvements in features, performance, and security.',
4+
loginFirst: 'Not logged in.\nPlease run `cresc login` in the project directory to login.',
5+
};

src/locales/zh.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export default {};
1+
export default {
2+
updateNotifier:
3+
'建议运行 `{updateCommand}` 来更新命令行工具以获得功能、性能和安全性的持续改进',
4+
loginFirst: '尚未登录。\n请在项目目录中运行`pushy login`命令来登录',
5+
};

src/utils/app-info-parser/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function mapInfoResource (apkInfo, resourceMap) {
3030
iteratorObj(apkInfo)
3131
return apkInfo
3232
function iteratorObj (obj) {
33-
for (var i in obj) {
33+
for (const i in obj) {
3434
if (isArray(obj[i])) {
3535
iteratorArray(obj[i])
3636
} else if (isObject(obj[i])) {

src/utils/i18n.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import i18next from 'i18next';
2+
import en from '../locales/en';
3+
import zh from '../locales/zh';
4+
import { IS_CRESC } from './constants';
5+
i18next.init({
6+
lng: IS_CRESC ? 'en' : 'zh',
7+
// debug: process.env.NODE_ENV !== 'production',
8+
resources: {
9+
en,
10+
zh,
11+
},
12+
});
13+
14+
declare module 'i18next' {
15+
// Extend CustomTypeOptions
16+
interface CustomTypeOptions {
17+
// custom namespace type, if you changed it
18+
defaultNS: 'en';
19+
// custom resources type
20+
resources: {
21+
en: typeof en;
22+
zh: typeof zh;
23+
};
24+
// other
25+
}
26+
}
27+
28+
export const t = i18next.t;

src/utils/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { checkPlugins } from './check-plugin';
1111
import { read } from 'read';
1212
import { tempDir } from './constants';
1313
import { depVersions } from './dep-versions';
14+
import { getCommitInfo } from './git';
1415

1516
export async function question(query: string, password?: boolean) {
1617
if (NO_INTERACTIVE) {
@@ -168,6 +169,8 @@ async function getLatestVersion(pkgNames: string[]) {
168169
}
169170

170171
export async function printVersionCommand() {
172+
const result = await getCommitInfo();
173+
console.log(JSON.stringify(result, null, 2));
171174
let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
172175
'react-native-update-cli',
173176
'react-native-update',

0 commit comments

Comments
 (0)