agent-publish-server 1.0.6 → 1.0.12

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/dist/cli.js CHANGED
@@ -12,7 +12,33 @@ program
12
12
  .version(packageJson.version, '-v, --version')
13
13
  .option('-c, --config <path>', '配置文件路径')
14
14
  .option('--cf <path>', '配置文件路径')
15
- .option('--config-file <path>', '配置文件路径');
15
+ .option('--config-file <path>', '配置文件路径')
16
+ .option('-p, --port <number>', '服务器端口号')
17
+ .option('-d, --dir <path>', '静态文件目录路径');
18
+ // 添加一个默认命令,用于处理没有指定任何子命令的情况
19
+ program
20
+ .action(() => {
21
+ const options = program.opts();
22
+ // 加载配置
23
+ const config = (0, config_1.loadConfig)(options);
24
+ // 命令行参数优先级高于配置文件
25
+ if (options.port) {
26
+ const port = parseInt(options.port, 10);
27
+ if (isNaN(port)) {
28
+ console.error('端口号必须是有效的数字');
29
+ process.exit(1);
30
+ }
31
+ config.port = port;
32
+ }
33
+ if (options.dir) {
34
+ config.dir = options.dir;
35
+ }
36
+ // 启动服务器
37
+ (0, server_1.startServer)(config).catch((error) => {
38
+ console.error('Server failed to start:', error);
39
+ process.exit(1);
40
+ });
41
+ });
16
42
  program
17
43
  .command('init')
18
44
  .description('初始化配置文件')
@@ -36,11 +62,3 @@ program
36
62
  process.exit(0);
37
63
  });
38
64
  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
@@ -12,20 +12,49 @@ const DEFAULT_CONFIG = {
12
12
  proxy: {}
13
13
  };
14
14
  function loadConfig(options) {
15
- const configPath = options.config ||
16
- options.c ||
17
- options.cf ||
18
- options.configFile ||
19
- 'agent_config.json';
15
+ // 尝试多个可能的配置文件路径
16
+ const configPaths = [
17
+ options.config || '',
18
+ options.c || '',
19
+ options.cf || '',
20
+ options.configFile || '',
21
+ 'agent_config.json',
22
+ '.agent_config.json',
23
+ 'agent.config.json'
24
+ ].filter(Boolean);
25
+ let configPath = '';
26
+ let absolutePath = '';
20
27
  try {
21
- const absolutePath = path_1.default.resolve(process.cwd(), configPath);
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);
28
+ // 遍历所有可能的配置文件路径
29
+ for (const cfgPath of configPaths) {
30
+ if (path_1.default.isAbsolute(cfgPath)) {
31
+ // 如果是绝对路径,直接检查文件是否存在
32
+ if (fs_1.default.existsSync(cfgPath)) {
33
+ absolutePath = cfgPath;
34
+ configPath = cfgPath;
35
+ break;
36
+ }
37
+ }
38
+ else if (cfgPath) {
39
+ // 如果是相对路径,尝试多个可能的路径
40
+ const possiblePaths = [
41
+ path_1.default.resolve(process.cwd(), cfgPath),
42
+ path_1.default.resolve(__dirname, cfgPath)
43
+ ];
44
+ for (const p of possiblePaths) {
45
+ if (fs_1.default.existsSync(p)) {
46
+ absolutePath = p;
47
+ configPath = cfgPath;
48
+ break;
49
+ }
50
+ }
51
+ if (absolutePath)
52
+ break;
53
+ }
54
+ }
55
+ if (!absolutePath) {
56
+ console.log('未找到配置文件,将使用默认配置');
57
+ return DEFAULT_CONFIG;
29
58
  }
30
59
  const configContent = fs_1.default.readFileSync(absolutePath, 'utf-8');
31
60
  const userConfig = JSON.parse(configContent);
package/dist/types.d.ts CHANGED
@@ -13,4 +13,6 @@ export interface CommandOptions {
13
13
  c?: string;
14
14
  cf?: string;
15
15
  configFile?: string;
16
+ port?: string;
17
+ dir?: string;
16
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-publish-server",
3
- "version": "1.0.6",
3
+ "version": "1.0.12",
4
4
  "description": "基于 nodejs+express+http-proxy-middleware 的前端服务启动插件",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",