@nasl/cli 0.1.1 → 0.1.3

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.
Files changed (53) hide show
  1. package/README.md +5 -5
  2. package/build/index.html +23 -0
  3. package/build/index.js +113 -0
  4. package/build/nasl.bundle.js +59104 -0
  5. package/build/platformConfig.js +41 -0
  6. package/build/webpack.config.js +88 -0
  7. package/out/apis/index.js +1 -1
  8. package/out/bin/nasl.js +23 -4
  9. package/out/bin/nasl.js.map +1 -1
  10. package/out/bin/naslc.js +0 -0
  11. package/out/commands/build.d.ts +8 -0
  12. package/out/commands/build.d.ts.map +1 -0
  13. package/out/commands/build.js +54 -0
  14. package/out/commands/build.js.map +1 -0
  15. package/out/commands/check.d.ts +2 -1
  16. package/out/commands/check.d.ts.map +1 -1
  17. package/out/commands/check.js +19 -11
  18. package/out/commands/check.js.map +1 -1
  19. package/out/commands/compile.d.ts +4 -3
  20. package/out/commands/compile.d.ts.map +1 -1
  21. package/out/commands/compile.js +4 -6
  22. package/out/commands/compile.js.map +1 -1
  23. package/out/commands/dep.js +1 -1
  24. package/out/commands/dep.js.map +1 -1
  25. package/out/commands/dev.d.ts +7 -1
  26. package/out/commands/dev.d.ts.map +1 -1
  27. package/out/commands/dev.js +12 -2
  28. package/out/commands/dev.js.map +1 -1
  29. package/out/commands/index.d.ts +1 -0
  30. package/out/commands/index.d.ts.map +1 -1
  31. package/out/commands/index.js +1 -0
  32. package/out/commands/index.js.map +1 -1
  33. package/out/services/compose.d.ts.map +1 -1
  34. package/out/services/compose.js +29 -2
  35. package/out/services/compose.js.map +1 -1
  36. package/out/services/resolve.d.ts +1 -1
  37. package/out/services/resolve.d.ts.map +1 -1
  38. package/out/services/resolve.js +23 -21
  39. package/out/services/resolve.js.map +1 -1
  40. package/out/types/command.d.ts +4 -0
  41. package/out/types/command.d.ts.map +1 -0
  42. package/out/types/command.js +3 -0
  43. package/out/types/command.js.map +1 -0
  44. package/out/types/config.js +1 -1
  45. package/out/types/index.d.ts +1 -0
  46. package/out/types/index.d.ts.map +1 -1
  47. package/out/types/index.js +1 -0
  48. package/out/types/index.js.map +1 -1
  49. package/out/utils/logger.d.ts +1 -0
  50. package/out/utils/logger.d.ts.map +1 -1
  51. package/out/utils/logger.js +51 -0
  52. package/out/utils/logger.js.map +1 -1
  53. package/package.json +11 -9
package/README.md CHANGED
@@ -57,10 +57,10 @@ nasl compile
57
57
  nasl compile src/app.frontendTypes.pc.frontends.pc.views.dashboard.tsx
58
58
  # 或使用简写
59
59
  naslc src/app.frontendTypes.pc.frontends.pc.views.dashboard.tsx
60
- nasl compile "src/app.enums.*.ts"
61
- nasl compile "src/app.{*.entities.*.ts,structures.*.ts,enums.*.ts}"
62
- nasl compile "src/app.logics.*.ts"
63
- nasl compile "src/*.tsx"
60
+ naslc "src/app.enums.*.ts"
61
+ naslc "src/app.{*.entities.*.ts,structures.*.ts,enums.*.ts}"
62
+ naslc "src/app.logics.*.ts"
63
+ naslc "src/*.tsx"
64
64
  ```
65
65
 
66
66
  ### 检查 NASL 代码
@@ -95,7 +95,7 @@ nasl dep
95
95
  nasl dev
96
96
  ```
97
97
 
98
- 启动开发服务后,默认可以访问 http://localhost:3000 查看预览效果。
98
+ 启动开发服务后,默认可以访问 http://localhost:3100 查看预览效果。
99
99
 
100
100
  ## 开发 CLI 工具
101
101
 
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <title>NASL Preview</title>
7
+ <!-- <script src="https://ide-sandbox.lcap.codewave-test.163yun.com/dependency/lodash@4.17.21/lodash.js"></script> -->
8
+ <script src="https://ide-sandbox.lcap.codewave-test.163yun.com/dependency/vue@3.5.13/umd/vue.global.js"></script>
9
+ <script src="https://ide-sandbox.lcap.codewave-test.163yun.com/dependency/vue-router@4.5.0/umd/vue-router.global.js"></script>
10
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/pc-template-vue3@2.2.0/cloudAdminDesigner.umd.min.js"></script>
11
+ <link rel="stylesheet" type="text/css" href="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.1.0/dist-theme/index.css" />
12
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.1.0/dist-theme/index.js"></script>
13
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.1.0/dist-theme/nasl.ui.json"></script>
14
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/@lcap/element-plus@1.1.0/dist-theme/i18n.json"></script>
15
+ <link rel="stylesheet" type="text/css" href="//minio-api.codewave-test.163yun.com/lowcode-static/packages/extension/cw_chart_js@0.2.2/dist-theme/index.css" />
16
+ <script src="//minio-api.codewave-test.163yun.com/lowcode-static/packages/extension/cw_chart_js@0.2.2/dist-theme/index.js"></script>
17
+ <script src="/nasl.bundle.js"></script>
18
+ <!-- webpack will inject bundle.js here -->
19
+ </head>
20
+ <body>
21
+ <div id="app"></div>
22
+ </body>
23
+ </html>
package/build/index.js ADDED
@@ -0,0 +1,113 @@
1
+ import { platformConfig } from './platformConfig';
2
+ import { get, pick } from 'lodash';
3
+
4
+ // 加载应用所需的文件
5
+ import '@/backendMock';
6
+ import { routes, metaData } from '@/router';
7
+ import '@/index.css';
8
+
9
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
10
+
11
+ // 应用初始化
12
+ class AppHandler {
13
+ constructor() {}
14
+
15
+ // 处理路由相关
16
+ handleRouter() {
17
+ // messager.sendCommand('getRoutes', [JSON.stringify(routes)]);
18
+ // window.afterRouter = async (to, from) => {
19
+ // try {
20
+ // // 获取 messager 实例
21
+ // const messager = window.messager;
22
+ // if (messager && typeof messager.sendCommand === 'function') {
23
+ // await messager.sendCommand('routeChanged', to.path);
24
+ // }
25
+ // } catch (err) {
26
+ // console.error('路由变化处理失败:', err);
27
+ // }
28
+ // };
29
+ }
30
+
31
+ initLogic(options = {}, Basic) {
32
+ const { logicsMap, backendApp } = options;
33
+ const logics = {};
34
+ const context = {
35
+ app: backendApp
36
+ };
37
+
38
+ const entityRE = /entities\.(\w+?)\.logics/;
39
+
40
+ Object.keys(logicsMap).forEach((path) => {
41
+ const isEntity = entityRE.test(path);
42
+ const backendPath = path.replace(entityRE, 'entities.$1Entity');
43
+ const prevPath = backendPath.split('.').slice(0, -1).join('.');
44
+
45
+ logics[path] = async function ({ query, body }) {
46
+ const func = get(context, backendPath);
47
+ const obj = get(context, prevPath);
48
+ body = body === undefined ? undefined : JSON.parse(JSON.stringify(body));
49
+
50
+ let result;
51
+ if (isEntity) {
52
+ if (path.endsWith('.get') || path.endsWith('.delete')) {
53
+ query = query === undefined ? undefined : JSON.parse(JSON.stringify(query));
54
+ result = func.call(obj, Object.values(query)[0]);
55
+ } else if (path.endsWith('.update')) {
56
+ if (body.properties) {
57
+ if (body.entity) body.entity = pick(body.entity, body.properties);
58
+ if (body.entities) body.entities = body.entities.map((entity) => pick(entity, body.properties));
59
+ }
60
+ result = func.call(obj, body.entity);
61
+ } else {
62
+ result = func.call(obj, body);
63
+ }
64
+ } else {
65
+ const argNames =
66
+ func
67
+ .toString()
68
+ .match(/function\s*\w*\(([^)]*?)\)\s*\{/)?.[1]
69
+ ?.split(',')
70
+ .map((name) => name.replace(/=.*$|\/\*.*?\*\//g, '').trim()) || [];
71
+ const args = argNames.map((name) => body[name]);
72
+ result = func.call(obj, ...args);
73
+ }
74
+
75
+ return result === undefined ? undefined : JSON.parse(JSON.stringify(result));
76
+ };
77
+ });
78
+
79
+ Basic.Config.globalProperties.set('$logics', logics);
80
+
81
+ return {
82
+ logics
83
+ };
84
+ }
85
+
86
+ async initialize() {
87
+ window.lcapStandardUI = window.ElementPlus;
88
+ try {
89
+ // this.handleRouter();
90
+ const override = {
91
+ enabled: true,
92
+ initLogic: this.initLogic,
93
+ };
94
+ let app = await window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, routes, { ...metaData, backendApp: window.backendApp, override });
95
+ app.use(window.Cw_chart_js);
96
+ app.use(window.ElementPlus);
97
+ window.frontendApp = app;
98
+
99
+ app.config.globalProperties.$utils.__proto__.isArrayInBounds = function (arr, index, canLast) {
100
+ return true;
101
+ }
102
+ } catch (error) {
103
+ console.error('Failed to initialize: sandbox:\n', error);
104
+ }
105
+ console.log('应用初始化完成');
106
+ }
107
+ }
108
+
109
+ // 启动应用
110
+ const appHandler = new AppHandler();
111
+ appHandler.initialize().catch((error) => {
112
+ console.error('应用初始化失败:', error);
113
+ });