@taole/deploy-helper 0.6.2 → 0.6.5

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.
Files changed (2) hide show
  1. package/lib/offlinePkg.mjs +44 -27
  2. package/package.json +1 -1
@@ -104,9 +104,27 @@ export async function syncApi(userDeployHelperConfig, mode, offlineConfig, packa
104
104
  }
105
105
 
106
106
  const packages = finalJsonData.packages || [];
107
- console.log(`${mode === "prod" ? "线上" : "测试"}环境当前离线包列表:`, packages.map(item => ({...item,items:'省略' + item.items.length + '个条目'})));
107
+ console.log(`${mode === "prod" ? "线上" : "测试"}环境当前离线包列表:`, packages.map(item => ({ ...item, items: '省略' + item.items.length + '个条目' })));
108
108
  }
109
109
 
110
+ /**
111
+ * hack
112
+ * 由于vite-plugin-dynamic-base插件和legacy插件同时使用, 生存的入口文件中代码有点问题,这里直接修改有问题的代码
113
+ */
114
+ function fixEntryHtml(config, offlineConfig) {
115
+ if (!offlineConfig || !config) return;
116
+ const entryHtmlPath = join(config.workDir, offlineConfig.distDir, "index.html");
117
+ if (!fs.existsSync(entryHtmlPath)) {
118
+ throw new Error(`构建产物${entryHtmlPath}不存在`);
119
+ }
120
+ const markLine = "} else if (item.tagName == 'script') {";
121
+ const replaceLine = `} else if (item.tagName == 'script')/*injected by deploy-helper*/{
122
+ if(item.attrs.id=='vite-legacy-polyfill')childNode.onload=function(){System.import(window.__dynamic_base__ + document.getElementById('vite-legacy-entry').getAttribute('data-src'))};
123
+ `;
124
+ let entryHtml = fs.readFileSync(entryHtmlPath, "utf-8");
125
+ entryHtml = entryHtml.replace(markLine, replaceLine);
126
+ fs.writeFileSync(entryHtmlPath, entryHtml);
127
+ }
110
128
 
111
129
  /**
112
130
  * @typedef {Object} CheckOfflinePkgResult
@@ -137,12 +155,14 @@ export function checkOfflinePkg(config) {
137
155
  const distPath = join(config.workDir, offlineConfig.distDir);
138
156
 
139
157
  // 如果offlineConfig.remove为true,则不构建离线包
140
- const willRemovePkg = offlineConfig && offlineConfig.name && offlineConfig.remove === true;
158
+ const willRemovePkg = offlineConfig && offlineConfig.name && offlineConfig.remove === true && offlineConfig.skip !== true;
159
+ const willSkip = !offlineConfig || !offlineConfig.name || offlineConfig.skip === true;
141
160
  if (willRemovePkg) {
142
161
  return {
143
162
  canBuild: true,
144
163
  errorMsg: "",
145
164
  hookPostBuild: async () => {
165
+ fixEntryHtml(config, offlineConfig);
146
166
  log(`开始删除离线包${offlineConfig.name}`);
147
167
  await syncApi(userDeployHelperConfig, config.mode, offlineConfig, null);
148
168
  }
@@ -151,8 +171,8 @@ export function checkOfflinePkg(config) {
151
171
  if (!fs.existsSync(distPath)) {
152
172
  errorMsg = `构建产物${distPath}不存在, 请先构建项目`;
153
173
  canBuildOfflinePkg = false;
154
- } else if (!offlineConfig || !offlineConfig.name) {
155
- errorMsg = ""; // 没有离线包配置文件,跳过构建离线包
174
+ } else if (offlineConfig && !offlineConfig.name) {
175
+ errorMsg = "离线包配置文件中未配置name, 请先配置";
156
176
  canBuildOfflinePkg = false;
157
177
  } else if (!userDeployHelperConfig || !userDeployHelperConfig.offlineApi || !userDeployHelperConfig.offlineApi.get || !userDeployHelperConfig.offlineApi.set) {
158
178
  errorMsg = "未配置离线包接口, 请移步看配置文档: https://alidocs.dingtalk.com/i/nodes/R1zknDm0WRkbz13oHn0LDz3ZVBQEx5rG?doc_type=wiki_doc";
@@ -171,41 +191,38 @@ export function checkOfflinePkg(config) {
171
191
  canBuildOfflinePkg = false;
172
192
  }
173
193
  }
174
- if (!canBuildOfflinePkg) {
175
- return {
176
- canBuild: canBuildOfflinePkg,
177
- errorMsg: errorMsg,
178
- }
179
- }
180
194
  let ossToken = "";
181
195
  if (canBuildOfflinePkg) {
182
196
  ossToken = getOssToken();
183
197
  if (!ossToken) {
184
198
  errorMsg = "获取ossToken失败";
185
199
  canBuildOfflinePkg = false;
200
+ }
201
+ }
202
+ if (willSkip) {
203
+ if (!offlineConfig) {
186
204
  return {
187
- canBuild: canBuildOfflinePkg,
188
- errorMsg: errorMsg,
205
+ canBuild: false,
206
+ errorMsg: ""
207
+ }
208
+ }
209
+ return {
210
+ canBuild: true,
211
+ errorMsg: "",
212
+ hookPostBuild: async () => {
213
+ fixEntryHtml(config, offlineConfig);
189
214
  }
190
215
  }
191
216
  }
217
+ if (!canBuildOfflinePkg) {
218
+ return {
219
+ canBuild: false,
220
+ errorMsg: errorMsg
221
+ }
222
+ }
192
223
  const hookPostBuild = async () => {
193
224
  // 在构建完成后,执行一些操作
194
- // hack
195
- // 由于vite-plugin-dynamic-base插件和legacy插件同时使用, 生存的入口文件中代码有点问题,这里直接修改有问题的代码
196
- // 暂时解决加载问题
197
- const entryHtmlPath = join(config.workDir, offlineConfig.distDir, "index.html");
198
- if (!fs.existsSync(entryHtmlPath)) {
199
- throw new Error(`构建产物${entryHtmlPath}不存在`);
200
- }
201
- const markLine = "} else if (item.tagName == 'script') {";
202
- const replaceLine = `${markLine}
203
- if(item.attrs.id=='vite-legacy-polyfill')childNode.onload=function(){System.import(window.__dynamic_base__ + document.getElementById('vite-legacy-entry').getAttribute('data-src'))};
204
- `;
205
- let entryHtml = fs.readFileSync(entryHtmlPath, "utf-8");
206
- entryHtml = entryHtml.replace(markLine, replaceLine);
207
- fs.writeFileSync(entryHtmlPath, entryHtml);
208
-
225
+ fixEntryHtml(config, offlineConfig);
209
226
  // 开始进行打包流程
210
227
  const offlinePkgDir = join(config.workDir, "./offlinepkgDist");
211
228
  if (fs.existsSync(offlinePkgDir)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "0.6.2",
3
+ "version": "0.6.5",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",