@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.
@@ -11,9 +11,16 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  return require.apply(this, arguments);
12
12
  throw Error('Dynamic require of "' + x + '" is not supported');
13
13
  });
14
+ var __esm = (fn, res) => function __init() {
15
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
+ };
14
17
  var __commonJS = (cb, mod) => function __require2() {
15
18
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
19
  };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
17
24
  var __copyProps = (to, from, except, desc) => {
18
25
  if (from && typeof from === "object" || typeof from === "function") {
19
26
  for (let key of __getOwnPropNames(from))
@@ -30,6 +37,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
37
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
38
  mod
32
39
  ));
40
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
41
  var __decorateClass = (decorators, target, key, kind) => {
34
42
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
35
43
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -2245,6 +2253,75 @@ var require_lib = __commonJS({
2245
2253
  }
2246
2254
  });
2247
2255
 
2256
+ // src/plugins/templates/auto-reload.js
2257
+ var auto_reload_exports = {};
2258
+ __export(auto_reload_exports, {
2259
+ default: () => auto_reload_default
2260
+ });
2261
+ var auto_reload_default;
2262
+ var init_auto_reload = __esm({
2263
+ "src/plugins/templates/auto-reload.js"() {
2264
+ "use strict";
2265
+ auto_reload_default = `
2266
+ const dom = document.createElement('div');
2267
+ dom.classList = "lcap-deploy-loading-container";
2268
+ dom.style.display = 'none';
2269
+ dom.innerHTML = "<div class='lcap-deploy-loading-icon'></div><div>\u6B63\u5728\u66F4\u65B0\u6700\u65B0\u53D1\u5E03\u5185\u5BB9...</div>";
2270
+ document.getElementsByTagName('body')[0].appendChild(dom);
2271
+
2272
+ const style = document.createElement('style');
2273
+ style.innerHTML = \`.lcap-deploy-loading-container {
2274
+ width: 208px;
2275
+ height: 40px;
2276
+ background: rgba(48, 48, 48, 0.8);
2277
+ box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
2278
+ border-radius: 4px;
2279
+ position: fixed;
2280
+ top: 120px;
2281
+ left: 50%;
2282
+ margin-left: -104px;
2283
+ color: #FFFFFF;
2284
+ font-size: 14px;
2285
+ justify-content: center;
2286
+ align-items: center;
2287
+ }
2288
+
2289
+ .lcap-deploy-loading-icon{
2290
+ width: 12px;
2291
+ height: 12px;
2292
+ margin-right: 10px;
2293
+ animation: loading-animation 0.8s infinite linear;
2294
+ border: 2px solid #f3f3f3;
2295
+ border-top: 2px solid rgb(109, 108, 108);
2296
+ border-right: 2px solid rgb(109, 108, 108);
2297
+ border-bottom: 2px solid rgb(109, 108, 108);
2298
+ border-radius: 50%;
2299
+ }
2300
+
2301
+ @keyframes loading-animation{
2302
+ 0% {
2303
+ transform: rotate(0deg);
2304
+ }
2305
+ 100% {
2306
+ transform: rotate(360deg);
2307
+ }
2308
+ }\`;
2309
+ document.getElementsByTagName('body')[0].appendChild(style);
2310
+
2311
+ window.addEventListener('message', function (e) {
2312
+ if(e.data ==="release-start"){
2313
+ document.querySelector(".lcap-deploy-loading-container").style.display ="flex"
2314
+ }
2315
+
2316
+ if(e.data==="release-end"){
2317
+ document.querySelector(".lcap-deploy-loading-container").style.display ="none"
2318
+ window.location.reload();
2319
+ }
2320
+ });
2321
+ `;
2322
+ }
2323
+ });
2324
+
2248
2325
  // playground/helper.ts
2249
2326
  var import_fs_extra = __toESM(require_lib());
2250
2327
  import { readFileSync } from "node:fs";
@@ -3505,8 +3582,8 @@ var reactComponentLibHackPlugin = makePlugin({
3505
3582
  }
3506
3583
 
3507
3584
  Object.assign(utils, {
3508
- jsonSerialize: JSON.stringify,
3509
- jsonDeserialize: JSON.parse,
3585
+ jsonSerialize: utils.JsonSerialize || JSON.stringify,
3586
+ jsonDeserialize: utils.JsonDeserialize || JSON.parse,
3510
3587
  });
3511
3588
 
3512
3589
  const logging = {
@@ -6677,29 +6754,6 @@ var coreVersion = materials.framework.version;
6677
6754
  function getPredefinedMaterialConfig() {
6678
6755
  return materials;
6679
6756
  }
6680
- function getPredefinedLibConstants() {
6681
- if (!reactUi || !vue3Ui) {
6682
- throw new Error("not found");
6683
- }
6684
- if (reactUi.name !== "@lcap/pc-react-ui") {
6685
- throw new Error("cannot find @lcap/pc-react-ui in material.config.js");
6686
- }
6687
- return {
6688
- reactUI: {
6689
- kind: "standard",
6690
- name: reactUi.name,
6691
- version: reactUi.version
6692
- },
6693
- vue3Ui: {
6694
- kind: "standard",
6695
- name: vue3Ui.name,
6696
- version: vue3Ui.version
6697
- },
6698
- basicTemplate: {
6699
- version: coreVersion
6700
- }
6701
- };
6702
- }
6703
6757
  var getPredefinedMaterialByTags = (() => {
6704
6758
  const materialConfig = getPredefinedMaterialConfig();
6705
6759
  let allMaterials = [];
@@ -6723,12 +6777,14 @@ var getPredefinedMaterialByTags = (() => {
6723
6777
  materialConfig.ui.pc.forEach((item) => {
6724
6778
  allMaterials.push({
6725
6779
  ...item,
6780
+ kind: "standard",
6726
6781
  tags: ["ui", "pc", item.frameworkKind, item.libName]
6727
6782
  });
6728
6783
  });
6729
6784
  materialConfig.ui.h5.forEach((item) => {
6730
6785
  allMaterials.push({
6731
6786
  ...item,
6787
+ kind: "standard",
6732
6788
  tags: ["ui", "h5", item.frameworkKind, item.libName]
6733
6789
  });
6734
6790
  });
@@ -6888,7 +6944,10 @@ function bindAttrToIR(b) {
6888
6944
  throw new Error("string\u4E0D\u53EF\u4E3Async");
6889
6945
  }
6890
6946
  if (b.i18nKey && b.value && b.frontend?.i18nInfo?.enabled) {
6891
- b.type = "dynamic";
6947
+ const frameworkKind = b.frontend?.frameworkKind;
6948
+ if (!["vue3"].includes(frameworkKind)) {
6949
+ b.type = "dynamic";
6950
+ }
6892
6951
  const wrapperExpr = CallFunction4.from(
6893
6952
  {
6894
6953
  calleeNamespace: "$i18n",
@@ -6992,7 +7051,7 @@ function bindEventToAction(b) {
6992
7051
  kind: "standalone"
6993
7052
  };
6994
7053
  }
6995
- var DefaultComponentLibraryName = getPredefinedLibConstants().reactUI.name;
7054
+ var DefaultComponentLibraryName = getPredefinedMaterialByTags(["ui", "pc", "react"])?.name;
6996
7055
  function getReferencedLibComponent(e) {
6997
7056
  const tag = e.tag;
6998
7057
  if (tag.startsWith("BS")) {
@@ -7658,8 +7717,8 @@ var NASLAppIRBuilderPlugin = class {
7658
7717
  });
7659
7718
  logger5.debug({ extensionPackages });
7660
7719
  const frameworkKind = frontend.frameworkKind;
7661
- const libs = getPredefinedLibConstants();
7662
- return [...extensionPackages, frameworkKind === "vue3" ? libs.vue3Ui : libs.reactUI];
7720
+ const uiLib = getPredefinedMaterialByTags(["ui", frontend.type, frameworkKind]);
7721
+ return [...extensionPackages, uiLib];
7663
7722
  };
7664
7723
  var buildConfigs = buildConfigs2, collectPackages = collectPackages2;
7665
7724
  config2.debug && breakpoint2.genBreakpoints(app);
@@ -9028,10 +9087,9 @@ function extractAppLevelFrontendDeps(app) {
9028
9087
  }
9029
9088
  function extractFrontendLevelDeps(frontend) {
9030
9089
  const deps = [];
9031
- if (frontend.frameworkKind === "react") {
9032
- deps.push(getPredefinedLibConstants().reactUI);
9033
- } else if (frontend.frameworkKind === "vue3") {
9034
- deps.push(getPredefinedLibConstants().vue3Ui);
9090
+ const uiLib = getPredefinedMaterialByTags(["ui", frontend.type, frontend.frameworkKind]);
9091
+ if (uiLib) {
9092
+ deps.push(uiLib);
9035
9093
  }
9036
9094
  return deps;
9037
9095
  }
@@ -9204,11 +9262,11 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config2) {
9204
9262
  }
9205
9263
  let packageJson = fs.read("/package.json")?.toString();
9206
9264
  packageJson = JSON.parse(packageJson);
9207
- if (!packageJson.dependencies) {
9208
- packageJson.dependencies = {};
9265
+ if (!packageJson.lcap_modules) {
9266
+ packageJson.lcap_modules = {};
9209
9267
  }
9210
9268
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
9211
- packageJson.dependencies[pkgName] = `.${targetPath}`;
9269
+ packageJson.lcap_modules[pkgName] = `.${targetPath}`;
9212
9270
  });
9213
9271
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
9214
9272
  logger15.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
@@ -9484,7 +9542,7 @@ export function loadAssets(){
9484
9542
  generateEntry(ir) {
9485
9543
  const entryScript = this.microFrontendManager.produceScript(ir);
9486
9544
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
9487
- const code = `
9545
+ let code = `
9488
9546
  export function startApp(){
9489
9547
  if(window.LcapMicro){
9490
9548
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
@@ -9495,6 +9553,11 @@ export function loadAssets(){
9495
9553
  }
9496
9554
  }
9497
9555
  `;
9556
+ const { env, isExport } = ir.configs.config;
9557
+ if (!isExport && env === "dev") {
9558
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
9559
+ code += autoReloadScript?.default || autoReloadScript;
9560
+ }
9498
9561
  const imports = [
9499
9562
  {
9500
9563
  from: "../init"
@@ -9562,23 +9625,28 @@ var VueRouterPlugin = class {
9562
9625
  }
9563
9626
  routeToCode(routes, componentPathManager, config2) {
9564
9627
  function serializeVueRoute(r, isRoot = false) {
9565
- const path2 = r.thisLevelPath ?? "/";
9628
+ const { accumulativePath, thisLevelPath } = r;
9629
+ const path2 = isRoot ? accumulativePath : thisLevelPath ?? "/";
9630
+ const basePath = config2.basePath;
9566
9631
  if (r.kind === "normal") {
9567
9632
  const children = r.children?.map((i) => serializeVueRoute(i)).filter(isNotNil) ?? [];
9568
9633
  const childrenStr = children.join(",\n");
9569
9634
  const componentCode = `component: ${r.elementMangledName ?? r.elementTemplate.identifier}`;
9570
- return `{path: "${isRoot ? r.accumulativePath : path2}", meta: ${JSON.stringify(
9635
+ return `{path: "${path2}", meta: ${JSON.stringify(
9571
9636
  r.meta
9572
9637
  )}, children: [${childrenStr}], ${componentCode} }`;
9573
9638
  } else if (r.kind === "redirect") {
9574
- const replaceWildCardForVue3 = (frameworkKind, path3) => {
9575
- if (frameworkKind === "vue3" && path3 === "*") {
9576
- return "/:pathMatch(.*)*";
9639
+ if (["vue3"].includes(config2.frameworkKind) && path2 === "*") {
9640
+ return `{ path: "/:pathMatch(.*)*", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
9641
+ }
9642
+ if (["vue3"].includes(config2.frameworkKind) && path2 === "/") {
9643
+ let result = `{ path: "/", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
9644
+ if (basePath !== "/") {
9645
+ result += `, { path: "${basePath}", redirect: ${JSON.stringify(basePath + r.redirect)} }`;
9577
9646
  }
9578
- return path3;
9579
- };
9580
- const processedPath = replaceWildCardForVue3(config2.frameworkKind, path2);
9581
- return `{path: "${processedPath}", redirect: ${JSON.stringify(r.redirect)}}`;
9647
+ return result;
9648
+ }
9649
+ return `{ path: "${path2}", redirect: to => to.path.replace(/\\/$/, '') + '/' + ${JSON.stringify(r.redirect)} }`;
9582
9650
  }
9583
9651
  notImplemented(r);
9584
9652
  }
@@ -9667,7 +9735,7 @@ var Vue3EntryBuilderPlugin = class {
9667
9735
  buildEntry(ir) {
9668
9736
  const entryScript = this.microFrontendManager.produceScript(ir);
9669
9737
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
9670
- const code = `
9738
+ let code = `
9671
9739
  if(window.LcapMicro){
9672
9740
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
9673
9741
  renderApp();
@@ -9685,6 +9753,11 @@ var Vue3EntryBuilderPlugin = class {
9685
9753
  from: "./public-path"
9686
9754
  } : void 0
9687
9755
  ].filter(isNotNil);
9756
+ const { env, isExport } = ir.configs.config;
9757
+ if (!isExport && env === "dev") {
9758
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
9759
+ code += autoReloadScript?.default || autoReloadScript;
9760
+ }
9688
9761
  return [
9689
9762
  new ReactFileDescription("main.ts", imports, [], [code]),
9690
9763
  publicPathScript ? new ReactFileDescription("public-path.ts", [], [], [publicPathScript]) : void 0
@@ -9710,10 +9783,13 @@ var Vue3LibrariesBuilderPlugin = class {
9710
9783
  */
9711
9784
  async buildLibrariesImport(ir, config2) {
9712
9785
  const importArr = [];
9786
+ const exportArr = [];
9713
9787
  const standardLib = ir.packages.find((x) => x.kind === "standard");
9714
9788
  if (standardLib) {
9715
9789
  const formattedName = kebab2Pascal(standardLib.name.split("/").at(-1));
9716
- importArr.push(`export * as ${formattedName} from '${standardLib.name}';`);
9790
+ importArr.push(`import * as ${formattedName} from '${standardLib.name}';`);
9791
+ exportArr.push(`export { ${formattedName} };`);
9792
+ exportArr.push(`window.lcapStandardUI = ${formattedName};`);
9717
9793
  const isPackageZipExists = await judgePackageZipExists(standardLib, config2.STATIC_URL);
9718
9794
  importArr.push(
9719
9795
  `import '${standardLib.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
@@ -9724,14 +9800,14 @@ var Vue3LibrariesBuilderPlugin = class {
9724
9800
  const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
9725
9801
  const isPackageZipExists = await judgePackageZipExists(ext, config2.STATIC_URL);
9726
9802
  const prefix = isPackageZipExists ? "" : "@extension/";
9727
- importArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
9803
+ exportArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
9728
9804
  if (ext.hasCss) {
9729
9805
  importArr.push(
9730
9806
  `import '${prefix}${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
9731
9807
  );
9732
9808
  }
9733
9809
  }
9734
- return new ReactFileDescription("libraries.ts", [], [], [importArr.join("\n")]);
9810
+ return new ReactFileDescription("libraries.ts", [], [], [[...importArr, ...exportArr].join("\n")]);
9735
9811
  }
9736
9812
  static install(c) {
9737
9813
  c.bind(Vue3LibrariesBuilderPlugin).toSelf();
@@ -9967,15 +10043,16 @@ var Vue3ApplicationAssemblerPlugin = class {
9967
10043
  const bizComponents = ir.bizComponents.flatMap((x) => {
9968
10044
  return this.vue3CodegenPlugin.genFiles(x, manager);
9969
10045
  });
9970
- let routePrefix = ir.configs.frontendDesc.path;
9971
- if (!/\/$/.test(routePrefix)) {
9972
- routePrefix += "/";
10046
+ let basePath = ir.configs.basePlatformConfig.basePath;
10047
+ if (!/\/$/.test(basePath)) {
10048
+ basePath += "/";
9973
10049
  }
9974
- const routesObjects = this.routesExtactor.extractRoute(ir.views, routePrefix, {
10050
+ const routesObjects = this.routesExtactor.extractRoute(ir.views, basePath, {
9975
10051
  lazy: true
9976
10052
  });
9977
10053
  const router = this.routerBuilder.routeToCode(routesObjects.routes, manager, {
9978
- frameworkKind: "vue3"
10054
+ frameworkKind: "vue3",
10055
+ basePath
9979
10056
  });
9980
10057
  const routerFile = new ReactFileDescription("router.ts", router.imports, [], [router.code]);
9981
10058
  const libraries = await this.librariesBuilder.buildLibrariesImport(ir, config2);
@@ -10028,6 +10105,30 @@ var Vue3PresetPlugin = class {
10028
10105
  const app = deserializeAppWhileKeepTypeAnnotation(appJson);
10029
10106
  const frontend = app.findNodeByPath(instruction.frontend.nodePath);
10030
10107
  const ir = this.irBuilder.buildIR(app, frontend, instruction.config);
10108
+ const needCompileViews = instruction.config?.needCompileViews ?? [];
10109
+ const isIncremental = needCompileViews.length > 0;
10110
+ if (isIncremental) {
10111
+ const filterChildComponents = (view, needCompileViews2) => {
10112
+ if (!view.childComponents?.length) {
10113
+ return;
10114
+ }
10115
+ view.childComponents = view.childComponents.filter((child) => {
10116
+ if (needCompileViews2.includes(child.__raw.nodePath)) {
10117
+ filterChildComponents(child, needCompileViews2);
10118
+ return true;
10119
+ }
10120
+ return false;
10121
+ });
10122
+ };
10123
+ ir.views = ir.views.filter((view) => {
10124
+ if (needCompileViews.includes(view.__raw.nodePath)) {
10125
+ filterChildComponents(view, needCompileViews);
10126
+ return true;
10127
+ }
10128
+ return false;
10129
+ });
10130
+ ir.bizComponents = [];
10131
+ }
10031
10132
  const assembledApplication = await this.applicationAssembler.assemble(ir, instruction.config);
10032
10133
  const finalizedFiles = await this.projectOrganizer.organize({
10033
10134
  baseDir: instruction.baseDir,
@@ -10105,36 +10206,6 @@ async function translateNASLToApp(app, frontend, config2, baseDir = "./out", con
10105
10206
  const logger15 = Logger("\u7FFB\u8BD1\u8FC7\u7A0B");
10106
10207
  logger15.debug({ config: config2 });
10107
10208
  async function genCode() {
10108
- const { needCompileViews = [] } = config2;
10109
- if (needCompileViews?.length > 0) {
10110
- let traverseChildren2 = function(view, callback) {
10111
- if (view.children?.length > 0) {
10112
- [...view.children].forEach((childView) => {
10113
- const deep = callback(childView);
10114
- if (deep) {
10115
- traverseChildren2(childView, callback);
10116
- }
10117
- });
10118
- }
10119
- };
10120
- var traverseChildren = traverseChildren2;
10121
- logger15.info("\u5F00\u59CB\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
10122
- [...frontend.views].forEach((view) => {
10123
- if (!needCompileViews.includes(view.nodePath)) {
10124
- view.delete();
10125
- console.log(`\u5220\u9664\u9875\u9762 ${view.nodePath}\uFF0C\u56E0\u4E3A\u5B83\u4E0D\u5728 needCompileViews \u4E2D`);
10126
- } else {
10127
- traverseChildren2(view, (childView) => {
10128
- if (!needCompileViews.includes(childView.nodePath)) {
10129
- childView.delete();
10130
- return false;
10131
- }
10132
- return true;
10133
- });
10134
- }
10135
- });
10136
- logger15.info("\u7ED3\u675F\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
10137
- }
10138
10209
  logger15.info("\u5F00\u59CB\u7FFB\u8BD1");
10139
10210
  try {
10140
10211
  const codeList2 = await container.get(ServiceMetaKind.NASLTranspiler).transpile({