@ruan-cat/vercel-deploy-tool 0.1.1 → 0.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruan-cat/vercel-deploy-tool",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "阮喵喵自用的vercel部署工具,用于实现复杂项目的部署。",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -42,6 +42,7 @@
42
42
  "dependencies": {
43
43
  "@dotenvx/dotenvx": "^1.11.5",
44
44
  "c12": "^1.11.2",
45
+ "commander": "^12.0.0",
45
46
  "consola": "^3.2.3",
46
47
  "cpx": "^1.5.0",
47
48
  "cpy": "^11.1.0",
@@ -66,8 +67,8 @@
66
67
  "scripts": {
67
68
  "—build-not-use-for-now": "tsc",
68
69
  "start": "node ./dist/index.js",
69
- "run": "vite-node ./src/index.ts --files",
70
- "test:config": "vite-node ./tests/config.test.ts --files",
70
+ "run": "node --import=tsx ./src/index.ts --env-path=.env.test",
71
+ "test:config": "node --import=tsx ./tests/config.test.ts --env-path=.env.test",
71
72
  "test:vitest": "vitest --ui --watch",
72
73
  "rm:node_modules": "rimraf node_modules"
73
74
  }
package/src/config.ts CHANGED
@@ -3,6 +3,7 @@ import { loadConfig } from "c12";
3
3
  import { config as dotenvConfig } from "@dotenvx/dotenvx";
4
4
  import { consola } from "consola";
5
5
  import { merge } from "lodash-es";
6
+ import { program } from "commander";
6
7
 
7
8
  /**
8
9
  * @description
@@ -92,6 +93,15 @@ export interface Config {
92
93
  /** 用户项目id */
93
94
  vercelProjectId: string;
94
95
 
96
+ /**
97
+ * 用户提供的 vercel.json 配置文件
98
+ * @description
99
+ * 有时候 用户需要提供自己的一套配置文件
100
+ *
101
+ * 这里提供配置路径
102
+ */
103
+ vercelJsonPath?: string;
104
+
95
105
  /** 在build命令阶段后 执行的用户命令 */
96
106
  afterBuildTasks?: string[];
97
107
 
@@ -130,12 +140,31 @@ declare module "@dotenvx/dotenvx" {
130
140
  }
131
141
  }
132
142
 
143
+ program
144
+ .name("vercel-deploy-tool")
145
+ // 环境变量的地址
146
+ .option("--env-path <path>", "环境变量的地址")
147
+ .parse();
148
+ const options = program.opts();
149
+
150
+ consola.info(" 查看命令行提供的参数 ", options);
151
+
133
152
  /** 初始化的当前的环境变量 */
134
153
  function initCurrentDotenvConfig() {
135
- const res = dotenvConfig({
136
- // 具体识别的路径,会自动识别根目录下面的env文件,故这里不作处理
137
- // path: "../../../.env"
138
- }).parsed;
154
+ // 如果存在环境变量路径 就使用并读取
155
+ const dotenvConfigParams = options?.envPath
156
+ ? {
157
+ path: options?.envPath,
158
+ }
159
+ : {};
160
+
161
+ const res = dotenvConfig(
162
+ dotenvConfigParams,
163
+ // {
164
+ // // 具体识别的路径,会自动识别根目录下面的env文件,故这里不作处理
165
+ // path: "../../../.env"
166
+ // }
167
+ ).parsed;
139
168
 
140
169
  consola.info(" 查看来自 @dotenvx/dotenvx 获取的环境变量: ");
141
170
  consola.box(res);
package/src/index.ts CHANGED
@@ -133,9 +133,15 @@ function getVercelTokenCommandArgument() {
133
133
  return <const>[`--token=${config.vercelToken}`];
134
134
  }
135
135
 
136
- /** 以命令参数数组的形式,获得项目vercel的本地配置 */
136
+ /**
137
+ * 以命令参数数组的形式,获得项目vercel的本地配置
138
+ * @description
139
+ * 如果用户自己提供了vercel的本地配置 那么就使用用户的。
140
+ *
141
+ * 否则就使用自己生成的文件。
142
+ */
137
143
  function getVercelLocalConfigCommandArgument() {
138
- return <const>[`--local-config=${vercelNullConfigPath}`];
144
+ return <const>[`--local-config=${config?.vercelJsonPath ?? vercelNullConfigPath}`];
139
145
  }
140
146
 
141
147
  /** 以命令参数数组的形式,获得工作目录 */