@ruan-cat/vercel-deploy-tool 0.12.1 → 1.0.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,254 @@
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
+ * 从约定俗成的配置处,获得用户配置文件
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const config = await loadConfig();
120
+ * ```
121
+ */
122
+ declare function loadConfig(): Promise<VercelDeployConfig>;
123
+ /**
124
+ * 默认导出:已初始化的配置实例(top-level await)
125
+ * @description
126
+ * 这是混合模式的一部分,提供默认的配置实例
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { config } from "@ruan-cat/vercel-deploy-tool/config/loader";
131
+ * console.log(config.vercelProjectName);
132
+ * ```
133
+ */
134
+ declare const config: VercelDeployConfig;
135
+ /**
136
+ * 导出配置获取函数
137
+ * @description
138
+ * 获取已加载的配置实例
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import { getConfig } from "@ruan-cat/vercel-deploy-tool";
143
+ * const config = getConfig();
144
+ * ```
145
+ */
146
+ declare function getConfig(): VercelDeployConfig;
147
+
148
+ /**
149
+ * 执行 Vercel 部署工作流
150
+ * @description
151
+ * 这是整个部署流程的总入口,使用 tasuku 编排所有任务
152
+ *
153
+ * 任务执行顺序:
154
+ * 1. Link 阶段(并行)
155
+ * 2. Build 阶段(并行)
156
+ * 3. AfterBuild 阶段(串行)
157
+ * 4. UserCommands + CopyDist 阶段(并行目标,串行步骤)
158
+ * 5. Deploy + Alias 阶段(并行目标,串行步骤)
159
+ */
160
+ declare function executeDeploymentWorkflow(config: VercelDeployConfig): Promise<void>;
161
+
162
+ /**
163
+ * Vercel 的空配置
164
+ * @description
165
+ * 设计理由:
166
+ *
167
+ * 用于驱动vercel构建简单的目录结构,不需要额外的配置
168
+ *
169
+ * 该配置会被写入到 `vercel.null.def.json` 文件中
170
+ *
171
+ * @see https://github.com/amondnet/vercel-action#method-1---via-vercel-interface
172
+ */
173
+ declare const VERCEL_NULL_CONFIG: {
174
+ readonly framework: null;
175
+ readonly buildCommand: null;
176
+ readonly installCommand: null;
177
+ readonly outputDirectory: null;
178
+ readonly devCommand: null;
179
+ readonly public: false;
180
+ /**
181
+ * 部署后提供干净的链接
182
+ * @see https://vercel.com/docs/projects/project-configuration#cleanurls
183
+ *
184
+ * @description
185
+ * 暂无效果
186
+ *
187
+ * 目前在 build-output-api 中,实现cleanUrls需要手动地写入配置文件
188
+ *
189
+ * 成本较大,目前不做投入。
190
+ */
191
+ readonly cleanUrls: true;
192
+ readonly git: {
193
+ readonly deploymentEnabled: {
194
+ readonly main: false;
195
+ };
196
+ };
197
+ };
198
+ /**
199
+ * 空配置文件的路径
200
+ * @description
201
+ * 生成空配置文件。这样用户在其他项目内,就不需要自己提供vercel配置文件了。
202
+ */
203
+ declare const VERCEL_NULL_CONFIG_PATH = "./vercel.null.def.json";
204
+ /** Vercel文件api指定要求的文件目录 */
205
+ declare const VERCEL_OUTPUT_STATIC = ".vercel/output/static";
206
+
207
+ /**
208
+ * 类型守卫:判断是否为 static 类型的部署目标
209
+ */
210
+ declare function isDeployTargetBase(target: DeployTarget): target is DeployTargetBase;
211
+ /**
212
+ * 类型守卫:判断是否为 userCommands 类型的部署目标
213
+ */
214
+ declare function isDeployTargetWithUserCommands(target: DeployTarget): target is DeployTargetWithUserCommands;
215
+ /**
216
+ * 获得 isCopyDist 配置
217
+ * @description
218
+ * 提供默认值处理
219
+ */
220
+ declare function getIsCopyDist(target: DeployTargetWithUserCommands): boolean;
221
+ /**
222
+ * 获得 isNeedVercelBuild 配置
223
+ * @description
224
+ * 提供默认值处理
225
+ */
226
+ declare function isNeedVercelBuild(target: DeployTarget): boolean;
227
+
228
+ /**
229
+ * 创建 deploy 命令
230
+ * @description
231
+ * 部署项目到 Vercel
232
+ *
233
+ * @example
234
+ * ```bash
235
+ * vercel-deploy-tool deploy
236
+ * vdt deploy
237
+ * ```
238
+ */
239
+ declare function createDeployCommand(): Command;
240
+
241
+ /**
242
+ * 创建 init 命令
243
+ * @description
244
+ * 初始化配置文件,生成 vercel-deploy-tool.config.ts 模板
245
+ *
246
+ * @example
247
+ * ```bash
248
+ * vercel-deploy-tool init
249
+ * vercel-deploy-tool init --force
250
+ * ```
251
+ */
252
+ declare function createInitCommand(): Command;
253
+
254
+ export { type DeployTarget, type DeployTargetBase, type DeployTargetType, type DeployTargetWithUserCommands, VERCEL_NULL_CONFIG, VERCEL_NULL_CONFIG_PATH, VERCEL_OUTPUT_STATIC, type VercelDeployConfig, config, createDeployCommand, createInitCommand, defineConfig, executeDeploymentWorkflow, getConfig, getIsCopyDist, isDeployTargetBase, isDeployTargetWithUserCommands, isNeedVercelBuild, loadConfig };