@lcap/nasl-unified-frontend-generator 4.0.1-rc.1 → 4.1.0-beta.10

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";
@@ -1396,6 +1483,7 @@ import {
1396
1483
  isUnparsed,
1397
1484
  isValidationRule,
1398
1485
  isVariable,
1486
+ isVariadicExpression,
1399
1487
  isWhileStatement
1400
1488
  } from "@lcap/nasl-concepts/asserts";
1401
1489
  import { transfromMetadataType, transformUnionTypeAnnotation } from "@lcap/nasl-concepts/service";
@@ -2585,6 +2673,9 @@ query: {`;
2585
2673
  s2.right,
2586
2674
  callbackBag
2587
2675
  )}`;
2676
+ } else if (isVariadicExpression(s2)) {
2677
+ const expressions = s2.expressions.map((exp) => getRuntimeStr(exp, callbackBag));
2678
+ return expressions.join(s2.operator);
2588
2679
  } else if (isMatchCase(s2)) {
2589
2680
  const p = s2.parentNode;
2590
2681
  if (!isMatch(p)) {
@@ -4125,7 +4216,7 @@ var ReactCodegenPlugin = class {
4125
4216
  const exts = packages.filter((x) => x.kind === "extension");
4126
4217
  const imports = exts.map((ext) => {
4127
4218
  return {
4128
- from: `@extension/${ext.name}`,
4219
+ from: `${ext.name}`,
4129
4220
  import: `* as ${kebab2Pascal(ext.name)}`
4130
4221
  };
4131
4222
  }).filter(isNotNil);
@@ -4332,40 +4423,40 @@ var metadataPlugin = makePlugin({
4332
4423
  // src/hack/material-config/material.config.js
4333
4424
  var materials = {
4334
4425
  framework: {
4335
- version: "2.0.1",
4426
+ version: "2.1.0",
4336
4427
  core: "@lcap/basic-template",
4337
4428
  pc: [
4338
4429
  {
4339
4430
  frameworkKind: "vue2",
4340
4431
  name: "@lcap/pc-template",
4341
- version: "2.0.1"
4432
+ version: "2.1.0"
4342
4433
  },
4343
4434
  {
4344
4435
  frameworkKind: "react",
4345
4436
  name: "@lcap/pc-template-react",
4346
- version: "2.0.1"
4437
+ version: "2.1.0"
4347
4438
  },
4348
4439
  {
4349
4440
  frameworkKind: "vue3",
4350
4441
  name: "@lcap/pc-template-vue3",
4351
- version: "2.0.1"
4442
+ version: "2.1.0"
4352
4443
  }
4353
4444
  ],
4354
4445
  h5: [
4355
4446
  {
4356
4447
  frameworkKind: "vue2",
4357
4448
  name: "@lcap/mobile-template",
4358
- version: "2.0.1"
4449
+ version: "2.1.0"
4359
4450
  },
4360
4451
  {
4361
4452
  frameworkKind: "react",
4362
4453
  name: "@lcap/mobile-template-react",
4363
- version: "2.0.1"
4454
+ version: "2.1.0"
4364
4455
  },
4365
4456
  {
4366
4457
  frameworkKind: "vue3",
4367
4458
  name: "@lcap/mobile-template-vue3",
4368
- version: "2.0.1"
4459
+ version: "2.1.0"
4369
4460
  }
4370
4461
  ]
4371
4462
  },
@@ -4416,7 +4507,7 @@ var materials = {
4416
4507
  frameworkVersion: "vue@3.5.13",
4417
4508
  name: "@lcap/vant",
4418
4509
  libName: "LcapVant",
4419
- version: "1.0.0-beta.1"
4510
+ version: "1.0.0"
4420
4511
  }
4421
4512
  ]
4422
4513
  },
@@ -4754,7 +4845,7 @@ function getReferencedLibComponent(e) {
4754
4845
  if (tag === "Router") {
4755
4846
  return { kind: "library", libraryName: "react-router-dom", tag: "Outlet" };
4756
4847
  }
4757
- const libraryName = foundExtension ? `@extension/${foundExtension.name}` : DefaultComponentLibraryName;
4848
+ const libraryName = foundExtension ? `${foundExtension.name}` : DefaultComponentLibraryName;
4758
4849
  return { kind: "library", libraryName, tag };
4759
4850
  } else if (tag) {
4760
4851
  return { kind: "library", libraryName: DefaultComponentLibraryName, tag };
@@ -5444,14 +5535,14 @@ var NASLAppIRBuilderPlugin = class {
5444
5535
  }
5445
5536
  enchanceHackForAppPackageInfos(app, commonAppConfig) {
5446
5537
  app.loadPackageInfos(getPredefinedMaterialConfig());
5447
- const config = getConfig();
5448
- if (commonAppConfig.allNodesAPI) {
5449
- config.allNodesAPI = commonAppConfig.allNodesAPI;
5450
- }
5451
- config.allNodesAPI ??= {};
5538
+ const naslStoreConfig = getConfig();
5539
+ naslStoreConfig.allNodesAPI = commonAppConfig.allNodesAPI || {};
5452
5540
  initialize({
5453
5541
  getConfig: () => {
5454
- return config;
5542
+ return {
5543
+ ...commonAppConfig || {},
5544
+ ...naslStoreConfig || {}
5545
+ };
5455
5546
  }
5456
5547
  });
5457
5548
  }
@@ -6953,6 +7044,7 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6953
7044
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
6954
7045
  packageJson.lcap_modules[pkgName] = `.${targetPath}`;
6955
7046
  });
7047
+ packageJson = setApplicationName(packageJson, config.app?.name || config.app?.id);
6956
7048
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
6957
7049
  logger13.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
6958
7050
  } catch (error) {
@@ -6961,6 +7053,12 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6961
7053
  }
6962
7054
  }
6963
7055
  }
7056
+ function setApplicationName(packageJson, appName = Date.now().toString()) {
7057
+ if (packageJson && appName) {
7058
+ packageJson.name = appName;
7059
+ }
7060
+ return packageJson;
7061
+ }
6964
7062
 
6965
7063
  // src/plugins/misc/bundler/bundler-config-data-plugin.ts
6966
7064
  var logger11 = Logger("BundlerConfigDataPlugin");
@@ -6972,7 +7070,8 @@ var BundlerConfigDataPlugin = class {
6972
7070
  const feDeps = [...extractAppLevelFrontendDeps(app), ...extractFrontendLevelDeps(frontend)];
6973
7071
  await downloadDependenciesToLcapModules(feDeps, fs, {
6974
7072
  STATIC_URL: config.STATIC_URL,
6975
- frameworkKind
7073
+ frameworkKind,
7074
+ app
6976
7075
  });
6977
7076
  const orginDependencies = await downloadDependenciesToPackages(feDeps, fs, {
6978
7077
  STATIC_URL: config.STATIC_URL
@@ -6982,13 +7081,12 @@ var BundlerConfigDataPlugin = class {
6982
7081
  if (target) {
6983
7082
  return {
6984
7083
  name: dep.name,
6985
- resolvedTo: `./src/${target}`.replace(/\/index\.js$/, ""),
6986
- scope: dep.kind === "extension" ? "@extension" : void 0
7084
+ resolvedTo: `./src/${target}`.replace(/\/index\.js$/, "")
6987
7085
  };
6988
7086
  }
6989
7087
  return void 0;
6990
7088
  }).filter(isNotNil).map((x) => {
6991
- const name = x.scope ? `${x.scope}/${x.name}` : x.name;
7089
+ const name = x.name;
6992
7090
  return {
6993
7091
  pkgName: name,
6994
7092
  ...x
@@ -7051,18 +7149,49 @@ var RspackConfigPlugin = class {
7051
7149
  );
7052
7150
  }
7053
7151
  rspackConfigSource = rspackConfigSource.replace(`const backendUrl = '';`, `const backendUrl = '${backendUrl}'`).replace(`const publicPath = '';`, `const publicPath = '${publicPath}';`).replace(`sourceMap: false,`, `sourceMap: ${config.env === "dev"},`).replace("alias: {}", `alias: {${aliasMapStr}}`).replace("const isDev = false", `const isDev = ${config.env === "dev"}`);
7054
- if (config.needCompileViews && config.needCompileViews.length > 0 && config.cacheChunksMapCode) {
7152
+ if (config.env === "dev" && config.needCompileViews && config.needCompileViews.length > 0 && config.cacheChunksMapCode) {
7055
7153
  rspackConfigSource = rspackConfigSource.replace("isIncremental: false", "isIncremental: true").replace("chunksMap: ''", `chunksMap: \`${config.cacheChunksMapCode}\``);
7056
7154
  }
7057
7155
  if (config.isExport) {
7058
7156
  rspackConfigSource = rspackConfigSource.replace(/\/\/ LcapPlugin start\s+new LcapPlugin\(\{[\s\S]*?\}\),\s+\/\/ LcapPlugin end/g, "");
7059
7157
  }
7158
+ rspackConfigSource = await this.processLoadOnDemand(rspackConfigSource, {
7159
+ app,
7160
+ frontend,
7161
+ config,
7162
+ fs,
7163
+ frameworkKind
7164
+ });
7060
7165
  fs.write(
7061
7166
  "/rspack.config.js",
7062
7167
  rspackConfigSource
7063
7168
  );
7064
7169
  }
7065
7170
  }
7171
+ /**
7172
+ * 处理按需加载
7173
+ * 注意:此功能仅在非dev环境下的vue3框架中可以启用。
7174
+ * @param source 源代码
7175
+ * @param options 选项
7176
+ * @returns 处理后的代码
7177
+ */
7178
+ async processLoadOnDemand(source, options) {
7179
+ let code = source;
7180
+ const { app, frontend, config, fs, frameworkKind } = options;
7181
+ const { env, feLoadDependenciesOnDemand, isExport } = config;
7182
+ const enablePerformance = feLoadDependenciesOnDemand && (isExport || env !== "dev") && ["vue3"].includes(frameworkKind);
7183
+ if (enablePerformance) {
7184
+ const feDeps = [...extractAppLevelFrontendDeps(app), ...extractFrontendLevelDeps(frontend)];
7185
+ code = code.replaceAll("// swc plugin placeholder", `experimental: {
7186
+ plugins: [
7187
+ ['@lcap/swc-plugin-import', require('./scripts/generateSwcImportPluginConfig')([
7188
+ ${feDeps.map((dep) => "'" + dep.name + "'").join(",\n")}
7189
+ ])]
7190
+ ]
7191
+ }`);
7192
+ }
7193
+ return code;
7194
+ }
7066
7195
  static install(c) {
7067
7196
  c.bind(ServiceMetaKind.FrontendBundlerFileConfig).to(RspackConfigPlugin).inSingletonScope();
7068
7197
  return c;
@@ -7227,7 +7356,7 @@ export function loadAssets(){
7227
7356
  generateEntry(ir) {
7228
7357
  const entryScript = this.microFrontendManager.produceScript(ir);
7229
7358
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7230
- const code = `
7359
+ let code = `
7231
7360
  export function startApp(){
7232
7361
  if(window.LcapMicro){
7233
7362
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
@@ -7238,6 +7367,11 @@ export function loadAssets(){
7238
7367
  }
7239
7368
  }
7240
7369
  `;
7370
+ const { env, isExport } = ir.configs.config;
7371
+ if (!isExport && env === "dev") {
7372
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
7373
+ code += autoReloadScript?.default || autoReloadScript;
7374
+ }
7241
7375
  const imports = [
7242
7376
  {
7243
7377
  from: "../init"
@@ -7415,7 +7549,7 @@ var Vue3EntryBuilderPlugin = class {
7415
7549
  buildEntry(ir) {
7416
7550
  const entryScript = this.microFrontendManager.produceScript(ir);
7417
7551
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7418
- const code = `
7552
+ let code = `
7419
7553
  if(window.LcapMicro){
7420
7554
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
7421
7555
  renderApp();
@@ -7433,6 +7567,11 @@ var Vue3EntryBuilderPlugin = class {
7433
7567
  from: "./public-path"
7434
7568
  } : void 0
7435
7569
  ].filter(isNotNil);
7570
+ const { env, isExport } = ir.configs.config;
7571
+ if (!isExport && env === "dev") {
7572
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
7573
+ code += autoReloadScript?.default || autoReloadScript;
7574
+ }
7436
7575
  return [
7437
7576
  new ReactFileDescription("main.ts", imports, [], [code]),
7438
7577
  publicPathScript ? new ReactFileDescription("public-path.ts", [], [], [publicPathScript]) : void 0
@@ -7461,10 +7600,8 @@ var Vue3LibrariesBuilderPlugin = class {
7461
7600
  const exportArr = [];
7462
7601
  const standardLib = ir.packages.find((x) => x.kind === "standard");
7463
7602
  if (standardLib) {
7464
- const formattedName = kebab2Pascal(standardLib.name.split("/").at(-1));
7465
- importArr.push(`import * as ${formattedName} from '${standardLib.name}';`);
7466
- exportArr.push(`export { ${formattedName} };`);
7467
- exportArr.push(`window.lcapStandardUI = ${formattedName};`);
7603
+ importArr.push(`import { ConfigProvider, transformKeys } from '${standardLib.name}';`);
7604
+ exportArr.push(`window.lcapStandardUI = { ConfigProvider, transformKeys };`);
7468
7605
  const isPackageZipExists = await judgePackageZipExists(standardLib, config.STATIC_URL);
7469
7606
  importArr.push(
7470
7607
  `import '${standardLib.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
@@ -7472,18 +7609,23 @@ var Vue3LibrariesBuilderPlugin = class {
7472
7609
  }
7473
7610
  const extensions = ir.packages.filter((x) => x.kind === "extension");
7474
7611
  for (const ext of extensions) {
7475
- const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
7476
7612
  const isPackageZipExists = await judgePackageZipExists(ext, config.STATIC_URL);
7477
- const prefix = isPackageZipExists ? "" : "@extension/";
7478
- exportArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
7479
7613
  if (ext.hasCss) {
7480
7614
  importArr.push(
7481
- `import '${prefix}${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7615
+ `import '${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7482
7616
  );
7483
7617
  }
7484
7618
  }
7485
7619
  return new ReactFileDescription("libraries.ts", [], [], [[...importArr, ...exportArr].join("\n")]);
7486
7620
  }
7621
+ findPackageByNameFromAllNodesAPI(name, allNodesAPI = {}) {
7622
+ for (const key in allNodesAPI) {
7623
+ if (allNodesAPI[key]?.package?.name === name) {
7624
+ return allNodesAPI[key].package;
7625
+ }
7626
+ }
7627
+ return void 0;
7628
+ }
7487
7629
  static install(c) {
7488
7630
  c.bind(Vue3LibrariesBuilderPlugin).toSelf();
7489
7631
  return c;
@@ -7881,6 +8023,36 @@ async function translateNASLToApp(app, frontend, config, baseDir = "./out", cont
7881
8023
  const logger13 = Logger("\u7FFB\u8BD1\u8FC7\u7A0B");
7882
8024
  logger13.debug({ config });
7883
8025
  async function genCode() {
8026
+ const { needCompileViews = [] } = config;
8027
+ if (needCompileViews?.length > 0) {
8028
+ let traverseChildren2 = function(view, callback) {
8029
+ if (view.children?.length > 0) {
8030
+ [...view.children].forEach((childView) => {
8031
+ const deep = callback(childView);
8032
+ if (deep) {
8033
+ traverseChildren2(childView, callback);
8034
+ }
8035
+ });
8036
+ }
8037
+ };
8038
+ var traverseChildren = traverseChildren2;
8039
+ logger13.info("\u5F00\u59CB\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
8040
+ [...frontend.views].forEach((view) => {
8041
+ if (!needCompileViews.includes(view.nodePath)) {
8042
+ view.delete();
8043
+ console.log(`\u5220\u9664\u9875\u9762 ${view.nodePath}\uFF0C\u56E0\u4E3A\u5B83\u4E0D\u5728 needCompileViews \u4E2D`);
8044
+ } else {
8045
+ traverseChildren2(view, (childView) => {
8046
+ if (!needCompileViews.includes(childView.nodePath)) {
8047
+ childView.delete();
8048
+ return false;
8049
+ }
8050
+ return true;
8051
+ });
8052
+ }
8053
+ });
8054
+ logger13.info("\u7ED3\u675F\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
8055
+ }
7884
8056
  logger13.info("\u5F00\u59CB\u7FFB\u8BD1");
7885
8057
  try {
7886
8058
  const codeList2 = await container.get(ServiceMetaKind.NASLTranspiler).transpile({
@@ -7977,7 +8149,11 @@ async function compileAsProject(app, frontend, config, container) {
7977
8149
  logger13.info("\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u6210\u529F");
7978
8150
  const files = res.files;
7979
8151
  Object.entries(files).forEach(([k, v]) => {
7980
- fs.write(k, v.code);
8152
+ if (typeof v.code === "string") {
8153
+ fs.write(k, v.code);
8154
+ } else if (v.code?.type === "Buffer") {
8155
+ fs.write(k, Buffer.from(v.code.data));
8156
+ }
7981
8157
  });
7982
8158
  } catch (error) {
7983
8159
  throw new Error(`\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u5931\u8D25`);