@lcap/nasl 4.4.0-beta.1 → 4.4.0-beta.3

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 (86) hide show
  1. package/out/generator/genBundleFiles.d.ts +2 -2
  2. package/out/generator/genBundleFiles.d.ts.map +1 -1
  3. package/out/generator/genBundleFiles.js +175 -138
  4. package/out/generator/genBundleFiles.js.map +1 -1
  5. package/out/generator/qiankun.d.ts +1 -1
  6. package/out/generator/qiankun.d.ts.map +1 -1
  7. package/out/generator/qiankun.js +4 -1
  8. package/out/generator/qiankun.js.map +1 -1
  9. package/out/generator/release-body/data.d.ts.map +1 -1
  10. package/out/generator/release-body/data.js +34 -1
  11. package/out/generator/release-body/data.js.map +1 -1
  12. package/out/generator/release-body/utils.d.ts +2 -6
  13. package/out/generator/release-body/utils.d.ts.map +1 -1
  14. package/out/generator/release-body/utils.js +101 -3
  15. package/out/generator/release-body/utils.js.map +1 -1
  16. package/out/generator/templates/chunk.d.ts +11 -0
  17. package/out/generator/templates/chunk.d.ts.map +1 -0
  18. package/out/generator/templates/chunk.js +29 -0
  19. package/out/generator/templates/chunk.js.map +1 -0
  20. package/out/generator/templates/runtime.d.ts +7 -0
  21. package/out/generator/templates/runtime.d.ts.map +1 -0
  22. package/out/generator/templates/runtime.js +409 -0
  23. package/out/generator/templates/runtime.js.map +1 -0
  24. package/out/generator/ui-library-declaration/basic.d.ts.map +1 -1
  25. package/out/generator/ui-library-declaration/basic.js +5 -5
  26. package/out/generator/ui-library-declaration/basic.js.map +1 -1
  27. package/out/generator/ui-library-declaration/dependency.d.ts.map +1 -1
  28. package/out/generator/ui-library-declaration/dependency.js +3 -3
  29. package/out/generator/ui-library-declaration/dependency.js.map +1 -1
  30. package/out/index.d.ts +1 -0
  31. package/out/index.d.ts.map +1 -1
  32. package/out/index.js +1 -0
  33. package/out/index.js.map +1 -1
  34. package/out/natural/getContext/nasl2Files.d.ts +15 -0
  35. package/out/natural/getContext/nasl2Files.d.ts.map +1 -0
  36. package/out/natural/getContext/nasl2Files.js +75 -0
  37. package/out/natural/getContext/nasl2Files.js.map +1 -0
  38. package/out/natural/index.d.ts +3 -1
  39. package/out/natural/index.d.ts.map +1 -1
  40. package/out/natural/index.js +3 -1
  41. package/out/natural/index.js.map +1 -1
  42. package/out/natural/parseNaturalTS.d.ts +2 -1
  43. package/out/natural/parseNaturalTS.d.ts.map +1 -1
  44. package/out/natural/parseNaturalTS.js +3 -3
  45. package/out/natural/parseNaturalTS.js.map +1 -1
  46. package/out/natural/parseNaturalTSXView.js +1 -1
  47. package/out/natural/parseNaturalTSXView.js.map +1 -1
  48. package/out/natural/transform2BatchActions.d.ts +96 -0
  49. package/out/natural/transform2BatchActions.d.ts.map +1 -0
  50. package/out/natural/transform2BatchActions.js +387 -0
  51. package/out/natural/transform2BatchActions.js.map +1 -0
  52. package/out/natural/transformTSCode.d.ts +2 -2
  53. package/out/natural/transformTSCode.d.ts.map +1 -1
  54. package/out/natural/transformTSCode.js +8 -7
  55. package/out/natural/transformTSCode.js.map +1 -1
  56. package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
  57. package/out/natural/transforms/transform2Logic.js +1 -0
  58. package/out/natural/transforms/transform2Logic.js.map +1 -1
  59. package/out/natural/transforms/transform2LogicItem.d.ts +2 -0
  60. package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
  61. package/out/natural/transforms/transform2LogicItem.js +9 -7
  62. package/out/natural/transforms/transform2LogicItem.js.map +1 -1
  63. package/out/server/naslServer.d.ts +1 -1
  64. package/out/server/naslServer.d.ts.map +1 -1
  65. package/out/server/naslServer.js +27 -27
  66. package/out/server/naslServer.js.map +1 -1
  67. package/out/service/storage/api.d.ts +9 -0
  68. package/out/service/storage/api.js +8 -0
  69. package/out/service/storage/api.js.map +1 -1
  70. package/out/service/storage/service.d.ts +3 -0
  71. package/out/service/storage/service.d.ts.map +1 -1
  72. package/out/service/storage/service.js +11 -0
  73. package/out/service/storage/service.js.map +1 -1
  74. package/out/service/storage/specTools.d.ts +34 -0
  75. package/out/service/storage/specTools.d.ts.map +1 -0
  76. package/out/service/storage/specTools.js +52 -0
  77. package/out/service/storage/specTools.js.map +1 -0
  78. package/out/utils/json-schema-to-nasl-type.d.ts +37 -0
  79. package/out/utils/json-schema-to-nasl-type.d.ts.map +1 -0
  80. package/out/utils/json-schema-to-nasl-type.js +195 -0
  81. package/out/utils/json-schema-to-nasl-type.js.map +1 -0
  82. package/package.json +11 -11
  83. package/out/generator/ui-library-declaration/utils.d.ts +0 -3
  84. package/out/generator/ui-library-declaration/utils.d.ts.map +0 -1
  85. package/out/generator/ui-library-declaration/utils.js +0 -20
  86. package/out/generator/ui-library-declaration/utils.js.map +0 -1
@@ -9,10 +9,10 @@ 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 stringifyMetaData(obj: any): string;
18
18
  export declare function genBundleFiles(app: App, frontend: Frontend, config: Config): Promise<any[]>;
@@ -22,7 +22,7 @@ export declare function getOneFiles(options: {
22
22
  frontend: Frontend;
23
23
  view: View;
24
24
  action: 'current' | 'all';
25
- cacheRouters: Route[];
25
+ cacheRouters: string;
26
26
  config: Config;
27
27
  }): Promise<any[]>;
28
28
  //# sourceMappingURL=genBundleFiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"genBundleFiles.d.ts","sourceRoot":"","sources":["../../src/generator/genBundleFiles.ts"],"names":[],"mappings":"AAWA,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;AAGD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,UA8BzC;AA+JD,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAmhChF;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,KAAK,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,kBA2IA"}
1
+ {"version":3,"file":"genBundleFiles.d.ts","sourceRoot":"","sources":["../../src/generator/genBundleFiles.ts"],"names":[],"mappings":"AAWA,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;AAGD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,UA8BzC;AAsOD,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBA2+BhF;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,kBAwKA"}
@@ -43,6 +43,8 @@ const microApp_1 = require("./microApp");
43
43
  // @ts-ignore FIXME 类型在构建前找不到的问题
44
44
  const nasl_unified_frontend_generator_2 = require("@lcap/nasl-unified-frontend-generator");
45
45
  const axios_1 = __importDefault(require("axios"));
46
+ const runtime_1 = require("./templates/runtime");
47
+ const chunk_1 = require("./templates/chunk");
46
48
  const officalEntityMap = {
47
49
  LCAPUser: ['id', 'createdTime', 'updatedTime', 'userId', 'userName', 'password', 'phone', 'email', 'displayName', 'status', 'source'],
48
50
  LCAPLogicViewMapping: ['id', 'logicIdentifier', 'resourceName', 'resourceType', 'group', 'changeTime'],
@@ -140,8 +142,8 @@ function genComponentCode(component) {
140
142
  })()`;
141
143
  }
142
144
  // 生成导入组件代码
143
- function genImportComponetCode(componentPath) {
144
- return `() => importComponent('${componentPath}')`;
145
+ function genImportComponetCode(chunkId) {
146
+ return `() => __webpack_require__.e("${chunkId}").then(__webpack_require__.bind(__webpack_require__, "./${chunkId}.js"))`;
145
147
  }
146
148
  // 生成导出组件代码
147
149
  function genExportComponetCode(component) {
@@ -149,12 +151,13 @@ function genExportComponetCode(component) {
149
151
  const optionCode = renderCode
150
152
  ? `render: __render__,\n staticRenderFns: __staticRenderFns__,`
151
153
  : `template: \`${component.template.replace(/[`$]/g, (m) => `\\${m}`)}\`,`;
152
- return `var componentOptions = ${component.script ? `(function(){\n${component.script.trim().replace(/export default |module\.exports +=/, 'return ')}\n})()` : '{}'};
154
+ let code = `var componentOptions = ${component.script ? `(function(){\n${component.script.trim().replace(/export default |module\.exports +=/, 'return ')}\n})()` : '{}'};
153
155
  ${renderCode}
154
156
  Object.assign(componentOptions, {
155
157
  ${optionCode}
156
158
  });
157
- return componentOptions;`;
159
+ `;
160
+ return code;
158
161
  }
159
162
  // 获取文件路径
160
163
  // name 或者 文件 至少有一个必填
@@ -167,27 +170,44 @@ const getCompletePath = (name, fileContent, config) => {
167
170
  fileName += `${(0, nasl_utils_1.genHash)(fileContent)}.`;
168
171
  }
169
172
  fileName += `min.js`;
170
- // if(config?.isExport && !fileName.includes('bundle')&& !fileName.includes('router')){
171
- // fileName =`${config.sysPrefixPath}/${fileName}`
172
- // }
173
173
  return fileName;
174
174
  };
175
- function genRouterFileContent(routes, defaultRoute) {
175
+ function genRouterFileContent(routes, defaultRoute, config) {
176
+ // 单页面发布
177
+ if (config.isOneFile) {
178
+ let code = config?.cacheRouters;
179
+ const changedChunks = config?.asyncChunksMap;
180
+ let newRoutesCode = 'window.lcap_routes = [\n';
181
+ routes.forEach((route) => {
182
+ newRoutesCode += `${routeToString(route)},\n`;
183
+ });
184
+ newRoutesCode += '];\n';
185
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
186
+ // 将start和end之间的代码替换掉
187
+ code = code.slice(0, code.indexOf(start) + start.length) + '\n' + newRoutesCode + code.slice(code.indexOf(end));
188
+ const placeholderIdx = code.indexOf('// lcap_changed_chunks placeholder');
189
+ // 前面插入代码
190
+ if (placeholderIdx !== -1) {
191
+ code = code.slice(0, placeholderIdx) + `Object.assign(lcap_changed_chunks, ${JSON.stringify(changedChunks)});\n` + code.slice(placeholderIdx);
192
+ }
193
+ return code;
194
+ }
176
195
  function routeToString(route) {
177
196
  let content = `{
178
197
  path: '${route.path}',\n`;
179
- if (route?.lazyPath) {
180
- const routeLazyPath = route.lazyPath;
181
- content += `lazyPath: '${routeLazyPath}',\n`;
182
- content += `component: ${genImportComponetCode(route.lazyPath)},\n`;
198
+ if (route?.fullPath) {
199
+ // 单页面发布时需要
200
+ content += `fullPath: '${route.fullPath}',\n`;
201
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
202
+ content += `component: ${genImportComponetCode(chunkId)},\n`;
183
203
  }
184
204
  if (route?.meta) {
185
205
  content += `meta: ${stringifyMetaData(route.meta)},`;
186
206
  }
187
- if (route?.children?.length) {
207
+ if (route.children?.length) {
188
208
  content += `children: [
189
- ${route.children.map(routeToString).join(',\n')}
190
- ],\n`;
209
+ ${route.children?.map?.(routeToString)?.join(',\n')}
210
+ ],\n`;
191
211
  }
192
212
  if (route?.redirect) {
193
213
  content += `redirect: '${route?.redirect}',\n`;
@@ -195,35 +215,64 @@ function genRouterFileContent(routes, defaultRoute) {
195
215
  content += '}';
196
216
  return content;
197
217
  }
218
+ // 生成异步块映射表
219
+ const name = config?.app?.name;
220
+ let code = `window["${name}LcapChunksMap"] = ${JSON5.stringify(config?.asyncChunksMap || {})};\n`;
198
221
  // 生成路由配置
199
- let routesStr = `const routers = [`;
222
+ code += `// lcap_routes start
223
+ window.lcap_routes = [\n`;
200
224
  routes.forEach((route) => {
201
- routesStr += `${routeToString(route)},\n`;
225
+ code += `${routeToString(route)},\n`;
202
226
  });
203
227
  if (defaultRoute) {
204
- routesStr += `{
228
+ code += `{
205
229
  path: '*',
206
230
  redirect: '${defaultRoute}',
207
231
  }\n`;
208
232
  }
209
- routesStr += `];
210
- return routers;`;
211
- return routesStr;
233
+ code += `];
234
+ // lcap_routes end\n`;
235
+ // changedChunk
236
+ code += `var lcap_changed_chunks = {};
237
+
238
+ // lcap_changed_chunks placeholder
239
+
240
+ Object.keys(lcap_changed_chunks).forEach(function(chunkId) {
241
+ window["${name}LcapChunksMap"][chunkId] = lcap_changed_chunks[chunkId];
242
+ });`;
243
+ return (0, chunk_1.generate)({
244
+ name: config?.app?.name,
245
+ chunkId: 'router',
246
+ moduleId: 'router',
247
+ content: code,
248
+ exports: [],
249
+ exec: false,
250
+ });
212
251
  }
213
252
  // 生成路由文件
214
253
  function genRouteFiles(routes, defaultRoute, config) {
215
254
  // 生成路由文件列表
216
255
  const routeFiles = [];
256
+ const asyncChunksMap = {};
217
257
  function routeToFile(route) {
218
258
  if (route?.component?.script) {
219
259
  const content = genExportComponetCode(route.component);
220
- const lazyPath = getCompletePath(null, content, config);
221
- route.lazyPath = lazyPath;
222
- // let outFilePath =`${config?.sysPrefixPath? config?.sysPrefixPath +'/' :''}${lazyPath}`;
260
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
261
+ const contentHash = (0, nasl_utils_1.genHash)(content);
223
262
  routeFiles.push({
224
- name: lazyPath,
225
- content,
263
+ name: chunkId + '.' + contentHash + '.js',
264
+ content: (0, chunk_1.generate)({
265
+ name: config?.app?.name,
266
+ chunkId,
267
+ moduleId: chunkId,
268
+ content,
269
+ exports: [
270
+ ['componentOptions', 'default'],
271
+ ],
272
+ exec: false,
273
+ }),
226
274
  });
275
+ asyncChunksMap[chunkId] = contentHash;
227
276
  }
228
277
  if (route?.children?.length) {
229
278
  route.children.map(routeToFile);
@@ -232,13 +281,16 @@ function genRouteFiles(routes, defaultRoute, config) {
232
281
  routes.forEach((route) => {
233
282
  routeToFile(route);
234
283
  });
235
- let routerPath = getCompletePath('router', null, config);
236
284
  routeFiles.push({
237
- name: routerPath,
285
+ name: getCompletePath('router', null, config),
238
286
  isRouterFile: true,
239
- content: genRouterFileContent(routes, defaultRoute),
287
+ content: genRouterFileContent(routes, defaultRoute, Object.assign({}, config, { asyncChunksMap })),
240
288
  });
241
- return routeFiles;
289
+ const { publicPath } = config;
290
+ return routeFiles.map(file => ({
291
+ ...file,
292
+ name: publicPath + file.name,
293
+ }));
242
294
  }
243
295
  async function genBundleFiles(app, frontend, config) {
244
296
  config.sysPrefixPath = app?.sysPrefixPath;
@@ -323,24 +375,8 @@ async function genBundleFiles(app, frontend, config) {
323
375
  (0, nasl_log_1.clearLogs)(app);
324
376
  }
325
377
  }
326
- const getBundleFileName = () => {
327
- if (config.isPreviewFe && config.previewVersion) {
328
- return `mockBundle-${config.previewVersion}`;
329
- }
330
- else {
331
- return 'bundle';
332
- }
333
- };
334
- let baseUrl = `${config.USER_STATIC_URL}/${config.tenant}/${app.id}/${config.env}`;
335
- let { basePath } = frontend;
336
- // isPreviewFe 资产中心的预览模式,优先级最高
337
- if (config.isPreviewFe) {
338
- baseUrl = `${config.USER_STATIC_URL}/asset-center/preview/${config.tenant}/${app.id}/${config.env}`;
339
- }
340
- else if (config.isExport) {
341
- baseUrl = '';
342
- }
343
- let completePath = `${baseUrl}${basePath || ''}/`;
378
+ // @ts-expect-error
379
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
344
380
  /**
345
381
  * vue.config.js page options
346
382
  */
@@ -380,11 +416,18 @@ async function genBundleFiles(app, frontend, config) {
380
416
  }
381
417
  }
382
418
  }
419
+ let fullPath = `/${viewName}`;
420
+ let parent = view.parentNode;
421
+ while (parent?.concept === 'View') {
422
+ fullPath = `/${parent.name}${fullPath}`;
423
+ parent = parent.parentNode;
424
+ }
383
425
  const route = {
384
426
  path: routePath,
385
427
  component: (0, compileComponent_1.compileComponent)(componentMap[view.id]),
386
428
  children: [],
387
429
  meta: view.getRouteMeta(),
430
+ fullPath,
388
431
  };
389
432
  const viewChildren = view.children;
390
433
  if (Array.isArray(viewChildren) && viewChildren.length) {
@@ -459,15 +502,7 @@ async function genBundleFiles(app, frontend, config) {
459
502
  // authResourcePathMap={}
460
503
  }
461
504
  const authResourcePaths = Object.keys(authResourcePathMap);
462
- const routerFiles = genRouteFiles(routes, defaultRoute, config);
463
- routerFiles.forEach(item => {
464
- let temp = completePath;
465
- // if(completePath=='/'){temp=''}else{temp = `${completePath}/`}
466
- if (config?.isExport && config?.sysPrefixPath?.length > 0) {
467
- temp = config?.sysPrefixPath + temp;
468
- }
469
- item.name = temp + item.name;
470
- });
505
+ const routerFiles = genRouteFiles(routes, defaultRoute, Object.assign({}, config, { app, publicPath }));
471
506
  let fileI18nInfo = {
472
507
  enabled: false,
473
508
  locale: 'zh-CN',
@@ -582,8 +617,6 @@ async function genBundleFiles(app, frontend, config) {
582
617
  }
583
618
  const assetsInfo = app.genAllAssetsInfo(STATIC_URL, frontend.type, frontendType.frameworkKind);
584
619
  const customNames = JSON5.stringify(assetsInfo.custom.names);
585
- let content1 = `(async function(){
586
- `;
587
620
  let contentScale = '';
588
621
  if (frontend.globalScaleEnabled)
589
622
  contentScale = `{
@@ -693,67 +726,6 @@ async function genBundleFiles(app, frontend, config) {
693
726
  let contentImport = `
694
727
  var platformConfig = ${platformConfig};
695
728
  var metaData = ${metaDataStr};
696
-
697
- var getCompletePath = (path) => {
698
- return '${config?.isExport ? config.sysPrefixPath : ''}${completePath}' + path;
699
- }
700
-
701
- // 低版本
702
- function importXMLHttpRequestComponent (scriptUrl) {
703
- return new Promise(function(resolve, reject) {
704
- var xhr = new XMLHttpRequest();
705
- xhr.open('GET', scriptUrl, true);
706
- xhr.onreadystatechange = function() {
707
- if (xhr.readyState === 4) {
708
- if (xhr.status === 200) {
709
- var scriptContent = xhr.responseText;
710
- try {
711
- var func = new Function('importComponent', 'window', scriptContent + '\\n//# sourceURL=' + scriptUrl);
712
- var result = func(window.importComponent, window);
713
- resolve(result);
714
- } catch (error) {
715
- if (typeof window.$appUtils.createErrorLayout === 'function') {
716
- window.$appUtils.createErrorLayout(error);
717
- }
718
- reject(error);
719
- }
720
- } else {
721
- reject(new Error('Failed to fetch script'));
722
- }
723
- }
724
- };
725
- xhr.send();
726
- });
727
- };
728
- function importFetchComponent(scriptUrl) {
729
- return fetch(scriptUrl)
730
- .then(function(response) {
731
- if (!response.ok) {
732
- throw new Error('Network response was not ok');
733
- }
734
- return response.text();
735
- }).then(function(scriptText) {
736
- var func = new Function('importComponent', 'window', scriptText + '\\n//# sourceURL=' + scriptUrl);
737
- var result = func(window.importComponent, window);
738
- return result;
739
- })
740
- .catch(error => {
741
- console.error('Error loading script:', error);
742
- if (typeof window.$appUtils.createErrorLayout === 'function') {
743
- window.$appUtils.createErrorLayout(error);
744
- }
745
- });
746
- }
747
- window.importComponent = (scriptUrl) => {
748
- scriptUrl = getCompletePath(scriptUrl);
749
- // 浏览器支持fetch,直接使用fetch
750
- if (window.fetch) {
751
- return importFetchComponent(scriptUrl);
752
- }
753
- return importXMLHttpRequestComponent(scriptUrl);
754
- }
755
-
756
- var routes = await importComponent('${getCompletePath('router', null, config)}?t=' + Date.now());
757
729
  `;
758
730
  // 按页面维度发布先不考虑鉴权,页面维度新增的页面都算是不鉴权的数组中
759
731
  // 只有完全页面维度新增的才会进入到这个数组中
@@ -772,11 +744,11 @@ async function genBundleFiles(app, frontend, config) {
772
744
  }
773
745
  });
774
746
  }
775
- iterateRouters(routes);` : '';
747
+ iterateRouters(window.lcap_routes);` : '';
776
748
  let contentCreateLCAPApp = `
777
749
  window.createLcapApp = () => {
778
750
  ${compRegStr}
779
- appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, routes, metaData);
751
+ var appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, window.lcap_routes, metaData);
780
752
  try {
781
753
  var push = appVM.$router.history.push;
782
754
  appVM.$router.history.push = function (a, b) {
@@ -855,8 +827,6 @@ async function genBundleFiles(app, frontend, config) {
855
827
  if(shortcutIconLink) parent.document.head.appendChild(shortcutIconLink);
856
828
  }
857
829
  ` : '';
858
- let content10 = `
859
- })();`;
860
830
  let contentDevOnly = config.env === 'dev' ? `
861
831
  var _div = document.createElement('div');
862
832
  _div.classList = "div-load"
@@ -972,10 +942,21 @@ async function genBundleFiles(app, frontend, config) {
972
942
  };
973
943
  fetchAnnoData();
974
944
  ` : '';
975
- let content = [content1, contentScale, contentStyleCss, contentDocIcon, contentCustomNames, contentImport,
976
- contentLogReportCode, contentRouter, contentCreateLCAPApp, contentPCIframe, content10,
977
- contentDevOnly, contentVueDirectives.join(''), contentViewElemAnno].join('');
978
- content1 = null;
945
+ let content = [
946
+ `__webpack_require__('./router.js');`,
947
+ contentScale,
948
+ contentStyleCss,
949
+ contentDocIcon,
950
+ contentCustomNames,
951
+ contentImport,
952
+ contentLogReportCode,
953
+ contentRouter,
954
+ contentCreateLCAPApp,
955
+ contentPCIframe,
956
+ contentDevOnly,
957
+ contentVueDirectives.join(''),
958
+ contentViewElemAnno
959
+ ].join('');
979
960
  contentScale = null;
980
961
  contentStyleCss = null;
981
962
  contentDocIcon = null;
@@ -985,19 +966,29 @@ async function genBundleFiles(app, frontend, config) {
985
966
  contentRouter = null;
986
967
  contentCreateLCAPApp = null;
987
968
  contentPCIframe = null;
988
- content10 = null;
989
969
  contentDevOnly = null;
990
970
  contentVueDirectives = null;
991
971
  contentViewElemAnno = null;
992
972
  const timestamp = Date.now();
993
973
  utils.delay(100);
994
- let bundleMinPath = completePath + getCompletePath(getBundleFileName(), content, config);
974
+ content = (0, chunk_1.generate)({
975
+ name: app.name,
976
+ chunkId: 'bundle',
977
+ moduleId: 'bundle',
978
+ content,
979
+ exports: [],
980
+ exec: true,
981
+ });
982
+ let clientPath = publicPath + 'client.js';
983
+ let runtimePath = publicPath + 'runtime.js';
984
+ let routerPath = publicPath + getCompletePath('router', null, config);
985
+ let bundleMinPath = publicPath + getCompletePath(getBundleFileName(config), content, config);
995
986
  const otherJsList = frontend?.appletsConfig?.enable ? ['//res.wx.qq.com/open/js/jweixin-1.3.2.js'] : [];
996
987
  const microAppIntegration = (0, microApp_1.integrateMicroApp)(frontend);
997
988
  if (config?.debug) {
998
989
  otherJsList.push(`${STATIC_URL}/packages/@lcap/breakpoint-client@1.0.0/dist/index.js?time=${timestamp}`);
999
990
  }
1000
- let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([bundleMinPath]);
991
+ let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([runtimePath, routerPath, bundleMinPath]);
1001
992
  let cssAssetsList = assetsInfo.basic.css.concat(assetsInfo.custom.css);
1002
993
  if (config.isPreviewFe) {
1003
994
  const changeToRelativePath = (str) => {
@@ -1108,6 +1099,11 @@ async function genBundleFiles(app, frontend, config) {
1108
1099
  refresh: config.refresh,
1109
1100
  }));
1110
1101
  }
1102
+ // encode url
1103
+ if ((0, nasl_unified_frontend_generator_2.isEnabledEncode)()) {
1104
+ jsAssetsList = jsAssetsList.map(nasl_unified_frontend_generator_2.encodeFetchFileURL);
1105
+ cssAssetsList = cssAssetsList.map(nasl_unified_frontend_generator_2.encodeFetchFileURL);
1106
+ }
1111
1107
  const dynamicAssets = optimizeAssetClassification(jsAssetsList);
1112
1108
  // CSS 资源默认最后
1113
1109
  if (cssAssetsList.length > 0) {
@@ -1188,18 +1184,26 @@ async function genBundleFiles(app, frontend, config) {
1188
1184
  `;
1189
1185
  const outputs = [
1190
1186
  {
1191
- name: bundleMinPath,
1192
- content,
1187
+ name: clientPath,
1188
+ content: assetsContent,
1193
1189
  },
1194
1190
  {
1195
- name: basePath ? `${baseUrl}${basePath}/client.js` : `${baseUrl}/client.js`,
1196
- content: assetsContent,
1191
+ name: runtimePath,
1192
+ content: (0, runtime_1.generate)({
1193
+ name: app.name,
1194
+ publicPath: JSON.stringify(publicPath),
1195
+ }),
1196
+ },
1197
+ {
1198
+ name: bundleMinPath,
1199
+ content,
1197
1200
  },
1198
1201
  ...routerFiles,
1199
1202
  ];
1200
1203
  assetsContent = null;
1201
1204
  content = null;
1202
1205
  processAssetsInOutputs(outputs, frontend, config);
1206
+ console.info('编译结果', outputs.map((x) => x.name));
1203
1207
  return outputs;
1204
1208
  }
1205
1209
  exports.genBundleFiles = genBundleFiles;
@@ -1332,16 +1336,23 @@ async function getOneFiles(options) {
1332
1336
  if (isRootView) {
1333
1337
  routePath = `${frontend.prefixPath}/${viewName}`;
1334
1338
  }
1339
+ let fullPath = `/${viewName}`;
1340
+ let parent = view.parentNode;
1341
+ while (parent?.concept === 'View') {
1342
+ fullPath = `/${parent.name}${fullPath}`;
1343
+ parent = parent.parentNode;
1344
+ }
1335
1345
  const route = {
1336
1346
  path: routePath,
1337
1347
  component: (0, compileComponent_1.compileComponent)(viewOption),
1338
1348
  children: [],
1339
1349
  meta: view.getRouteMeta(),
1350
+ fullPath,
1340
1351
  };
1341
1352
  return route;
1342
1353
  }
1343
- let currentView = view;
1344
1354
  let currentRoute = null;
1355
+ let currentView = view;
1345
1356
  while (currentView?.concept === 'View') {
1346
1357
  if (currentRoute) {
1347
1358
  const child = currentRoute;
@@ -1375,6 +1386,7 @@ async function getOneFiles(options) {
1375
1386
  // 如果找到了现有路由,更新 component 和 meta
1376
1387
  existingRoute.component = newRoute.component;
1377
1388
  existingRoute.meta = newRoute.meta;
1389
+ existingRoute.fullPath = newRoute.fullPath;
1378
1390
  // 递归合并子路由
1379
1391
  if (newRoute.children) {
1380
1392
  existingRoute.children = existingRoute.children || [];
@@ -1391,9 +1403,25 @@ async function getOneFiles(options) {
1391
1403
  routes.unshift(newRoute);
1392
1404
  }
1393
1405
  }
1406
+ let existingRoutes = [];
1407
+ try {
1408
+ // 获取// lcap_routes start 到 // lcap_routes end 之间的代码
1409
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
1410
+ const routesCode = cacheRouters
1411
+ .substring(cacheRouters.indexOf(start) + start.length, cacheRouters.indexOf(end))
1412
+ .replace('window.lcap_routes = ', 'return ');
1413
+ const fn = new Function(`${routesCode}`);
1414
+ existingRoutes = fn();
1415
+ }
1416
+ catch (error) {
1417
+ console.error('路由代码 eval 失败:', error);
1418
+ }
1394
1419
  // Bug-3156542745982976: 原本直接找到顶层直接删除,在新增节点,遗漏处理中间层也有节点的情况,单页发布就直接增量合并,为了性能,暂时不考虑删除节点
1395
- addOrUpdateRoute(cacheRouters, currentRoute);
1396
- const routerFiles = genRouteFiles(cacheRouters, null);
1420
+ addOrUpdateRoute(existingRoutes, currentRoute);
1421
+ // @ts-expect-error
1422
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
1423
+ const routerFiles = genRouteFiles(existingRoutes, null, Object.assign({}, config, { app, cacheRouters, isOneFile: true, publicPath }));
1424
+ console.info('编译结果', routerFiles.map((x) => x.name));
1397
1425
  return routerFiles;
1398
1426
  }
1399
1427
  exports.getOneFiles = getOneFiles;
@@ -1487,4 +1515,13 @@ function processAssetsInOutputs(outputs, frontend, config) {
1487
1515
  });
1488
1516
  }
1489
1517
  }
1518
+ function getBundleFileName(config) {
1519
+ if (config.isPreviewFe && config.previewVersion) {
1520
+ return `mockBundle-${config.previewVersion}`;
1521
+ }
1522
+ else {
1523
+ return 'bundle';
1524
+ }
1525
+ }
1526
+ ;
1490
1527
  //# sourceMappingURL=genBundleFiles.js.map