Skip to content

Commit b2d32ed

Browse files
committed
opt: code
1 parent 1cd15f6 commit b2d32ed

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/constants.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ const CONFIG_PATH = path.join(__dirname, '../config.json');
77
const PACKAGE_PATH = path.join(__dirname, '../package.json');
88
const MPTLRC = path.join(<string>process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], '.mptlrc.json');
99

10-
// 采用ISO 639-1标准语言代码,除了一些特殊语言,如繁体中文
11-
const LANGUAGE_MAP: Tl.SupportLangs[] = [
10+
const LANGUAGE_MAP = [
1211
{ zh: "自动检测", en: "auto", code: "auto" },
1312
{ zh: "中文", en: "chinese", code: "zh" },
1413
{ zh: "繁体中文", en: "traditional_chinese", code: "cht" },
@@ -29,7 +28,7 @@ const LANGUAGE_ZH = {
2928
target: "目标语言"
3029
}
3130

32-
const DEFAULTLANGUAGE: Tl.DefaultLangs = {
31+
const DEFAULTLANGUAGE = {
3332
source: "auto",
3433
target: "zh"
3534
};

src/updated_config.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { isExistConfig, readFile, writeFile } from "@util/helpers";
22
import { MPTLRC, CONFIG_PATH } from "@/constants";
33

4-
// npm install 或者 npm update 更新配置文件
54
(async () => {
6-
if (process.env.SKIP_POSTINSTALL !== "true") {
7-
const config = <Tl.Config>await readFile(CONFIG_PATH);
8-
const isExist = await isExistConfig(MPTLRC);
9-
if (!isExist) {
10-
await writeFile(MPTLRC, config);
11-
} else {
12-
const localConfig = await readFile(MPTLRC);
13-
Object.assign(config, localConfig);
14-
await writeFile(MPTLRC, config);
15-
}
5+
const config = <Tl.Config>await readFile(CONFIG_PATH);
6+
const isExist = await isExistConfig(MPTLRC);
7+
if (!isExist) {
8+
await writeFile(MPTLRC, config);
9+
} else {
10+
const localConfig = await readFile(MPTLRC);
11+
Object.assign(config, localConfig);
12+
await writeFile(MPTLRC, config);
1613
}
1714
})();

src/util/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function writeFile(path: string, content: Tl.Config): Promise<void> {
3030
})
3131
}
3232

33-
async function isExistConfig(path: string) {
33+
async function isExistConfig(path: string): Promise<boolean> {
3434
return new Promise(resolve => {
3535
fs.access(path, (err) => err ? resolve(false) : resolve(true));
3636
})

0 commit comments

Comments
 (0)