agent-publish-server 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/dist/cli.js +35 -8
  2. package/package.json +1 -1
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('1.0.0')
12
+ .version(packageJson.version, '-v, --version')
10
13
  .option('-c, --config <path>', '配置文件路径')
11
14
  .option('--cf <path>', '配置文件路径')
12
- .option('--config-file <path>', '配置文件路径')
13
- .parse(process.argv);
14
- const options = program.opts();
15
- const config = (0, config_1.loadConfig)(options);
16
- (0, server_1.startServer)(config).catch((error) => {
17
- console.error('Server failed to start:', error);
18
- process.exit(1);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-publish-server",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "基于 nodejs+express+http-proxy-middleware 的前端服务启动插件",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",