agent-publish-server 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/dist/config.js +18 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,11 +16,30 @@ agent-publish-server
|
|
|
16
16
|
|
|
17
17
|
## 配置
|
|
18
18
|
|
|
19
|
+
### 配置文件路径
|
|
20
|
+
|
|
21
|
+
你可以通过以下方式指定配置文件路径:
|
|
22
|
+
|
|
23
|
+
1. 使用相对路径(相对于当前工作目录):
|
|
24
|
+
|
|
19
25
|
```bash
|
|
20
|
-
# 配置文件路径
|
|
21
26
|
agent-publish-server -c ./agent_config.json
|
|
22
27
|
```
|
|
23
28
|
|
|
29
|
+
2. 使用绝对路径:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
agent-publish-server -c /path/to/agent_config.json
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
3. 使用初始化命令创建默认配置:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
agent-publish-server init
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 配置文件格式
|
|
42
|
+
|
|
24
43
|
```json
|
|
25
44
|
{
|
|
26
45
|
"port": 8080, // 端口号
|
package/dist/config.js
CHANGED
|
@@ -19,14 +19,26 @@ function loadConfig(options) {
|
|
|
19
19
|
'agent_config.json';
|
|
20
20
|
try {
|
|
21
21
|
const absolutePath = path_1.default.resolve(process.cwd(), configPath);
|
|
22
|
-
if (fs_1.default.existsSync(absolutePath)) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (!fs_1.default.existsSync(absolutePath)) {
|
|
23
|
+
console.error(`配置文件不存在: ${absolutePath}`);
|
|
24
|
+
console.log('你可以通过以下方式指定配置文件路径:');
|
|
25
|
+
console.log('1. 使用相对路径:agent-publish-server -c ./agent_config.json');
|
|
26
|
+
console.log('2. 使用绝对路径:agent-publish-server -c /path/to/agent_config.json');
|
|
27
|
+
console.log('3. 使用 agent-publish-server init 命令创建默认配置文件');
|
|
28
|
+
process.exit(1);
|
|
26
29
|
}
|
|
30
|
+
const configContent = fs_1.default.readFileSync(absolutePath, 'utf-8');
|
|
31
|
+
const userConfig = JSON.parse(configContent);
|
|
32
|
+
return { ...DEFAULT_CONFIG, ...userConfig };
|
|
27
33
|
}
|
|
28
34
|
catch (error) {
|
|
29
|
-
|
|
35
|
+
if (error instanceof SyntaxError) {
|
|
36
|
+
console.error(`配置文件格式错误: ${configPath}`);
|
|
37
|
+
console.error('请确保配置文件是有效的 JSON 格式');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.error(`加载配置文件失败: ${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
process.exit(1);
|
|
30
43
|
}
|
|
31
|
-
return DEFAULT_CONFIG;
|
|
32
44
|
}
|