@ruan-cat/vercel-deploy-tool 0.0.13 → 0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruan-cat/vercel-deploy-tool",
3
- "version": "0.0.13",
3
+ "version": "0.1.0",
4
4
  "description": "阮喵喵自用的vercel部署工具,用于实现复杂项目的部署。",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -44,6 +44,8 @@
44
44
  "c12": "^1.11.2",
45
45
  "consola": "^3.2.3",
46
46
  "cpx": "^1.5.0",
47
+ "cpy": "^11.1.0",
48
+ "del": "^8.0.0",
47
49
  "execa": "^9.3.1",
48
50
  "lodash-es": "4.17.21",
49
51
  "mkdirp": "^3.0.1",
@@ -54,6 +56,8 @@
54
56
  "@ruan-cat/utils": "^1.1.1"
55
57
  },
56
58
  "devDependencies": {
59
+ "@types/cpx": "^1.5.5",
60
+ "@types/gulp": "^4.0.17",
57
61
  "@types/lodash-es": "^4.17.12",
58
62
  "@types/node": "^22.5.1",
59
63
  "@vitest/ui": "^2.0.5",
package/src/index.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  // 学习一下如何使用 https://github.com/sindresorhus/execa/blob/main/readme.md
2
2
  import fs from "node:fs";
3
+ import { dirname, resolve } from "node:path";
4
+ import { cp } from "node:fs/promises";
3
5
  import { execa } from "execa";
4
6
  import { concat, isEmpty, isUndefined } from "lodash-es";
5
7
  import { consola } from "consola";
6
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";
7
13
 
8
14
  import {
9
15
  initVercelConfig,
@@ -204,8 +210,14 @@ function generateBuildTask(deployTarget: DeployTarget) {
204
210
  * # 输出目录
205
211
  * shx ls -R .vercel/output/static
206
212
  * ```
213
+ *
214
+ * @version 1
215
+ * @deprecated
216
+ * 不再使用该方式
217
+ *
218
+ * 不打算在用户侧的项目内,使用 `pnpm dlx ???` 这样的命令来完成依赖安装。这样效率太低了。
207
219
  */
208
- function generateCopyDistTasks(deployTarget: WithUserCommands) {
220
+ function generateCopyDistTasks_v1(deployTarget: WithUserCommands) {
209
221
  function delDirectoryCmd() {
210
222
  return <const>`pnpm dlx rimraf ${vercelOutputStatic}`;
211
223
  }
@@ -252,6 +264,65 @@ function generateCopyDistTasks(deployTarget: WithUserCommands) {
252
264
  return copyDistTasks;
253
265
  }
254
266
 
267
+ /**
268
+ * 针对单个部署目标,生成一系列移动目录的任务
269
+ * @description
270
+ * 生成以下任务
271
+ *
272
+ * - 删除目录
273
+ * - 新建目录
274
+ * - 复制粘贴
275
+ */
276
+ function generateCopyDistTasks(deployTarget: WithUserCommands) {
277
+ const targetCWD = deployTarget.targetCWD;
278
+ const outputDirectory = deployTarget.outputDirectory;
279
+
280
+ /**
281
+ * 路径拼接工具
282
+ * @private
283
+ * 仅考虑为内部使用 不是通用工具
284
+ *
285
+ * 本函数仅仅拼接部分路径
286
+ */
287
+ function joinPath<T extends string>(dir: T) {
288
+ const resPath = resolve(targetCWD, dir);
289
+ // console.log(" in joinPath => ", resPath);
290
+ return <`${string}${typeof targetCWD}/${T}`>resPath;
291
+ }
292
+
293
+ const pathVercelOutputStatic = joinPath(vercelOutputStatic);
294
+ const pathOutputDirectory = joinPath(outputDirectory);
295
+
296
+ async function delVercelOutputStatic() {
297
+ consola.start(` 开始删除文件任务 `);
298
+ await deleteAsync(pathVercelOutputStatic);
299
+ consola.success(` 删除该路径的文件: ${pathVercelOutputStatic} `);
300
+ }
301
+
302
+ async function createVercelOutputStatic() {
303
+ consola.start(` 开始创建文件夹任务 `);
304
+ await mkdirpSync(pathVercelOutputStatic);
305
+ consola.success(` 创建的新目录为: ${pathVercelOutputStatic} `);
306
+ }
307
+
308
+ async function cpyDistToVercelOutputStatic() {
309
+ consola.start(` 开始文件复制任务 `);
310
+ consola.info(` 从 ${pathOutputDirectory} 开始 `);
311
+ consola.info(` 复制到 ${pathVercelOutputStatic} 内`);
312
+ // 该写法无误 在liunx github工作流环境下,能完成文件复制。
313
+ await cpy(pathOutputDirectory, pathVercelOutputStatic);
314
+ // await cp(pathOutputDirectory, pathVercelOutputStatic, { recursive: true });
315
+ // await cpx.copy(pathOutputDirectory, pathVercelOutputStatic);
316
+ consola.success(` 完成文件复制任务 `);
317
+ }
318
+
319
+ const resTasks = [delVercelOutputStatic, createVercelOutputStatic, cpyDistToVercelOutputStatic].map((asyncFn) => {
320
+ return generateSimpleAsyncTask(asyncFn);
321
+ });
322
+
323
+ return resTasks;
324
+ }
325
+
255
326
  /**
256
327
  * 生成alias任务
257
328
  * @description
@@ -0,0 +1,20 @@
1
+ import { dirname, resolve } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import * as fs from "node:fs";
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+
8
+ /** 路径拼接工具 */
9
+ export function pathResolve(dir: string) {
10
+ const resPath = resolve(__dirname, ".", dir);
11
+ // console.log(" in tool pathResolve => ", resPath);
12
+ return resPath;
13
+ }
14
+
15
+ /** 路径拼接工具 */
16
+ export function joinPath(dir: string) {
17
+ const resPath = resolve(__dirname, ".", dir);
18
+ // console.log(" in tool pathResolve => ", resPath);
19
+ return resPath;
20
+ }