@taole/deploy-helper 0.6.5 → 0.7.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/index.mjs CHANGED
@@ -17,8 +17,8 @@ const __dirname = path.dirname(__filename);
17
17
 
18
18
  const TEST_SERVER_HOST = "192.168.0.35";
19
19
 
20
- function fmtAssetsCommit(msg){
21
- if(msg.startsWith("-#")){
20
+ function fmtAssetsCommit(msg) {
21
+ if (msg.startsWith("-#")) {
22
22
  return msg;
23
23
  }
24
24
  return `-#DH-1 ${msg}`;
@@ -139,7 +139,7 @@ async function main() {
139
139
  console.log(`command: scpevt {file} 复制文件{file}到events测试服务器{file}`);
140
140
  console.log(`command: scpevt {file} {dest} 复制文件{file}到events测试服务器{dest}`);
141
141
  console.log(`command: pipeline {pipelineName|pipelineId} [branch] 触发流水线{pipelineName|pipelineId}, 指定分支(可省略)`);
142
- console.log(`command: offlinepkgrm {name} [mode] 删除离线包{name}, 指定模式(可省略,默认test)`);
142
+ console.log(`command: offlinepkgrm {name} {platform} [mode] 删除离线包{name}, 指定平台{platform}, 指定模式(可省略,默认test)`);
143
143
  process.exit(0);
144
144
  }
145
145
  log(`deploy-helper v${version} start`);
@@ -207,7 +207,12 @@ async function main() {
207
207
  log(`name参数不能为空`);
208
208
  process.exit(1);
209
209
  }
210
- const mode = process.argv[4] || "test";
210
+ const platform = process.argv[4];
211
+ if (!platform) {
212
+ log(`platform参数不能为空`);
213
+ process.exit(1);
214
+ }
215
+ const mode = process.argv[5] || "test";
211
216
  if (!["prod", "test"].includes(mode)) {
212
217
  log(`mode参数只能是prod或test`);
213
218
  process.exit(1);
@@ -217,7 +222,7 @@ async function main() {
217
222
  log(`配置文件未配置离线包api接口, 请先配置`);
218
223
  process.exit(1);
219
224
  }
220
- await syncOfflinePkgApi(userDeployHelperConfig, mode, { name, remove: true }, null);
225
+ await syncOfflinePkgApi(userDeployHelperConfig, mode, { name, remove: true, platform }, null);
221
226
  process.exit(0);
222
227
  }
223
228
  try {
@@ -253,11 +258,11 @@ async function main() {
253
258
  workDir: workDir,
254
259
  mode,
255
260
  });
256
- if(!offlinePkgResult.canBuild && offlinePkgResult.errorMsg) {
261
+ if (!offlinePkgResult.canBuild && offlinePkgResult.errorMsg) {
257
262
  log(`${offlinePkgResult.errorMsg}`);
258
263
  process.exit(1);
259
264
  }
260
- if(offlinePkgResult.canBuild) {
265
+ if (offlinePkgResult.canBuild) {
261
266
  await offlinePkgResult.hookPostBuild();
262
267
  }
263
268
 
@@ -53,7 +53,12 @@ export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packa
53
53
  const setPath = userDeployHelperConfig.offlineApi.set;
54
54
  const getUrl = `${apiDomain}${getPath}`;
55
55
  const setUrl = `${apiDomain}${setPath}`;
56
- const nowRes = await fetch(getUrl);
56
+ const envPrefix = `${mode === "prod" ? "线上环境" : "测试环境"}[platform=${offlineConfig.platform}]`;
57
+ const nowRes = await fetch(getUrl, {
58
+ headers: {
59
+ platform: String(offlineConfig.platform),
60
+ }
61
+ });
57
62
  const nowData = await nowRes.json();
58
63
  let needSetData = true;
59
64
  let finalJsonData = null;
@@ -88,14 +93,21 @@ export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packa
88
93
  const setRes = await fetch(setUrl, {
89
94
  method: "POST",
90
95
  body: formdata,
96
+ headers: {
97
+ platform: String(offlineConfig.platform),
98
+ }
91
99
  });
92
100
  const setData = await setRes.json();
93
101
  if (!setData || setData.error !== 0) {
94
102
  throw new Error(`更新离线包列表失败, 更新离线包当前配置失败: ${setData.error_msg || "未知错误"}`);
95
103
  }
96
- log(`${mode === "prod" ? "线上" : "测试"}环境离线包列表更新完成: ${JSON.stringify(setData)}`);
104
+ log(`${envPrefix}离线包列表更新完成: ${JSON.stringify(setData)}`);
97
105
  // 再次获取列表,确保更新成功
98
- const nowRes2 = await fetch(getUrl);
106
+ const nowRes2 = await fetch(getUrl, {
107
+ headers: {
108
+ platform: String(offlineConfig.platform),
109
+ }
110
+ });
99
111
  const nowData2 = await nowRes2.json();
100
112
  if (!nowData2 || nowData2.error !== 0) {
101
113
  throw new Error(`再次获取离线包列表失败, 获取离线包当前配置失败: ${nowData2.error_msg || "未知错误"}`);
@@ -104,7 +116,7 @@ export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packa
104
116
  }
105
117
 
106
118
  const packages = finalJsonData.packages || [];
107
- console.log(`${mode === "prod" ? "线上" : "测试"}环境当前离线包列表:`, packages.map(item => ({ ...item, items: '省略' + item.items.length + '个条目' })));
119
+ console.log(`${envPrefix}当前离线包列表:`, packages.map(item => ({ ...item, items: '省略' + item.items.length + '个条目' })));
108
120
  }
109
121
 
110
122
  /**
@@ -149,10 +161,11 @@ export function checkOfflinePkg(config) {
149
161
  const offlineConfig = getJsonConfig(config.workDir, "offline.config.json");
150
162
  if (offlineConfig) {
151
163
  offlineConfig.distDir = offlineConfig.distDir || "dist";
164
+ offlineConfig.platform = offlineConfig.platform || 3; // 3,4是点点
152
165
  }
153
166
  const packageJson = getJsonConfig(config.workDir, "package.json");
154
167
  const userDeployHelperConfig = getUserDeployHelperConfig();
155
- const distPath = join(config.workDir, offlineConfig.distDir);
168
+ const distPath = join(config.workDir, offlineConfig && offlineConfig.distDir ? offlineConfig.distDir : "dist");
156
169
 
157
170
  // 如果offlineConfig.remove为true,则不构建离线包
158
171
  const willRemovePkg = offlineConfig && offlineConfig.name && offlineConfig.remove === true && offlineConfig.skip !== true;
@@ -221,6 +234,7 @@ export function checkOfflinePkg(config) {
221
234
  }
222
235
  }
223
236
  const hookPostBuild = async () => {
237
+ if(!offlineConfig || !config) return;
224
238
  // 在构建完成后,执行一些操作
225
239
  fixEntryHtml(config, offlineConfig);
226
240
  // 开始进行打包流程
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",