@lcap/nasl-unified-frontend-generator 3.13.2-beta.13 → 3.13.2-beta.14

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/dist/index.d.mts CHANGED
@@ -1139,7 +1139,7 @@ declare class ReactCodegenPlugin implements JavaScriptDomain.FrontendApplication
1139
1139
  * @returns 生成的React文件描述列表
1140
1140
  */
1141
1141
  recursivelyGenReactComponent(c: GeneralComponentIR, dict: ComponentIRToPathDict, folder?: FolderPath, irConfig?: NASLAppIR['configs']): ReactFileDescription[];
1142
- buildRoutes(views: ViewComponentIR[], componentIRToPathDict: ComponentIRToPathDict): ReactFileDescription;
1142
+ buildRoutes(views: ViewComponentIR[], componentIRToPathDict: ComponentIRToPathDict, basePath: string): ReactFileDescription;
1143
1143
  /**
1144
1144
  * 构建平台配置文件
1145
1145
  * @param ir - NASL应用中间表示
@@ -1197,7 +1197,7 @@ declare class NameMangler {
1197
1197
  declare const reactRouterPlugin: {
1198
1198
  name: string;
1199
1199
  functions: {
1200
- routeToCode(routes: RouteIR[], componentIRToPathDict: ComponentIRToPathDict): {
1200
+ routeToCode(routes: RouteIR[], componentIRToPathDict: ComponentIRToPathDict, basePath: string): {
1201
1201
  code: string;
1202
1202
  imports: ImportIR[];
1203
1203
  };
@@ -1578,7 +1578,7 @@ declare namespace JavaScriptDomain {
1578
1578
  * @param componentIRToPathDict - 组件
1579
1579
  * @returns 路由文件
1580
1580
  */
1581
- buildRoutes(views: GeneralComponentIR[], componentIRToPathDict: ComponentIRToPathDict): ReactFileDescription;
1581
+ buildRoutes(views: GeneralComponentIR[], componentIRToPathDict: ComponentIRToPathDict, basePath: string): ReactFileDescription;
1582
1582
  /**
1583
1583
  * 构建主CSS入口文件
1584
1584
  * @param packages - 包信息
package/dist/index.d.ts CHANGED
@@ -1139,7 +1139,7 @@ declare class ReactCodegenPlugin implements JavaScriptDomain.FrontendApplication
1139
1139
  * @returns 生成的React文件描述列表
1140
1140
  */
1141
1141
  recursivelyGenReactComponent(c: GeneralComponentIR, dict: ComponentIRToPathDict, folder?: FolderPath, irConfig?: NASLAppIR['configs']): ReactFileDescription[];
1142
- buildRoutes(views: ViewComponentIR[], componentIRToPathDict: ComponentIRToPathDict): ReactFileDescription;
1142
+ buildRoutes(views: ViewComponentIR[], componentIRToPathDict: ComponentIRToPathDict, basePath: string): ReactFileDescription;
1143
1143
  /**
1144
1144
  * 构建平台配置文件
1145
1145
  * @param ir - NASL应用中间表示
@@ -1197,7 +1197,7 @@ declare class NameMangler {
1197
1197
  declare const reactRouterPlugin: {
1198
1198
  name: string;
1199
1199
  functions: {
1200
- routeToCode(routes: RouteIR[], componentIRToPathDict: ComponentIRToPathDict): {
1200
+ routeToCode(routes: RouteIR[], componentIRToPathDict: ComponentIRToPathDict, basePath: string): {
1201
1201
  code: string;
1202
1202
  imports: ImportIR[];
1203
1203
  };
@@ -1578,7 +1578,7 @@ declare namespace JavaScriptDomain {
1578
1578
  * @param componentIRToPathDict - 组件
1579
1579
  * @returns 路由文件
1580
1580
  */
1581
- buildRoutes(views: GeneralComponentIR[], componentIRToPathDict: ComponentIRToPathDict): ReactFileDescription;
1581
+ buildRoutes(views: GeneralComponentIR[], componentIRToPathDict: ComponentIRToPathDict, basePath: string): ReactFileDescription;
1582
1582
  /**
1583
1583
  * 构建主CSS入口文件
1584
1584
  * @param packages - 包信息
package/dist/index.js CHANGED
@@ -967,7 +967,7 @@ var routesExtractionPlugin = makePlugin({
967
967
  return {
968
968
  accumulativePath: `${path}/`,
969
969
  thisLevelPath: ``,
970
- redirect: `${path}/${child.elementTemplate.identifier}`,
970
+ redirect: `${child.elementTemplate.identifier}`,
971
971
  kind: "redirect"
972
972
  };
973
973
  }
@@ -985,8 +985,8 @@ var routesExtractionPlugin = makePlugin({
985
985
  if (possibleIndexComponent) {
986
986
  routes.push({
987
987
  accumulativePath: "/",
988
- thisLevelPath: `/`,
989
- redirect: `${routePrefix}${possibleIndexComponent.identifier}`,
988
+ thisLevelPath: ``,
989
+ redirect: `${possibleIndexComponent.identifier}`,
990
990
  kind: "redirect"
991
991
  });
992
992
  }
@@ -995,7 +995,7 @@ var routesExtractionPlugin = makePlugin({
995
995
  routes.push({
996
996
  accumulativePath: "*",
997
997
  thisLevelPath: "*",
998
- redirect: `${routePrefix}${fallbackComponent.identifier}`,
998
+ redirect: `${fallbackComponent.identifier}`,
999
999
  kind: "redirect"
1000
1000
  });
1001
1001
  }
@@ -2146,7 +2146,8 @@ query: {`;
2146
2146
  let url2 = "`";
2147
2147
  const viewArr = s3.genViewArr();
2148
2148
  if (Array.isArray(viewArr) && viewArr.length) {
2149
- url2 += `/${viewArr.join("/")}`;
2149
+ const prefixPath = s3.frontend?.prefixPath;
2150
+ url2 += `${prefixPath}/${viewArr.join("/")}`;
2150
2151
  const { completeArguments } = s3;
2151
2152
  if (completeArguments.length) {
2152
2153
  const node = s3.viewNode;
@@ -2690,7 +2691,7 @@ var NameMangler = class {
2690
2691
  var reactRouterPlugin = makePlugin({
2691
2692
  name: "ReactRouter",
2692
2693
  functions: {
2693
- routeToCode(routes, componentIRToPathDict) {
2694
+ routeToCode(routes, componentIRToPathDict, basePath) {
2694
2695
  const self = { ...jsxCodeGenPlugin.functions, ...javaScriptCodeGenPlugin.functions };
2695
2696
  const nameMangler = new NameMangler();
2696
2697
  const importConfigMap = /* @__PURE__ */ new WeakMap();
@@ -2759,7 +2760,7 @@ var reactRouterPlugin = makePlugin({
2759
2760
  ];
2760
2761
  const routesConfig = routes.map(serializeReactRoute).filter(isNotNil).join(",\n");
2761
2762
  const routerConfigStr = `const defaultRoutes = [{
2762
- path: '/',
2763
+ path: '${basePath || "/"}',
2763
2764
  children: [
2764
2765
  ${routesConfig}
2765
2766
  ],
@@ -2793,7 +2794,7 @@ var reactRouterPlugin = makePlugin({
2793
2794
  const basename =
2794
2795
  window.LcapMicro?.routePrefix
2795
2796
  ? ensureStartsWithSlash(window.LcapMicro?.routePrefix)
2796
- : platformConfig.appConfig.basePath;
2797
+ : undefined;
2797
2798
 
2798
2799
  const router = createRouter(routes, { resources, userInfo, basename, beforeEach: ({meta})=>{
2799
2800
  window?.beforeRouter?.({meta});
@@ -3651,16 +3652,16 @@ var ReactCodegenPlugin = class {
3651
3652
  }) : []
3652
3653
  ]);
3653
3654
  }
3654
- buildRoutes(views, componentIRToPathDict) {
3655
+ buildRoutes(views, componentIRToPathDict, basePath) {
3655
3656
  const self = {
3656
3657
  ...routesExtractionPlugin.functions,
3657
3658
  ...reactRouterPlugin.functions
3658
3659
  };
3659
- const { routes: routeIRs } = self.extractRoute(views, "/", {
3660
+ const { routes: routeIRs } = self.extractRoute(views, basePath, {
3660
3661
  lazy: this.frontendPerformance?.performanceOptions?.lazy ?? true,
3661
3662
  frameworkKind: "react"
3662
3663
  });
3663
- const { code, imports } = self.routeToCode(routeIRs, componentIRToPathDict);
3664
+ const { code, imports } = self.routeToCode(routeIRs, componentIRToPathDict, basePath);
3664
3665
  return new ReactFileDescription("Router", [...imports], [], [code]);
3665
3666
  }
3666
3667
  /**
@@ -3672,7 +3673,8 @@ var ReactCodegenPlugin = class {
3672
3673
  const self = {
3673
3674
  ...routesExtractionPlugin.functions
3674
3675
  };
3675
- const { authResourcePaths, baseResourcePaths } = self.extractRoute(ir.views, "/", {
3676
+ const basePath = ir.configs.basePlatformConfig.basePath + "/";
3677
+ const { authResourcePaths, baseResourcePaths } = self.extractRoute(ir.views, basePath, {
3676
3678
  lazy: false,
3677
3679
  frameworkKind: "react"
3678
3680
  });
@@ -3928,7 +3930,8 @@ var ReactCodegenPlugin = class {
3928
3930
  const bizComponents = ir.bizComponents.flatMap(
3929
3931
  (x) => this.recursivelyGenReactComponent(x, componentIRToPathDict, void 0, ir.configs)
3930
3932
  );
3931
- const routes = this.buildRoutes(ir.views, componentIRToPathDict);
3933
+ const basePath = ir.configs.basePlatformConfig.basePath + "/";
3934
+ const routes = this.buildRoutes(ir.views, componentIRToPathDict, basePath);
3932
3935
  const masterCss = await this.buildMasterCss(ir.configs.themeCSS, ir.packages);
3933
3936
  const globalVariables = await this.buildGlobalFrontendVariableFile(
3934
3937
  ir.configs.globalVariables,
@@ -4159,7 +4162,7 @@ var materials = {
4159
4162
  frameworkVersion: "vue@3.5.13",
4160
4163
  libName: "ElementPlus",
4161
4164
  name: "@lcap/element-plus",
4162
- version: "1.0.0-beta.1"
4165
+ version: "1.0.0"
4163
4166
  }
4164
4167
  ],
4165
4168
  h5: [
@@ -7114,23 +7117,28 @@ var VueRouterPlugin = class {
7114
7117
  }
7115
7118
  routeToCode(routes, componentPathManager, config) {
7116
7119
  function serializeVueRoute(r, isRoot = false) {
7117
- const path = r.thisLevelPath ?? "/";
7120
+ const { accumulativePath, thisLevelPath } = r;
7121
+ const path = isRoot ? accumulativePath : thisLevelPath ?? "/";
7122
+ const basePath = config.basePath;
7118
7123
  if (r.kind === "normal") {
7119
7124
  const children = r.children?.map((i) => serializeVueRoute(i)).filter(isNotNil) ?? [];
7120
7125
  const childrenStr = children.join(",\n");
7121
7126
  const componentCode = `component: ${r.elementMangledName ?? r.elementTemplate.identifier}`;
7122
- return `{path: "${isRoot ? r.accumulativePath : path}", meta: ${JSON.stringify(
7127
+ return `{path: "${path}", meta: ${JSON.stringify(
7123
7128
  r.meta
7124
7129
  )}, children: [${childrenStr}], ${componentCode} }`;
7125
7130
  } else if (r.kind === "redirect") {
7126
- const replaceWildCardForVue3 = (frameworkKind, path2) => {
7127
- if (frameworkKind === "vue3" && path2 === "*") {
7128
- return "/:pathMatch(.*)*";
7131
+ if (["vue3"].includes(config.frameworkKind) && path === "*") {
7132
+ return `{ path: "/:pathMatch(.*)*", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
7133
+ }
7134
+ if (["vue3"].includes(config.frameworkKind) && path === "/") {
7135
+ let result = `{ path: "/", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
7136
+ if (basePath !== "/") {
7137
+ result += `, { path: "${basePath}", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
7129
7138
  }
7130
- return path2;
7131
- };
7132
- const processedPath = replaceWildCardForVue3(config.frameworkKind, path);
7133
- return `{path: "${processedPath}", redirect: ${JSON.stringify(r.redirect)}}`;
7139
+ return result;
7140
+ }
7141
+ return `{ path: "${path}", redirect: to => to.path.replace(/\\/$/, '') + '/' + ${JSON.stringify(r.redirect)} }`;
7134
7142
  }
7135
7143
  notImplemented(r);
7136
7144
  }
@@ -7531,15 +7539,16 @@ var Vue3ApplicationAssemblerPlugin = class {
7531
7539
  const bizComponents = ir.bizComponents.flatMap((x) => {
7532
7540
  return this.vue3CodegenPlugin.genFiles(x, manager);
7533
7541
  });
7534
- let routePrefix = ir.configs.frontendDesc.path;
7535
- if (!/\/$/.test(routePrefix)) {
7536
- routePrefix += "/";
7542
+ let basePath = ir.configs.basePlatformConfig.basePath;
7543
+ if (!/\/$/.test(basePath)) {
7544
+ basePath += "/";
7537
7545
  }
7538
- const routesObjects = this.routesExtactor.extractRoute(ir.views, routePrefix, {
7546
+ const routesObjects = this.routesExtactor.extractRoute(ir.views, basePath, {
7539
7547
  lazy: true
7540
7548
  });
7541
7549
  const router = this.routerBuilder.routeToCode(routesObjects.routes, manager, {
7542
- frameworkKind: "vue3"
7550
+ frameworkKind: "vue3",
7551
+ basePath
7543
7552
  });
7544
7553
  const routerFile = new ReactFileDescription("router.ts", router.imports, [], [router.code]);
7545
7554
  const libraries = await this.librariesBuilder.buildLibrariesImport(ir, config);