Skip to content

Commit

Permalink
✨ feat(vercel-deploy-tool): 增加了 --env-path 环境变量地址配置。使用命令行运行项目时,可以手动传递…
Browse files Browse the repository at this point in the history
…环境变量的值。传递命令行的值即可。
  • Loading branch information
ruan-cat committed Nov 12, 2024
1 parent e5f7170 commit fb398c5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
7 changes: 7 additions & 0 deletions demos/vercel-deploy-tool/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VITE_APP_TITLE=零壹OA项目
VITE_API_URL = /api
VITE_CAPTCHA_PREFIX = /captcha

VITE_app_port = 3000
VITE_proxy_prefix = "/api"
VITE_base_url = "/api"
16 changes: 15 additions & 1 deletion demos/vercel-deploy-tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# @ruan-cat/vercel-deploy-tool

## 0.3.0

### Minor Changes

- 增加了 --env-path 环境变量地址配置。使用命令行运行项目时,可以手动传递环境变量的值。传递命令行的值即可。

举例如下:

```bash
node --import=tsx ./tests/config.test.ts --env-path=.env.test
```

传递 --env-path 变量,并提供地址即可。

## 0.2.0

### Minor Changes

- 提供 vercelJsonPath 配置。
- 提供 vercelJsonPath 配置。允许用户上传自定义的 vercel.json 文件。

## 0.1.1

Expand Down
9 changes: 5 additions & 4 deletions demos/vercel-deploy-tool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ruan-cat/vercel-deploy-tool",
"version": "0.2.0",
"version": "0.3.0",
"description": "阮喵喵自用的vercel部署工具,用于实现复杂项目的部署。",
"type": "module",
"main": "./src/index.ts",
Expand All @@ -17,8 +17,8 @@
"scripts": {
"—build-not-use-for-now": "tsc",
"start": "node ./dist/index.js",
"run": "vite-node ./src/index.ts --files",
"test:config": "vite-node ./tests/config.test.ts --files",
"run": "node --import=tsx ./src/index.ts --env-path=.env.test",
"test:config": "node --import=tsx ./tests/config.test.ts --env-path=.env.test",
"test:vitest": "vitest --ui --watch",
"rm:node_modules": "rimraf node_modules"
},
Expand Down Expand Up @@ -51,6 +51,7 @@
"@dotenvx/dotenvx": "^1.11.5",
"@ruan-cat/utils": "workspace:^",
"c12": "^1.11.2",
"commander": "^12.0.0",
"consola": "^3.2.3",
"cpx": "^1.5.0",
"cpy": "^11.1.0",
Expand All @@ -71,4 +72,4 @@
"@vitest/ui": "^2.0.5",
"vitest": "^2.0.5"
}
}
}
28 changes: 24 additions & 4 deletions demos/vercel-deploy-tool/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loadConfig } from "c12";
import { config as dotenvConfig } from "@dotenvx/dotenvx";
import { consola } from "consola";
import { merge } from "lodash-es";
import { program } from "commander";

/**
* @description
Expand Down Expand Up @@ -139,12 +140,31 @@ declare module "@dotenvx/dotenvx" {
}
}

program
.name("vercel-deploy-tool")
// 环境变量的地址
.option("--env-path <path>", "环境变量的地址")
.parse();
const options = program.opts();

consola.info(" 查看命令行提供的参数 ", options);

/** 初始化的当前的环境变量 */
function initCurrentDotenvConfig() {
const res = dotenvConfig({
// 具体识别的路径,会自动识别根目录下面的env文件,故这里不作处理
// path: "../../../.env"
}).parsed;
// 如果存在环境变量路径 就使用并读取
const dotenvConfigParams = options?.envPath
? {
path: options?.envPath,
}
: {};

const res = dotenvConfig(
dotenvConfigParams,
// {
// // 具体识别的路径,会自动识别根目录下面的env文件,故这里不作处理
// path: "../../../.env"
// }
).parsed;

consola.info(" 查看来自 @dotenvx/dotenvx 获取的环境变量: ");
consola.box(res);
Expand Down

0 comments on commit fb398c5

Please sign in to comment.