@ruan-cat/vercel-deploy-tool 0.12.2 → 1.1.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.
@@ -0,0 +1,247 @@
1
+ import { Command } from 'commander';
2
+
3
+ /**
4
+ * @description
5
+ * 从 drizzle-kit 学的类型验证技巧
6
+ */
7
+ type Verify<T, U extends T> = U;
8
+ /** 部署目标类型 */
9
+ type DeployTargetType = "static" | "userCommands";
10
+ /** 基础配置 */
11
+ interface DeployTargetBase {
12
+ /** 部署目标分类 */
13
+ type: DeployTargetType;
14
+ /** 目标的工作目录 */
15
+ targetCWD: `./${string}`;
16
+ /** 生产环境的访问url */
17
+ url: string[];
18
+ /**
19
+ * 是否需要vercel的build命令?
20
+ * @description
21
+ * 某些情况下用户已经能够准备好vercel的目录结构,不需要依赖于 `vercel build` 命令完成目录构建
22
+ *
23
+ * 故设计此配置允许用户直接跳过 `vercel build` 命令
24
+ * @default true
25
+ */
26
+ isNeedVercelBuild?: boolean;
27
+ }
28
+ /**
29
+ * 带有用户命令的配置
30
+ */
31
+ interface DeployTargetWithUserCommands extends DeployTargetBase {
32
+ type: Verify<DeployTargetType, "userCommands">;
33
+ /**
34
+ * 用户命令
35
+ * @description
36
+ * 实际部署的构建命令,通常是真实参与部署的命令
37
+ *
38
+ * @example ["pnpm -C=./packages/docs-01-star build:docs"]
39
+ * @example ["pnpm -C=./packages/monorepo-5 build:docs"]
40
+ */
41
+ userCommands: string[];
42
+ /**
43
+ * 部署输出路径
44
+ *
45
+ * @version 2
46
+ * @description
47
+ * 填写打包目录的路径即可。不包含glob语法。
48
+ * @example "docs/.vitepress/dist"
49
+ * @example "src/.vuepress/dist"
50
+ */
51
+ outputDirectory: string;
52
+ /**
53
+ * 是否移动打包目录至特定的vercel部署目录?
54
+ * @description
55
+ * 执行完用户命令后,一般会执行文件移动命令,以便于部署
56
+ *
57
+ * 该配置用于控制是否执行文件移动命令
58
+ *
59
+ * @default true
60
+ */
61
+ isCopyDist?: boolean;
62
+ }
63
+ /** 部署目标的具体项目配置 */
64
+ type DeployTarget = DeployTargetBase | DeployTargetWithUserCommands;
65
+ /** Vercel部署工具的配置 */
66
+ interface VercelDeployConfig {
67
+ /** 项目名称 */
68
+ vercelProjectName: string;
69
+ /** 用户token */
70
+ vercelToken: string;
71
+ /** 用户组织id */
72
+ vercelOrgId: string;
73
+ /** 用户项目id */
74
+ vercelProjectId: string;
75
+ /**
76
+ * 用户提供的 vercel.json 配置文件
77
+ * @description
78
+ * 有时候用户需要提供自己的一套配置文件
79
+ *
80
+ * 这里提供配置路径
81
+ */
82
+ vercelJsonPath?: string;
83
+ /** 在build命令阶段后执行的用户命令 */
84
+ afterBuildTasks?: string[];
85
+ /**
86
+ * 部署目标
87
+ * @description
88
+ * 考虑到可能要部署一揽子的项目,所以这里使用数组
89
+ *
90
+ * 考虑monorepo的情况
91
+ */
92
+ deployTargets: DeployTarget[];
93
+ }
94
+
95
+ /**
96
+ * 定义配置的辅助函数
97
+ * @description
98
+ * 提供类型提示和智能补全
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import { defineConfig } from "@ruan-cat/vercel-deploy-tool";
103
+ *
104
+ * export default defineConfig({
105
+ * vercelProjectName: "my-project",
106
+ * // ...
107
+ * });
108
+ * ```
109
+ */
110
+ declare function defineConfig(config: VercelDeployConfig): VercelDeployConfig;
111
+
112
+ /**
113
+ * 异步加载配置(工厂函数模式)
114
+ * @description
115
+ * 从约定俗成的配置处,获得用户配置文件。不会在模块导入时自动执行,避免 top-level await 引起的执行时警告。
116
+ *
117
+ * 环境变量优先级:
118
+ * 1) 命令行传入的 env-path(通过 VERCEL_DEPLOY_TOOL_ENV_PATH 或 deploy 命令参数注入)
119
+ * 2) Node 进程已有的 process.env
120
+ * 3) c12 默认加载的 .env* 文件
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * const config = await loadConfig();
125
+ * ```
126
+ */
127
+ declare function loadConfig(): Promise<VercelDeployConfig>;
128
+ /**
129
+ * 导出配置获取函数(带缓存)
130
+ * @description
131
+ * 首次调用会触发加载,后续复用结果。避免 top-level await。
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * import { getConfig } from "@ruan-cat/vercel-deploy-tool";
136
+ * const config = await getConfig();
137
+ * ```
138
+ */
139
+ declare function getConfig(): Promise<VercelDeployConfig>;
140
+
141
+ /**
142
+ * 执行 Vercel 部署工作流
143
+ * @description
144
+ * 这是整个部署流程的总入口,使用 tasuku 编排所有任务
145
+ *
146
+ * 任务执行顺序:
147
+ * 1. Link 阶段(并行)
148
+ * 2. Build 阶段(并行)
149
+ * 3. AfterBuild 阶段(串行)
150
+ * 4. UserCommands + CopyDist 阶段(并行目标,串行步骤)
151
+ * 5. Deploy + Alias 阶段(并行目标,串行步骤)
152
+ */
153
+ declare function executeDeploymentWorkflow(config: VercelDeployConfig): Promise<void>;
154
+
155
+ /**
156
+ * Vercel 的空配置
157
+ * @description
158
+ * 设计理由:
159
+ *
160
+ * 用于驱动vercel构建简单的目录结构,不需要额外的配置
161
+ *
162
+ * 该配置会被写入到 `vercel.null.def.json` 文件中
163
+ *
164
+ * @see https://github.com/amondnet/vercel-action#method-1---via-vercel-interface
165
+ */
166
+ declare const VERCEL_NULL_CONFIG: {
167
+ readonly framework: null;
168
+ readonly buildCommand: null;
169
+ readonly installCommand: null;
170
+ readonly outputDirectory: null;
171
+ readonly devCommand: null;
172
+ readonly public: false;
173
+ /**
174
+ * 部署后提供干净的链接
175
+ * @see https://vercel.com/docs/projects/project-configuration#cleanurls
176
+ *
177
+ * @description
178
+ * 暂无效果
179
+ *
180
+ * 目前在 build-output-api 中,实现cleanUrls需要手动地写入配置文件
181
+ *
182
+ * 成本较大,目前不做投入。
183
+ */
184
+ readonly cleanUrls: true;
185
+ readonly git: {
186
+ readonly deploymentEnabled: {
187
+ readonly main: false;
188
+ };
189
+ };
190
+ };
191
+ /**
192
+ * 空配置文件的路径
193
+ * @description
194
+ * 生成空配置文件。这样用户在其他项目内,就不需要自己提供vercel配置文件了。
195
+ */
196
+ declare const VERCEL_NULL_CONFIG_PATH = "./vercel.null.def.json";
197
+ /** Vercel文件api指定要求的文件目录 */
198
+ declare const VERCEL_OUTPUT_STATIC = ".vercel/output/static";
199
+
200
+ /**
201
+ * 类型守卫:判断是否为 static 类型的部署目标
202
+ */
203
+ declare function isDeployTargetBase(target: DeployTarget): target is DeployTargetBase;
204
+ /**
205
+ * 类型守卫:判断是否为 userCommands 类型的部署目标
206
+ */
207
+ declare function isDeployTargetWithUserCommands(target: DeployTarget): target is DeployTargetWithUserCommands;
208
+ /**
209
+ * 获得 isCopyDist 配置
210
+ * @description
211
+ * 提供默认值处理
212
+ */
213
+ declare function getIsCopyDist(target: DeployTargetWithUserCommands): boolean;
214
+ /**
215
+ * 获得 isNeedVercelBuild 配置
216
+ * @description
217
+ * 提供默认值处理
218
+ */
219
+ declare function isNeedVercelBuild(target: DeployTarget): boolean;
220
+
221
+ /**
222
+ * 创建 deploy 命令
223
+ * @description
224
+ * 部署项目到 Vercel
225
+ *
226
+ * @example
227
+ * ```bash
228
+ * vercel-deploy-tool deploy
229
+ * vdt deploy
230
+ * ```
231
+ */
232
+ declare function createDeployCommand(): Command;
233
+
234
+ /**
235
+ * 创建 init 命令
236
+ * @description
237
+ * 初始化配置文件,生成 vercel-deploy-tool.config.ts 模板
238
+ *
239
+ * @example
240
+ * ```bash
241
+ * vercel-deploy-tool init
242
+ * vercel-deploy-tool init --force
243
+ * ```
244
+ */
245
+ declare function createInitCommand(): Command;
246
+
247
+ export { type DeployTarget, type DeployTargetBase, type DeployTargetType, type DeployTargetWithUserCommands, VERCEL_NULL_CONFIG, VERCEL_NULL_CONFIG_PATH, VERCEL_OUTPUT_STATIC, type VercelDeployConfig, createDeployCommand, createInitCommand, defineConfig, executeDeploymentWorkflow, getConfig, getIsCopyDist, isDeployTargetBase, isDeployTargetWithUserCommands, isNeedVercelBuild, loadConfig };