@ruan-cat/vercel-deploy-tool 0.9.3 → 0.10.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/README.md +1 -60
- package/package.json +15 -11
- package/src/config.ts +37 -24
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ import "@ruan-cat/vercel-deploy-tool/src/index.ts";
|
|
|
114
114
|
"pnpm": ">=9"
|
|
115
115
|
},
|
|
116
116
|
"scripts": {
|
|
117
|
-
"deploy-vercel": "
|
|
117
|
+
"deploy-vercel": "tsx ./bin/vercel-deploy-tool.ts"
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
```
|
|
@@ -127,64 +127,6 @@ pnpm i -D tsx
|
|
|
127
127
|
|
|
128
128
|
运行 `pnpm run deploy-vercel` 命令就能部署项目到 vercel 了。
|
|
129
129
|
|
|
130
|
-
### 配置 github action(可选)
|
|
131
|
-
|
|
132
|
-
```yaml
|
|
133
|
-
name: 自写的vercel部署工具
|
|
134
|
-
env:
|
|
135
|
-
# 必须密文提供token
|
|
136
|
-
VERCEL_TOKEN: ${{ secrets.vercel_token }}
|
|
137
|
-
# 可以明文提供组织id和项目id
|
|
138
|
-
# VERCEL_ORG_ID: ${{ secrets.vercel_orgId }}
|
|
139
|
-
# VERCEL_PROJECT_ID: ${{ secrets.vercel_projectId }}
|
|
140
|
-
|
|
141
|
-
on:
|
|
142
|
-
push:
|
|
143
|
-
branches:
|
|
144
|
-
# 可以自选分支 为了避免过快耗尽vercel额度,建议只在main分支内触发部署
|
|
145
|
-
- main
|
|
146
|
-
|
|
147
|
-
jobs:
|
|
148
|
-
Deploy-Production:
|
|
149
|
-
runs-on: ubuntu-latest
|
|
150
|
-
steps:
|
|
151
|
-
- name: 检出分支
|
|
152
|
-
uses: actions/checkout@v4
|
|
153
|
-
|
|
154
|
-
- name: 安装pnpm
|
|
155
|
-
uses: pnpm/action-setup@v4
|
|
156
|
-
with:
|
|
157
|
-
# 若项目提供了packageManager配置 这里可以不提供该配置
|
|
158
|
-
# version: 9
|
|
159
|
-
# 必须安装 vercel @dotenvx/dotenvx tsx 这三个全局包
|
|
160
|
-
run_install: |
|
|
161
|
-
- recursive: true
|
|
162
|
-
- args: [--global, "vercel", "@dotenvx/dotenvx", "tsx"]
|
|
163
|
-
|
|
164
|
-
- name: 安装node
|
|
165
|
-
uses: actions/setup-node@v4
|
|
166
|
-
with:
|
|
167
|
-
node-version: 20.15.1
|
|
168
|
-
cache: pnpm
|
|
169
|
-
|
|
170
|
-
- name: 检查版本
|
|
171
|
-
run: |
|
|
172
|
-
node -v
|
|
173
|
-
pnpm -v
|
|
174
|
-
vc -v
|
|
175
|
-
|
|
176
|
-
- name: pnpm全局检查依赖包
|
|
177
|
-
run: pnpm ls -g
|
|
178
|
-
|
|
179
|
-
- name: 运行自写的vercel部署工具
|
|
180
|
-
# 读取环境变量
|
|
181
|
-
# https://dotenvx.com/docs/cis/github-actions#install-dotenvx
|
|
182
|
-
# pnpm run your-command
|
|
183
|
-
run: |
|
|
184
|
-
curl -sfS https://dotenvx.sh/install.sh | sh
|
|
185
|
-
pnpm dotenvx run -- pnpm run deploy-vercel
|
|
186
|
-
```
|
|
187
|
-
|
|
188
130
|
## 路线图
|
|
189
131
|
|
|
190
132
|
- [x] 封装打包命令,`vc deploy` 命令,并赋予生产环境 url。
|
|
@@ -192,4 +134,3 @@ jobs:
|
|
|
192
134
|
- [x] github action 运行产物。
|
|
193
135
|
- [x] github action 全局安装新开发的包,实现纯工作流的部署。
|
|
194
136
|
- [x] 去其他项目,自主完成配置与部署。
|
|
195
|
-
- [ ] 封装 node 的 bin 命令,发包。
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/vercel-deploy-tool",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "阮喵喵自用的vercel部署工具,用于实现复杂项目的部署。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
7
7
|
"types": "./src/index.ts",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://vercel-deploy-tool.ruancat6312.top",
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/ruan-cat/monorepo/issues"
|
|
11
11
|
},
|
|
@@ -41,27 +41,31 @@
|
|
|
41
41
|
"tsconfig.json"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@dotenvx/dotenvx": "^1.
|
|
45
|
-
"c12": "^3.0
|
|
44
|
+
"@dotenvx/dotenvx": "^1.48.3",
|
|
45
|
+
"c12": "^3.1.0",
|
|
46
46
|
"commander": "^13.1.0",
|
|
47
|
-
"consola": "^3.4.
|
|
47
|
+
"consola": "^3.4.2",
|
|
48
48
|
"gradient-string": "^3.0.0",
|
|
49
49
|
"lodash-es": "^4.17.21",
|
|
50
50
|
"pathe": "^2.0.3",
|
|
51
51
|
"rimraf": "^6.0.1",
|
|
52
|
-
"vercel": "^41.
|
|
53
|
-
"@ruan-cat/utils": "^4.
|
|
52
|
+
"vercel": "^41.7.8",
|
|
53
|
+
"@ruan-cat/utils": "^4.9.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/gulp": "^4.0.17",
|
|
57
57
|
"@types/lodash-es": "^4.17.12",
|
|
58
|
-
"@types/node": "^22.
|
|
59
|
-
"execa": "^9.
|
|
58
|
+
"@types/node": "^22.16.5",
|
|
59
|
+
"execa": "^9.6.0",
|
|
60
|
+
"vitepress": "^1.6.3",
|
|
61
|
+
"@ruan-cat/vitepress-preset-config": "^0.16.1"
|
|
60
62
|
},
|
|
61
63
|
"scripts": {
|
|
64
|
+
"docs:dev": "vitepress dev docs --port 8080",
|
|
65
|
+
"build:docs": "vitepress build docs",
|
|
62
66
|
"—build-not-use-for-now": "tsc",
|
|
63
67
|
"start": "node ./dist/index.js",
|
|
64
|
-
"run": "
|
|
65
|
-
"test:config": "
|
|
68
|
+
"run": "tsx ./src/index.ts --env-path=.env.test",
|
|
69
|
+
"test:config": "dotenvx run -f .env.test -f .env.test-2 -- tsx ./tests/config.test.ts"
|
|
66
70
|
}
|
|
67
71
|
}
|
package/src/config.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { resolve } from "pathe";
|
|
|
2
2
|
import { loadConfig } from "c12";
|
|
3
3
|
import { config as dotenvConfig } from "@dotenvx/dotenvx";
|
|
4
4
|
import { consola } from "consola";
|
|
5
|
-
import {
|
|
5
|
+
import { isUndefined } from "lodash-es";
|
|
6
6
|
import { program } from "commander";
|
|
7
|
+
import { printFormat } from "@ruan-cat/utils";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @description
|
|
@@ -162,9 +163,21 @@ program
|
|
|
162
163
|
.parse();
|
|
163
164
|
const options = program.opts();
|
|
164
165
|
|
|
166
|
+
const envPath = options?.envPath;
|
|
167
|
+
|
|
168
|
+
if (!isUndefined(envPath)) {
|
|
169
|
+
consola.warn(` 警告 :envPath 参数已被弃用,请使用 dotenvx 命令行工具来注入环境变量 `);
|
|
170
|
+
}
|
|
171
|
+
|
|
165
172
|
consola.info(" 查看命令行提供的参数 ", options);
|
|
166
173
|
|
|
167
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* 初始化的当前的环境变量
|
|
176
|
+
* @deprecated
|
|
177
|
+
* 设计变更
|
|
178
|
+
*
|
|
179
|
+
* 本函数目前不会再继续用 dotenvConfig 来获取环境变量了
|
|
180
|
+
*/
|
|
168
181
|
function initCurrentDotenvConfig() {
|
|
169
182
|
// 如果存在环境变量路径 就使用并读取
|
|
170
183
|
const dotenvConfigParams = options?.envPath
|
|
@@ -173,17 +186,15 @@ function initCurrentDotenvConfig() {
|
|
|
173
186
|
}
|
|
174
187
|
: {};
|
|
175
188
|
|
|
176
|
-
const res = dotenvConfig(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
consola.
|
|
185
|
-
consola.box(res);
|
|
186
|
-
|
|
189
|
+
const res = dotenvConfig().parsed;
|
|
190
|
+
// dotenvConfigParams,
|
|
191
|
+
// {
|
|
192
|
+
// // 具体识别的路径,会自动识别根目录下面的env文件,故这里不作处理
|
|
193
|
+
// path: "../../../.env"
|
|
194
|
+
// }
|
|
195
|
+
// consola.info(" 查看来自 @dotenvx/dotenvx 获取的环境变量: ");
|
|
196
|
+
// consola.box(process.env);
|
|
197
|
+
// consola.success(" process.env ", process.env);
|
|
187
198
|
return res;
|
|
188
199
|
}
|
|
189
200
|
|
|
@@ -213,7 +224,7 @@ async function loadUserConfig() {
|
|
|
213
224
|
});
|
|
214
225
|
|
|
215
226
|
consola.success(" 完成加载用户配置 ");
|
|
216
|
-
consola.box(config);
|
|
227
|
+
consola.box(printFormat(config));
|
|
217
228
|
|
|
218
229
|
return config;
|
|
219
230
|
}
|
|
@@ -224,29 +235,31 @@ async function loadUserConfig() {
|
|
|
224
235
|
* 初始化环境变量
|
|
225
236
|
*/
|
|
226
237
|
export async function initVercelConfig() {
|
|
227
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* 当前的环境变量
|
|
240
|
+
* @deprecated
|
|
241
|
+
*/
|
|
228
242
|
const currentDotenvConfig = initCurrentDotenvConfig();
|
|
229
243
|
|
|
230
244
|
/** 用户配置 */
|
|
231
245
|
const userConfig = await loadUserConfig();
|
|
232
246
|
|
|
233
|
-
const vercelOrgId =
|
|
234
|
-
const vercelProjectId =
|
|
235
|
-
const vercelToken =
|
|
247
|
+
const vercelOrgId = process.env.VERCEL_ORG_ID;
|
|
248
|
+
const vercelProjectId = process.env.VERCEL_PROJECT_ID;
|
|
249
|
+
const vercelToken = process.env.VERCEL_TOKEN;
|
|
236
250
|
|
|
237
|
-
if (!
|
|
251
|
+
if (!isUndefined(vercelOrgId)) {
|
|
238
252
|
userConfig.vercelOrgId = vercelOrgId;
|
|
239
253
|
}
|
|
240
|
-
if (!
|
|
254
|
+
if (!isUndefined(vercelProjectId)) {
|
|
241
255
|
userConfig.vercelProjectId = vercelProjectId;
|
|
242
256
|
}
|
|
243
|
-
if (!
|
|
257
|
+
if (!isUndefined(vercelToken)) {
|
|
244
258
|
userConfig.vercelToken = vercelToken;
|
|
245
259
|
}
|
|
246
260
|
|
|
247
|
-
consola.success(
|
|
248
|
-
|
|
249
|
-
consola.box(userConfig);
|
|
261
|
+
consola.success(` 完成初始化项目配置 `);
|
|
262
|
+
consola.box(printFormat(userConfig));
|
|
250
263
|
|
|
251
264
|
return userConfig;
|
|
252
265
|
}
|