@hile/cli 1.0.10 → 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.
- package/README.md +3 -0
- package/dist/index.js +10 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,9 +33,12 @@ hile start --dev # 开发模式:NODE_ENV=development,扫描 src/ 目录
|
|
|
33
33
|
| 选项 | 说明 | 默认值 |
|
|
34
34
|
|------|------|--------|
|
|
35
35
|
| `-d, --dev` | 开发模式:设置 `NODE_ENV=development`,使用 tsx 运行 TypeScript,扫描 `src/` | `false` |
|
|
36
|
+
| `-e, --env-file <path>` | 加载指定 env 文件到 `process.env`(与 Node 原生 `--env-file` 语义一致:先加载的优先,已存在的 key 不覆盖)。可多次指定 | — |
|
|
36
37
|
|
|
37
38
|
未使用 `--dev` 时,CLI 会将 `process.env.NODE_ENV` 设为 `production`;使用 `--dev` 时设为 `development`,便于业务代码区分环境。
|
|
38
39
|
|
|
40
|
+
**示例:** `hile start --env-file .env --env-file .env.local` 会先加载 `.env`,再加载 `.env.local`(后者不会覆盖前者已设置的变量)。依赖 Node 20.12+ 原生 `process.loadEnvFile()`。
|
|
41
|
+
|
|
39
42
|
### 其他
|
|
40
43
|
|
|
41
44
|
```bash
|
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.
|
|
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": "
|
|
32
|
+
"gitHead": "1070e55ba47e976946b8e1536dfda43211c3251a"
|
|
33
33
|
}
|