@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.
@@ -3,3 +3,4 @@
3
3
  * 若 shutdown() 未完成,进程会挂起,不会被关闭(受 FORCE_EXIT_AFTER_MS 上限保护)。
4
4
  */
5
5
  export declare function registerExitHook(offEvent: () => void): void;
6
+ export declare function useExit(fn: () => void | Promise<void>): Promise<void>;
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.7",
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": "0b49771becc5022233ce273bd293f22654f1f631"
35
+ "gitHead": "fc98c3e1ecf57f6cb4aded9caef28da0a35b7f30"
35
36
  }