@taole/deploy-helper 1.1.3 → 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.
- package/lib/lightDeploy.mjs +42 -22
- package/package.json +1 -1
package/lib/lightDeploy.mjs
CHANGED
|
@@ -18,7 +18,10 @@ function getErrorMessage(resJson, fallback) {
|
|
|
18
18
|
return fallback;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
async function apiCdnUpload(
|
|
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);
|
|
@@ -31,7 +34,9 @@ async function apiCdnUpload({ distZipPath, prefix, mode, includeHtml, entryHtmlM
|
|
|
31
34
|
}
|
|
32
35
|
if (entryHtmlMap) {
|
|
33
36
|
const entryHtmlMapStr =
|
|
34
|
-
typeof entryHtmlMap === "string"
|
|
37
|
+
typeof entryHtmlMap === "string"
|
|
38
|
+
? entryHtmlMap
|
|
39
|
+
: JSON.stringify(entryHtmlMap);
|
|
35
40
|
formData.append("entryHtmlMap", entryHtmlMapStr);
|
|
36
41
|
}
|
|
37
42
|
formData.append(
|
|
@@ -60,9 +65,17 @@ async function apiCdnUpload({ distZipPath, prefix, mode, includeHtml, entryHtmlM
|
|
|
60
65
|
* @param {*} mode 部署环境
|
|
61
66
|
*/
|
|
62
67
|
export async function lightDeploy(config, mode) {
|
|
63
|
-
const projectJson = JSON.parse(
|
|
68
|
+
const projectJson = JSON.parse(
|
|
69
|
+
fs.readFileSync(path.join(process.cwd(), "package.json"), "utf-8")
|
|
70
|
+
);
|
|
64
71
|
const version = projectJson.version;
|
|
65
|
-
log(`light模式, 开始部署`, {
|
|
72
|
+
log(`light模式, 开始部署`, {
|
|
73
|
+
mode,
|
|
74
|
+
prefix: config.prefix,
|
|
75
|
+
includeHtml: config.includeHtml,
|
|
76
|
+
type: config.cdnType,
|
|
77
|
+
version,
|
|
78
|
+
});
|
|
66
79
|
|
|
67
80
|
if (!mode || (mode !== "test" && mode !== "prod")) {
|
|
68
81
|
throw new Error("部署环境无效,仅支持 test 或 prod");
|
|
@@ -85,7 +98,7 @@ export async function lightDeploy(config, mode) {
|
|
|
85
98
|
throw new Error(`${distPath} 不存在,请先执行构建`);
|
|
86
99
|
}
|
|
87
100
|
|
|
88
|
-
const distZipPath = path.join(workDir, "
|
|
101
|
+
const distZipPath = path.join(workDir, "cdnDist.zip");
|
|
89
102
|
if (fs.existsSync(distZipPath)) {
|
|
90
103
|
fs.unlinkSync(distZipPath);
|
|
91
104
|
}
|
|
@@ -95,23 +108,30 @@ export async function lightDeploy(config, mode) {
|
|
|
95
108
|
log(`打包完成: ${distZipPath}`);
|
|
96
109
|
|
|
97
110
|
const includeHtml = config.includeHtml === true;
|
|
98
|
-
log(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
prefix,
|
|
103
|
-
mode,
|
|
104
|
-
includeHtml,
|
|
105
|
-
entryHtmlMap: config.entryHtmlMap,
|
|
106
|
-
type: config.cdnType,
|
|
107
|
-
version,
|
|
108
|
-
},
|
|
109
|
-
userCache
|
|
111
|
+
log(
|
|
112
|
+
`开始上传至 CDN,mode=${mode}, prefix=${prefix}, type=${
|
|
113
|
+
config.cdnType || "project"
|
|
114
|
+
}, version=${version}, includeHtml=${includeHtml}`
|
|
110
115
|
);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
}
|
|
114
136
|
}
|
|
115
|
-
|
|
116
|
-
log(`CDN 上传成功`, result);
|
|
117
137
|
}
|