@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.d.mts CHANGED
@@ -28,6 +28,7 @@ interface CommonAppConfig {
28
28
  isExport?: boolean;
29
29
  needCompileViews?: string[];
30
30
  cacheChunksMapCode?: string;
31
+ feLoadDependenciesOnDemand?: boolean;
31
32
  /**
32
33
  * 插件用的配置项
33
34
  */
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ interface CommonAppConfig {
28
28
  isExport?: boolean;
29
29
  needCompileViews?: string[];
30
30
  cacheChunksMapCode?: string;
31
+ feLoadDependenciesOnDemand?: boolean;
31
32
  /**
32
33
  * 插件用的配置项
33
34
  */
package/dist/index.js CHANGED
@@ -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 __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -37,6 +40,75 @@ var __decorateClass = (decorators, target, key, kind) => {
37
40
  };
38
41
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
39
42
 
43
+ // src/plugins/templates/auto-reload.js
44
+ var auto_reload_exports = {};
45
+ __export(auto_reload_exports, {
46
+ default: () => auto_reload_default
47
+ });
48
+ var auto_reload_default;
49
+ var init_auto_reload = __esm({
50
+ "src/plugins/templates/auto-reload.js"() {
51
+ "use strict";
52
+ auto_reload_default = `
53
+ const dom = document.createElement('div');
54
+ dom.classList = "lcap-deploy-loading-container";
55
+ dom.style.display = 'none';
56
+ dom.innerHTML = "<div class='lcap-deploy-loading-icon'></div><div>\u6B63\u5728\u66F4\u65B0\u6700\u65B0\u53D1\u5E03\u5185\u5BB9...</div>";
57
+ document.getElementsByTagName('body')[0].appendChild(dom);
58
+
59
+ const style = document.createElement('style');
60
+ style.innerHTML = \`.lcap-deploy-loading-container {
61
+ width: 208px;
62
+ height: 40px;
63
+ background: rgba(48, 48, 48, 0.8);
64
+ box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
65
+ border-radius: 4px;
66
+ position: fixed;
67
+ top: 120px;
68
+ left: 50%;
69
+ margin-left: -104px;
70
+ color: #FFFFFF;
71
+ font-size: 14px;
72
+ justify-content: center;
73
+ align-items: center;
74
+ }
75
+
76
+ .lcap-deploy-loading-icon{
77
+ width: 12px;
78
+ height: 12px;
79
+ margin-right: 10px;
80
+ animation: loading-animation 0.8s infinite linear;
81
+ border: 2px solid #f3f3f3;
82
+ border-top: 2px solid rgb(109, 108, 108);
83
+ border-right: 2px solid rgb(109, 108, 108);
84
+ border-bottom: 2px solid rgb(109, 108, 108);
85
+ border-radius: 50%;
86
+ }
87
+
88
+ @keyframes loading-animation{
89
+ 0% {
90
+ transform: rotate(0deg);
91
+ }
92
+ 100% {
93
+ transform: rotate(360deg);
94
+ }
95
+ }\`;
96
+ document.getElementsByTagName('body')[0].appendChild(style);
97
+
98
+ window.addEventListener('message', function (e) {
99
+ if(e.data ==="release-start"){
100
+ document.querySelector(".lcap-deploy-loading-container").style.display ="flex"
101
+ }
102
+
103
+ if(e.data==="release-end"){
104
+ document.querySelector(".lcap-deploy-loading-container").style.display ="none"
105
+ window.location.reload();
106
+ }
107
+ });
108
+ `;
109
+ }
110
+ });
111
+
40
112
  // src/index.ts
41
113
  var src_exports = {};
42
114
  __export(src_exports, {
@@ -2545,6 +2617,9 @@ query: {`;
2545
2617
  s2.right,
2546
2618
  callbackBag
2547
2619
  )}`;
2620
+ } else if ((0, import_asserts.isVariadicExpression)(s2)) {
2621
+ const expressions = s2.expressions.map((exp) => getRuntimeStr(exp, callbackBag));
2622
+ return expressions.join(s2.operator);
2548
2623
  } else if ((0, import_asserts.isMatchCase)(s2)) {
2549
2624
  const p = s2.parentNode;
2550
2625
  if (!(0, import_asserts.isMatch)(p)) {
@@ -4085,7 +4160,7 @@ var ReactCodegenPlugin = class {
4085
4160
  const exts = packages.filter((x) => x.kind === "extension");
4086
4161
  const imports = exts.map((ext) => {
4087
4162
  return {
4088
- from: `@extension/${ext.name}`,
4163
+ from: `${ext.name}`,
4089
4164
  import: `* as ${kebab2Pascal(ext.name)}`
4090
4165
  };
4091
4166
  }).filter(isNotNil);
@@ -4292,40 +4367,40 @@ var metadataPlugin = makePlugin({
4292
4367
  // src/hack/material-config/material.config.js
4293
4368
  var materials = {
4294
4369
  framework: {
4295
- version: "2.0.1",
4370
+ version: "2.1.0",
4296
4371
  core: "@lcap/basic-template",
4297
4372
  pc: [
4298
4373
  {
4299
4374
  frameworkKind: "vue2",
4300
4375
  name: "@lcap/pc-template",
4301
- version: "2.0.1"
4376
+ version: "2.1.0"
4302
4377
  },
4303
4378
  {
4304
4379
  frameworkKind: "react",
4305
4380
  name: "@lcap/pc-template-react",
4306
- version: "2.0.1"
4381
+ version: "2.1.0"
4307
4382
  },
4308
4383
  {
4309
4384
  frameworkKind: "vue3",
4310
4385
  name: "@lcap/pc-template-vue3",
4311
- version: "2.0.1"
4386
+ version: "2.1.0"
4312
4387
  }
4313
4388
  ],
4314
4389
  h5: [
4315
4390
  {
4316
4391
  frameworkKind: "vue2",
4317
4392
  name: "@lcap/mobile-template",
4318
- version: "2.0.1"
4393
+ version: "2.1.0"
4319
4394
  },
4320
4395
  {
4321
4396
  frameworkKind: "react",
4322
4397
  name: "@lcap/mobile-template-react",
4323
- version: "2.0.1"
4398
+ version: "2.1.0"
4324
4399
  },
4325
4400
  {
4326
4401
  frameworkKind: "vue3",
4327
4402
  name: "@lcap/mobile-template-vue3",
4328
- version: "2.0.1"
4403
+ version: "2.1.0"
4329
4404
  }
4330
4405
  ]
4331
4406
  },
@@ -4376,7 +4451,7 @@ var materials = {
4376
4451
  frameworkVersion: "vue@3.5.13",
4377
4452
  name: "@lcap/vant",
4378
4453
  libName: "LcapVant",
4379
- version: "1.0.0-beta.1"
4454
+ version: "1.0.0"
4380
4455
  }
4381
4456
  ]
4382
4457
  },
@@ -4714,7 +4789,7 @@ function getReferencedLibComponent(e) {
4714
4789
  if (tag === "Router") {
4715
4790
  return { kind: "library", libraryName: "react-router-dom", tag: "Outlet" };
4716
4791
  }
4717
- const libraryName = foundExtension ? `@extension/${foundExtension.name}` : DefaultComponentLibraryName;
4792
+ const libraryName = foundExtension ? `${foundExtension.name}` : DefaultComponentLibraryName;
4718
4793
  return { kind: "library", libraryName, tag };
4719
4794
  } else if (tag) {
4720
4795
  return { kind: "library", libraryName: DefaultComponentLibraryName, tag };
@@ -5404,14 +5479,14 @@ var NASLAppIRBuilderPlugin = class {
5404
5479
  }
5405
5480
  enchanceHackForAppPackageInfos(app, commonAppConfig) {
5406
5481
  app.loadPackageInfos(getPredefinedMaterialConfig());
5407
- const config = (0, import_nasl_concepts9.getConfig)();
5408
- if (commonAppConfig.allNodesAPI) {
5409
- config.allNodesAPI = commonAppConfig.allNodesAPI;
5410
- }
5411
- config.allNodesAPI ??= {};
5482
+ const naslStoreConfig = (0, import_nasl_concepts9.getConfig)();
5483
+ naslStoreConfig.allNodesAPI = commonAppConfig.allNodesAPI || {};
5412
5484
  (0, import_nasl_concepts9.initialize)({
5413
5485
  getConfig: () => {
5414
- return config;
5486
+ return {
5487
+ ...commonAppConfig || {},
5488
+ ...naslStoreConfig || {}
5489
+ };
5415
5490
  }
5416
5491
  });
5417
5492
  }
@@ -6913,6 +6988,7 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6913
6988
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
6914
6989
  packageJson.lcap_modules[pkgName] = `.${targetPath}`;
6915
6990
  });
6991
+ packageJson = setApplicationName(packageJson, config.app?.name || config.app?.id);
6916
6992
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
6917
6993
  logger13.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
6918
6994
  } catch (error) {
@@ -6921,6 +6997,12 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6921
6997
  }
6922
6998
  }
6923
6999
  }
7000
+ function setApplicationName(packageJson, appName = Date.now().toString()) {
7001
+ if (packageJson && appName) {
7002
+ packageJson.name = appName;
7003
+ }
7004
+ return packageJson;
7005
+ }
6924
7006
 
6925
7007
  // src/plugins/misc/bundler/bundler-config-data-plugin.ts
6926
7008
  var logger11 = Logger("BundlerConfigDataPlugin");
@@ -6932,7 +7014,8 @@ var BundlerConfigDataPlugin = class {
6932
7014
  const feDeps = [...extractAppLevelFrontendDeps(app), ...extractFrontendLevelDeps(frontend)];
6933
7015
  await downloadDependenciesToLcapModules(feDeps, fs, {
6934
7016
  STATIC_URL: config.STATIC_URL,
6935
- frameworkKind
7017
+ frameworkKind,
7018
+ app
6936
7019
  });
6937
7020
  const orginDependencies = await downloadDependenciesToPackages(feDeps, fs, {
6938
7021
  STATIC_URL: config.STATIC_URL
@@ -6942,13 +7025,12 @@ var BundlerConfigDataPlugin = class {
6942
7025
  if (target) {
6943
7026
  return {
6944
7027
  name: dep.name,
6945
- resolvedTo: `./src/${target}`.replace(/\/index\.js$/, ""),
6946
- scope: dep.kind === "extension" ? "@extension" : void 0
7028
+ resolvedTo: `./src/${target}`.replace(/\/index\.js$/, "")
6947
7029
  };
6948
7030
  }
6949
7031
  return void 0;
6950
7032
  }).filter(isNotNil).map((x) => {
6951
- const name = x.scope ? `${x.scope}/${x.name}` : x.name;
7033
+ const name = x.name;
6952
7034
  return {
6953
7035
  pkgName: name,
6954
7036
  ...x
@@ -7011,18 +7093,49 @@ var RspackConfigPlugin = class {
7011
7093
  );
7012
7094
  }
7013
7095
  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"}`);
7014
- if (config.needCompileViews && config.needCompileViews.length > 0 && config.cacheChunksMapCode) {
7096
+ if (config.env === "dev" && config.needCompileViews && config.needCompileViews.length > 0 && config.cacheChunksMapCode) {
7015
7097
  rspackConfigSource = rspackConfigSource.replace("isIncremental: false", "isIncremental: true").replace("chunksMap: ''", `chunksMap: \`${config.cacheChunksMapCode}\``);
7016
7098
  }
7017
7099
  if (config.isExport) {
7018
7100
  rspackConfigSource = rspackConfigSource.replace(/\/\/ LcapPlugin start\s+new LcapPlugin\(\{[\s\S]*?\}\),\s+\/\/ LcapPlugin end/g, "");
7019
7101
  }
7102
+ rspackConfigSource = await this.processLoadOnDemand(rspackConfigSource, {
7103
+ app,
7104
+ frontend,
7105
+ config,
7106
+ fs,
7107
+ frameworkKind
7108
+ });
7020
7109
  fs.write(
7021
7110
  "/rspack.config.js",
7022
7111
  rspackConfigSource
7023
7112
  );
7024
7113
  }
7025
7114
  }
7115
+ /**
7116
+ * 处理按需加载
7117
+ * 注意:此功能仅在非dev环境下的vue3框架中可以启用。
7118
+ * @param source 源代码
7119
+ * @param options 选项
7120
+ * @returns 处理后的代码
7121
+ */
7122
+ async processLoadOnDemand(source, options) {
7123
+ let code = source;
7124
+ const { app, frontend, config, fs, frameworkKind } = options;
7125
+ const { env, feLoadDependenciesOnDemand, isExport } = config;
7126
+ const enablePerformance = feLoadDependenciesOnDemand && (isExport || env !== "dev") && ["vue3"].includes(frameworkKind);
7127
+ if (enablePerformance) {
7128
+ const feDeps = [...extractAppLevelFrontendDeps(app), ...extractFrontendLevelDeps(frontend)];
7129
+ code = code.replaceAll("// swc plugin placeholder", `experimental: {
7130
+ plugins: [
7131
+ ['@lcap/swc-plugin-import', require('./scripts/generateSwcImportPluginConfig')([
7132
+ ${feDeps.map((dep) => "'" + dep.name + "'").join(",\n")}
7133
+ ])]
7134
+ ]
7135
+ }`);
7136
+ }
7137
+ return code;
7138
+ }
7026
7139
  static install(c) {
7027
7140
  c.bind(ServiceMetaKind.FrontendBundlerFileConfig).to(RspackConfigPlugin).inSingletonScope();
7028
7141
  return c;
@@ -7187,7 +7300,7 @@ export function loadAssets(){
7187
7300
  generateEntry(ir) {
7188
7301
  const entryScript = this.microFrontendManager.produceScript(ir);
7189
7302
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7190
- const code = `
7303
+ let code = `
7191
7304
  export function startApp(){
7192
7305
  if(window.LcapMicro){
7193
7306
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
@@ -7198,6 +7311,11 @@ export function loadAssets(){
7198
7311
  }
7199
7312
  }
7200
7313
  `;
7314
+ const { env, isExport } = ir.configs.config;
7315
+ if (!isExport && env === "dev") {
7316
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
7317
+ code += autoReloadScript?.default || autoReloadScript;
7318
+ }
7201
7319
  const imports = [
7202
7320
  {
7203
7321
  from: "../init"
@@ -7375,7 +7493,7 @@ var Vue3EntryBuilderPlugin = class {
7375
7493
  buildEntry(ir) {
7376
7494
  const entryScript = this.microFrontendManager.produceScript(ir);
7377
7495
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7378
- const code = `
7496
+ let code = `
7379
7497
  if(window.LcapMicro){
7380
7498
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
7381
7499
  renderApp();
@@ -7393,6 +7511,11 @@ var Vue3EntryBuilderPlugin = class {
7393
7511
  from: "./public-path"
7394
7512
  } : void 0
7395
7513
  ].filter(isNotNil);
7514
+ const { env, isExport } = ir.configs.config;
7515
+ if (!isExport && env === "dev") {
7516
+ const autoReloadScript = (init_auto_reload(), __toCommonJS(auto_reload_exports));
7517
+ code += autoReloadScript?.default || autoReloadScript;
7518
+ }
7396
7519
  return [
7397
7520
  new ReactFileDescription("main.ts", imports, [], [code]),
7398
7521
  publicPathScript ? new ReactFileDescription("public-path.ts", [], [], [publicPathScript]) : void 0
@@ -7421,10 +7544,8 @@ var Vue3LibrariesBuilderPlugin = class {
7421
7544
  const exportArr = [];
7422
7545
  const standardLib = ir.packages.find((x) => x.kind === "standard");
7423
7546
  if (standardLib) {
7424
- const formattedName = kebab2Pascal(standardLib.name.split("/").at(-1));
7425
- importArr.push(`import * as ${formattedName} from '${standardLib.name}';`);
7426
- exportArr.push(`export { ${formattedName} };`);
7427
- exportArr.push(`window.lcapStandardUI = ${formattedName};`);
7547
+ importArr.push(`import { ConfigProvider, transformKeys } from '${standardLib.name}';`);
7548
+ exportArr.push(`window.lcapStandardUI = { ConfigProvider, transformKeys };`);
7428
7549
  const isPackageZipExists = await judgePackageZipExists(standardLib, config.STATIC_URL);
7429
7550
  importArr.push(
7430
7551
  `import '${standardLib.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
@@ -7432,18 +7553,23 @@ var Vue3LibrariesBuilderPlugin = class {
7432
7553
  }
7433
7554
  const extensions = ir.packages.filter((x) => x.kind === "extension");
7434
7555
  for (const ext of extensions) {
7435
- const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
7436
7556
  const isPackageZipExists = await judgePackageZipExists(ext, config.STATIC_URL);
7437
- const prefix = isPackageZipExists ? "" : "@extension/";
7438
- exportArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
7439
7557
  if (ext.hasCss) {
7440
7558
  importArr.push(
7441
- `import '${prefix}${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7559
+ `import '${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7442
7560
  );
7443
7561
  }
7444
7562
  }
7445
7563
  return new ReactFileDescription("libraries.ts", [], [], [[...importArr, ...exportArr].join("\n")]);
7446
7564
  }
7565
+ findPackageByNameFromAllNodesAPI(name, allNodesAPI = {}) {
7566
+ for (const key in allNodesAPI) {
7567
+ if (allNodesAPI[key]?.package?.name === name) {
7568
+ return allNodesAPI[key].package;
7569
+ }
7570
+ }
7571
+ return void 0;
7572
+ }
7447
7573
  static install(c) {
7448
7574
  c.bind(Vue3LibrariesBuilderPlugin).toSelf();
7449
7575
  return c;
@@ -7841,6 +7967,36 @@ async function translateNASLToApp(app, frontend, config, baseDir = "./out", cont
7841
7967
  const logger13 = Logger("\u7FFB\u8BD1\u8FC7\u7A0B");
7842
7968
  logger13.debug({ config });
7843
7969
  async function genCode() {
7970
+ const { needCompileViews = [] } = config;
7971
+ if (needCompileViews?.length > 0) {
7972
+ let traverseChildren2 = function(view, callback) {
7973
+ if (view.children?.length > 0) {
7974
+ [...view.children].forEach((childView) => {
7975
+ const deep = callback(childView);
7976
+ if (deep) {
7977
+ traverseChildren2(childView, callback);
7978
+ }
7979
+ });
7980
+ }
7981
+ };
7982
+ var traverseChildren = traverseChildren2;
7983
+ logger13.info("\u5F00\u59CB\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
7984
+ [...frontend.views].forEach((view) => {
7985
+ if (!needCompileViews.includes(view.nodePath)) {
7986
+ view.delete();
7987
+ console.log(`\u5220\u9664\u9875\u9762 ${view.nodePath}\uFF0C\u56E0\u4E3A\u5B83\u4E0D\u5728 needCompileViews \u4E2D`);
7988
+ } else {
7989
+ traverseChildren2(view, (childView) => {
7990
+ if (!needCompileViews.includes(childView.nodePath)) {
7991
+ childView.delete();
7992
+ return false;
7993
+ }
7994
+ return true;
7995
+ });
7996
+ }
7997
+ });
7998
+ logger13.info("\u7ED3\u675F\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
7999
+ }
7844
8000
  logger13.info("\u5F00\u59CB\u7FFB\u8BD1");
7845
8001
  try {
7846
8002
  const codeList2 = await container.get(ServiceMetaKind.NASLTranspiler).transpile({
@@ -7937,7 +8093,11 @@ async function compileAsProject(app, frontend, config, container) {
7937
8093
  logger13.info("\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u6210\u529F");
7938
8094
  const files = res.files;
7939
8095
  Object.entries(files).forEach(([k, v]) => {
7940
- fs.write(k, v.code);
8096
+ if (typeof v.code === "string") {
8097
+ fs.write(k, v.code);
8098
+ } else if (v.code?.type === "Buffer") {
8099
+ fs.write(k, Buffer.from(v.code.data));
8100
+ }
7941
8101
  });
7942
8102
  } catch (error) {
7943
8103
  throw new Error(`\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u5931\u8D25`);