@taole/deploy-helper 0.6.6 → 0.7.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.
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,10 +116,11 @@ 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
  /**
123
+ * @deprecated 不再需要这个函数, 如果插件使用的是@taole/vite-plugin-dynamic-base, 则不需要这个函数
111
124
  * hack
112
125
  * 由于vite-plugin-dynamic-base插件和legacy插件同时使用, 生存的入口文件中代码有点问题,这里直接修改有问题的代码
113
126
  */
@@ -149,10 +162,16 @@ export function checkOfflinePkg(config) {
149
162
  const offlineConfig = getJsonConfig(config.workDir, "offline.config.json");
150
163
  if (offlineConfig) {
151
164
  offlineConfig.distDir = offlineConfig.distDir || "dist";
165
+ offlineConfig.platform = offlineConfig.platform || 3; // 3,4是点点
152
166
  }
153
167
  const packageJson = getJsonConfig(config.workDir, "package.json");
154
168
  const userDeployHelperConfig = getUserDeployHelperConfig();
155
169
  const distPath = join(config.workDir, offlineConfig && offlineConfig.distDir ? offlineConfig.distDir : "dist");
170
+ const allDeps = {
171
+ ...packageJson.devDependencies,
172
+ ...packageJson.dependencies,
173
+ };
174
+ const useOldPDB = !!allDeps['vite-plugin-dynamic-base'];
156
175
 
157
176
  // 如果offlineConfig.remove为true,则不构建离线包
158
177
  const willRemovePkg = offlineConfig && offlineConfig.name && offlineConfig.remove === true && offlineConfig.skip !== true;
@@ -162,7 +181,9 @@ export function checkOfflinePkg(config) {
162
181
  canBuild: true,
163
182
  errorMsg: "",
164
183
  hookPostBuild: async () => {
165
- fixEntryHtml(config, offlineConfig);
184
+ if (useOldPDB) {
185
+ fixEntryHtml(config, offlineConfig);
186
+ }
166
187
  log(`开始删除离线包${offlineConfig.name}`);
167
188
  await syncApi(userDeployHelperConfig, config.mode, offlineConfig, null);
168
189
  }
@@ -181,13 +202,8 @@ export function checkOfflinePkg(config) {
181
202
  errorMsg = "啊没有package.json?";
182
203
  canBuildOfflinePkg = false;
183
204
  } else {
184
- // 暂时不检查这个
185
- const allDeps = {
186
- ...packageJson.devDependencies,
187
- ...packageJson.dependencies,
188
- };
189
- if (!allDeps['@vitejs/plugin-legacy'] || !allDeps['vite-plugin-dynamic-base']) {
190
- errorMsg = "检查到项目中未安装依赖@vitejs/plugin-legacy和vite-plugin-dynamic-base, 请先安装依赖并调整构建代码以支持离线化,相关文档:https://alidocs.dingtalk.com/i/nodes/ydxXB52LJqexwD71F9K5XNMrJqjMp697?doc_type=wiki_doc";
205
+ if (!allDeps['@vitejs/plugin-legacy'] || (!allDeps['vite-plugin-dynamic-base'] && !allDeps['@taole/vite-plugin-dynamic-base'])) {
206
+ errorMsg = "检查到项目中未安装依赖@vitejs/plugin-legacy和@taole/vite-plugin-dynamic-base, 请先安装依赖并调整构建代码以支持离线化,相关文档:https://alidocs.dingtalk.com/i/nodes/ydxXB52LJqexwD71F9K5XNMrJqjMp697?doc_type=wiki_doc";
191
207
  canBuildOfflinePkg = false;
192
208
  }
193
209
  }
@@ -210,7 +226,9 @@ export function checkOfflinePkg(config) {
210
226
  canBuild: true,
211
227
  errorMsg: "",
212
228
  hookPostBuild: async () => {
213
- fixEntryHtml(config, offlineConfig);
229
+ if (useOldPDB) {
230
+ fixEntryHtml(config, offlineConfig);
231
+ }
214
232
  }
215
233
  }
216
234
  }
@@ -221,9 +239,11 @@ export function checkOfflinePkg(config) {
221
239
  }
222
240
  }
223
241
  const hookPostBuild = async () => {
224
- if(!offlineConfig || !config) return;
242
+ if (!offlineConfig || !config) return;
225
243
  // 在构建完成后,执行一些操作
226
- fixEntryHtml(config, offlineConfig);
244
+ if (useOldPDB) {
245
+ fixEntryHtml(config, offlineConfig);
246
+ }
227
247
  // 开始进行打包流程
228
248
  const offlinePkgDir = join(config.workDir, "./offlinepkgDist");
229
249
  if (fs.existsSync(offlinePkgDir)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "0.6.6",
3
+ "version": "0.7.1",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",