@lcap/nasl-unified-frontend-generator 4.0.1-rc.0 → 4.1.0-beta.2

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";
@@ -6947,11 +7034,11 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6947
7034
  }
6948
7035
  let packageJson = fs.read("/package.json")?.toString();
6949
7036
  packageJson = JSON.parse(packageJson);
6950
- if (!packageJson.dependencies) {
6951
- packageJson.dependencies = {};
7037
+ if (!packageJson.lcap_modules) {
7038
+ packageJson.lcap_modules = {};
6952
7039
  }
6953
7040
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
6954
- packageJson.dependencies[pkgName] = `.${targetPath}`;
7041
+ packageJson.lcap_modules[pkgName] = `.${targetPath}`;
6955
7042
  });
6956
7043
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
6957
7044
  logger13.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
@@ -7227,7 +7314,7 @@ export function loadAssets(){
7227
7314
  generateEntry(ir) {
7228
7315
  const entryScript = this.microFrontendManager.produceScript(ir);
7229
7316
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7230
- const code = `
7317
+ let code = `
7231
7318
  export function startApp(){
7232
7319
  if(window.LcapMicro){
7233
7320
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
@@ -7238,6 +7325,11 @@ export function loadAssets(){
7238
7325
  }
7239
7326
  }
7240
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
+ }
7241
7333
  const imports = [
7242
7334
  {
7243
7335
  from: "../init"
@@ -7415,7 +7507,7 @@ var Vue3EntryBuilderPlugin = class {
7415
7507
  buildEntry(ir) {
7416
7508
  const entryScript = this.microFrontendManager.produceScript(ir);
7417
7509
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
7418
- const code = `
7510
+ let code = `
7419
7511
  if(window.LcapMicro){
7420
7512
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
7421
7513
  renderApp();
@@ -7433,6 +7525,11 @@ var Vue3EntryBuilderPlugin = class {
7433
7525
  from: "./public-path"
7434
7526
  } : void 0
7435
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
+ }
7436
7533
  return [
7437
7534
  new ReactFileDescription("main.ts", imports, [], [code]),
7438
7535
  publicPathScript ? new ReactFileDescription("public-path.ts", [], [], [publicPathScript]) : void 0
@@ -7881,6 +7978,36 @@ async function translateNASLToApp(app, frontend, config, baseDir = "./out", cont
7881
7978
  const logger13 = Logger("\u7FFB\u8BD1\u8FC7\u7A0B");
7882
7979
  logger13.debug({ config });
7883
7980
  async function genCode() {
7981
+ const { needCompileViews = [] } = config;
7982
+ if (needCompileViews?.length > 0) {
7983
+ let traverseChildren2 = function(view, callback) {
7984
+ if (view.children?.length > 0) {
7985
+ [...view.children].forEach((childView) => {
7986
+ const deep = callback(childView);
7987
+ if (deep) {
7988
+ traverseChildren2(childView, callback);
7989
+ }
7990
+ });
7991
+ }
7992
+ };
7993
+ var traverseChildren = traverseChildren2;
7994
+ logger13.info("\u5F00\u59CB\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
7995
+ [...frontend.views].forEach((view) => {
7996
+ if (!needCompileViews.includes(view.nodePath)) {
7997
+ view.delete();
7998
+ console.log(`\u5220\u9664\u9875\u9762 ${view.nodePath}\uFF0C\u56E0\u4E3A\u5B83\u4E0D\u5728 needCompileViews \u4E2D`);
7999
+ } else {
8000
+ traverseChildren2(view, (childView) => {
8001
+ if (!needCompileViews.includes(childView.nodePath)) {
8002
+ childView.delete();
8003
+ return false;
8004
+ }
8005
+ return true;
8006
+ });
8007
+ }
8008
+ });
8009
+ logger13.info("\u7ED3\u675F\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
8010
+ }
7884
8011
  logger13.info("\u5F00\u59CB\u7FFB\u8BD1");
7885
8012
  try {
7886
8013
  const codeList2 = await container.get(ServiceMetaKind.NASLTranspiler).transpile({