Skip to content

Commit 328b1f5

Browse files
committed
update i18n
1 parent ef7f6a2 commit 328b1f5

File tree

9 files changed

+119
-63
lines changed

9 files changed

+119
-63
lines changed

src/api.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ import ProgressBar from 'progress';
66
import packageJson from '../package.json';
77
import tcpp from 'tcp-ping';
88
import filesizeParser from 'filesize-parser';
9-
import { pricingPageUrl, credentialFile, IS_CRESC } from './utils/constants';
9+
import {
10+
pricingPageUrl,
11+
credentialFile,
12+
defaultEndpoint,
13+
} from './utils/constants';
1014
import type { Session } from 'types';
1115
import FormData from 'form-data';
16+
import { t } from './utils/i18n';
1217

1318
const tcpPing = util.promisify(tcpp.ping);
1419

1520
let session: Session | undefined;
1621
let savedSession: Session | undefined;
1722

18-
const defaultEndpoint = IS_CRESC
19-
? 'https://api.cresc.dev'
20-
: 'https://update.reactnative.cn/api';
21-
2223
const host =
2324
process.env.PUSHY_REGISTRY || process.env.RNU_API || defaultEndpoint;
2425

@@ -73,7 +74,7 @@ async function query(url: string, options: fetch.RequestInit) {
7374
if (resp.status !== 200) {
7475
const message = json?.message || resp.statusText;
7576
if (resp.status === 401) {
76-
throw new Error('登录信息已过期,请使用 pushy login 命令重新登录');
77+
throw new Error(t('loginExpired'));
7778
}
7879
throw new Error(message);
7980
}
@@ -133,10 +134,13 @@ export async function uploadFile(fn: string, key?: string) {
133134

134135
const fileSize = fs.statSync(fn).size;
135136
if (maxSize && fileSize > filesizeParser(maxSize)) {
137+
const readableFileSize = `${(fileSize / 1048576).toFixed(1)}m`;
136138
throw new Error(
137-
`此文件大小 ${(fileSize / 1048576).toFixed(
138-
1,
139-
)}m , 超出当前额度 ${maxSize} 。您可以考虑升级付费业务以提升此额度。详情请访问: ${pricingPageUrl}`,
139+
t('fileSizeExceeded', {
140+
fileSize: readableFileSize,
141+
maxSize,
142+
pricingPageUrl,
143+
}),
140144
);
141145
}
142146

src/locales/en.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@ Best practices for lock files:
1414
3. Pay attention to changes in the lock file during code review.
1515
This can reduce the risk of inconsistent dependencies and supply chain attacks.
1616
`,
17+
loginExpired:
18+
'Login information has expired. Please use `cresc login` command to re-login',
19+
fileSizeExceeded:
20+
'This file size is {{fileSize}} , exceeding the current quota {{maxSize}} . You may consider upgrading to a higher plan to increase this quota. Details can be found at: {{pricingPageUrl}}',
21+
bundleNotFound:
22+
'Bundle file not found. Please ensure that this {{packageType}} is a release version and the bundle file name is the default `{{entryFile}}`',
23+
buildTimeNotFound:
24+
'Cannot get the build timestamp of this package. Please update `react-native-update` to the latest version and re-package and upload.',
25+
latestVersionTag: '(latest: {{version}})',
26+
rnuVersionNotFound:
27+
'react-native-update: Cannot get the version number. Please run the command in the project directory',
1728
};

src/locales/zh.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,14 @@ export default {
1313
`,
1414
multipleLocksFound:
1515
'检测到多种不同格式的锁文件({lockFiles}),这可能导致依赖关系不一致而使热更异常。',
16+
loginExpired: '登录信息已过期,请使用 `pushy login` 命令重新登录',
17+
fileSizeExceeded:
18+
'此文件大小 {{fileSize}} , 超出当前额度 {{maxSize}} 。您可以考虑升级付费业务以提升此额度。详情请访问: {{pricingPageUrl}}',
19+
bundleNotFound:
20+
'找不到 bundle 文件。请确保此 {{packageType}} 为 release 版本,且 bundle 文件名为默认的 `{{entryFile}}`',
21+
buildTimeNotFound:
22+
'无法获取此包的编译时间戳。请更新 `react-native-update` 到最新版本后重新打包上传。',
23+
latestVersionTag: '(最新:{{version}})',
24+
rnuVersionNotFound:
25+
'react-native-update: 无法获取版本号。请在项目目录中运行命令',
1626
};

src/utils/app-info-parser/index.js renamed to src/utils/app-info-parser/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ const AppParser = require('./app');
44
const supportFileTypes = ['ipa', 'apk', 'app'];
55

66
class AppInfoParser {
7+
file: string | File;
8+
parser: any;
79
/**
810
* parser for parsing .ipa or .apk file
9-
* @param {String | File | Blob} file // file's path in Node, instance of File or Blob in Browser
11+
* @param {String | File} file // file's path in Node, instance of File in Browser
1012
*/
11-
constructor(file) {
13+
constructor(file: string | File) {
1214
if (!file) {
1315
throw new Error(
14-
"Param miss: file(file's path in Node, instance of File or Blob in browser).",
16+
"Param miss: file(file's path in Node, instance of File in browser).",
1517
);
1618
}
17-
const splits = (file.name || file).split('.');
19+
const splits = (typeof file === 'string' ? file : file.name).split('.');
1820
const fileType = splits[splits.length - 1].toLowerCase();
1921
if (!supportFileTypes.includes(fileType)) {
2022
throw new Error(
@@ -40,4 +42,4 @@ class AppInfoParser {
4042
}
4143
}
4244

43-
module.exports = AppInfoParser;
45+
export default AppInfoParser;

src/utils/check-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export async function checkPlugins(): Promise<BundleParams> {
1717
const isEnabled = await plugin.detect();
1818
if (isEnabled && plugin.bundleParams) {
1919
Object.assign(params, plugin.bundleParams);
20-
console.log(`检测到 ${plugin.name} 插件,应用相应打包配置`);
20+
console.log(`detected ${plugin.name} plugin`);
2121
}
2222
} catch (err) {
23-
console.warn(`检测 ${plugin.name} 插件时出错:`, err);
23+
console.warn(`error while detecting ${plugin.name} plugin:`, err);
2424
}
2525
}
2626

src/utils/constants.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import path from 'node:path';
22

3-
const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
4-
| 'cresc'
5-
| 'pushy';
3+
const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
64
export const IS_CRESC = scriptName === 'cresc';
75

86
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
@@ -11,3 +9,7 @@ export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
119
export const pricingPageUrl = IS_CRESC
1210
? 'https://cresc.dev/pricing'
1311
: 'https://pushy.reactnative.cn/pricing.html';
12+
13+
export const defaultEndpoint = IS_CRESC
14+
? 'https://api.cresc.dev'
15+
: 'https://update.reactnative.cn/api';

src/utils/i18n.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import i18next from 'i18next';
22
import en from '../locales/en';
33
import zh from '../locales/zh';
44
import { IS_CRESC } from './constants';
5+
56
i18next.init({
67
lng: IS_CRESC ? 'en' : 'zh',
78
// debug: process.env.NODE_ENV !== 'production',
9+
// debug: true,
810
resources: {
9-
en,
10-
zh,
11+
en: {
12+
translation: en,
13+
},
14+
zh: {
15+
translation: zh,
16+
},
1117
},
1218
});
1319

src/utils/index.ts

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import latestVersion from '@badisi/latest-version';
99
import { checkPlugins } from './check-plugin';
1010

1111
import { read } from 'read';
12-
import { tempDir } from './constants';
12+
import { IS_CRESC, tempDir } from './constants';
1313
import { depVersions } from './dep-versions';
14+
import { t } from './i18n';
1415

1516
export async function question(query: string, password?: boolean) {
1617
if (NO_INTERACTIVE) {
@@ -46,7 +47,10 @@ export async function getApkInfo(fn: string) {
4647
);
4748
if (!bundleFile) {
4849
throw new Error(
49-
'找不到bundle文件。请确保此apk为release版本,且bundle文件名为默认的index.android.bundle',
50+
t('bundleNotFound', {
51+
packageType: 'apk',
52+
entryFile: 'index.android.bundle',
53+
}),
5054
);
5155
}
5256
const updateJsonFile = await appInfoParser.parser.getEntry(
@@ -66,21 +70,22 @@ export async function getApkInfo(fn: string) {
6670
}
6771
}
6872
if (buildTime == 0) {
69-
throw new Error(
70-
'无法获取此包的编译时间戳。请更新 react-native-update 到最新版本后重新打包上传。',
71-
);
73+
throw new Error(t('buildTimeNotFound'));
7274
}
7375
return { versionName, buildTime, ...appCredential };
7476
}
7577

76-
export async function getAppInfo(fn) {
78+
export async function getAppInfo(fn: string) {
7779
const appInfoParser = new AppInfoParser(fn);
7880
const bundleFile = await appInfoParser.parser.getEntryFromHarmonyApp(
7981
/rawfile\/bundle.harmony.js/,
8082
);
8183
if (!bundleFile) {
8284
throw new Error(
83-
'找不到bundle文件。请确保此app为release版本,且bundle文件名为默认的bundle.harmony.js',
85+
t('bundleNotFound', {
86+
packageType: 'app',
87+
entryFile: 'bundle.harmony.js',
88+
}),
8489
);
8590
}
8691
const updateJsonFile = await appInfoParser.parser.getEntryFromHarmonyApp(
@@ -103,9 +108,7 @@ export async function getAppInfo(fn) {
103108
buildTime = pushy_build_time;
104109
}
105110
if (buildTime == 0) {
106-
throw new Error(
107-
'无法获取此包的编译时间戳。请更新 react-native-update 到最新版本后重新打包上传。',
108-
);
111+
throw new Error(t('buildTimeNotFound'));
109112
}
110113
return { versionName, buildTime, ...appCredential };
111114
}
@@ -117,7 +120,10 @@ export async function getIpaInfo(fn: string) {
117120
);
118121
if (!bundleFile) {
119122
throw new Error(
120-
'找不到bundle文件。请确保此ipa为release版本,且bundle文件名为默认的main.jsbundle',
123+
t('bundleNotFound', {
124+
packageType: 'ipa',
125+
entryFile: 'main.jsbundle',
126+
}),
121127
);
122128
}
123129
const updateJsonFile = await appInfoParser.parser.getEntry(
@@ -139,9 +145,7 @@ export async function getIpaInfo(fn: string) {
139145
);
140146
}
141147
if (!buildTimeTxtBuffer) {
142-
throw new Error(
143-
'无法获取此包的编译时间戳。请更新 react-native-update 到最新版本后重新打包上传。',
144-
);
148+
throw new Error(t('buildTimeNotFound'));
145149
}
146150
const buildTime = buildTimeTxtBuffer.toString().replace('\n', '');
147151
return { versionName, buildTime, ...appCredential };
@@ -168,40 +172,51 @@ async function getLatestVersion(pkgNames: string[]) {
168172
}
169173

170174
export async function printVersionCommand() {
171-
let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
175+
let [latestRnuCliVersion, latestRnuVersion] = await getLatestVersion([
172176
'react-native-update-cli',
173177
'react-native-update',
174178
]);
175-
latestPushyCliVersion = latestPushyCliVersion
176-
? ` (最新:${chalk.green(latestPushyCliVersion)})`
179+
latestRnuCliVersion = latestRnuCliVersion
180+
? ` ${t('latestVersionTag', {
181+
version: chalk.green(latestRnuCliVersion),
182+
})}`
177183
: '';
178184
console.log(
179-
`react-native-update-cli: ${pkg.version}${latestPushyCliVersion}`,
185+
`react-native-update-cli: ${pkg.version}${latestRnuCliVersion}`,
180186
);
181-
let pushyVersion = '';
182-
pushyVersion = depVersions['react-native-update'];
183-
latestPushyVersion = latestPushyVersion
184-
? ` (最新:${chalk.green(latestPushyVersion)}`
187+
let rnuVersion = '';
188+
rnuVersion = depVersions['react-native-update'];
189+
latestRnuVersion = latestRnuVersion
190+
? ` ${t('latestVersionTag', { version: chalk.green(latestRnuVersion) })}`
185191
: '';
186-
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
187-
if (pushyVersion) {
188-
if (semverSatisfies(pushyVersion, '<8.5.2')) {
189-
console.warn(
190-
`当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
191-
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
192-
);
193-
} else if (semverSatisfies(pushyVersion, '9.0.0 - 9.2.1')) {
194-
console.warn(
195-
`当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更): npm i react-native-update@9 .
196-
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
197-
);
198-
} else if (semverSatisfies(pushyVersion, '10.0.0 - 10.17.0')) {
199-
console.warn(
200-
'当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10',
201-
);
192+
console.log(`react-native-update: ${rnuVersion}${latestRnuVersion}`);
193+
if (rnuVersion) {
194+
if (IS_CRESC) {
195+
if (semverSatisfies(rnuVersion, '<10.27.0')) {
196+
console.error(
197+
'Unsupported version, please update to the latest version: npm i react-native-update@latest',
198+
);
199+
process.exit(1);
200+
}
201+
} else {
202+
if (semverSatisfies(rnuVersion, '<8.5.2')) {
203+
console.warn(
204+
`当前版本已不再支持,请至少升级到 v8 的最新小版本后重新打包(代码无需改动): npm i react-native-update@8 .
205+
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
206+
);
207+
} else if (semverSatisfies(rnuVersion, '9.0.0 - 9.2.1')) {
208+
console.warn(
209+
`当前版本已不再支持,请至少升级到 v9 的最新小版本后重新打包(代码无需改动,可直接热更): npm i react-native-update@9 .
210+
如有使用安装 apk 的功能,请注意添加所需权限 https://pushy.reactnative.cn/docs/api#async-function-downloadandinstallapkurl`,
211+
);
212+
} else if (semverSatisfies(rnuVersion, '10.0.0 - 10.17.0')) {
213+
console.warn(
214+
'当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10',
215+
);
216+
}
202217
}
203218
} else {
204-
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
219+
console.log(t('rnuVersionNotFound'));
205220
}
206221
}
207222

src/versions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { choosePackage } from './package';
66
import { compare } from 'compare-versions';
77
import { depVersions } from './utils/dep-versions';
88
import { getCommitInfo } from './utils/git';
9+
import { Platform } from 'types';
910

1011
async function showVersion(appId: string, offset: number) {
1112
const { data, count } = await get(`/app/${appId}/version/list`);
@@ -61,7 +62,7 @@ async function chooseVersion(appId: string) {
6162
const cmd = await question(
6263
'Enter versionId or page Up/page Down/Begin(U/D/B)',
6364
);
64-
switch (cmd.toLowerCase()) {
65+
switch (cmd.toUpperCase()) {
6566
case 'U':
6667
offset = Math.max(0, offset - 10);
6768
break;
@@ -82,7 +83,12 @@ async function chooseVersion(appId: string) {
8283
}
8384

8485
export const commands = {
85-
publish: async function ({ args, options }) {
86+
publish: async function ({ args, options }: { args: string[]; options: {
87+
name: string;
88+
description?: string;
89+
metaInfo?: string;
90+
platform?: Platform;
91+
} }) {
8692
const fn = args[0];
8793
const { name, description, metaInfo } = options;
8894

@@ -136,7 +142,7 @@ export const commands = {
136142
versionId = null;
137143
}
138144

139-
let pkgId;
145+
let pkgId: string | undefined;
140146
let pkgVersion = options.packageVersion;
141147
let minPkgVersion = options.minPackageVersion;
142148
let maxPkgVersion = options.maxPackageVersion;

0 commit comments

Comments
 (0)