@taole/deploy-helper 1.1.3 → 1.1.5-beta.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.
@@ -18,7 +18,10 @@ function getErrorMessage(resJson, fallback) {
18
18
  return fallback;
19
19
  }
20
20
 
21
- async function apiCdnUpload({ distZipPath, prefix, mode, includeHtml, entryHtmlMap, type, version }, 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);
@@ -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" ? entryHtmlMap : JSON.stringify(entryHtmlMap);
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(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
+ );
64
71
  const version = projectJson.version;
65
- log(`light模式, 开始部署`, { mode, prefix: config.prefix, includeHtml: config.includeHtml, type: config.cdnType, version });
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, "dist.zip");
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(`开始上传至 CDN,mode=${mode}, prefix=${prefix}, type=${config.cdnType || "project"}, version=${version}, includeHtml=${includeHtml}`);
99
- const result = await apiCdnUpload(
100
- {
101
- distZipPath,
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
- if (fs.existsSync(distZipPath)) {
113
- 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
+ }
114
136
  }
115
-
116
- log(`CDN 上传成功`, result);
117
137
  }
package/lib/project.mjs CHANGED
@@ -8,6 +8,25 @@ import { getCache as getLoginCache } from "./login.mjs";
8
8
 
9
9
  const isDev = false;
10
10
  const apiHost = isDev ? "http://localhost:9000" : "https://fapi.tuwan.com";
11
+ const WEB_ACT_REPO_PATH = "69b3821af7b43e00d420cb32/Web-Act";
12
+
13
+ function extractWebActProjectNameFromRemote(remoteUrl) {
14
+ if (!remoteUrl) {
15
+ return null;
16
+ }
17
+ const match = remoteUrl.match(new RegExp(`${WEB_ACT_REPO_PATH}/([^/.]+)(?:\\.git)?/?$`));
18
+ return match ? match[1] : null;
19
+ }
20
+
21
+ async function checkPackageNameWithGitRemote(git, packageName) {
22
+ const remotes = await git.getRemotes(true);
23
+ const remoteUrls = remotes.flatMap((remote) => [remote.refs.fetch, remote.refs.push]).filter(Boolean);
24
+ const gitProjectName = remoteUrls.map(extractWebActProjectNameFromRemote).find(Boolean);
25
+
26
+ if (gitProjectName && gitProjectName !== packageName) {
27
+ throw new Error(`项目名称不匹配: git仓库项目名称为${gitProjectName}, package.json name为${packageName}`);
28
+ }
29
+ }
11
30
 
12
31
  export function genArchive(outputPath, dir) {
13
32
  return new Promise((resolve, reject) => {
@@ -240,6 +259,7 @@ export const cmdProjectPublish = async () => {
240
259
  log("package.json或者其version字段或name字段不存在");
241
260
  process.exit(1);
242
261
  }
262
+ await checkPackageNameWithGitRemote(git, packageJson.name);
243
263
 
244
264
  const newVersion = await apiGetProjectVersion(packageJson.name, userCache);
245
265
  packageJson.version = newVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "1.1.3",
3
+ "version": "1.1.5-beta.1",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",