@hile/cli 1.0.15 → 1.0.17

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 (3) hide show
  1. package/README.md +11 -0
  2. package/dist/index.js +39 -1
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -46,6 +46,17 @@ hile start --env-file .env --env-file .env.local
46
46
 
47
47
  依赖 Node 20.12+ 原生 `process.loadEnvFile()`。
48
48
 
49
+ ### 启动日志(基于 @hile/core 事件)
50
+
51
+ CLI 已接入容器事件日志,默认会输出:
52
+
53
+ - 服务启动:`service:init` / `service:ready`(含耗时)
54
+ - 服务失败:`service:error`
55
+ - 关闭阶段:`service:shutdown:start` / `service:shutdown:done`
56
+ - 容器关闭:`container:shutdown:start` / `container:shutdown:done`
57
+
58
+ 这使得线上启动问题与关闭过程更容易观测。
59
+
49
60
  ### 其他命令
50
61
 
51
62
  ```bash
package/dist/index.js CHANGED
@@ -11,6 +11,37 @@ const require = createRequire(import.meta.url);
11
11
  function loadEnvFile(filePath) {
12
12
  process.loadEnvFile(resolve(process.cwd(), filePath));
13
13
  }
14
+ function logContainerEvent(event) {
15
+ switch (event.type) {
16
+ case 'service:init':
17
+ console.info(`[hile] service#${event.id} init`);
18
+ break;
19
+ case 'service:ready':
20
+ console.info(`[hile] service#${event.id} ready (${event.durationMs}ms)`);
21
+ break;
22
+ case 'service:error':
23
+ console.error(`[hile] service#${event.id} failed (${event.durationMs}ms):`, event.error);
24
+ break;
25
+ case 'service:shutdown:start':
26
+ console.info(`[hile] service#${event.id} stopping`);
27
+ break;
28
+ case 'service:shutdown:done':
29
+ console.info(`[hile] service#${event.id} stopped (${event.durationMs}ms)`);
30
+ break;
31
+ case 'service:shutdown:error':
32
+ console.error(`[hile] service#${event.id} shutdown error:`, event.error);
33
+ break;
34
+ case 'container:shutdown:start':
35
+ console.info('[hile] container shutdown start');
36
+ break;
37
+ case 'container:shutdown:done':
38
+ console.info(`[hile] container shutdown done (${event.durationMs}ms)`);
39
+ break;
40
+ case 'container:error':
41
+ console.error('[hile] container error:', event.error);
42
+ break;
43
+ }
44
+ }
14
45
  program.version(pkg.version, '-v, --version', '当前版本号');
15
46
  /**
16
47
  * 启动服务
@@ -41,6 +72,9 @@ program
41
72
  else {
42
73
  process.env.NODE_ENV = 'production';
43
74
  }
75
+ const offEvent = process.env.NODE_ENV === 'development'
76
+ ? container.on(logContainerEvent)
77
+ : () => { };
44
78
  const cwd = process.cwd();
45
79
  const files = [];
46
80
  // 加载 package.json 文件
@@ -68,13 +102,17 @@ program
68
102
  // 如果没有服务要加载,则提示
69
103
  if (!files.length) {
70
104
  console.warn('no services to load');
105
+ offEvent();
71
106
  return;
72
107
  }
73
108
  // 注册退出钩子,在进程退出时销毁所有服务
74
109
  exitHook(exit => {
75
110
  container.shutdown()
76
111
  .catch(e => console.error(e))
77
- .finally(exit);
112
+ .finally(() => {
113
+ offEvent();
114
+ exit();
115
+ });
78
116
  });
79
117
  });
80
118
  program.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -23,11 +23,11 @@
23
23
  "vitest": "^4.0.18"
24
24
  },
25
25
  "dependencies": {
26
- "@hile/core": "^1.0.17",
26
+ "@hile/core": "^1.0.19",
27
27
  "async-exit-hook": "^2.0.1",
28
28
  "commander": "^14.0.3",
29
29
  "glob": "^13.0.6",
30
30
  "tsx": "^4.21.0"
31
31
  },
32
- "gitHead": "6672fc4cdc551c4265912cc85ee2e96fc44bc4c9"
32
+ "gitHead": "4bb9d38b309e72c720f2cba579ce5c498d27e044"
33
33
  }