@taole/deploy-helper 1.1.2 → 1.1.4

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.
Files changed (2) hide show
  1. package/lib/lightDeploy.mjs +48 -22
  2. package/package.json +1 -1
@@ -18,14 +18,25 @@ function getErrorMessage(resJson, fallback) {
18
18
  return fallback;
19
19
  }
20
20
 
21
- async function apiCdnUpload({ distZipPath, prefix, mode, includeHtml, entryHtmlMap }, userCache) {
21
+ async function apiCdnUpload(
22
+ { distZipPath, prefix, mode, includeHtml, entryHtmlMap, type, version },
23
+ userCache
24
+ ) {
22
25
  const formData = new FormData();
23
26
  formData.append("prefix", prefix);
24
27
  formData.append("mode", mode);
25
28
  formData.append("includeHtml", includeHtml ? "true" : "false");
29
+ if (type) {
30
+ formData.append("type", type);
31
+ }
32
+ if (version) {
33
+ formData.append("version", version);
34
+ }
26
35
  if (entryHtmlMap) {
27
36
  const entryHtmlMapStr =
28
- typeof entryHtmlMap === "string" ? entryHtmlMap : JSON.stringify(entryHtmlMap);
37
+ typeof entryHtmlMap === "string"
38
+ ? entryHtmlMap
39
+ : JSON.stringify(entryHtmlMap);
29
40
  formData.append("entryHtmlMap", entryHtmlMapStr);
30
41
  }
31
42
  formData.append(
@@ -54,9 +65,17 @@ async function apiCdnUpload({ distZipPath, prefix, mode, includeHtml, entryHtmlM
54
65
  * @param {*} mode 部署环境
55
66
  */
56
67
  export async function lightDeploy(config, mode) {
57
- const projectJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8"));
68
+ const projectJson = JSON.parse(
69
+ fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8")
70
+ );
58
71
  const version = projectJson.version;
59
- log(`light模式, 开始部署`, { mode, prefix: config.prefix, includeHtml: config.includeHtml, version });
72
+ log(`light模式, 开始部署`, {
73
+ mode,
74
+ prefix: config.prefix,
75
+ includeHtml: config.includeHtml,
76
+ type: config.cdnType,
77
+ version,
78
+ });
60
79
 
61
80
  if (!mode || (mode !== "test" && mode !== "prod")) {
62
81
  throw new Error("部署环境无效,仅支持 test 或 prod");
@@ -79,7 +98,7 @@ export async function lightDeploy(config, mode) {
79
98
  throw new Error(`${distPath} 不存在,请先执行构建`);
80
99
  }
81
100
 
82
- const distZipPath = path.join(workDir, "dist.zip");
101
+ const distZipPath = path.join(workDir, "cdnDist.zip");
83
102
  if (fs.existsSync(distZipPath)) {
84
103
  fs.unlinkSync(distZipPath);
85
104
  }
@@ -89,23 +108,30 @@ export async function lightDeploy(config, mode) {
89
108
  log(`打包完成: ${distZipPath}`);
90
109
 
91
110
  const includeHtml = config.includeHtml === true;
92
- log(`开始上传至 CDN,mode=${mode}, prefix=${prefix}, includeHtml=${includeHtml}`);
93
- const result = await apiCdnUpload(
94
- {
95
- distZipPath,
96
- prefix,
97
- mode,
98
- includeHtml,
99
- entryHtmlMap: config.entryHtmlMap,
100
- type: config.cdnType,
101
- version,
102
- },
103
- userCache
111
+ log(
112
+ `开始上传至 CDN,mode=${mode}, prefix=${prefix}, type=${
113
+ config.cdnType || "project"
114
+ }, version=${version}, includeHtml=${includeHtml}`
104
115
  );
105
-
106
- if (fs.existsSync(distZipPath)) {
107
- fs.unlinkSync(distZipPath);
116
+ try {
117
+ const result = await apiCdnUpload(
118
+ {
119
+ distZipPath,
120
+ prefix,
121
+ mode,
122
+ includeHtml,
123
+ entryHtmlMap: config.entryHtmlMap,
124
+ type: config.cdnType,
125
+ version,
126
+ },
127
+ userCache
128
+ );
129
+ log(`CDN 上传成功`, result);
130
+ } catch (error) {
131
+ throw error;
132
+ } finally {
133
+ if (fs.existsSync(distZipPath)) {
134
+ fs.unlinkSync(distZipPath);
135
+ }
108
136
  }
109
-
110
- log(`CDN 上传成功`, result);
111
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",