@taole/deploy-helper 0.6.1 → 0.6.2

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
@@ -124,7 +124,7 @@ async function main() {
124
124
  // return;
125
125
  // other commands
126
126
  let command = process.argv[2];
127
- if (!["init", "prod", "test", "scp", "scpevt", "pipeline", "rmofflinepkg"].includes(command)) {
127
+ if (!["init", "prod", "test", "scp", "scpevt", "pipeline", "offlinepkgrm"].includes(command)) {
128
128
  command = "help";
129
129
  }
130
130
 
@@ -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: rmofflinepkg {name} [mode] 删除离线包{name}, 指定模式(可省略,默认test)`);
142
+ console.log(`command: offlinepkgrm {name} [mode] 删除离线包{name}, 指定模式(可省略,默认test)`);
143
143
  process.exit(0);
144
144
  }
145
145
  log(`deploy-helper v${version} start`);
@@ -201,7 +201,7 @@ async function main() {
201
201
  process.exit(1);
202
202
  }
203
203
 
204
- } else if (command === "rmofflinepkg") {
204
+ } else if (command === "offlinepkgrm") {
205
205
  const name = process.argv[3];
206
206
  if (!name) {
207
207
  log(`name参数不能为空`);
@@ -218,7 +218,6 @@ async function main() {
218
218
  process.exit(1);
219
219
  }
220
220
  await syncOfflinePkgApi(userDeployHelperConfig, mode, { name, remove: true }, null);
221
- log(`${mode === 'prod' ? '线上' : '测试'}环境删除离线包${name}完成`);
222
221
  process.exit(0);
223
222
  }
224
223
  try {
@@ -80,6 +80,7 @@ export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packa
80
80
  }
81
81
  jsonData.packages = jsonData.packages.filter(item => item.name !== offlineConfig.name);
82
82
  }
83
+ jsonData.packages = jsonData.packages.filter(item => item.name);
83
84
  if (needSetData) {
84
85
  // console.log('jsonData', jsonData);
85
86
  var formdata = new FormData();
@@ -92,7 +93,7 @@ export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packa
92
93
  if (!setData || setData.error !== 0) {
93
94
  throw new Error(`更新离线包列表失败, 更新离线包当前配置失败: ${setData.error_msg || "未知错误"}`);
94
95
  }
95
- log(`离线包列表更新完成: ${JSON.stringify(setData)}`);
96
+ log(`${mode === "prod" ? "线上" : "测试"}环境离线包列表更新完成: ${JSON.stringify(setData)}`);
96
97
  // 再次获取列表,确保更新成功
97
98
  const nowRes2 = await fetch(getUrl);
98
99
  const nowData2 = await nowRes2.json();
@@ -103,8 +104,7 @@ export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packa
103
104
  }
104
105
 
105
106
  const packages = finalJsonData.packages || [];
106
- console.log(`${mode === "prod" ? "线上" : "测试"}环境当前离线包列表:`, packages);
107
-
107
+ console.log(`${mode === "prod" ? "线上" : "测试"}环境当前离线包列表:`, packages.map(item => ({...item,items:'省略' + item.items.length + '个条目'})));
108
108
  }
109
109
 
110
110
 
@@ -135,6 +135,19 @@ export function checkOfflinePkg(config) {
135
135
  const packageJson = getJsonConfig(config.workDir, "package.json");
136
136
  const userDeployHelperConfig = getUserDeployHelperConfig();
137
137
  const distPath = join(config.workDir, offlineConfig.distDir);
138
+
139
+ // 如果offlineConfig.remove为true,则不构建离线包
140
+ const willRemovePkg = offlineConfig && offlineConfig.name && offlineConfig.remove === true;
141
+ if (willRemovePkg) {
142
+ return {
143
+ canBuild: true,
144
+ errorMsg: "",
145
+ hookPostBuild: async () => {
146
+ log(`开始删除离线包${offlineConfig.name}`);
147
+ await syncApi(userDeployHelperConfig, config.mode, offlineConfig, null);
148
+ }
149
+ }
150
+ }
138
151
  if (!fs.existsSync(distPath)) {
139
152
  errorMsg = `构建产物${distPath}不存在, 请先构建项目`;
140
153
  canBuildOfflinePkg = false;
@@ -142,10 +155,10 @@ export function checkOfflinePkg(config) {
142
155
  errorMsg = ""; // 没有离线包配置文件,跳过构建离线包
143
156
  canBuildOfflinePkg = false;
144
157
  } else if (!userDeployHelperConfig || !userDeployHelperConfig.offlineApi || !userDeployHelperConfig.offlineApi.get || !userDeployHelperConfig.offlineApi.set) {
145
- errorMsg = "未配置离线包接口";
158
+ errorMsg = "未配置离线包接口, 请移步看配置文档: https://alidocs.dingtalk.com/i/nodes/R1zknDm0WRkbz13oHn0LDz3ZVBQEx5rG?doc_type=wiki_doc";
146
159
  canBuildOfflinePkg = false;
147
160
  } else if (!packageJson) {
148
- errorMsg = "package.json";
161
+ errorMsg = "啊没有package.json?";
149
162
  canBuildOfflinePkg = false;
150
163
  } else {
151
164
  // 暂时不检查这个
@@ -153,8 +166,8 @@ export function checkOfflinePkg(config) {
153
166
  ...packageJson.devDependencies,
154
167
  ...packageJson.dependencies,
155
168
  };
156
- if(!allDeps['@vitejs/plugin-legacy'] || !allDeps['vite-plugin-dynamic-base']){
157
- errorMsg = "检查到项目中未安装依赖@vitejs/plugin-legacy和vite-plugin-dynamic-base, 请先安装依赖并调整构建代码以支持离线化";
169
+ if (!allDeps['@vitejs/plugin-legacy'] || !allDeps['vite-plugin-dynamic-base']) {
170
+ errorMsg = "检查到项目中未安装依赖@vitejs/plugin-legacy和vite-plugin-dynamic-base, 请先安装依赖并调整构建代码以支持离线化,相关文档:https://alidocs.dingtalk.com/i/nodes/ydxXB52LJqexwD71F9K5XNMrJqjMp697?doc_type=wiki_doc";
158
171
  canBuildOfflinePkg = false;
159
172
  }
160
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",