@ruan-cat/vercel-deploy-tool 0.3.1 → 0.4.2
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 +1 -7
- package/src/config.ts +7 -0
- package/src/index.ts +59 -43
- package/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruan-cat/vercel-deploy-tool",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "阮喵喵自用的vercel部署工具,用于实现复杂项目的部署。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -44,12 +44,7 @@
|
|
|
44
44
|
"c12": "^1.11.2",
|
|
45
45
|
"commander": "^12.0.0",
|
|
46
46
|
"consola": "^3.2.3",
|
|
47
|
-
"cpx": "^1.5.0",
|
|
48
|
-
"cpy": "^11.1.0",
|
|
49
|
-
"del": "^8.0.0",
|
|
50
|
-
"execa": "^9.3.1",
|
|
51
47
|
"lodash-es": "4.17.21",
|
|
52
|
-
"mkdirp": "^3.0.1",
|
|
53
48
|
"pathe": "^1.1.2",
|
|
54
49
|
"rimraf": "^6.0.1",
|
|
55
50
|
"shx": "^0.3.4",
|
|
@@ -57,7 +52,6 @@
|
|
|
57
52
|
"@ruan-cat/utils": "^1.3.0"
|
|
58
53
|
},
|
|
59
54
|
"devDependencies": {
|
|
60
|
-
"@types/cpx": "^1.5.5",
|
|
61
55
|
"@types/gulp": "^4.0.17",
|
|
62
56
|
"@types/lodash-es": "^4.17.12",
|
|
63
57
|
"@types/node": "^22.5.1"
|
package/src/config.ts
CHANGED
|
@@ -57,10 +57,17 @@ export interface WithUserCommands extends Base {
|
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* 部署输出路径
|
|
60
|
+
*
|
|
61
|
+
* @version 1
|
|
60
62
|
* @description
|
|
61
63
|
* 这里要填写满足 cpx 库能够识别glob语法的路径
|
|
62
64
|
* @example docs/.vitepress/dist/**\/*
|
|
63
65
|
* @example src/.vuepress/dist/**\/*
|
|
66
|
+
*
|
|
67
|
+
* @version 2
|
|
68
|
+
* @description
|
|
69
|
+
* 填写打包目录的路径即可。不包含glob语法。
|
|
70
|
+
* @example docs/.vitepress/dist
|
|
64
71
|
*/
|
|
65
72
|
outputDirectory: string;
|
|
66
73
|
|
package/src/index.ts
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
// 学习一下如何使用 https://github.com/sindresorhus/execa/blob/main/readme.md
|
|
2
|
-
import fs from "node:fs";
|
|
3
2
|
import { dirname, resolve } from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import fs, {
|
|
5
|
+
// 文件是否存在
|
|
6
|
+
existsSync,
|
|
7
|
+
// 复制文件
|
|
8
|
+
copyFileSync,
|
|
9
|
+
// 复制目录
|
|
10
|
+
cpSync,
|
|
11
|
+
// 删除目录
|
|
12
|
+
rmSync,
|
|
13
|
+
// 新建文件夹
|
|
14
|
+
mkdir,
|
|
15
|
+
} from "node:fs";
|
|
16
|
+
|
|
6
17
|
import { concat, isEmpty, isUndefined } from "lodash-es";
|
|
7
18
|
import { consola } from "consola";
|
|
8
|
-
import { isConditionsEvery, isConditionsSome } from "@ruan-cat/utils";
|
|
9
|
-
import { deleteAsync } from "del";
|
|
10
|
-
import { mkdirpSync } from "mkdirp";
|
|
11
|
-
import cpy from "cpy";
|
|
12
|
-
import cpx from "cpx";
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
initVercelConfig,
|
|
16
|
-
config,
|
|
17
|
-
getConfig,
|
|
18
|
-
type Config,
|
|
19
|
-
type Base,
|
|
20
|
-
type DeployTarget,
|
|
21
|
-
type WithUserCommands,
|
|
22
|
-
} from "./config";
|
|
23
|
-
import { generateSimpleAsyncTask } from "@ruan-cat/utils/src/simple-promise-tools";
|
|
24
19
|
|
|
25
20
|
import {
|
|
21
|
+
isConditionsEvery,
|
|
22
|
+
isConditionsSome,
|
|
23
|
+
generateSimpleAsyncTask,
|
|
26
24
|
definePromiseTasks,
|
|
27
25
|
executePromiseTasks,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} from "
|
|
26
|
+
} from "@ruan-cat/utils";
|
|
27
|
+
import type { Task } from "@ruan-cat/utils";
|
|
28
|
+
|
|
29
|
+
import { config, getConfig } from "./config";
|
|
30
|
+
import type { Config, Base, DeployTarget, WithUserCommands } from "./config";
|
|
33
31
|
|
|
34
32
|
/**
|
|
35
33
|
* vercel 的空配置
|
|
@@ -162,13 +160,16 @@ function getTargetCWDCommandArgument(deployTarget: DeployTarget) {
|
|
|
162
160
|
}
|
|
163
161
|
|
|
164
162
|
/**
|
|
165
|
-
*
|
|
163
|
+
* 生成简单的执行命令函数
|
|
166
164
|
* @description
|
|
167
165
|
* 对 execa 做简单的包装
|
|
166
|
+
*
|
|
167
|
+
* 封装 spawnSync 函数
|
|
168
|
+
* @version 2
|
|
168
169
|
*/
|
|
169
170
|
function generateExeca(execaSimpleParams: { command: string; parameters: string[] }) {
|
|
170
171
|
const { command, parameters } = execaSimpleParams;
|
|
171
|
-
return generateSimpleAsyncTask(() =>
|
|
172
|
+
return generateSimpleAsyncTask(() => spawnSync(command, parameters, { shell: true }));
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
/**
|
|
@@ -273,7 +274,7 @@ function generateCopyDistTasks_v1(deployTarget: WithUserCommands) {
|
|
|
273
274
|
command,
|
|
274
275
|
parameters: [],
|
|
275
276
|
});
|
|
276
|
-
const {
|
|
277
|
+
const { stdout } = await commandFunction();
|
|
277
278
|
consola.info(` 执行了命令 🐓: `, command);
|
|
278
279
|
// consola.box(stdout);
|
|
279
280
|
});
|
|
@@ -303,7 +304,7 @@ function generateCopyDistTasks(deployTarget: WithUserCommands) {
|
|
|
303
304
|
* 本函数仅仅拼接部分路径
|
|
304
305
|
*/
|
|
305
306
|
function joinPath<T extends string>(dir: T) {
|
|
306
|
-
const resPath = resolve(targetCWD, dir);
|
|
307
|
+
const resPath = resolve(process.cwd(), targetCWD, dir);
|
|
307
308
|
// console.log(" in joinPath => ", resPath);
|
|
308
309
|
return <`${string}${typeof targetCWD}/${T}`>resPath;
|
|
309
310
|
}
|
|
@@ -313,13 +314,13 @@ function generateCopyDistTasks(deployTarget: WithUserCommands) {
|
|
|
313
314
|
|
|
314
315
|
async function delVercelOutputStatic() {
|
|
315
316
|
consola.start(` 开始删除文件任务 `);
|
|
316
|
-
|
|
317
|
+
rmSync(pathVercelOutputStatic, { recursive: true });
|
|
317
318
|
consola.success(` 删除该路径的文件: ${pathVercelOutputStatic} `);
|
|
318
319
|
}
|
|
319
320
|
|
|
320
321
|
async function createVercelOutputStatic() {
|
|
321
322
|
consola.start(` 开始创建文件夹任务 `);
|
|
322
|
-
|
|
323
|
+
mkdir(pathVercelOutputStatic, () => {});
|
|
323
324
|
consola.success(` 创建的新目录为: ${pathVercelOutputStatic} `);
|
|
324
325
|
}
|
|
325
326
|
|
|
@@ -327,10 +328,7 @@ function generateCopyDistTasks(deployTarget: WithUserCommands) {
|
|
|
327
328
|
consola.start(` 开始文件复制任务 `);
|
|
328
329
|
consola.info(` 从 ${pathOutputDirectory} 开始 `);
|
|
329
330
|
consola.info(` 复制到 ${pathVercelOutputStatic} 内`);
|
|
330
|
-
|
|
331
|
-
await cpy(pathOutputDirectory, pathVercelOutputStatic);
|
|
332
|
-
// await cp(pathOutputDirectory, pathVercelOutputStatic, { recursive: true });
|
|
333
|
-
// await cpx.copy(pathOutputDirectory, pathVercelOutputStatic);
|
|
331
|
+
cpSync(pathOutputDirectory, pathVercelOutputStatic, { recursive: true });
|
|
334
332
|
consola.success(` 完成文件复制任务 `);
|
|
335
333
|
}
|
|
336
334
|
|
|
@@ -398,8 +396,9 @@ function generateAfterBuildTasksConfig(config: Config): Task {
|
|
|
398
396
|
parameters: [],
|
|
399
397
|
});
|
|
400
398
|
consola.start(` 开始用户 afterBuildTasks 命令任务 `);
|
|
401
|
-
const {
|
|
402
|
-
consola.success(` 完成用户 afterBuildTasks 命令任务 ${code} `);
|
|
399
|
+
const { stdout } = await userCommand();
|
|
400
|
+
// consola.success(` 完成用户 afterBuildTasks 命令任务 ${code} `);
|
|
401
|
+
consola.success(` 完成用户 afterBuildTasks 命令任务 `);
|
|
403
402
|
// consola.box(stdout);
|
|
404
403
|
});
|
|
405
404
|
}),
|
|
@@ -441,9 +440,9 @@ async function main() {
|
|
|
441
440
|
return generateSimpleAsyncTask(async () => {
|
|
442
441
|
const build = generateBuildTask(deployTarget);
|
|
443
442
|
consola.start(` 开始build任务 `);
|
|
444
|
-
const {
|
|
443
|
+
const { stdout } = await build();
|
|
445
444
|
consola.success(` 完成build任务 `);
|
|
446
|
-
consola.info(` 完成命令 ${code} `);
|
|
445
|
+
// consola.info(` 完成命令 ${code} `);
|
|
447
446
|
// consola.box(stdout);
|
|
448
447
|
});
|
|
449
448
|
}),
|
|
@@ -475,8 +474,11 @@ async function main() {
|
|
|
475
474
|
parameters: [],
|
|
476
475
|
});
|
|
477
476
|
consola.start(` 开始用户命令任务 `);
|
|
478
|
-
const
|
|
479
|
-
|
|
477
|
+
const child = await userCommand();
|
|
478
|
+
process.stdout.write(child.stdout);
|
|
479
|
+
process.stderr.write(child.stderr);
|
|
480
|
+
// consola.success(` 完成用户命令任务 ${code} `);
|
|
481
|
+
consola.success(` 完成用户命令任务 `);
|
|
480
482
|
// consola.box(stdout);
|
|
481
483
|
});
|
|
482
484
|
}),
|
|
@@ -511,9 +513,23 @@ async function main() {
|
|
|
511
513
|
generateSimpleAsyncTask(async () => {
|
|
512
514
|
const deploy = generateDeployTask(deployTarget);
|
|
513
515
|
consola.start(` 开始部署任务 `);
|
|
514
|
-
const { stdout
|
|
516
|
+
const { stdout, error, stderr } = await deploy();
|
|
517
|
+
|
|
518
|
+
if (error) {
|
|
519
|
+
consola.error(" 部署失败了 \n");
|
|
520
|
+
consola.error(error);
|
|
521
|
+
process.stderr.write(stderr);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const vercelUrl = stdout.toString();
|
|
515
526
|
consola.success(` 完成部署任务 检查生成的url为 \n `);
|
|
516
527
|
consola.box(vercelUrl);
|
|
528
|
+
|
|
529
|
+
consola.success(` 部署任务输出如下: \n`);
|
|
530
|
+
process.stdout.write(stdout);
|
|
531
|
+
console.log(`\n`);
|
|
532
|
+
|
|
517
533
|
return vercelUrl;
|
|
518
534
|
}),
|
|
519
535
|
|
|
@@ -524,8 +540,8 @@ async function main() {
|
|
|
524
540
|
return generateSimpleAsyncTask(async (vercelUrl: string) => {
|
|
525
541
|
const alias = generateAliasTask(vercelUrl, userUrl);
|
|
526
542
|
consola.start(` 开始别名任务 `);
|
|
527
|
-
const { stdout
|
|
528
|
-
consola.success(` 执行了: ${command} `);
|
|
543
|
+
const { stdout } = await alias();
|
|
544
|
+
// consola.success(` 执行了: ${command} `);
|
|
529
545
|
consola.success(` 完成别名任务 可用的别名地址为 \n`);
|
|
530
546
|
consola.box(`https://${userUrl}`);
|
|
531
547
|
});
|