agent-publish-server 1.0.4 → 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/cli.js +35 -8
- 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/cli.js
CHANGED
|
@@ -4,16 +4,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
const server_1 = require("./server");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
7
9
|
const program = new commander_1.Command();
|
|
10
|
+
const packageJson = require('../package.json');
|
|
8
11
|
program
|
|
9
|
-
.version(
|
|
12
|
+
.version(packageJson.version, '-v, --version')
|
|
10
13
|
.option('-c, --config <path>', '配置文件路径')
|
|
11
14
|
.option('--cf <path>', '配置文件路径')
|
|
12
|
-
.option('--config-file <path>', '配置文件路径')
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
.option('--config-file <path>', '配置文件路径');
|
|
16
|
+
program
|
|
17
|
+
.command('init')
|
|
18
|
+
.description('初始化配置文件')
|
|
19
|
+
.action(() => {
|
|
20
|
+
const defaultConfig = {
|
|
21
|
+
port: 8080,
|
|
22
|
+
dir: './',
|
|
23
|
+
proxy: {
|
|
24
|
+
'/api': {
|
|
25
|
+
target: 'http://localhost:3000',
|
|
26
|
+
changeOrigin: true,
|
|
27
|
+
pathRewrite: {
|
|
28
|
+
'^/api': ''
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const configPath = (0, path_1.join)(process.cwd(), 'agent_config.json');
|
|
34
|
+
(0, fs_1.writeFileSync)(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
35
|
+
console.log('配置文件已创建:agent_config.json');
|
|
36
|
+
process.exit(0);
|
|
19
37
|
});
|
|
38
|
+
program.parse(process.argv);
|
|
39
|
+
if (!program.args.length) {
|
|
40
|
+
const options = program.opts();
|
|
41
|
+
const config = (0, config_1.loadConfig)(options);
|
|
42
|
+
(0, server_1.startServer)(config).catch((error) => {
|
|
43
|
+
console.error('Server failed to start:', error);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
});
|
|
46
|
+
}
|
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
|
}
|