@ruan-cat/vercel-deploy-tool 0.3.0 → 0.3.1
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 +5 -8
- package/src/index.ts +14 -2
- package/tsconfig.json +7 -2
- package/src/utils/define-promise-tasks.ts +0 -138
- package/src/utils/simple-promise-tools.ts +0 -94
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/vercel-deploy-tool",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "阮喵喵自用的vercel部署工具,用于实现复杂项目的部署。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
7
7
|
"types": "./src/index.ts",
|
|
8
|
-
"homepage": "https://github.com/ruan-cat/vercel-monorepo-test/tree/main/
|
|
8
|
+
"homepage": "https://github.com/ruan-cat/vercel-monorepo-test/tree/main/packages/vercel-deploy-tool",
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/ruan-cat/vercel-monorepo-test/issues"
|
|
11
11
|
},
|
|
@@ -53,23 +53,20 @@
|
|
|
53
53
|
"pathe": "^1.1.2",
|
|
54
54
|
"rimraf": "^6.0.1",
|
|
55
55
|
"shx": "^0.3.4",
|
|
56
|
-
"vercel": "^
|
|
57
|
-
"@ruan-cat/utils": "^1.
|
|
56
|
+
"vercel": "^39.1.2",
|
|
57
|
+
"@ruan-cat/utils": "^1.3.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/cpx": "^1.5.5",
|
|
61
61
|
"@types/gulp": "^4.0.17",
|
|
62
62
|
"@types/lodash-es": "^4.17.12",
|
|
63
|
-
"@types/node": "^22.5.1"
|
|
64
|
-
"@vitest/ui": "^2.0.5",
|
|
65
|
-
"vitest": "^2.0.5"
|
|
63
|
+
"@types/node": "^22.5.1"
|
|
66
64
|
},
|
|
67
65
|
"scripts": {
|
|
68
66
|
"—build-not-use-for-now": "tsc",
|
|
69
67
|
"start": "node ./dist/index.js",
|
|
70
68
|
"run": "node --import=tsx ./src/index.ts --env-path=.env.test",
|
|
71
69
|
"test:config": "node --import=tsx ./tests/config.test.ts --env-path=.env.test",
|
|
72
|
-
"test:vitest": "vitest --ui --watch",
|
|
73
70
|
"rm:node_modules": "rimraf node_modules"
|
|
74
71
|
}
|
|
75
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
type DeployTarget,
|
|
21
21
|
type WithUserCommands,
|
|
22
22
|
} from "./config";
|
|
23
|
-
import { generateSimpleAsyncTask } from "
|
|
23
|
+
import { generateSimpleAsyncTask } from "@ruan-cat/utils/src/simple-promise-tools";
|
|
24
24
|
|
|
25
25
|
import {
|
|
26
26
|
definePromiseTasks,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
type ParallelTasks,
|
|
30
30
|
type QueueTasks,
|
|
31
31
|
type Task,
|
|
32
|
-
} from "
|
|
32
|
+
} from "@ruan-cat/utils/src/define-promise-tasks";
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* vercel 的空配置
|
|
@@ -49,6 +49,18 @@ export const vercelNullConfig = <const>{
|
|
|
49
49
|
outputDirectory: null,
|
|
50
50
|
devCommand: null,
|
|
51
51
|
public: false,
|
|
52
|
+
/**
|
|
53
|
+
* 部署后提供干净的链接
|
|
54
|
+
* @see https://vercel.com/docs/projects/project-configuration#cleanurls
|
|
55
|
+
*
|
|
56
|
+
* @description
|
|
57
|
+
* 暂无效果
|
|
58
|
+
*
|
|
59
|
+
* 目前在 build-output-api 中,实现cleanUrls需要手动地写入配置文件
|
|
60
|
+
*
|
|
61
|
+
* 成本较大,目前不做投入。
|
|
62
|
+
*/
|
|
63
|
+
cleanUrls: true,
|
|
52
64
|
git: {
|
|
53
65
|
deploymentEnabled: {
|
|
54
66
|
main: false,
|
package/tsconfig.json
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"references": [
|
|
4
|
+
{
|
|
5
|
+
"path": "../../tsconfig.md.json"
|
|
6
|
+
}
|
|
7
|
+
],
|
|
3
8
|
"compilerOptions": {
|
|
4
9
|
"target": "ESNext",
|
|
5
10
|
"module": "ESNext",
|
|
@@ -31,8 +36,8 @@
|
|
|
31
36
|
"include": [
|
|
32
37
|
"./src/**/*.ts",
|
|
33
38
|
"./tests/**/*.test.ts",
|
|
34
|
-
"./tests/**/*.ts"
|
|
35
|
-
// "src",
|
|
39
|
+
"./tests/**/*.ts",
|
|
40
|
+
"../utils/src/define-promise-tasks.ts" // "src",
|
|
36
41
|
// "tests"
|
|
37
42
|
]
|
|
38
43
|
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type SimpleAsyncTask,
|
|
3
|
-
type SimpleAsyncTaskWithType,
|
|
4
|
-
generateSimpleAsyncTask,
|
|
5
|
-
runPromiseByConcurrency,
|
|
6
|
-
runPromiseByQueue,
|
|
7
|
-
} from "./simple-promise-tools";
|
|
8
|
-
|
|
9
|
-
export const taskTypes = <const>["single", "parallel", "queue"];
|
|
10
|
-
|
|
11
|
-
export type TaskType = (typeof taskTypes)[number];
|
|
12
|
-
|
|
13
|
-
export interface BaseTask {
|
|
14
|
-
/** 任务类型 */
|
|
15
|
-
type: TaskType;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// type Task = SimpleAsyncTaskWithType | TasksConfig;
|
|
19
|
-
export type Task = SimpleAsyncTask | TasksConfig;
|
|
20
|
-
|
|
21
|
-
export interface SingleTasks extends BaseTask {
|
|
22
|
-
type: "single";
|
|
23
|
-
tasks: Task;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface ParallelTasks extends BaseTask {
|
|
27
|
-
type: "parallel";
|
|
28
|
-
tasks: Task[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface QueueTasks extends BaseTask {
|
|
32
|
-
type: "queue";
|
|
33
|
-
tasks: Task[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type TasksConfig = SingleTasks | ParallelTasks | QueueTasks;
|
|
37
|
-
|
|
38
|
-
export type PromiseTasksConfig = TasksConfig;
|
|
39
|
-
|
|
40
|
-
function isSingleTasks(config: TasksConfig): config is SingleTasks {
|
|
41
|
-
return config.type === "single";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function isParallelTasks(config: TasksConfig): config is ParallelTasks {
|
|
45
|
-
return config.type === "parallel";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isQueueTasks(config: TasksConfig): config is QueueTasks {
|
|
49
|
-
return config.type === "queue";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isSimpleAsyncTask(config: Task): config is SimpleAsyncTask {
|
|
53
|
-
return typeof config === "function";
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function isTasksConfig(config: Task): config is TasksConfig {
|
|
57
|
-
return typeof config === "object";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 定义异步任务对象
|
|
62
|
-
* @description
|
|
63
|
-
* 这个对象是一揽子异步任务的配置
|
|
64
|
-
*/
|
|
65
|
-
export function definePromiseTasks(config: TasksConfig) {
|
|
66
|
-
return config;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @private 一个工具函数 用于生成异步函数数组
|
|
71
|
-
* @deprecated 在处理串行任务时 疑似有故障
|
|
72
|
-
*/
|
|
73
|
-
function getPromises(tasks: Task[]): ((...args: any) => Promise<any>)[] {
|
|
74
|
-
return tasks.map((task) => {
|
|
75
|
-
return async function (...args: any) {
|
|
76
|
-
if (isSimpleAsyncTask(task)) {
|
|
77
|
-
return await task(...args);
|
|
78
|
-
} else {
|
|
79
|
-
return await executePromiseTasks(task);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* 执行异步函数对象
|
|
87
|
-
*/
|
|
88
|
-
export async function executePromiseTasks(
|
|
89
|
-
config: TasksConfig,
|
|
90
|
-
/**
|
|
91
|
-
* 上一次递归执行时提供的参数
|
|
92
|
-
* @description
|
|
93
|
-
* 考虑到递归函数 这里提供了一个参数 用于传递上一次递归执行的结果
|
|
94
|
-
*/
|
|
95
|
-
lastParams: any = null,
|
|
96
|
-
): Promise<any> {
|
|
97
|
-
if (isSingleTasks(config)) {
|
|
98
|
-
if (isSimpleAsyncTask(config.tasks)) {
|
|
99
|
-
// 实际执行的 tasks 往往是无参函数 这里为了保险,故主动传递参数
|
|
100
|
-
return await config.tasks(lastParams);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return await executePromiseTasks(config.tasks, lastParams);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (isParallelTasks(config)) {
|
|
107
|
-
return await Promise.all(
|
|
108
|
-
config.tasks.map((task) => {
|
|
109
|
-
if (isSimpleAsyncTask(task)) {
|
|
110
|
-
// console.log(` 并行任务遇到单独的异步函数 `);
|
|
111
|
-
return task(lastParams);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// console.log(` 并行任务遇到嵌套结构 `);
|
|
115
|
-
return executePromiseTasks(task, lastParams);
|
|
116
|
-
}),
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (isQueueTasks(config)) {
|
|
121
|
-
let res: Awaited<any>;
|
|
122
|
-
for await (const task of config.tasks) {
|
|
123
|
-
if (isSimpleAsyncTask(task)) {
|
|
124
|
-
// console.log(` 串行任务遇到单独的异步函数 `);
|
|
125
|
-
|
|
126
|
-
res = await task(lastParams);
|
|
127
|
-
lastParams = res;
|
|
128
|
-
// console.log(` 串行任务 单独 res `, res);
|
|
129
|
-
} else {
|
|
130
|
-
res = await executePromiseTasks(task, lastParams);
|
|
131
|
-
lastParams = res;
|
|
132
|
-
// console.log(` 串行任务 配置 res `, res);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return res;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { consola } from "consola";
|
|
2
|
-
import { uniqueId } from "lodash-es";
|
|
3
|
-
|
|
4
|
-
export function wait(time: number) {
|
|
5
|
-
return new Promise<void>((resolve) => {
|
|
6
|
-
setTimeout(() => {
|
|
7
|
-
resolve();
|
|
8
|
-
}, time);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const getCounter = () => uniqueId();
|
|
13
|
-
|
|
14
|
-
/** 创建简单的异步任务 */
|
|
15
|
-
export function generateSimpleAsyncTask<T extends (...args: any) => any>(func: T) {
|
|
16
|
-
const taskId = getCounter();
|
|
17
|
-
|
|
18
|
-
return function (...args: any) {
|
|
19
|
-
// consola.info(` 这是第 ${taskId} 个异步任务 `);
|
|
20
|
-
// consola.start(" 这里是新创建的异步函数 检查参数: ", ...args);
|
|
21
|
-
|
|
22
|
-
return new Promise<ReturnType<T>>((resolve, reject) => {
|
|
23
|
-
// consola.start(" 内部promise 检查参数: ", ...args);
|
|
24
|
-
resolve(func(...args));
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type SimpleAsyncTask = ReturnType<typeof generateSimpleAsyncTask>;
|
|
30
|
-
|
|
31
|
-
/** @deprecated */
|
|
32
|
-
export type SimpleAsyncTaskWithType = <T = any>(...args: any) => Promise<T>;
|
|
33
|
-
|
|
34
|
-
export const initFlag = <const>"initFlag";
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 以队列串行的形式 串行运行异步函数
|
|
38
|
-
* @see https://github.com/ascoders/weekly/blob/master/前沿技术/77.精读《用%20Reduce%20实现%20Promise%20串行执行》.md
|
|
39
|
-
* @version 1
|
|
40
|
-
*/
|
|
41
|
-
async function runPromiseByQueueV1<T>(promises: ((...args: any) => Promise<T>)[]) {
|
|
42
|
-
promises.reduce(
|
|
43
|
-
async function (previousPromise, nextPromise, currentIndex) {
|
|
44
|
-
const response = await previousPromise;
|
|
45
|
-
// consola.log(` reduce串行函数 currentIndex= ${currentIndex} res =`, response);
|
|
46
|
-
return await nextPromise(response);
|
|
47
|
-
},
|
|
48
|
-
Promise.resolve(initFlag) as Promise<any>,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 以队列串行的形式 串行运行异步函数
|
|
54
|
-
* @version 2
|
|
55
|
-
*/
|
|
56
|
-
export async function runPromiseByQueue<T>(promises: ((...args: any) => Promise<T>)[]) {
|
|
57
|
-
let response: typeof initFlag | Awaited<T> = initFlag;
|
|
58
|
-
for await (const promise of promises) {
|
|
59
|
-
response = await promise(response);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 以并行的形式 并发运行异步函数
|
|
65
|
-
*/
|
|
66
|
-
export async function runPromiseByConcurrency<T>(promises: ((...args: any) => Promise<T>)[]) {
|
|
67
|
-
await Promise.all(promises.map((promise) => promise()));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const testPromises = [
|
|
71
|
-
generateSimpleAsyncTask(async function (params) {
|
|
72
|
-
await wait(400);
|
|
73
|
-
consola.log(" 这里是 1 号函数 ");
|
|
74
|
-
consola.log(" 查看上一个函数返回过来的参数: ", params);
|
|
75
|
-
return 1;
|
|
76
|
-
}),
|
|
77
|
-
|
|
78
|
-
generateSimpleAsyncTask(async function (params) {
|
|
79
|
-
await wait(500);
|
|
80
|
-
consola.log(" 这里是 2 号函数 ");
|
|
81
|
-
consola.log(" 查看上一个函数返回过来的参数: ", params);
|
|
82
|
-
return 2;
|
|
83
|
-
}),
|
|
84
|
-
|
|
85
|
-
generateSimpleAsyncTask(async function (params) {
|
|
86
|
-
await wait(500);
|
|
87
|
-
consola.log(" 这里是 3 号函数 ");
|
|
88
|
-
consola.log(" 查看上一个函数返回过来的参数: ", params);
|
|
89
|
-
return 3;
|
|
90
|
-
}),
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
// 测试队列函数的传参能力 发现这里是可以实现传参的
|
|
94
|
-
// runPromiseByQueue(testPromises);
|