Skip to content

Commit bff7b86

Browse files
committed
fixed: 修改更新逻辑
1 parent 3d92bc0 commit bff7b86

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "tlm",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"type": "module",
55
"description": "Terminal packages that support multiple translation platforms",
66
"main": "./dist/cli.js",
77
"bin": {
88
"tlm": "./dist/cli.js"
99
},
1010
"scripts": {
11-
"start": "tsc-watch --onSuccess \"tsc-alias\"",
11+
"dev": "tsc-watch --onSuccess \"tsc-alias\"",
1212
"build": "tsc && tsc-alias",
13-
"postinstall": "node ./dist/updated_config.js",
13+
"postinstall": "node ./updated_config.js",
1414
"test": "echo \"Error: no test specified\" && exit 1"
1515
},
1616
"exports": {
@@ -21,6 +21,7 @@
2121
},
2222
"files": [
2323
"dist/",
24+
"updated_config",
2425
"config.json",
2526
"README_EN.md"
2627
],
@@ -57,8 +58,9 @@
5758
"@types/crypto-js": "^4.2.2",
5859
"@types/node": "^20.14.11",
5960
"@types/node-fetch": "^2.6.11",
61+
"cross-env": "^7.0.3",
6062
"tsc-alias": "^1.8.10",
6163
"tsc-watch": "^6.2.0",
6264
"typescript": "^5.5.3"
6365
}
64-
}
66+
}

src/constants.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { fileURLToPath } from 'url';
22
import path from "path";
33

4-
const __fileName = fileURLToPath(import.meta.url);
5-
const __dirname = path.dirname(__fileName);
6-
const CONFIG_PATH = path.join(__dirname, '../config.json');
7-
const PACKAGE_PATH = path.join(__dirname, '../package.json');
4+
const FILENAME = fileURLToPath(import.meta.url);
5+
const DIRNAME = path.dirname(FILENAME);
6+
const CONFIG_PATH = path.join(DIRNAME, '../config.json');
7+
const PACKAGE_PATH = path.join(DIRNAME, '../package.json');
88
const TLMRC = path.join(<string>process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], '.tlmrc.json');
99

1010
const LANGUAGE_MAP = [
@@ -26,7 +26,7 @@ const LANGUAGE_MAP = [
2626
const LANGUAGE_ZH = {
2727
source: "源语言",
2828
target: "目标语言"
29-
}
29+
};
3030

3131
const DEFAULT_LANGUAGE = {
3232
source: "auto",
@@ -40,4 +40,4 @@ export {
4040
LANGUAGE_ZH,
4141
LANGUAGE_MAP,
4242
DEFAULT_LANGUAGE
43-
}
43+
};

src/updated_config.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
},
2525
"include": [
2626
"src/**/*.ts",
27-
"updated_config.ts",
2827
"index.d.ts",
2928
],
3029
"exclude": [

updated_config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { fileURLToPath } from 'url';
4+
5+
const FILENAME = fileURLToPath(import.meta.url);
6+
const DIRNAME = path.dirname(FILENAME);
7+
const CONFIG_PATH = path.join(DIRNAME, './config.json');
8+
const TLMRC = path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], '.tlmrc.json');
9+
10+
11+
try {
12+
// 直接读取配置文件内容
13+
let config = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
14+
15+
try {
16+
// 尝试读取 tlmrc 文件,如果存在则合并配置
17+
const localConfig = JSON.parse(fs.readFileSync(TLMRC, 'utf8'));
18+
Object.assign(config, localConfig);
19+
} catch (err) {
20+
// 如果 tlmrc 文件不存在,则忽略错误
21+
console.log('No existing tlmrc file found.');
22+
}
23+
24+
// 写入或更新 tlmrc 文件
25+
fs.writeFileSync(TLMRC, JSON.stringify(config, null, 2), 'utf8');
26+
console.log('Configuration updated successfully.');
27+
} catch (err) {
28+
console.error('Error processing configuration:', err);
29+
}

0 commit comments

Comments
 (0)