@lcap/nasl-unified-frontend-generator 4.0.0-beta.9 → 4.0.0-creator.1

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.
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __commonJS = (cb, mod) => function __require() {
9
12
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
13
  };
@@ -2244,6 +2247,75 @@ var require_lib = __commonJS({
2244
2247
  }
2245
2248
  });
2246
2249
 
2250
+ // src/plugins/templates/auto-reload.js
2251
+ var auto_reload_exports = {};
2252
+ __export(auto_reload_exports, {
2253
+ default: () => auto_reload_default
2254
+ });
2255
+ var auto_reload_default;
2256
+ var init_auto_reload = __esm({
2257
+ "src/plugins/templates/auto-reload.js"() {
2258
+ "use strict";
2259
+ auto_reload_default = `
2260
+ const dom = document.createElement('div');
2261
+ dom.classList = "lcap-deploy-loading-container";
2262
+ dom.style.display = 'none';
2263
+ dom.innerHTML = "<div class='lcap-deploy-loading-icon'></div><div>\u6B63\u5728\u66F4\u65B0\u6700\u65B0\u53D1\u5E03\u5185\u5BB9...</div>";
2264
+ document.getElementsByTagName('body')[0].appendChild(dom);
2265
+
2266
+ const style = document.createElement('style');
2267
+ style.innerHTML = \`.lcap-deploy-loading-container {
2268
+ width: 208px;
2269
+ height: 40px;
2270
+ background: rgba(48, 48, 48, 0.8);
2271
+ box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
2272
+ border-radius: 4px;
2273
+ position: fixed;
2274
+ top: 120px;
2275
+ left: 50%;
2276
+ margin-left: -104px;
2277
+ color: #FFFFFF;
2278
+ font-size: 14px;
2279
+ justify-content: center;
2280
+ align-items: center;
2281
+ }
2282
+
2283
+ .lcap-deploy-loading-icon{
2284
+ width: 12px;
2285
+ height: 12px;
2286
+ margin-right: 10px;
2287
+ animation: loading-animation 0.8s infinite linear;
2288
+ border: 2px solid #f3f3f3;
2289
+ border-top: 2px solid rgb(109, 108, 108);
2290
+ border-right: 2px solid rgb(109, 108, 108);
2291
+ border-bottom: 2px solid rgb(109, 108, 108);
2292
+ border-radius: 50%;
2293
+ }
2294
+
2295
+ @keyframes loading-animation{
2296
+ 0% {
2297
+ transform: rotate(0deg);
2298
+ }
2299
+ 100% {
2300
+ transform: rotate(360deg);
2301
+ }
2302
+ }\`;
2303
+ document.getElementsByTagName('body')[0].appendChild(style);
2304
+
2305
+ window.addEventListener('message', function (e) {
2306
+ if(e.data ==="release-start"){
2307
+ document.querySelector(".lcap-deploy-loading-container").style.display ="flex"
2308
+ }
2309
+
2310
+ if(e.data==="release-end"){
2311
+ document.querySelector(".lcap-deploy-loading-container").style.display ="none"
2312
+ window.location.reload();
2313
+ }
2314
+ });
2315
+ `;
2316
+ }
2317
+ });
2318
+
2247
2319
  // playground/helper.ts
2248
2320
  var helper_exports = {};
2249
2321
  __export(helper_exports, {
@@ -3461,8 +3533,8 @@ var reactComponentLibHackPlugin = makePlugin({
3461
3533
  }
3462
3534
 
3463
3535
  Object.assign(utils, {
3464
- jsonSerialize: JSON.stringify,
3465
- jsonDeserialize: JSON.parse,
3536
+ jsonSerialize: utils.JsonSerialize || JSON.stringify,
3537
+ jsonDeserialize: utils.JsonDeserialize || JSON.parse,
3466
3538
  });
3467
3539
 
3468
3540
  const logging = {
@@ -6554,29 +6626,6 @@ var coreVersion = materials.framework.version;
6554
6626
  function getPredefinedMaterialConfig() {
6555
6627
  return materials;
6556
6628
  }
6557
- function getPredefinedLibConstants() {
6558
- if (!reactUi || !vue3Ui) {
6559
- throw new Error("not found");
6560
- }
6561
- if (reactUi.name !== "@lcap/pc-react-ui") {
6562
- throw new Error("cannot find @lcap/pc-react-ui in material.config.js");
6563
- }
6564
- return {
6565
- reactUI: {
6566
- kind: "standard",
6567
- name: reactUi.name,
6568
- version: reactUi.version
6569
- },
6570
- vue3Ui: {
6571
- kind: "standard",
6572
- name: vue3Ui.name,
6573
- version: vue3Ui.version
6574
- },
6575
- basicTemplate: {
6576
- version: coreVersion
6577
- }
6578
- };
6579
- }
6580
6629
  var getPredefinedMaterialByTags = (() => {
6581
6630
  const materialConfig = getPredefinedMaterialConfig();
6582
6631
  let allMaterials = [];
@@ -6600,12 +6649,14 @@ var getPredefinedMaterialByTags = (() => {
6600
6649
  materialConfig.ui.pc.forEach((item) => {
6601
6650
  allMaterials.push({
6602
6651
  ...item,
6652
+ kind: "standard",
6603
6653
  tags: ["ui", "pc", item.frameworkKind, item.libName]
6604
6654
  });
6605
6655
  });
6606
6656
  materialConfig.ui.h5.forEach((item) => {
6607
6657
  allMaterials.push({
6608
6658
  ...item,
6659
+ kind: "standard",
6609
6660
  tags: ["ui", "h5", item.frameworkKind, item.libName]
6610
6661
  });
6611
6662
  });
@@ -6765,7 +6816,10 @@ function bindAttrToIR(b) {
6765
6816
  throw new Error("string\u4E0D\u53EF\u4E3Async");
6766
6817
  }
6767
6818
  if (b.i18nKey && b.value && b.frontend?.i18nInfo?.enabled) {
6768
- b.type = "dynamic";
6819
+ const frameworkKind = b.frontend?.frameworkKind;
6820
+ if (!["vue3"].includes(frameworkKind)) {
6821
+ b.type = "dynamic";
6822
+ }
6769
6823
  const wrapperExpr = import_nasl_concepts9.CallFunction.from(
6770
6824
  {
6771
6825
  calleeNamespace: "$i18n",
@@ -6869,7 +6923,7 @@ function bindEventToAction(b) {
6869
6923
  kind: "standalone"
6870
6924
  };
6871
6925
  }
6872
- var DefaultComponentLibraryName = getPredefinedLibConstants().reactUI.name;
6926
+ var DefaultComponentLibraryName = getPredefinedMaterialByTags(["ui", "pc", "react"])?.name;
6873
6927
  function getReferencedLibComponent(e) {
6874
6928
  const tag = e.tag;
6875
6929
  if (tag.startsWith("BS")) {
@@ -7535,8 +7589,8 @@ var NASLAppIRBuilderPlugin = class {
7535
7589
  });
7536
7590
  logger5.debug({ extensionPackages });
7537
7591
  const frameworkKind = frontend.frameworkKind;
7538
- const libs = getPredefinedLibConstants();
7539
- return [...extensionPackages, frameworkKind === "vue3" ? libs.vue3Ui : libs.reactUI];
7592
+ const uiLib = getPredefinedMaterialByTags(["ui", frontend.type, frameworkKind]);
7593
+ return [...extensionPackages, uiLib];
7540
7594
  };
7541
7595
  var buildConfigs = buildConfigs2, collectPackages = collectPackages2;
7542
7596
  config2.debug && breakpoint2.genBreakpoints(app);
@@ -8905,10 +8959,9 @@ function extractAppLevelFrontendDeps(app) {
8905
8959
  }
8906
8960
  function extractFrontendLevelDeps(frontend) {
8907
8961
  const deps = [];
8908
- if (frontend.frameworkKind === "react") {
8909
- deps.push(getPredefinedLibConstants().reactUI);
8910
- } else if (frontend.frameworkKind === "vue3") {
8911
- deps.push(getPredefinedLibConstants().vue3Ui);
8962
+ const uiLib = getPredefinedMaterialByTags(["ui", frontend.type, frontend.frameworkKind]);
8963
+ if (uiLib) {
8964
+ deps.push(uiLib);
8912
8965
  }
8913
8966
  return deps;
8914
8967
  }
@@ -9081,11 +9134,11 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config2) {
9081
9134
  }
9082
9135
  let packageJson = fs.read("/package.json")?.toString();
9083
9136
  packageJson = JSON.parse(packageJson);
9084
- if (!packageJson.dependencies) {
9085
- packageJson.dependencies = {};
9137
+ if (!packageJson.lcap_modules) {
9138
+ packageJson.lcap_modules = {};
9086
9139
  }
9087
9140
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
9088
- packageJson.dependencies[pkgName] = `.${targetPath}`;
9141
+ packageJson.lcap_modules[pkgName] = `.${targetPath}`;
9089
9142
  });
9090
9143
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
9091
9144
  logger15.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
@@ -9361,7 +9414,7 @@ export function loadAssets(){
9361
9414
  generateEntry(ir) {
9362
9415
  const entryScript = this.microFrontendManager.produceScript(ir);
9363
9416
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
9364
- const code = `
9417
+ let code = `
9365
9418
  export function startApp(){
9366
9419
  if(window.LcapMicro){
9367
9420
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
@@ -9372,6 +9425,11 @@ export function loadAssets(){
9372
9425
  }
9373
9426
  }
9374
9427
  `;
9428
+ const { env, isExport } = ir.configs.config;
9429
+ if (!isExport && env === "dev") {
9430
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
9431
+ code += autoReloadScript?.default || autoReloadScript;
9432
+ }
9375
9433
  const imports = [
9376
9434
  {
9377
9435
  from: "../init"
@@ -9439,23 +9497,28 @@ var VueRouterPlugin = class {
9439
9497
  }
9440
9498
  routeToCode(routes, componentPathManager, config2) {
9441
9499
  function serializeVueRoute(r, isRoot = false) {
9442
- const path2 = r.thisLevelPath ?? "/";
9500
+ const { accumulativePath, thisLevelPath } = r;
9501
+ const path2 = isRoot ? accumulativePath : thisLevelPath ?? "/";
9502
+ const basePath = config2.basePath;
9443
9503
  if (r.kind === "normal") {
9444
9504
  const children = r.children?.map((i) => serializeVueRoute(i)).filter(isNotNil) ?? [];
9445
9505
  const childrenStr = children.join(",\n");
9446
9506
  const componentCode = `component: ${r.elementMangledName ?? r.elementTemplate.identifier}`;
9447
- return `{path: "${isRoot ? r.accumulativePath : path2}", meta: ${JSON.stringify(
9507
+ return `{path: "${path2}", meta: ${JSON.stringify(
9448
9508
  r.meta
9449
9509
  )}, children: [${childrenStr}], ${componentCode} }`;
9450
9510
  } else if (r.kind === "redirect") {
9451
- const replaceWildCardForVue3 = (frameworkKind, path3) => {
9452
- if (frameworkKind === "vue3" && path3 === "*") {
9453
- return "/:pathMatch(.*)*";
9511
+ if (["vue3"].includes(config2.frameworkKind) && path2 === "*") {
9512
+ return `{ path: "/:pathMatch(.*)*", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
9513
+ }
9514
+ if (["vue3"].includes(config2.frameworkKind) && path2 === "/") {
9515
+ let result = `{ path: "/", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
9516
+ if (basePath !== "/") {
9517
+ result += `, { path: "${basePath}", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
9454
9518
  }
9455
- return path3;
9456
- };
9457
- const processedPath = replaceWildCardForVue3(config2.frameworkKind, path2);
9458
- return `{path: "${processedPath}", redirect: ${JSON.stringify(r.redirect)}}`;
9519
+ return result;
9520
+ }
9521
+ return `{ path: "${path2}", redirect: to => to.path.replace(/\\/$/, '') + '/' + ${JSON.stringify(r.redirect)} }`;
9459
9522
  }
9460
9523
  notImplemented(r);
9461
9524
  }
@@ -9544,7 +9607,7 @@ var Vue3EntryBuilderPlugin = class {
9544
9607
  buildEntry(ir) {
9545
9608
  const entryScript = this.microFrontendManager.produceScript(ir);
9546
9609
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
9547
- const code = `
9610
+ let code = `
9548
9611
  if(window.LcapMicro){
9549
9612
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
9550
9613
  renderApp();
@@ -9562,6 +9625,11 @@ var Vue3EntryBuilderPlugin = class {
9562
9625
  from: "./public-path"
9563
9626
  } : void 0
9564
9627
  ].filter(isNotNil);
9628
+ const { env, isExport } = ir.configs.config;
9629
+ if (!isExport && env === "dev") {
9630
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
9631
+ code += autoReloadScript?.default || autoReloadScript;
9632
+ }
9565
9633
  return [
9566
9634
  new ReactFileDescription("main.ts", imports, [], [code]),
9567
9635
  publicPathScript ? new ReactFileDescription("public-path.ts", [], [], [publicPathScript]) : void 0
@@ -9587,10 +9655,13 @@ var Vue3LibrariesBuilderPlugin = class {
9587
9655
  */
9588
9656
  async buildLibrariesImport(ir, config2) {
9589
9657
  const importArr = [];
9658
+ const exportArr = [];
9590
9659
  const standardLib = ir.packages.find((x) => x.kind === "standard");
9591
9660
  if (standardLib) {
9592
9661
  const formattedName = kebab2Pascal(standardLib.name.split("/").at(-1));
9593
- importArr.push(`export * as ${formattedName} from '${standardLib.name}';`);
9662
+ importArr.push(`import * as ${formattedName} from '${standardLib.name}';`);
9663
+ exportArr.push(`export { ${formattedName} };`);
9664
+ exportArr.push(`window.lcapStandardUI = ${formattedName};`);
9594
9665
  const isPackageZipExists = await judgePackageZipExists(standardLib, config2.STATIC_URL);
9595
9666
  importArr.push(
9596
9667
  `import '${standardLib.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
@@ -9601,14 +9672,14 @@ var Vue3LibrariesBuilderPlugin = class {
9601
9672
  const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
9602
9673
  const isPackageZipExists = await judgePackageZipExists(ext, config2.STATIC_URL);
9603
9674
  const prefix = isPackageZipExists ? "" : "@extension/";
9604
- importArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
9675
+ exportArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
9605
9676
  if (ext.hasCss) {
9606
9677
  importArr.push(
9607
9678
  `import '${prefix}${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
9608
9679
  );
9609
9680
  }
9610
9681
  }
9611
- return new ReactFileDescription("libraries.ts", [], [], [importArr.join("\n")]);
9682
+ return new ReactFileDescription("libraries.ts", [], [], [[...importArr, ...exportArr].join("\n")]);
9612
9683
  }
9613
9684
  static install(c) {
9614
9685
  c.bind(Vue3LibrariesBuilderPlugin).toSelf();
@@ -9844,15 +9915,16 @@ var Vue3ApplicationAssemblerPlugin = class {
9844
9915
  const bizComponents = ir.bizComponents.flatMap((x) => {
9845
9916
  return this.vue3CodegenPlugin.genFiles(x, manager);
9846
9917
  });
9847
- let routePrefix = ir.configs.frontendDesc.path;
9848
- if (!/\/$/.test(routePrefix)) {
9849
- routePrefix += "/";
9918
+ let basePath = ir.configs.basePlatformConfig.basePath;
9919
+ if (!/\/$/.test(basePath)) {
9920
+ basePath += "/";
9850
9921
  }
9851
- const routesObjects = this.routesExtactor.extractRoute(ir.views, routePrefix, {
9922
+ const routesObjects = this.routesExtactor.extractRoute(ir.views, basePath, {
9852
9923
  lazy: true
9853
9924
  });
9854
9925
  const router = this.routerBuilder.routeToCode(routesObjects.routes, manager, {
9855
- frameworkKind: "vue3"
9926
+ frameworkKind: "vue3",
9927
+ basePath
9856
9928
  });
9857
9929
  const routerFile = new ReactFileDescription("router.ts", router.imports, [], [router.code]);
9858
9930
  const libraries = await this.librariesBuilder.buildLibrariesImport(ir, config2);
@@ -9905,6 +9977,30 @@ var Vue3PresetPlugin = class {
9905
9977
  const app = deserializeAppWhileKeepTypeAnnotation(appJson);
9906
9978
  const frontend = app.findNodeByPath(instruction.frontend.nodePath);
9907
9979
  const ir = this.irBuilder.buildIR(app, frontend, instruction.config);
9980
+ const needCompileViews = instruction.config?.needCompileViews ?? [];
9981
+ const isIncremental = needCompileViews.length > 0;
9982
+ if (isIncremental) {
9983
+ const filterChildComponents = (view, needCompileViews2) => {
9984
+ if (!view.childComponents?.length) {
9985
+ return;
9986
+ }
9987
+ view.childComponents = view.childComponents.filter((child) => {
9988
+ if (needCompileViews2.includes(child.__raw.nodePath)) {
9989
+ filterChildComponents(child, needCompileViews2);
9990
+ return true;
9991
+ }
9992
+ return false;
9993
+ });
9994
+ };
9995
+ ir.views = ir.views.filter((view) => {
9996
+ if (needCompileViews.includes(view.__raw.nodePath)) {
9997
+ filterChildComponents(view, needCompileViews);
9998
+ return true;
9999
+ }
10000
+ return false;
10001
+ });
10002
+ ir.bizComponents = [];
10003
+ }
9908
10004
  const assembledApplication = await this.applicationAssembler.assemble(ir, instruction.config);
9909
10005
  const finalizedFiles = await this.projectOrganizer.organize({
9910
10006
  baseDir: instruction.baseDir,
@@ -9982,36 +10078,6 @@ async function translateNASLToApp(app, frontend, config2, baseDir = "./out", con
9982
10078
  const logger15 = Logger("\u7FFB\u8BD1\u8FC7\u7A0B");
9983
10079
  logger15.debug({ config: config2 });
9984
10080
  async function genCode() {
9985
- const { needCompileViews = [] } = config2;
9986
- if (needCompileViews?.length > 0) {
9987
- let traverseChildren2 = function(view, callback) {
9988
- if (view.children?.length > 0) {
9989
- [...view.children].forEach((childView) => {
9990
- const deep = callback(childView);
9991
- if (deep) {
9992
- traverseChildren2(childView, callback);
9993
- }
9994
- });
9995
- }
9996
- };
9997
- var traverseChildren = traverseChildren2;
9998
- logger15.info("\u5F00\u59CB\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
9999
- [...frontend.views].forEach((view) => {
10000
- if (!needCompileViews.includes(view.nodePath)) {
10001
- view.delete();
10002
- console.log(`\u5220\u9664\u9875\u9762 ${view.nodePath}\uFF0C\u56E0\u4E3A\u5B83\u4E0D\u5728 needCompileViews \u4E2D`);
10003
- } else {
10004
- traverseChildren2(view, (childView) => {
10005
- if (!needCompileViews.includes(childView.nodePath)) {
10006
- childView.delete();
10007
- return false;
10008
- }
10009
- return true;
10010
- });
10011
- }
10012
- });
10013
- logger15.info("\u7ED3\u675F\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
10014
- }
10015
10081
  logger15.info("\u5F00\u59CB\u7FFB\u8BD1");
10016
10082
  try {
10017
10083
  const codeList2 = await container.get(ServiceMetaKind.NASLTranspiler).transpile({