@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.
package/dist/index.mjs CHANGED
@@ -1,5 +1,23 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __esm = (fn, res) => function __init() {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ };
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
3
21
  var __decorateClass = (decorators, target, key, kind) => {
4
22
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
23
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -11,6 +29,75 @@ var __decorateClass = (decorators, target, key, kind) => {
11
29
  };
12
30
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
13
31
 
32
+ // src/plugins/templates/auto-reload.js
33
+ var auto_reload_exports = {};
34
+ __export(auto_reload_exports, {
35
+ default: () => auto_reload_default
36
+ });
37
+ var auto_reload_default;
38
+ var init_auto_reload = __esm({
39
+ "src/plugins/templates/auto-reload.js"() {
40
+ "use strict";
41
+ auto_reload_default = `
42
+ const dom = document.createElement('div');
43
+ dom.classList = "lcap-deploy-loading-container";
44
+ dom.style.display = 'none';
45
+ dom.innerHTML = "<div class='lcap-deploy-loading-icon'></div><div>\u6B63\u5728\u66F4\u65B0\u6700\u65B0\u53D1\u5E03\u5185\u5BB9...</div>";
46
+ document.getElementsByTagName('body')[0].appendChild(dom);
47
+
48
+ const style = document.createElement('style');
49
+ style.innerHTML = \`.lcap-deploy-loading-container {
50
+ width: 208px;
51
+ height: 40px;
52
+ background: rgba(48, 48, 48, 0.8);
53
+ box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
54
+ border-radius: 4px;
55
+ position: fixed;
56
+ top: 120px;
57
+ left: 50%;
58
+ margin-left: -104px;
59
+ color: #FFFFFF;
60
+ font-size: 14px;
61
+ justify-content: center;
62
+ align-items: center;
63
+ }
64
+
65
+ .lcap-deploy-loading-icon{
66
+ width: 12px;
67
+ height: 12px;
68
+ margin-right: 10px;
69
+ animation: loading-animation 0.8s infinite linear;
70
+ border: 2px solid #f3f3f3;
71
+ border-top: 2px solid rgb(109, 108, 108);
72
+ border-right: 2px solid rgb(109, 108, 108);
73
+ border-bottom: 2px solid rgb(109, 108, 108);
74
+ border-radius: 50%;
75
+ }
76
+
77
+ @keyframes loading-animation{
78
+ 0% {
79
+ transform: rotate(0deg);
80
+ }
81
+ 100% {
82
+ transform: rotate(360deg);
83
+ }
84
+ }\`;
85
+ document.getElementsByTagName('body')[0].appendChild(style);
86
+
87
+ window.addEventListener('message', function (e) {
88
+ if(e.data ==="release-start"){
89
+ document.querySelector(".lcap-deploy-loading-container").style.display ="flex"
90
+ }
91
+
92
+ if(e.data==="release-end"){
93
+ document.querySelector(".lcap-deploy-loading-container").style.display ="none"
94
+ window.location.reload();
95
+ }
96
+ });
97
+ `;
98
+ }
99
+ });
100
+
14
101
  // src/compile.ts
15
102
  import axios2 from "axios";
16
103
  import { trimStart } from "lodash";
@@ -1266,8 +1353,8 @@ var reactComponentLibHackPlugin = makePlugin({
1266
1353
  }
1267
1354
 
1268
1355
  Object.assign(utils, {
1269
- jsonSerialize: JSON.stringify,
1270
- jsonDeserialize: JSON.parse,
1356
+ jsonSerialize: utils.JsonSerialize || JSON.stringify,
1357
+ jsonDeserialize: utils.JsonDeserialize || JSON.parse,
1271
1358
  });
1272
1359
 
1273
1360
  const logging = {
@@ -4439,29 +4526,6 @@ var coreVersion = materials.framework.version;
4439
4526
  function getPredefinedMaterialConfig() {
4440
4527
  return materials;
4441
4528
  }
4442
- function getPredefinedLibConstants() {
4443
- if (!reactUi || !vue3Ui) {
4444
- throw new Error("not found");
4445
- }
4446
- if (reactUi.name !== "@lcap/pc-react-ui") {
4447
- throw new Error("cannot find @lcap/pc-react-ui in material.config.js");
4448
- }
4449
- return {
4450
- reactUI: {
4451
- kind: "standard",
4452
- name: reactUi.name,
4453
- version: reactUi.version
4454
- },
4455
- vue3Ui: {
4456
- kind: "standard",
4457
- name: vue3Ui.name,
4458
- version: vue3Ui.version
4459
- },
4460
- basicTemplate: {
4461
- version: coreVersion
4462
- }
4463
- };
4464
- }
4465
4529
  var getPredefinedMaterialByTags = (() => {
4466
4530
  const materialConfig = getPredefinedMaterialConfig();
4467
4531
  let allMaterials = [];
@@ -4485,12 +4549,14 @@ var getPredefinedMaterialByTags = (() => {
4485
4549
  materialConfig.ui.pc.forEach((item) => {
4486
4550
  allMaterials.push({
4487
4551
  ...item,
4552
+ kind: "standard",
4488
4553
  tags: ["ui", "pc", item.frameworkKind, item.libName]
4489
4554
  });
4490
4555
  });
4491
4556
  materialConfig.ui.h5.forEach((item) => {
4492
4557
  allMaterials.push({
4493
4558
  ...item,
4559
+ kind: "standard",
4494
4560
  tags: ["ui", "h5", item.frameworkKind, item.libName]
4495
4561
  });
4496
4562
  });
@@ -4650,7 +4716,10 @@ function bindAttrToIR(b) {
4650
4716
  throw new Error("string\u4E0D\u53EF\u4E3Async");
4651
4717
  }
4652
4718
  if (b.i18nKey && b.value && b.frontend?.i18nInfo?.enabled) {
4653
- b.type = "dynamic";
4719
+ const frameworkKind = b.frontend?.frameworkKind;
4720
+ if (!["vue3"].includes(frameworkKind)) {
4721
+ b.type = "dynamic";
4722
+ }
4654
4723
  const wrapperExpr = CallFunction4.from(
4655
4724
  {
4656
4725
  calleeNamespace: "$i18n",
@@ -4754,7 +4823,7 @@ function bindEventToAction(b) {
4754
4823
  kind: "standalone"
4755
4824
  };
4756
4825
  }
4757
- var DefaultComponentLibraryName = getPredefinedLibConstants().reactUI.name;
4826
+ var DefaultComponentLibraryName = getPredefinedMaterialByTags(["ui", "pc", "react"])?.name;
4758
4827
  function getReferencedLibComponent(e) {
4759
4828
  const tag = e.tag;
4760
4829
  if (tag.startsWith("BS")) {
@@ -5420,8 +5489,8 @@ var NASLAppIRBuilderPlugin = class {
5420
5489
  });
5421
5490
  logger5.debug({ extensionPackages });
5422
5491
  const frameworkKind = frontend.frameworkKind;
5423
- const libs = getPredefinedLibConstants();
5424
- return [...extensionPackages, frameworkKind === "vue3" ? libs.vue3Ui : libs.reactUI];
5492
+ const uiLib = getPredefinedMaterialByTags(["ui", frontend.type, frameworkKind]);
5493
+ return [...extensionPackages, uiLib];
5425
5494
  };
5426
5495
  var buildConfigs = buildConfigs2, collectPackages = collectPackages2;
5427
5496
  config.debug && breakpoint2.genBreakpoints(app);
@@ -6790,10 +6859,9 @@ function extractAppLevelFrontendDeps(app) {
6790
6859
  }
6791
6860
  function extractFrontendLevelDeps(frontend) {
6792
6861
  const deps = [];
6793
- if (frontend.frameworkKind === "react") {
6794
- deps.push(getPredefinedLibConstants().reactUI);
6795
- } else if (frontend.frameworkKind === "vue3") {
6796
- deps.push(getPredefinedLibConstants().vue3Ui);
6862
+ const uiLib = getPredefinedMaterialByTags(["ui", frontend.type, frontend.frameworkKind]);
6863
+ if (uiLib) {
6864
+ deps.push(uiLib);
6797
6865
  }
6798
6866
  return deps;
6799
6867
  }
@@ -6966,11 +7034,11 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6966
7034
  }
6967
7035
  let packageJson = fs.read("/package.json")?.toString();
6968
7036
  packageJson = JSON.parse(packageJson);
6969
- if (!packageJson.dependencies) {
6970
- packageJson.dependencies = {};
7037
+ if (!packageJson.lcap_modules) {
7038
+ packageJson.lcap_modules = {};
6971
7039
  }
6972
7040
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
6973
- packageJson.dependencies[pkgName] = `.${targetPath}`;
7041
+ packageJson.lcap_modules[pkgName] = `.${targetPath}`;
6974
7042
  });
6975
7043
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
6976
7044
  logger13.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
@@ -7246,7 +7314,7 @@ export function loadAssets(){
7246
7314
  generateEntry(ir) {
7247
7315
  const entryScript = this.microFrontendManager.produceScript(ir);
7248
7316
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7249
- const code = `
7317
+ let code = `
7250
7318
  export function startApp(){
7251
7319
  if(window.LcapMicro){
7252
7320
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
@@ -7257,6 +7325,11 @@ export function loadAssets(){
7257
7325
  }
7258
7326
  }
7259
7327
  `;
7328
+ const { env, isExport } = ir.configs.config;
7329
+ if (!isExport && env === "dev") {
7330
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
7331
+ code += autoReloadScript?.default || autoReloadScript;
7332
+ }
7260
7333
  const imports = [
7261
7334
  {
7262
7335
  from: "../init"
@@ -7324,23 +7397,28 @@ var VueRouterPlugin = class {
7324
7397
  }
7325
7398
  routeToCode(routes, componentPathManager, config) {
7326
7399
  function serializeVueRoute(r, isRoot = false) {
7327
- const path = r.thisLevelPath ?? "/";
7400
+ const { accumulativePath, thisLevelPath } = r;
7401
+ const path = isRoot ? accumulativePath : thisLevelPath ?? "/";
7402
+ const basePath = config.basePath;
7328
7403
  if (r.kind === "normal") {
7329
7404
  const children = r.children?.map((i) => serializeVueRoute(i)).filter(isNotNil) ?? [];
7330
7405
  const childrenStr = children.join(",\n");
7331
7406
  const componentCode = `component: ${r.elementMangledName ?? r.elementTemplate.identifier}`;
7332
- return `{path: "${isRoot ? r.accumulativePath : path}", meta: ${JSON.stringify(
7407
+ return `{path: "${path}", meta: ${JSON.stringify(
7333
7408
  r.meta
7334
7409
  )}, children: [${childrenStr}], ${componentCode} }`;
7335
7410
  } else if (r.kind === "redirect") {
7336
- const replaceWildCardForVue3 = (frameworkKind, path2) => {
7337
- if (frameworkKind === "vue3" && path2 === "*") {
7338
- return "/:pathMatch(.*)*";
7411
+ if (["vue3"].includes(config.frameworkKind) && path === "*") {
7412
+ return `{ path: "/:pathMatch(.*)*", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
7413
+ }
7414
+ if (["vue3"].includes(config.frameworkKind) && path === "/") {
7415
+ let result = `{ path: "/", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
7416
+ if (basePath !== "/") {
7417
+ result += `, { path: "${basePath}", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
7339
7418
  }
7340
- return path2;
7341
- };
7342
- const processedPath = replaceWildCardForVue3(config.frameworkKind, path);
7343
- return `{path: "${processedPath}", redirect: ${JSON.stringify(r.redirect)}}`;
7419
+ return result;
7420
+ }
7421
+ return `{ path: "${path}", redirect: to => to.path.replace(/\\/$/, '') + '/' + ${JSON.stringify(r.redirect)} }`;
7344
7422
  }
7345
7423
  notImplemented(r);
7346
7424
  }
@@ -7429,7 +7507,7 @@ var Vue3EntryBuilderPlugin = class {
7429
7507
  buildEntry(ir) {
7430
7508
  const entryScript = this.microFrontendManager.produceScript(ir);
7431
7509
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7432
- const code = `
7510
+ let code = `
7433
7511
  if(window.LcapMicro){
7434
7512
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
7435
7513
  renderApp();
@@ -7447,6 +7525,11 @@ var Vue3EntryBuilderPlugin = class {
7447
7525
  from: "./public-path"
7448
7526
  } : void 0
7449
7527
  ].filter(isNotNil);
7528
+ const { env, isExport } = ir.configs.config;
7529
+ if (!isExport && env === "dev") {
7530
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
7531
+ code += autoReloadScript?.default || autoReloadScript;
7532
+ }
7450
7533
  return [
7451
7534
  new ReactFileDescription("main.ts", imports, [], [code]),
7452
7535
  publicPathScript ? new ReactFileDescription("public-path.ts", [], [], [publicPathScript]) : void 0
@@ -7472,10 +7555,13 @@ var Vue3LibrariesBuilderPlugin = class {
7472
7555
  */
7473
7556
  async buildLibrariesImport(ir, config) {
7474
7557
  const importArr = [];
7558
+ const exportArr = [];
7475
7559
  const standardLib = ir.packages.find((x) => x.kind === "standard");
7476
7560
  if (standardLib) {
7477
7561
  const formattedName = kebab2Pascal(standardLib.name.split("/").at(-1));
7478
- importArr.push(`export * as ${formattedName} from '${standardLib.name}';`);
7562
+ importArr.push(`import * as ${formattedName} from '${standardLib.name}';`);
7563
+ exportArr.push(`export { ${formattedName} };`);
7564
+ exportArr.push(`window.lcapStandardUI = ${formattedName};`);
7479
7565
  const isPackageZipExists = await judgePackageZipExists(standardLib, config.STATIC_URL);
7480
7566
  importArr.push(
7481
7567
  `import '${standardLib.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
@@ -7486,14 +7572,14 @@ var Vue3LibrariesBuilderPlugin = class {
7486
7572
  const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
7487
7573
  const isPackageZipExists = await judgePackageZipExists(ext, config.STATIC_URL);
7488
7574
  const prefix = isPackageZipExists ? "" : "@extension/";
7489
- importArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
7575
+ exportArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
7490
7576
  if (ext.hasCss) {
7491
7577
  importArr.push(
7492
7578
  `import '${prefix}${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7493
7579
  );
7494
7580
  }
7495
7581
  }
7496
- return new ReactFileDescription("libraries.ts", [], [], [importArr.join("\n")]);
7582
+ return new ReactFileDescription("libraries.ts", [], [], [[...importArr, ...exportArr].join("\n")]);
7497
7583
  }
7498
7584
  static install(c) {
7499
7585
  c.bind(Vue3LibrariesBuilderPlugin).toSelf();
@@ -7729,15 +7815,16 @@ var Vue3ApplicationAssemblerPlugin = class {
7729
7815
  const bizComponents = ir.bizComponents.flatMap((x) => {
7730
7816
  return this.vue3CodegenPlugin.genFiles(x, manager);
7731
7817
  });
7732
- let routePrefix = ir.configs.frontendDesc.path;
7733
- if (!/\/$/.test(routePrefix)) {
7734
- routePrefix += "/";
7818
+ let basePath = ir.configs.basePlatformConfig.basePath;
7819
+ if (!/\/$/.test(basePath)) {
7820
+ basePath += "/";
7735
7821
  }
7736
- const routesObjects = this.routesExtactor.extractRoute(ir.views, routePrefix, {
7822
+ const routesObjects = this.routesExtactor.extractRoute(ir.views, basePath, {
7737
7823
  lazy: true
7738
7824
  });
7739
7825
  const router = this.routerBuilder.routeToCode(routesObjects.routes, manager, {
7740
- frameworkKind: "vue3"
7826
+ frameworkKind: "vue3",
7827
+ basePath
7741
7828
  });
7742
7829
  const routerFile = new ReactFileDescription("router.ts", router.imports, [], [router.code]);
7743
7830
  const libraries = await this.librariesBuilder.buildLibrariesImport(ir, config);
@@ -7790,6 +7877,30 @@ var Vue3PresetPlugin = class {
7790
7877
  const app = deserializeAppWhileKeepTypeAnnotation(appJson);
7791
7878
  const frontend = app.findNodeByPath(instruction.frontend.nodePath);
7792
7879
  const ir = this.irBuilder.buildIR(app, frontend, instruction.config);
7880
+ const needCompileViews = instruction.config?.needCompileViews ?? [];
7881
+ const isIncremental = needCompileViews.length > 0;
7882
+ if (isIncremental) {
7883
+ const filterChildComponents = (view, needCompileViews2) => {
7884
+ if (!view.childComponents?.length) {
7885
+ return;
7886
+ }
7887
+ view.childComponents = view.childComponents.filter((child) => {
7888
+ if (needCompileViews2.includes(child.__raw.nodePath)) {
7889
+ filterChildComponents(child, needCompileViews2);
7890
+ return true;
7891
+ }
7892
+ return false;
7893
+ });
7894
+ };
7895
+ ir.views = ir.views.filter((view) => {
7896
+ if (needCompileViews.includes(view.__raw.nodePath)) {
7897
+ filterChildComponents(view, needCompileViews);
7898
+ return true;
7899
+ }
7900
+ return false;
7901
+ });
7902
+ ir.bizComponents = [];
7903
+ }
7793
7904
  const assembledApplication = await this.applicationAssembler.assemble(ir, instruction.config);
7794
7905
  const finalizedFiles = await this.projectOrganizer.organize({
7795
7906
  baseDir: instruction.baseDir,
@@ -7867,36 +7978,6 @@ async function translateNASLToApp(app, frontend, config, baseDir = "./out", cont
7867
7978
  const logger13 = Logger("\u7FFB\u8BD1\u8FC7\u7A0B");
7868
7979
  logger13.debug({ config });
7869
7980
  async function genCode() {
7870
- const { needCompileViews = [] } = config;
7871
- if (needCompileViews?.length > 0) {
7872
- let traverseChildren2 = function(view, callback) {
7873
- if (view.children?.length > 0) {
7874
- [...view.children].forEach((childView) => {
7875
- const deep = callback(childView);
7876
- if (deep) {
7877
- traverseChildren2(childView, callback);
7878
- }
7879
- });
7880
- }
7881
- };
7882
- var traverseChildren = traverseChildren2;
7883
- logger13.info("\u5F00\u59CB\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
7884
- [...frontend.views].forEach((view) => {
7885
- if (!needCompileViews.includes(view.nodePath)) {
7886
- view.delete();
7887
- console.log(`\u5220\u9664\u9875\u9762 ${view.nodePath}\uFF0C\u56E0\u4E3A\u5B83\u4E0D\u5728 needCompileViews \u4E2D`);
7888
- } else {
7889
- traverseChildren2(view, (childView) => {
7890
- if (!needCompileViews.includes(childView.nodePath)) {
7891
- childView.delete();
7892
- return false;
7893
- }
7894
- return true;
7895
- });
7896
- }
7897
- });
7898
- logger13.info("\u7ED3\u675F\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
7899
- }
7900
7981
  logger13.info("\u5F00\u59CB\u7FFB\u8BD1");
7901
7982
  try {
7902
7983
  const codeList2 = await container.get(ServiceMetaKind.NASLTranspiler).transpile({