@hile/cli 1.0.19 → 1.0.21
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 +1 -1
- package/dist/index.js +12 -15
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { glob } from 'glob';
|
|
|
6
6
|
import { resolve } from 'node:path';
|
|
7
7
|
import { container, isService, loadService } from '@hile/core';
|
|
8
8
|
import { createRequire } from 'node:module';
|
|
9
|
+
import { pathToFileURL } from 'node:url';
|
|
9
10
|
const require = createRequire(import.meta.url);
|
|
10
11
|
/** 加载 env 文件到 process.env(Node 20.12+ 原生 process.loadEnvFile) */
|
|
11
12
|
function loadEnvFile(filePath) {
|
|
@@ -22,46 +23,41 @@ const c = {
|
|
|
22
23
|
};
|
|
23
24
|
const colorize = process.stdout.isTTY;
|
|
24
25
|
function logContainerEvent(event) {
|
|
25
|
-
const pad = (s, n) => s.padEnd(n);
|
|
26
|
-
const padNum = (n, width) => n.toString().padStart(width);
|
|
27
26
|
const tag = colorize ? `${c.dim}${c.cyan}${TAG}${c.reset}` : TAG;
|
|
28
27
|
const target = (s) => (colorize ? `${c.cyan}${s}${c.reset}` : s);
|
|
29
28
|
const ok = (s) => (colorize ? `${c.green}${s}${c.reset}` : s);
|
|
30
29
|
const warn = (s) => (colorize ? `${c.yellow}${s}${c.reset}` : s);
|
|
31
30
|
const err = (s) => (colorize ? `${c.red}${s}${c.reset}` : s);
|
|
32
31
|
const dim = (s) => (colorize ? `${c.dim}${s}${c.reset}` : s);
|
|
33
|
-
const fmt = (t, status, durationMs) => durationMs !== undefined
|
|
34
|
-
? `${tag} ${target(pad(t, 14))} ${status} ${dim(padNum(durationMs, 5) + 'ms')}`
|
|
35
|
-
: `${tag} ${target(pad(t, 14))} ${status}`;
|
|
36
32
|
switch (event.type) {
|
|
37
33
|
case 'service:init':
|
|
38
|
-
console.info(
|
|
34
|
+
console.info(`${tag} ${target(`service#${event.id}`)} ${dim('init')}`);
|
|
39
35
|
break;
|
|
40
36
|
case 'service:ready':
|
|
41
|
-
console.info(
|
|
37
|
+
console.info(`${tag} ${target(`service#${event.id}`)} ${ok('ready')} ${dim(`(${event.durationMs}ms)`)}`);
|
|
42
38
|
break;
|
|
43
39
|
case 'service:error':
|
|
44
|
-
console.error(
|
|
40
|
+
console.error(`${tag} ${target(`service#${event.id}`)} ${err('failed')} ${dim(`(${event.durationMs}ms)`)}`);
|
|
45
41
|
console.error(event.error);
|
|
46
42
|
break;
|
|
47
43
|
case 'service:shutdown:start':
|
|
48
|
-
console.info(
|
|
44
|
+
console.info(`${tag} ${target(`service#${event.id}`)} ${warn('stopping')}`);
|
|
49
45
|
break;
|
|
50
46
|
case 'service:shutdown:done':
|
|
51
|
-
console.info(
|
|
47
|
+
console.info(`${tag} ${target(`service#${event.id}`)} ${dim('stopped')} ${dim(`(${event.durationMs}ms)`)}`);
|
|
52
48
|
break;
|
|
53
49
|
case 'service:shutdown:error':
|
|
54
|
-
console.error(
|
|
50
|
+
console.error(`${tag} ${target(`service#${event.id}`)} ${err('shutdown error')}`);
|
|
55
51
|
console.error(event.error);
|
|
56
52
|
break;
|
|
57
53
|
case 'container:shutdown:start':
|
|
58
|
-
console.info(
|
|
54
|
+
console.info(`${tag} ${target('container')} ${dim('shutdown start')}`);
|
|
59
55
|
break;
|
|
60
56
|
case 'container:shutdown:done':
|
|
61
|
-
console.info(
|
|
57
|
+
console.info(`${tag} ${target('container')} ${ok('shutdown done')} ${dim(`(${event.durationMs}ms)`)}`);
|
|
62
58
|
break;
|
|
63
59
|
case 'container:error':
|
|
64
|
-
console.error(
|
|
60
|
+
console.error(`${tag} ${target('container')} ${err('error')}`);
|
|
65
61
|
console.error(event.error);
|
|
66
62
|
break;
|
|
67
63
|
}
|
|
@@ -117,7 +113,8 @@ program
|
|
|
117
113
|
// 加载所有自启动服务
|
|
118
114
|
// file: 文件路径或者模块名称
|
|
119
115
|
await Promise.all(files.map(async (file) => {
|
|
120
|
-
const
|
|
116
|
+
const _file = pathToFileURL(file).href;
|
|
117
|
+
const target = await import(_file);
|
|
121
118
|
const fn = target?.default ?? target;
|
|
122
119
|
if (!fn || !isService(fn))
|
|
123
120
|
throw new Error(`invalid service file: ${file}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hile/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"vitest": "^4.0.18"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@hile/core": "^1.0.
|
|
28
|
+
"@hile/core": "^1.0.22",
|
|
29
29
|
"async-exit-hook": "^2.0.1",
|
|
30
30
|
"commander": "^14.0.3",
|
|
31
31
|
"glob": "^13.0.6",
|
|
32
32
|
"tsx": "^4.21.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "ffc0bf9ab4d0e251244c174536bac79c1f2f77fe"
|
|
35
35
|
}
|