@hile/cli 1.0.11 → 1.0.13

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/index.js +10 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -7,6 +7,10 @@ import { resolve } from 'node:path';
7
7
  import { container, isService, loadService } from '@hile/core';
8
8
  import { createRequire } from 'node:module';
9
9
  const require = createRequire(import.meta.url);
10
+ /** 加载 env 文件到 process.env(Node 20.12+ 原生 process.loadEnvFile) */
11
+ function loadEnvFile(filePath) {
12
+ process.loadEnvFile(resolve(process.cwd(), filePath));
13
+ }
10
14
  program.version(pkg.version, '-v, --version', '当前版本号');
11
15
  /**
12
16
  * 启动服务
@@ -21,8 +25,14 @@ program.version(pkg.version, '-v, --version', '当前版本号');
21
25
  program
22
26
  .command('start')
23
27
  .option('-d, --dev', '开发模式', false)
28
+ .option('-e, --env-file <path>', '加载指定 env 文件(兼容 Node --env-file 语义;可多次指定,先加载的不被后加载覆盖)', (v, acc) => (acc.push(v), acc), [])
24
29
  .description('启动服务,加载所有后缀为 boot.ts 或 boot.js 的服务,并注册退出钩子,在进程退出时销毁所有服务')
25
30
  .action(async (options) => {
31
+ // 先加载 --env-file(与 Node --env-file 行为一致:先加载的优先,已存在的 key 不被覆盖)
32
+ const envFiles = options.envFile ?? [];
33
+ for (const p of envFiles) {
34
+ loadEnvFile(p);
35
+ }
26
36
  // 开发模式下,使用 tsx 运行
27
37
  if (options.dev) {
28
38
  await import('tsx/esm');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hile/cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -29,5 +29,5 @@
29
29
  "glob": "^13.0.6",
30
30
  "tsx": "^4.21.0"
31
31
  },
32
- "gitHead": "5708e7878ab54a917c32d4fdbbd66c07d9d8f04d"
32
+ "gitHead": "1070e55ba47e976946b8e1536dfda43211c3251a"
33
33
  }