@lcap/nasl 3.13.3-rc.3 → 3.13.3-rc.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.
@@ -9,16 +9,19 @@ export interface Route {
9
9
  component?: RawOptions;
10
10
  children?: Array<Route>;
11
11
  redirect?: string;
12
- lazyPath?: string;
13
12
  meta?: {
14
13
  [key: string]: any;
15
14
  };
15
+ fullPath?: string;
16
16
  }
17
17
  export declare function genBundleFiles(app: App, frontend: Frontend, config: Config): Promise<any[]>;
18
18
  export declare function genFrontendBundleFiles(app: App, frontends: Array<Frontend>, config: Config): Promise<any[]>;
19
19
  export declare function getOneFiles(options: {
20
+ app: App;
21
+ frontend: Frontend;
20
22
  view: View;
21
- action: string;
22
- cacheRouters: Route[];
23
- }): any[];
23
+ action: 'current' | 'all';
24
+ cacheRouters: string;
25
+ config: Config;
26
+ }): Promise<any[]>;
24
27
  //# sourceMappingURL=genBundleFiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"genBundleFiles.d.ts","sourceRoot":"","sources":["../../src/generator/genBundleFiles.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,GAAG,EAAU,IAAI,EAAE,QAAQ,EAAmG,MAAM,aAAa,CAAC;AAC3J,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAM/B,OAAO,KAAK,EAAE,yBAAyB,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAqBhF,eAAO,IAAI,UAAU,UAAgC,CAAA;AACrD,eAAO,IAAI,mBAAmB,UAAyD,CAAA;AAEvF,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,GAAG,WAanD;AACD,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAA;CACF;AA0JD,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAmgChF;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,kBA2ChG;AA+BD,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,KAAK,EAAE,CAAA;CAAE,SAgGzF"}
1
+ {"version":3,"file":"genBundleFiles.d.ts","sourceRoot":"","sources":["../../src/generator/genBundleFiles.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,GAAG,EAAU,IAAI,EAAE,QAAQ,EAAmG,MAAM,aAAa,CAAC;AAC3J,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAM/B,OAAO,KAAK,EAAE,yBAAyB,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAsBhF,eAAO,IAAI,UAAU,UAAgC,CAAA;AACrD,eAAO,IAAI,mBAAmB,UAAyD,CAAA;AAEvF,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,GAAG,WAanD;AACD,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAA;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA+ND,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBA87BhF;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,kBA2ChG;AA+BD,wBAAsB,WAAW,CAAC,OAAO,EAAE;IACzC,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,kBA6HA"}
@@ -41,6 +41,8 @@ const microApp_1 = require("./microApp");
41
41
  // @ts-ignore FIXME wudengke 类型在构建前找不到的问题
42
42
  const nasl_unified_frontend_generator_2 = require("@lcap/nasl-unified-frontend-generator");
43
43
  const axios_1 = __importDefault(require("axios"));
44
+ const runtime_1 = require("./templates/runtime");
45
+ const chunk_1 = require("./templates/chunk");
44
46
  const officalEntityMap = {
45
47
  LCAPUser: ['id', 'createdTime', 'updatedTime', 'userId', 'userName', 'password', 'phone', 'email', 'displayName', 'status', 'source'],
46
48
  LCAPLogicViewMapping: ['id', 'logicIdentifier', 'resourceName', 'resourceType', 'group', 'changeTime'],
@@ -114,8 +116,8 @@ function genComponentCode(component) {
114
116
  })()`;
115
117
  }
116
118
  // 生成导入组件代码
117
- function genImportComponetCode(componentPath) {
118
- return `() => importComponent('${componentPath}')`;
119
+ function genImportComponetCode(chunkId) {
120
+ return `() => __webpack_require__.e("${chunkId}").then(__webpack_require__.bind(__webpack_require__, "./${chunkId}.js"))`;
119
121
  }
120
122
  // 生成导出组件代码
121
123
  function genExportComponetCode(component) {
@@ -123,7 +125,7 @@ function genExportComponetCode(component) {
123
125
  Object.assign(componentOptions, {
124
126
  template: \`${component.template.replace(/[`$]/g, (m) => `\\${m}`)}\`,
125
127
  });
126
- return componentOptions;`;
128
+ `;
127
129
  }
128
130
  // 获取文件路径
129
131
  // name 或者 文件 至少有一个必填
@@ -136,27 +138,44 @@ const getCompletePath = (name, fileContent, config) => {
136
138
  fileName += `${(0, nasl_utils_1.genHash)(fileContent)}.`;
137
139
  }
138
140
  fileName += `min.js`;
139
- // if(config?.isExport && !fileName.includes('bundle')&& !fileName.includes('router')){
140
- // fileName =`${config.sysPrefixPath}/${fileName}`
141
- // }
142
141
  return fileName;
143
142
  };
144
- function genRouterFileContent(routes, defaultRoute) {
143
+ function genRouterFileContent(routes, defaultRoute, config) {
144
+ // 单页面发布
145
+ if (config.isOneFile) {
146
+ let code = config?.cacheRouters;
147
+ const changedChunks = config?.asyncChunksMap;
148
+ let newRoutesCode = 'window.lcap_routes = [\n';
149
+ routes.forEach((route) => {
150
+ newRoutesCode += `${routeToString(route)},\n`;
151
+ });
152
+ newRoutesCode += '];\n';
153
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
154
+ // 将start和end之间的代码替换掉
155
+ code = code.slice(0, code.indexOf(start) + start.length) + '\n' + newRoutesCode + code.slice(code.indexOf(end));
156
+ const placeholderIdx = code.indexOf('// lcap_changed_chunks placeholder');
157
+ // 前面插入代码
158
+ if (placeholderIdx !== -1) {
159
+ code = code.slice(0, placeholderIdx) + `Object.assign(lcap_changed_chunks, ${JSON.stringify(changedChunks)});\n` + code.slice(placeholderIdx);
160
+ }
161
+ return code;
162
+ }
145
163
  function routeToString(route) {
146
164
  let content = `{
147
165
  path: '${route.path}',\n`;
148
- if (route?.lazyPath) {
149
- const routeLazyPath = route.lazyPath;
150
- content += `lazyPath: '${routeLazyPath}',\n`;
151
- content += `component: ${genImportComponetCode(route.lazyPath)},\n`;
166
+ if (route?.fullPath) {
167
+ // 单页面发布时需要
168
+ content += `fullPath: '${route.fullPath}',\n`;
169
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
170
+ content += `component: ${genImportComponetCode(chunkId)},\n`;
152
171
  }
153
172
  if (route?.meta) {
154
173
  content += `meta: ${stringifyMetaData(route.meta)},`;
155
174
  }
156
- if (route?.children?.length) {
175
+ if (route.children?.length) {
157
176
  content += `children: [
158
- ${route.children.map(routeToString).join(',\n')}
159
- ],\n`;
177
+ ${route.children?.map?.(routeToString)?.join(',\n')}
178
+ ],\n`;
160
179
  }
161
180
  if (route?.redirect) {
162
181
  content += `redirect: '${route?.redirect}',\n`;
@@ -164,35 +183,64 @@ function genRouterFileContent(routes, defaultRoute) {
164
183
  content += '}';
165
184
  return content;
166
185
  }
186
+ // 生成异步块映射表
187
+ const name = config?.app?.name;
188
+ let code = `window["${name}LcapChunksMap"] = ${JSON5.stringify(config?.asyncChunksMap || {})};\n`;
167
189
  // 生成路由配置
168
- let routesStr = `const routers = [`;
190
+ code += `// lcap_routes start
191
+ window.lcap_routes = [\n`;
169
192
  routes.forEach((route) => {
170
- routesStr += `${routeToString(route)},\n`;
193
+ code += `${routeToString(route)},\n`;
171
194
  });
172
195
  if (defaultRoute) {
173
- routesStr += `{
196
+ code += `{
174
197
  path: '*',
175
198
  redirect: '${defaultRoute}',
176
199
  }\n`;
177
200
  }
178
- routesStr += `];
179
- return routers;`;
180
- return routesStr;
201
+ code += `];
202
+ // lcap_routes end\n`;
203
+ // changedChunk
204
+ code += `var lcap_changed_chunks = {};
205
+
206
+ // lcap_changed_chunks placeholder
207
+
208
+ Object.keys(lcap_changed_chunks).forEach(function(chunkId) {
209
+ window["${name}LcapChunksMap"][chunkId] = lcap_changed_chunks[chunkId];
210
+ });`;
211
+ return (0, chunk_1.generate)({
212
+ name: config?.app?.name,
213
+ chunkId: 'router',
214
+ moduleId: 'router',
215
+ content: code,
216
+ exports: [],
217
+ exec: false,
218
+ });
181
219
  }
182
220
  // 生成路由文件
183
221
  function genRouteFiles(routes, defaultRoute, config) {
184
222
  // 生成路由文件列表
185
223
  const routeFiles = [];
224
+ const asyncChunksMap = {};
186
225
  function routeToFile(route) {
187
226
  if (route?.component?.script) {
188
227
  const content = genExportComponetCode(route.component);
189
- const lazyPath = getCompletePath(null, content, config);
190
- route.lazyPath = lazyPath;
191
- // let outFilePath =`${config?.sysPrefixPath? config?.sysPrefixPath +'/' :''}${lazyPath}`;
228
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
229
+ const contentHash = (0, nasl_utils_1.genHash)(content);
192
230
  routeFiles.push({
193
- name: lazyPath,
194
- content,
231
+ name: chunkId + '.' + contentHash + '.js',
232
+ content: (0, chunk_1.generate)({
233
+ name: config?.app?.name,
234
+ chunkId,
235
+ moduleId: chunkId,
236
+ content,
237
+ exports: [
238
+ ['componentOptions', 'default'],
239
+ ],
240
+ exec: false,
241
+ }),
195
242
  });
243
+ asyncChunksMap[chunkId] = contentHash;
196
244
  }
197
245
  if (route?.children?.length) {
198
246
  route.children.map(routeToFile);
@@ -201,13 +249,16 @@ function genRouteFiles(routes, defaultRoute, config) {
201
249
  routes.forEach((route) => {
202
250
  routeToFile(route);
203
251
  });
204
- let routerPath = getCompletePath('router', null, config);
205
252
  routeFiles.push({
206
- name: routerPath,
253
+ name: getCompletePath('router', null, config),
207
254
  isRouterFile: true,
208
- content: genRouterFileContent(routes, defaultRoute),
255
+ content: genRouterFileContent(routes, defaultRoute, Object.assign({}, config, { asyncChunksMap })),
209
256
  });
210
- return routeFiles;
257
+ const { publicPath } = config;
258
+ return routeFiles.map(file => ({
259
+ ...file,
260
+ name: publicPath + file.name,
261
+ }));
211
262
  }
212
263
  async function genBundleFiles(app, frontend, config) {
213
264
  config.sysPrefixPath = app?.sysPrefixPath;
@@ -222,6 +273,7 @@ async function genBundleFiles(app, frontend, config) {
222
273
  const fnLowcodeDomain = config?.envLcpDomain?.[config?.env]?.lcpDomain || config?.lowcodeDomain;
223
274
  const modules = [];
224
275
  const views = [];
276
+ const isExport = !!config.isExport;
225
277
  const STATIC_URL = config.isExport ? '' : config.STATIC_URL;
226
278
  app.dependencies && modules.push(...app.dependencies);
227
279
  app.interfaceDependencies && modules.push(...app.interfaceDependencies);
@@ -289,24 +341,19 @@ async function genBundleFiles(app, frontend, config) {
289
341
  (0, nasl_log_1.clearLogs)(app);
290
342
  }
291
343
  }
292
- const getBundleFileName = () => {
293
- if (config.isPreviewFe && config.previewVersion) {
294
- return `mockBundle-${config.previewVersion}`;
295
- }
296
- else {
297
- return 'bundle';
298
- }
299
- };
300
- let baseUrl = `${config.USER_STATIC_URL}/${config.tenant}/${app.id}/${config.env}`;
301
- let { basePath } = frontend;
302
- if (config.isExport) {
303
- baseUrl = '';
304
- // basePath = '';
305
- }
306
- if (config.isPreviewFe) {
307
- baseUrl = `${config.USER_STATIC_URL}/asset-center/preview/${config.tenant}/${app.id}/${config.env}`;
344
+ // @ts-expect-error
345
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
346
+ /**
347
+ * 为什么要加这个呢,因为导出静态资源的场景下,所有资源都会经过一道loadJSWrap
348
+ * 这个loadJSWrap会补上统一前缀,但是不带端路径
349
+ * 所以client.js里的资源需要是:
350
+ * /packages/pc-ui/index.js
351
+ * /m/bundle.js
352
+ */
353
+ let basePath = frontend.basePath || '/';
354
+ if (!basePath.endsWith('/')) {
355
+ basePath += '/';
308
356
  }
309
- let completePath = `${baseUrl}${basePath || ''}/`;
310
357
  /**
311
358
  * vue.config.js page options
312
359
  */
@@ -346,11 +393,18 @@ async function genBundleFiles(app, frontend, config) {
346
393
  }
347
394
  }
348
395
  }
396
+ let fullPath = `/${viewName}`;
397
+ let parent = view.parentNode;
398
+ while (parent?.concept === 'View') {
399
+ fullPath = `/${parent.name}${fullPath}`;
400
+ parent = parent.parentNode;
401
+ }
349
402
  const route = {
350
403
  path: routePath,
351
404
  component: (0, compileComponent_1.compileComponent)(componentMap[view.id]),
352
405
  children: [],
353
406
  meta: view.getRouteMeta(),
407
+ fullPath,
354
408
  };
355
409
  const viewChildren = view.children;
356
410
  if (Array.isArray(viewChildren) && viewChildren.length) {
@@ -425,15 +479,7 @@ async function genBundleFiles(app, frontend, config) {
425
479
  // authResourcePathMap={}
426
480
  }
427
481
  const authResourcePaths = Object.keys(authResourcePathMap);
428
- const routerFiles = genRouteFiles(routes, defaultRoute, config);
429
- routerFiles.forEach(item => {
430
- let temp = completePath;
431
- // if(completePath=='/'){temp=''}else{temp = `${completePath}/`}
432
- if (config?.isExport && config?.sysPrefixPath?.length > 0) {
433
- temp = config?.sysPrefixPath + temp;
434
- }
435
- item.name = temp + item.name;
436
- });
482
+ const routerFiles = genRouteFiles(routes, defaultRoute, Object.assign({}, config, { app, publicPath }));
437
483
  let fileI18nInfo = {
438
484
  enabled: false,
439
485
  locale: 'zh-CN',
@@ -533,8 +579,6 @@ async function genBundleFiles(app, frontend, config) {
533
579
  }
534
580
  const assetsInfo = app.genAllAssetsInfo(STATIC_URL, frontend.type, frontendType.frameworkKind);
535
581
  const customNames = JSON5.stringify(assetsInfo.custom.names);
536
- let content1 = `(async function(){
537
- `;
538
582
  let contentScale = '';
539
583
  if (frontend.globalScaleEnabled)
540
584
  contentScale = `{
@@ -644,110 +688,6 @@ async function genBundleFiles(app, frontend, config) {
644
688
  let contentImport = `
645
689
  var platformConfig = ${platformConfig};
646
690
  var metaData = ${metaDataStr};
647
-
648
- var getCompletePath = (path) => {
649
- return '${config?.isExport ? config.sysPrefixPath : ''}${completePath}' + path;
650
- }
651
-
652
- function createErrorLayout(error) {
653
- // 创建错误元素并添加到页面
654
- const errorDiv = document.createElement('div');
655
- errorDiv.style.display = 'none'; // 默认隐藏,只有在有错误时才显示
656
-
657
- // 创建 h2 元素
658
- const h2 = document.createElement('h2');
659
- h2.textContent = 'An error occurred:';
660
- errorDiv.appendChild(h2);
661
-
662
- const close = document.createElement('div');
663
- close.textContent = 'Close';
664
- close.style.position = 'fixed';
665
- close.style.top = '20px';
666
- close.style.right = '20px';
667
- close.style.cursor = 'pointer';
668
- close.onclick = () => document.body.removeChild(errorDiv);
669
- errorDiv.appendChild(close);
670
-
671
- // 创建 pre 元素用于显示 error.?message
672
- const preMessage = document.createElement('pre');
673
- preMessage.textContent = error && error.message;
674
- preMessage.style.fontSize = '14px';
675
- errorDiv.appendChild(preMessage);
676
-
677
- // 创建 pre 元素用于显示 error.?stack
678
- const preStack = document.createElement('pre');
679
- preStack.textContent = error && error.stack;
680
- preStack.style.fontSize = '14px';
681
- errorDiv.appendChild(preStack);
682
-
683
- errorDiv.style.display = 'block';
684
- errorDiv.style.position = 'fixed';
685
- errorDiv.style.top = 0;
686
- errorDiv.style.bottom = 0;
687
- errorDiv.style.left = 0;
688
- errorDiv.style.right = 0;
689
- errorDiv.style.maxWidth = '100%';
690
- errorDiv.style.width = '100%';
691
- errorDiv.style.padding = '16px';
692
- errorDiv.style.boxSizing = 'border-box';
693
- errorDiv.style.backgroundColor = 'white';
694
- errorDiv.style.zIndex = 1000; // 确保错误元素在最上层
695
-
696
- document.body.appendChild(errorDiv);
697
- }
698
-
699
- // 低版本
700
- function importXMLHttpRequestComponent (scriptUrl) {
701
- return new Promise(function(resolve, reject) {
702
- var xhr = new XMLHttpRequest();
703
- xhr.open('GET', scriptUrl, true);
704
- xhr.onreadystatechange = function() {
705
- if (xhr.readyState === 4) {
706
- if (xhr.status === 200) {
707
- var scriptContent = xhr.responseText;
708
- try {
709
- var func = new Function('importComponent', 'window', scriptContent + '\\n//# sourceURL=' + scriptUrl);
710
- var result = func(window.importComponent, window);
711
- resolve(result);
712
- } catch (error) {
713
- createErrorLayout(error);
714
- reject(error);
715
- }
716
- } else {
717
- reject(new Error('Failed to fetch script'));
718
- }
719
- }
720
- };
721
- xhr.send();
722
- });
723
- };
724
- function importFetchComponent(scriptUrl) {
725
- return fetch(scriptUrl)
726
- .then(function(response) {
727
- if (!response.ok) {
728
- throw new Error('Network response was not ok');
729
- }
730
- return response.text();
731
- }).then(function(scriptText) {
732
- var func = new Function('importComponent', 'window', scriptText + '\\n//# sourceURL=' + scriptUrl);
733
- var result = func(window.importComponent, window);
734
- return result;
735
- })
736
- .catch(error => {
737
- console.error('Error loading script:', error);
738
- createErrorLayout(error);
739
- });
740
- }
741
- window.importComponent = (scriptUrl) => {
742
- scriptUrl = getCompletePath(scriptUrl);
743
- // 浏览器支持fetch,直接使用fetch
744
- if (window.fetch) {
745
- return importFetchComponent(scriptUrl);
746
- }
747
- return importXMLHttpRequestComponent(scriptUrl);
748
- }
749
-
750
- var routes = await importComponent('${getCompletePath('router', null, config)}?t=' + Date.now());
751
691
  `;
752
692
  // 按页面维度发布先不考虑鉴权,页面维度新增的页面都算是不鉴权的数组中
753
693
  // 只有完全页面维度新增的才会进入到这个数组中
@@ -766,11 +706,11 @@ async function genBundleFiles(app, frontend, config) {
766
706
  }
767
707
  });
768
708
  }
769
- iterateRouters(routes);` : '';
709
+ iterateRouters(window.lcap_routes);` : '';
770
710
  let contentCreateLCAPApp = `
771
711
  window.createLcapApp = () => {
772
712
  ${compRegStr}
773
- appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, routes, metaData);
713
+ var appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, window.lcap_routes, metaData);
774
714
  try {
775
715
  var push = appVM.$router.history.push;
776
716
  appVM.$router.history.push = function (a, b) {
@@ -825,6 +765,8 @@ async function genBundleFiles(app, frontend, config) {
825
765
  curParentHID = incrementID;
826
766
  });
827
767
  window.addEventListener('popstate', function (e) {
768
+ // 如果有 state,但没有 HID,说明是未知跳转,不判定前进后退
769
+ if(e.state && e.state.HID === undefined) return;
828
770
  if(curHID > (e.state ? e.state.HID : undefined)){
829
771
  isBack = true;
830
772
  } else {
@@ -847,8 +789,6 @@ async function genBundleFiles(app, frontend, config) {
847
789
  if(shortcutIconLink) parent.document.head.appendChild(shortcutIconLink);
848
790
  }
849
791
  ` : '';
850
- let content10 = `
851
- })();`;
852
792
  let contentDevOnly = config.env === 'dev' ? `
853
793
  var _div = document.createElement('div');
854
794
  _div.classList = "div-load"
@@ -964,10 +904,21 @@ async function genBundleFiles(app, frontend, config) {
964
904
  };
965
905
  fetchAnnoData();
966
906
  ` : '';
967
- let content = [content1, contentScale, contentStyleCss, contentDocIcon, contentCustomNames, contentImport,
968
- contentLogReportCode, contentRouter, contentCreateLCAPApp, contentPCIframe, content10,
969
- contentDevOnly, contentVueDirectives.join(''), contentViewElemAnno].join('');
970
- content1 = null;
907
+ let content = [
908
+ `__webpack_require__('./router.js');`,
909
+ contentScale,
910
+ contentStyleCss,
911
+ contentDocIcon,
912
+ contentCustomNames,
913
+ contentImport,
914
+ contentLogReportCode,
915
+ contentRouter,
916
+ contentCreateLCAPApp,
917
+ contentPCIframe,
918
+ contentDevOnly,
919
+ contentVueDirectives.join(''),
920
+ contentViewElemAnno
921
+ ].join('');
971
922
  contentScale = null;
972
923
  contentStyleCss = null;
973
924
  contentDocIcon = null;
@@ -977,18 +928,35 @@ async function genBundleFiles(app, frontend, config) {
977
928
  contentRouter = null;
978
929
  contentCreateLCAPApp = null;
979
930
  contentPCIframe = null;
980
- content10 = null;
981
931
  contentDevOnly = null;
982
932
  contentVueDirectives = null;
983
933
  contentViewElemAnno = null;
934
+ const timeStamp = Date.now();
984
935
  utils.delay(100);
985
- let bundleMinPath = completePath + getCompletePath(getBundleFileName(), content, config);
936
+ content = (0, chunk_1.generate)({
937
+ name: app.name,
938
+ chunkId: 'bundle',
939
+ moduleId: 'bundle',
940
+ content,
941
+ exports: [],
942
+ exec: true,
943
+ });
944
+ const routerFileName = getCompletePath('router', null, config);
945
+ const bundleFileName = getCompletePath(getBundleFileName(config), content, config);
946
+ let clientPath = publicPath + 'client.js';
947
+ let runtimePath = publicPath + 'runtime.js';
948
+ let routerPath = publicPath + routerFileName;
949
+ let bundleMinPath = publicPath + bundleFileName;
986
950
  const otherJsList = frontend?.appletsConfig?.enable ? ['//res.wx.qq.com/open/js/jweixin-1.3.2.js'] : [];
987
951
  const microAppIntegration = (0, microApp_1.integrateMicroApp)(frontend);
988
952
  if (config?.debug) {
989
953
  otherJsList.push(`${STATIC_URL}/packages/@lcap/breakpoint-client@1.0.0/dist/index.js?time=${Date.now()}`);
990
954
  }
991
- let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([bundleMinPath]);
955
+ let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([
956
+ isExport ? (basePath + 'runtime.js') : runtimePath,
957
+ (isExport ? (basePath + routerFileName) : routerPath) + `?t=${timeStamp}`,
958
+ isExport ? (basePath + bundleFileName) : bundleMinPath,
959
+ ]);
992
960
  let cssAssetsList = assetsInfo.basic.css.concat(assetsInfo.custom.css);
993
961
  if (config.isPreviewFe) {
994
962
  const changeToRelativePath = (str) => {
@@ -1152,18 +1120,26 @@ async function genBundleFiles(app, frontend, config) {
1152
1120
  `;
1153
1121
  const outputs = [
1154
1122
  {
1155
- name: bundleMinPath,
1156
- content,
1123
+ name: clientPath,
1124
+ content: assetsContent,
1157
1125
  },
1158
1126
  {
1159
- name: basePath ? `${baseUrl}${basePath}/client.js` : `${baseUrl}/client.js`,
1160
- content: assetsContent,
1127
+ name: runtimePath,
1128
+ content: (0, runtime_1.generate)({
1129
+ name: app.name,
1130
+ publicPath: JSON.stringify(publicPath),
1131
+ }),
1132
+ },
1133
+ {
1134
+ name: bundleMinPath,
1135
+ content,
1161
1136
  },
1162
1137
  ...routerFiles,
1163
1138
  ];
1164
1139
  assetsContent = null;
1165
1140
  content = null;
1166
1141
  processAssetsInOutputs(outputs, frontend, config);
1142
+ console.info('编译结果', outputs.map((x) => x.name));
1167
1143
  return outputs;
1168
1144
  }
1169
1145
  exports.genBundleFiles = genBundleFiles;
@@ -1235,9 +1211,8 @@ async function traverseForToVueOptions(start, cb) {
1235
1211
  }
1236
1212
  utils.timeSlicingWithGenerator(__traverse(start));
1237
1213
  }
1238
- function getOneFiles(options) {
1239
- const { view, action, cacheRouters } = options;
1240
- const frontend = view.frontend;
1214
+ async function getOneFiles(options) {
1215
+ const { app, frontend, view, action, cacheRouters, config } = options;
1241
1216
  /**
1242
1217
  * 几种情况
1243
1218
  * 1.完全新增了页面从顶层到下面都是新的页面, 发顶层 (仅自己 和 )
@@ -1255,16 +1230,23 @@ function getOneFiles(options) {
1255
1230
  if (isRootView) {
1256
1231
  routePath = `${frontend.prefixPath}/${viewName}`;
1257
1232
  }
1233
+ let fullPath = `/${viewName}`;
1234
+ let parent = view.parentNode;
1235
+ while (parent?.concept === 'View') {
1236
+ fullPath = `/${parent.name}${fullPath}`;
1237
+ parent = parent.parentNode;
1238
+ }
1258
1239
  const route = {
1259
1240
  path: routePath,
1260
1241
  component: (0, compileComponent_1.compileComponent)(viewOption),
1261
1242
  children: [],
1262
1243
  meta: view.getRouteMeta(),
1244
+ fullPath,
1263
1245
  };
1264
1246
  return route;
1265
1247
  }
1266
- let currentView = view;
1267
1248
  let currentRoute = null;
1249
+ let currentView = view;
1268
1250
  while (currentView?.concept === 'View') {
1269
1251
  if (currentRoute) {
1270
1252
  const child = currentRoute;
@@ -1298,6 +1280,7 @@ function getOneFiles(options) {
1298
1280
  // 如果找到了现有路由,更新 component 和 meta
1299
1281
  existingRoute.component = newRoute.component;
1300
1282
  existingRoute.meta = newRoute.meta;
1283
+ existingRoute.fullPath = newRoute.fullPath;
1301
1284
  // 递归合并子路由
1302
1285
  if (newRoute.children) {
1303
1286
  existingRoute.children = existingRoute.children || [];
@@ -1323,13 +1306,29 @@ function getOneFiles(options) {
1323
1306
  // 直接推入新路由
1324
1307
  routes.unshift(newRoute);
1325
1308
  }
1309
+ let existingRoutes = [];
1310
+ try {
1311
+ // 获取// lcap_routes start 到 // lcap_routes end 之间的代码
1312
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
1313
+ const routesCode = cacheRouters
1314
+ .substring(cacheRouters.indexOf(start) + start.length, cacheRouters.indexOf(end))
1315
+ .replace('window.lcap_routes = ', 'return ');
1316
+ const fn = new Function(`${routesCode}`);
1317
+ existingRoutes = fn();
1318
+ }
1319
+ catch (error) {
1320
+ console.error('路由代码 eval 失败:', error);
1321
+ }
1326
1322
  if (action === 'all') {
1327
- coverUpdateRoute(cacheRouters, currentRoute);
1323
+ coverUpdateRoute(existingRoutes, currentRoute);
1328
1324
  }
1329
1325
  else {
1330
- addOrUpdateRoute(cacheRouters, currentRoute);
1326
+ addOrUpdateRoute(existingRoutes, currentRoute);
1331
1327
  }
1332
- const routerFiles = genRouteFiles(cacheRouters, null);
1328
+ // @ts-expect-error
1329
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
1330
+ const routerFiles = genRouteFiles(existingRoutes, null, Object.assign({}, config, { app, cacheRouters, isOneFile: true, publicPath }));
1331
+ console.info('编译结果', routerFiles.map((x) => x.name));
1333
1332
  return routerFiles;
1334
1333
  }
1335
1334
  exports.getOneFiles = getOneFiles;
@@ -1349,7 +1348,10 @@ function findAndReplaceStaticResources(text, callback) {
1349
1348
  protocolPositions.push(match1.index);
1350
1349
  }
1351
1350
  // 静态资源后缀
1352
- const imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'tiff', 'svg', 'ico', 'heic', 'heif', 'avif', 'mp4', 'mkv', 'mov', 'avi', 'wmv', 'flv', 'webm', 'm4v'];
1351
+ const imageExtensions = [
1352
+ 'png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'tiff', 'svg', 'ico', 'heic', 'heif', 'avif', 'mp4', 'mkv', 'mov', 'avi', 'wmv', 'flv', 'webm', 'm4v',
1353
+ 'xlsx', 'xls', 'csv', 'docx', 'doc', 'pdf', 'pptx', 'ppt', 'md', 'java', 'py', 'js', 'yml', 'conf', 'json', 'xml',
1354
+ ];
1353
1355
  const extensionPattern = new RegExp(`\\.(${imageExtensions.join('|')})`, 'gi');
1354
1356
  const extensionPositions = [];
1355
1357
  let match2;
@@ -1381,11 +1383,10 @@ function findAndReplaceStaticResources(text, callback) {
1381
1383
  return modifiedText;
1382
1384
  }
1383
1385
  function processAssetsInOutputs(outputs, frontend, config) {
1384
- const assets = config.assets;
1386
+ const assetsMap = config.assetsMap;
1385
1387
  // 导出源码才处理
1386
- if (config.isExport && Array.isArray(assets) && assets.length) {
1388
+ if (config.isExport && assetsMap?.size) {
1387
1389
  function replaceContentFilePath(content) {
1388
- const assetsMap = config.assetsMap;
1389
1390
  content = findAndReplaceStaticResources(content, (url) => {
1390
1391
  const asset = utils.getAssetFromAssetsMap(assetsMap, url);
1391
1392
  if (asset) {
@@ -1421,4 +1422,13 @@ function processAssetsInOutputs(outputs, frontend, config) {
1421
1422
  });
1422
1423
  }
1423
1424
  }
1425
+ function getBundleFileName(config) {
1426
+ if (config.isPreviewFe && config.previewVersion) {
1427
+ return `mockBundle-${config.previewVersion}`;
1428
+ }
1429
+ else {
1430
+ return 'bundle';
1431
+ }
1432
+ }
1433
+ ;
1424
1434
  //# sourceMappingURL=genBundleFiles.js.map