@hile/cli 1.1.7 → 1.1.9
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/exitHook.d.ts +1 -0
- package/dist/exitHook.js +24 -0
- package/dist/index.js +11 -0
- package/package.json +3 -2
package/dist/exitHook.d.ts
CHANGED
package/dist/exitHook.js
CHANGED
|
@@ -35,3 +35,27 @@ export function registerExitHook(offEvent) {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
+
export async function useExit(fn) {
|
|
39
|
+
exitHook(async (exit) => {
|
|
40
|
+
try {
|
|
41
|
+
await Promise.resolve(fn());
|
|
42
|
+
await new Promise((resolve, reject) => {
|
|
43
|
+
try {
|
|
44
|
+
if (process.stdin.isTTY) {
|
|
45
|
+
process.stdin.unref();
|
|
46
|
+
}
|
|
47
|
+
resolve();
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
reject(e);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error(e);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
exit();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ import { execSync } from 'node:child_process';
|
|
|
6
6
|
import { existsSync, readFileSync } from 'node:fs';
|
|
7
7
|
import { dirname, join, resolve } from 'node:path';
|
|
8
8
|
import { createRequire } from 'node:module';
|
|
9
|
+
import { Registry } from '@hile/micro';
|
|
10
|
+
import { useExit } from './exitHook.js';
|
|
9
11
|
const requireCli = createRequire(import.meta.url);
|
|
10
12
|
/** 从包入口文件路径向上找到 `package.json` 的 `name` 与 `packageName` 一致的目录 */
|
|
11
13
|
function packageDirFromResolvedMain(resolvedMain, packageName) {
|
|
@@ -106,5 +108,14 @@ program
|
|
|
106
108
|
silent: options.silent
|
|
107
109
|
});
|
|
108
110
|
});
|
|
111
|
+
program.command('registry')
|
|
112
|
+
.option('-p, --port <port>', '注册中心端口', '9876')
|
|
113
|
+
.description('启动注册中心')
|
|
114
|
+
.action(async (options) => {
|
|
115
|
+
const port = options.port ? Number(options.port) : 9876;
|
|
116
|
+
const registry = new Registry();
|
|
117
|
+
useExit(await registry.listen(port));
|
|
118
|
+
console.log(`+ [registry] started on port ${port}`);
|
|
119
|
+
});
|
|
109
120
|
program.parseAsync(process.argv);
|
|
110
121
|
export * from './start.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hile/cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,10 +26,11 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@hile/core": "^1.1.2",
|
|
29
|
+
"@hile/micro": "^1.0.3",
|
|
29
30
|
"async-exit-hook": "^2.0.1",
|
|
30
31
|
"commander": "^14.0.3",
|
|
31
32
|
"glob": "^13.0.6",
|
|
32
33
|
"tsx": "^4.21.0"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "fc98c3e1ecf57f6cb4aded9caef28da0a35b7f30"
|
|
35
36
|
}
|