@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.
@@ -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";
@@ -9185,11 +9262,11 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config2) {
9185
9262
  }
9186
9263
  let packageJson = fs.read("/package.json")?.toString();
9187
9264
  packageJson = JSON.parse(packageJson);
9188
- if (!packageJson.dependencies) {
9189
- packageJson.dependencies = {};
9265
+ if (!packageJson.lcap_modules) {
9266
+ packageJson.lcap_modules = {};
9190
9267
  }
9191
9268
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
9192
- packageJson.dependencies[pkgName] = `.${targetPath}`;
9269
+ packageJson.lcap_modules[pkgName] = `.${targetPath}`;
9193
9270
  });
9194
9271
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
9195
9272
  logger15.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
@@ -9465,7 +9542,7 @@ export function loadAssets(){
9465
9542
  generateEntry(ir) {
9466
9543
  const entryScript = this.microFrontendManager.produceScript(ir);
9467
9544
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
9468
- const code = `
9545
+ let code = `
9469
9546
  export function startApp(){
9470
9547
  if(window.LcapMicro){
9471
9548
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
@@ -9476,6 +9553,11 @@ export function loadAssets(){
9476
9553
  }
9477
9554
  }
9478
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
+ }
9479
9561
  const imports = [
9480
9562
  {
9481
9563
  from: "../init"
@@ -9653,7 +9735,7 @@ var Vue3EntryBuilderPlugin = class {
9653
9735
  buildEntry(ir) {
9654
9736
  const entryScript = this.microFrontendManager.produceScript(ir);
9655
9737
  const publicPathScript = this.microFrontendManager.producePublicPathScript(ir);
9656
- const code = `
9738
+ let code = `
9657
9739
  if(window.LcapMicro){
9658
9740
  // \u5DF2\u7ECF\u88AB\u52A0\u8F7D\u4E8E\u5FAE\u524D\u7AEF\u73AF\u5883
9659
9741
  renderApp();
@@ -9671,6 +9753,11 @@ var Vue3EntryBuilderPlugin = class {
9671
9753
  from: "./public-path"
9672
9754
  } : void 0
9673
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
+ }
9674
9761
  return [
9675
9762
  new ReactFileDescription("main.ts", imports, [], [code]),
9676
9763
  publicPathScript ? new ReactFileDescription("public-path.ts", [], [], [publicPathScript]) : void 0
@@ -10119,6 +10206,36 @@ async function translateNASLToApp(app, frontend, config2, baseDir = "./out", con
10119
10206
  const logger15 = Logger("\u7FFB\u8BD1\u8FC7\u7A0B");
10120
10207
  logger15.debug({ config: config2 });
10121
10208
  async function genCode() {
10209
+ const { needCompileViews = [] } = config2;
10210
+ if (needCompileViews?.length > 0) {
10211
+ let traverseChildren2 = function(view, callback) {
10212
+ if (view.children?.length > 0) {
10213
+ [...view.children].forEach((childView) => {
10214
+ const deep = callback(childView);
10215
+ if (deep) {
10216
+ traverseChildren2(childView, callback);
10217
+ }
10218
+ });
10219
+ }
10220
+ };
10221
+ var traverseChildren = traverseChildren2;
10222
+ logger15.info("\u5F00\u59CB\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
10223
+ [...frontend.views].forEach((view) => {
10224
+ if (!needCompileViews.includes(view.nodePath)) {
10225
+ view.delete();
10226
+ console.log(`\u5220\u9664\u9875\u9762 ${view.nodePath}\uFF0C\u56E0\u4E3A\u5B83\u4E0D\u5728 needCompileViews \u4E2D`);
10227
+ } else {
10228
+ traverseChildren2(view, (childView) => {
10229
+ if (!needCompileViews.includes(childView.nodePath)) {
10230
+ childView.delete();
10231
+ return false;
10232
+ }
10233
+ return true;
10234
+ });
10235
+ }
10236
+ });
10237
+ logger15.info("\u7ED3\u675F\u6309\u9700\u7FFB\u8BD1\u9875\u9762");
10238
+ }
10122
10239
  logger15.info("\u5F00\u59CB\u7FFB\u8BD1");
10123
10240
  try {
10124
10241
  const codeList2 = await container.get(ServiceMetaKind.NASLTranspiler).transpile({