@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.
- package/README.md +375 -75
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +578 -0
- package/dist/index.d.ts +247 -0
- package/dist/index.js +566 -0
- package/package.json +14 -6
- package/src/cli.ts +61 -0
- package/src/commands/deploy.ts +50 -0
- package/src/commands/init.ts +92 -0
- package/src/config/define-config.ts +20 -0
- package/src/config/loader.ts +95 -0
- package/src/config/schema.ts +108 -0
- package/src/core/executor.ts +50 -0
- package/src/core/tasks/after-build.ts +46 -0
- package/src/core/tasks/alias.ts +37 -0
- package/src/core/tasks/build.ts +50 -0
- package/src/core/tasks/copy-dist.ts +59 -0
- package/src/core/tasks/deploy.ts +54 -0
- package/src/core/tasks/index.ts +144 -0
- package/src/core/tasks/link.ts +49 -0
- package/src/core/tasks/user-commands.ts +31 -0
- package/src/core/vercel.ts +55 -0
- package/src/index.ts +68 -550
- package/src/templates/vercel-deploy-tool.config.ts +129 -0
- package/src/types/index.ts +14 -0
- package/src/utils/type-guards.ts +33 -0
- package/src/utils/vercel-null-config.ts +46 -0
- package/tsconfig.json +3 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { defineConfig } from "@ruan-cat/vercel-deploy-tool";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vercel 部署工具配置
|
|
5
|
+
* @description
|
|
6
|
+
* 配置 Vercel 部署的各项参数
|
|
7
|
+
*
|
|
8
|
+
* @see https://vercel-deploy-tool.ruancat6312.top
|
|
9
|
+
*/
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
/**
|
|
12
|
+
* Vercel 项目名称
|
|
13
|
+
* @description
|
|
14
|
+
* 在 Vercel 控制台中创建的项目名称
|
|
15
|
+
*/
|
|
16
|
+
vercelProjectName: "your-project-name",
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Vercel Token
|
|
20
|
+
* @description
|
|
21
|
+
* 从 Vercel 账户设置中获取的 API Token
|
|
22
|
+
* 建议使用环境变量
|
|
23
|
+
*/
|
|
24
|
+
vercelToken: process.env.VERCEL_TOKEN || "",
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Vercel 组织 ID
|
|
28
|
+
* @description
|
|
29
|
+
* Vercel 组织的唯一标识符
|
|
30
|
+
* 建议使用环境变量
|
|
31
|
+
*/
|
|
32
|
+
vercelOrgId: process.env.VERCEL_ORG_ID || "",
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Vercel 项目 ID
|
|
36
|
+
* @description
|
|
37
|
+
* Vercel 项目的唯一标识符
|
|
38
|
+
* 建议使用环境变量
|
|
39
|
+
*/
|
|
40
|
+
vercelProjectId: process.env.VERCEL_PROJECT_ID || "",
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 自定义 Vercel 配置文件路径(可选)
|
|
44
|
+
* @description
|
|
45
|
+
* 如果需要使用自定义的 vercel.json 配置文件,可以在这里指定路径
|
|
46
|
+
*/
|
|
47
|
+
// vercelJsonPath: "./custom-vercel.json",
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 构建后执行的命令(可选)
|
|
51
|
+
* @description
|
|
52
|
+
* 在 Vercel build 阶段后执行的命令
|
|
53
|
+
*/
|
|
54
|
+
// afterBuildTasks: [
|
|
55
|
+
// "echo 'Build completed'",
|
|
56
|
+
// "pnpm run post-build",
|
|
57
|
+
// ],
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 部署目标
|
|
61
|
+
* @description
|
|
62
|
+
* 配置需要部署的项目列表
|
|
63
|
+
* 支持 monorepo 中的多个子项目
|
|
64
|
+
*/
|
|
65
|
+
deployTargets: [
|
|
66
|
+
{
|
|
67
|
+
/**
|
|
68
|
+
* 部署类型
|
|
69
|
+
* @description
|
|
70
|
+
* - "static": 静态站点
|
|
71
|
+
* - "userCommands": 需要执行用户命令的项目
|
|
72
|
+
*/
|
|
73
|
+
type: "userCommands",
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 目标工作目录
|
|
77
|
+
* @description
|
|
78
|
+
* 项目在 monorepo 中的相对路径
|
|
79
|
+
*/
|
|
80
|
+
targetCWD: "./packages/docs",
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 生产环境访问 URL
|
|
84
|
+
* @description
|
|
85
|
+
* 部署后的自定义域名列表
|
|
86
|
+
*/
|
|
87
|
+
url: ["docs.example.com", "www.example.com"],
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 用户命令
|
|
91
|
+
* @description
|
|
92
|
+
* 构建项目的命令列表
|
|
93
|
+
*/
|
|
94
|
+
userCommands: ["pnpm build:docs"],
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 输出目录
|
|
98
|
+
* @description
|
|
99
|
+
* 构建产物的输出路径(相对于 targetCWD)
|
|
100
|
+
*/
|
|
101
|
+
outputDirectory: "docs/.vitepress/dist",
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 是否复制构建产物(可选)
|
|
105
|
+
* @description
|
|
106
|
+
* 是否将构建产物复制到 Vercel 指定的输出目录
|
|
107
|
+
* @default true
|
|
108
|
+
*/
|
|
109
|
+
// isCopyDist: true,
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 是否需要 Vercel Build(可选)
|
|
113
|
+
* @description
|
|
114
|
+
* 是否需要执行 `vercel build` 命令
|
|
115
|
+
* @default true
|
|
116
|
+
*/
|
|
117
|
+
// isNeedVercelBuild: true,
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
// 可以添加更多部署目标
|
|
121
|
+
// {
|
|
122
|
+
// type: "userCommands",
|
|
123
|
+
// targetCWD: "./packages/app",
|
|
124
|
+
// url: ["app.example.com"],
|
|
125
|
+
// userCommands: ["pnpm build"],
|
|
126
|
+
// outputDirectory: "dist",
|
|
127
|
+
// },
|
|
128
|
+
],
|
|
129
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DeployTarget, DeployTargetWithUserCommands, DeployTargetBase } from "../config/schema";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 类型守卫:判断是否为 static 类型的部署目标
|
|
5
|
+
*/
|
|
6
|
+
export function isDeployTargetBase(target: DeployTarget): target is DeployTargetBase {
|
|
7
|
+
return target.type === "static";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 类型守卫:判断是否为 userCommands 类型的部署目标
|
|
12
|
+
*/
|
|
13
|
+
export function isDeployTargetWithUserCommands(target: DeployTarget): target is DeployTargetWithUserCommands {
|
|
14
|
+
return target.type === "userCommands";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 获得 isCopyDist 配置
|
|
19
|
+
* @description
|
|
20
|
+
* 提供默认值处理
|
|
21
|
+
*/
|
|
22
|
+
export function getIsCopyDist(target: DeployTargetWithUserCommands): boolean {
|
|
23
|
+
return target.isCopyDist ?? true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 获得 isNeedVercelBuild 配置
|
|
28
|
+
* @description
|
|
29
|
+
* 提供默认值处理
|
|
30
|
+
*/
|
|
31
|
+
export function isNeedVercelBuild(target: DeployTarget): boolean {
|
|
32
|
+
return target.isNeedVercelBuild ?? true;
|
|
33
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel 的空配置
|
|
3
|
+
* @description
|
|
4
|
+
* 设计理由:
|
|
5
|
+
*
|
|
6
|
+
* 用于驱动vercel构建简单的目录结构,不需要额外的配置
|
|
7
|
+
*
|
|
8
|
+
* 该配置会被写入到 `vercel.null.def.json` 文件中
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/amondnet/vercel-action#method-1---via-vercel-interface
|
|
11
|
+
*/
|
|
12
|
+
export const VERCEL_NULL_CONFIG = {
|
|
13
|
+
framework: null,
|
|
14
|
+
buildCommand: null,
|
|
15
|
+
installCommand: null,
|
|
16
|
+
outputDirectory: null,
|
|
17
|
+
devCommand: null,
|
|
18
|
+
public: false,
|
|
19
|
+
/**
|
|
20
|
+
* 部署后提供干净的链接
|
|
21
|
+
* @see https://vercel.com/docs/projects/project-configuration#cleanurls
|
|
22
|
+
*
|
|
23
|
+
* @description
|
|
24
|
+
* 暂无效果
|
|
25
|
+
*
|
|
26
|
+
* 目前在 build-output-api 中,实现cleanUrls需要手动地写入配置文件
|
|
27
|
+
*
|
|
28
|
+
* 成本较大,目前不做投入。
|
|
29
|
+
*/
|
|
30
|
+
cleanUrls: true,
|
|
31
|
+
git: {
|
|
32
|
+
deploymentEnabled: {
|
|
33
|
+
main: false,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
} as const;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 空配置文件的路径
|
|
40
|
+
* @description
|
|
41
|
+
* 生成空配置文件。这样用户在其他项目内,就不需要自己提供vercel配置文件了。
|
|
42
|
+
*/
|
|
43
|
+
export const VERCEL_NULL_CONFIG_PATH = "./vercel.null.def.json";
|
|
44
|
+
|
|
45
|
+
/** Vercel文件api指定要求的文件目录 */
|
|
46
|
+
export const VERCEL_OUTPUT_STATIC = ".vercel/output/static";
|