@nasl/cli 0.1.0

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 (98) hide show
  1. package/README.md +84 -0
  2. package/out/apis/index.d.ts +17 -0
  3. package/out/apis/index.d.ts.map +1 -0
  4. package/out/apis/index.js +83 -0
  5. package/out/apis/index.js.map +1 -0
  6. package/out/bin/nasl-compile.d.ts +3 -0
  7. package/out/bin/nasl-compile.d.ts.map +1 -0
  8. package/out/bin/nasl-compile.js +22 -0
  9. package/out/bin/nasl-compile.js.map +1 -0
  10. package/out/bin/nasl.d.ts +3 -0
  11. package/out/bin/nasl.d.ts.map +1 -0
  12. package/out/bin/nasl.js +54 -0
  13. package/out/bin/nasl.js.map +1 -0
  14. package/out/bin/naslc.d.ts +3 -0
  15. package/out/bin/naslc.d.ts.map +1 -0
  16. package/out/bin/naslc.js +18 -0
  17. package/out/bin/naslc.js.map +1 -0
  18. package/out/commands/check.d.ts +5 -0
  19. package/out/commands/check.d.ts.map +1 -0
  20. package/out/commands/check.js +30 -0
  21. package/out/commands/check.js.map +1 -0
  22. package/out/commands/compile.d.ts +9 -0
  23. package/out/commands/compile.d.ts.map +1 -0
  24. package/out/commands/compile.js +85 -0
  25. package/out/commands/compile.js.map +1 -0
  26. package/out/commands/dev.d.ts +5 -0
  27. package/out/commands/dev.d.ts.map +1 -0
  28. package/out/commands/dev.js +16 -0
  29. package/out/commands/dev.js.map +1 -0
  30. package/out/commands/index.d.ts +5 -0
  31. package/out/commands/index.d.ts.map +1 -0
  32. package/out/commands/index.js +21 -0
  33. package/out/commands/index.js.map +1 -0
  34. package/out/commands/init.d.ts +5 -0
  35. package/out/commands/init.d.ts.map +1 -0
  36. package/out/commands/init.js +75 -0
  37. package/out/commands/init.js.map +1 -0
  38. package/out/commands/transpile.d.ts +5 -0
  39. package/out/commands/transpile.d.ts.map +1 -0
  40. package/out/commands/transpile.js +123 -0
  41. package/out/commands/transpile.js.map +1 -0
  42. package/out/index.d.ts +14 -0
  43. package/out/index.d.ts.map +1 -0
  44. package/out/index.js +30 -0
  45. package/out/index.js.map +1 -0
  46. package/out/services/compose.d.ts +3 -0
  47. package/out/services/compose.d.ts.map +1 -0
  48. package/out/services/compose.js +36 -0
  49. package/out/services/compose.js.map +1 -0
  50. package/out/services/resolve.d.ts +18 -0
  51. package/out/services/resolve.d.ts.map +1 -0
  52. package/out/services/resolve.js +107 -0
  53. package/out/services/resolve.js.map +1 -0
  54. package/out/services/resolveFiles.d.ts +18 -0
  55. package/out/services/resolveFiles.d.ts.map +1 -0
  56. package/out/services/resolveFiles.js +103 -0
  57. package/out/services/resolveFiles.js.map +1 -0
  58. package/out/types/api.d.ts +107 -0
  59. package/out/types/api.d.ts.map +1 -0
  60. package/out/types/api.js +6 -0
  61. package/out/types/api.js.map +1 -0
  62. package/out/types/config.d.ts +27 -0
  63. package/out/types/config.d.ts.map +1 -0
  64. package/out/types/config.js +19 -0
  65. package/out/types/config.js.map +1 -0
  66. package/out/types/createAxios.d.ts +2 -0
  67. package/out/types/createAxios.d.ts.map +1 -0
  68. package/out/types/createAxios.js +17 -0
  69. package/out/types/createAxios.js.map +1 -0
  70. package/out/types/index.d.ts +3 -0
  71. package/out/types/index.d.ts.map +1 -0
  72. package/out/types/index.js +19 -0
  73. package/out/types/index.js.map +1 -0
  74. package/out/utils/config.d.ts +19 -0
  75. package/out/utils/config.d.ts.map +1 -0
  76. package/out/utils/config.js +114 -0
  77. package/out/utils/config.js.map +1 -0
  78. package/out/utils/exec.d.ts +11 -0
  79. package/out/utils/exec.d.ts.map +1 -0
  80. package/out/utils/exec.js +27 -0
  81. package/out/utils/exec.js.map +1 -0
  82. package/out/utils/file.d.ts +9 -0
  83. package/out/utils/file.d.ts.map +1 -0
  84. package/out/utils/file.js +67 -0
  85. package/out/utils/file.js.map +1 -0
  86. package/out/utils/index.d.ts +4 -0
  87. package/out/utils/index.d.ts.map +1 -0
  88. package/out/utils/index.js +20 -0
  89. package/out/utils/index.js.map +1 -0
  90. package/out/utils/logger.d.ts +27 -0
  91. package/out/utils/logger.d.ts.map +1 -0
  92. package/out/utils/logger.js +49 -0
  93. package/out/utils/logger.js.map +1 -0
  94. package/out/utils/string.d.ts +2 -0
  95. package/out/utils/string.d.ts.map +1 -0
  96. package/out/utils/string.js +7 -0
  97. package/out/utils/string.js.map +1 -0
  98. package/package.json +47 -0
@@ -0,0 +1,27 @@
1
+ export type NASLRepresentation = 'NaturalTS' | 'NASL';
2
+ /**
3
+ * NASL 配置文件类型定义
4
+ */
5
+ export interface NASLConfig {
6
+ /** NASL 编译服务的基础 URL */
7
+ serverBaseURL: string;
8
+ /** NASL 语言的表示 */
9
+ representation: NASLRepresentation;
10
+ /** 命名空间解析策略 */
11
+ namespaceResolution: 'filename-as-namespace' | 'using-ts-namespace-in-one-file';
12
+ /** IDE 版本 */
13
+ ideVersion: string;
14
+ /** 源代码目录 */
15
+ srcDir: string;
16
+ /** 输出目录 */
17
+ outDir: string;
18
+ }
19
+ /**
20
+ * 默认配置
21
+ */
22
+ export declare const DEFAULT_CONFIG: NASLConfig;
23
+ /**
24
+ * 配置文件名称
25
+ */
26
+ export declare const CONFIG_FILE_NAME = "nasl.config.json";
27
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,MAAM,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,uBAAuB;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB;IACjB,cAAc,EAAE,kBAAkB,CAAC;IACnC,eAAe;IACf,mBAAmB,EAAE,uBAAuB,GAAG,gCAAgC,CAAC;IAChF,aAAa;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW;IACX,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,UAO5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,qBAAqB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG_FILE_NAME = exports.DEFAULT_CONFIG = void 0;
4
+ /**
5
+ * 默认配置
6
+ */
7
+ exports.DEFAULT_CONFIG = {
8
+ serverBaseURL: 'https://nasl.lcap.163yun.com/api/v1/nasl',
9
+ representation: 'NaturalTS',
10
+ namespaceResolution: 'filename-as-namespace',
11
+ ideVersion: '4.1',
12
+ srcDir: 'src',
13
+ outDir: 'out',
14
+ };
15
+ /**
16
+ * 配置文件名称
17
+ */
18
+ exports.CONFIG_FILE_NAME = 'nasl.config.json';
19
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":";;;AAoBA;;GAEG;AACU,QAAA,cAAc,GAAe;IACtC,aAAa,EAAE,0CAA0C;IACzD,cAAc,EAAE,WAAW;IAC3B,mBAAmB,EAAE,uBAAuB;IAC5C,UAAU,EAAE,KAAK;IACjB,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;CAChB,CAAC;AAEF;;GAEG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function createAxios(baseURL: string): import("axios").AxiosInstance;
2
+ //# sourceMappingURL=createAxios.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAxios.d.ts","sourceRoot":"","sources":["../../src/types/createAxios.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,iCAQ1C"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createAxios = createAxios;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ function createAxios(baseURL) {
9
+ return axios_1.default.create({
10
+ baseURL,
11
+ headers: {
12
+ 'Content-Type': 'application/json',
13
+ },
14
+ timeout: 120000,
15
+ });
16
+ }
17
+ //# sourceMappingURL=createAxios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAxios.js","sourceRoot":"","sources":["../../src/types/createAxios.ts"],"names":[],"mappings":";;;;;AAEA,kCAQC;AAVD,kDAA0B;AAE1B,SAAgB,WAAW,CAAC,OAAe;IACvC,OAAO,eAAK,CAAC,MAAM,CAAC;QAChB,OAAO;QACP,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;SACrC;QACD,OAAO,EAAE,MAAM;KAClB,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './config';
2
+ export * from './api';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config"), exports);
18
+ __exportStar(require("./api"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,wCAAsB"}
@@ -0,0 +1,19 @@
1
+ import type { NASLConfig } from '../types/config';
2
+ /**
3
+ * 查找配置文件所在目录
4
+ * 从当前目录向上查找,直到找到包含 nasl.config.json 的目录
5
+ */
6
+ export declare function findConfigDir(startDir?: string): string | null;
7
+ /**
8
+ * 加载配置文件
9
+ */
10
+ export declare function loadConfig(configDir?: string): NASLConfig;
11
+ /**
12
+ * 保存配置文件
13
+ */
14
+ export declare function saveConfig(config: NASLConfig, targetDir?: string): void;
15
+ /**
16
+ * 获取项目根目录(包含配置文件的目录)
17
+ */
18
+ export declare function getProjectRoot(): string;
19
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAoB7E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,CAyBzD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,GAAE,MAAsB,GAAG,IAAI,CAUtF;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CASvC"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.findConfigDir = findConfigDir;
37
+ exports.loadConfig = loadConfig;
38
+ exports.saveConfig = saveConfig;
39
+ exports.getProjectRoot = getProjectRoot;
40
+ const fs = __importStar(require("fs-extra"));
41
+ const path = __importStar(require("path"));
42
+ const config_1 = require("../types/config");
43
+ const logger_1 = require("./logger");
44
+ /**
45
+ * 查找配置文件所在目录
46
+ * 从当前目录向上查找,直到找到包含 nasl.config.json 的目录
47
+ */
48
+ function findConfigDir(startDir = process.cwd()) {
49
+ let currentDir = startDir;
50
+ // eslint-disable-next-line no-constant-condition
51
+ while (true) {
52
+ const configPath = path.join(currentDir, config_1.CONFIG_FILE_NAME);
53
+ if (fs.existsSync(configPath)) {
54
+ return currentDir;
55
+ }
56
+ const parentDir = path.dirname(currentDir);
57
+ // 已经到达根目录
58
+ if (parentDir === currentDir) {
59
+ return null;
60
+ }
61
+ currentDir = parentDir;
62
+ }
63
+ }
64
+ /**
65
+ * 加载配置文件
66
+ */
67
+ function loadConfig(configDir) {
68
+ const dir = configDir || findConfigDir();
69
+ if (!dir) {
70
+ logger_1.Logger.error(`未找到配置文件 ${config_1.CONFIG_FILE_NAME},请先运行 nasl-init 初始化配置`);
71
+ process.exit(1);
72
+ }
73
+ const configPath = path.join(dir, config_1.CONFIG_FILE_NAME);
74
+ try {
75
+ const content = fs.readFileSync(configPath, 'utf-8');
76
+ const config = JSON.parse(content);
77
+ // 验证必需字段
78
+ if (!config.serverBaseURL || !config.ideVersion || !config.srcDir || !config.outDir) {
79
+ logger_1.Logger.error('配置文件格式不正确,缺少必需字段');
80
+ process.exit(1);
81
+ }
82
+ return config;
83
+ }
84
+ catch (error) {
85
+ logger_1.Logger.error(`读取配置文件失败: ${error.message}`);
86
+ process.exit(1);
87
+ }
88
+ }
89
+ /**
90
+ * 保存配置文件
91
+ */
92
+ function saveConfig(config, targetDir = process.cwd()) {
93
+ const configPath = path.join(targetDir, config_1.CONFIG_FILE_NAME);
94
+ try {
95
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
96
+ logger_1.Logger.success(`配置文件已创建: ${configPath}`);
97
+ }
98
+ catch (error) {
99
+ logger_1.Logger.error(`保存配置文件失败: ${error.message}`);
100
+ process.exit(1);
101
+ }
102
+ }
103
+ /**
104
+ * 获取项目根目录(包含配置文件的目录)
105
+ */
106
+ function getProjectRoot() {
107
+ const configDir = findConfigDir();
108
+ if (!configDir) {
109
+ logger_1.Logger.error(`未找到配置文件 ${config_1.CONFIG_FILE_NAME},请先运行 nasl-init 初始化配置`);
110
+ process.exit(1);
111
+ }
112
+ return configDir;
113
+ }
114
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":";;;;;;;;;;;;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rB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 使用 spawnSync 的 shell inherit 模式,直接对接主进程的 stdio
3
+ * 如果 code 非 0,则直接结束
4
+ * @param args 命令参数,每一项可以为字符串或是字符串数组
5
+ * @example
6
+ * justExecSync('rm', '-rf', 'node_modules')
7
+ * justExecSync('git clone', 'xxx')
8
+ */
9
+ export declare function justExecSync(...args: Array<string>): void;
10
+ export declare function justExecCommandSync(command: string, cwd?: string): void;
11
+ //# sourceMappingURL=exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,QAIlD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,QAOhE"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.justExecSync = justExecSync;
4
+ exports.justExecCommandSync = justExecCommandSync;
5
+ const child_process_1 = require("child_process");
6
+ /**
7
+ * 使用 spawnSync 的 shell inherit 模式,直接对接主进程的 stdio
8
+ * 如果 code 非 0,则直接结束
9
+ * @param args 命令参数,每一项可以为字符串或是字符串数组
10
+ * @example
11
+ * justExecSync('rm', '-rf', 'node_modules')
12
+ * justExecSync('git clone', 'xxx')
13
+ */
14
+ function justExecSync(...args) {
15
+ const command = args.join(' ');
16
+ console.log(command);
17
+ justExecCommandSync(command);
18
+ }
19
+ function justExecCommandSync(command, cwd) {
20
+ console.log(command);
21
+ const result = (0, child_process_1.spawnSync)(command, { shell: true, stdio: 'inherit', cwd });
22
+ if (result.status) {
23
+ console.error(String(result.stderr || result.stdout));
24
+ process.exit(1);
25
+ }
26
+ }
27
+ //# sourceMappingURL=exec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":";;AAUA,oCAIC;AAED,kDAOC;AAvBD,iDAAiD;AAEjD;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,GAAG,IAAmB;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,SAAgB,mBAAmB,CAAC,OAAe,EAAE,GAAY;IAC7D,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1E,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 读取文件内容
3
+ */
4
+ export declare function readFileWithLog(filePath: string): string;
5
+ /**
6
+ * 写入文件
7
+ */
8
+ export declare function writeFileWithLog(filePath: string, content: string): void;
9
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/utils/file.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CASxE"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readFileWithLog = readFileWithLog;
37
+ exports.writeFileWithLog = writeFileWithLog;
38
+ const fs = __importStar(require("fs-extra"));
39
+ const path = __importStar(require("path"));
40
+ const logger_1 = require("./logger");
41
+ /**
42
+ * 读取文件内容
43
+ */
44
+ function readFileWithLog(filePath) {
45
+ try {
46
+ return fs.readFileSync(filePath, 'utf-8');
47
+ }
48
+ catch (error) {
49
+ logger_1.Logger.error(`读取文件失败 ${filePath}: ${error.message}`);
50
+ throw error;
51
+ }
52
+ }
53
+ /**
54
+ * 写入文件
55
+ */
56
+ function writeFileWithLog(filePath, content) {
57
+ try {
58
+ const dir = path.dirname(filePath);
59
+ fs.ensureDirSync(dir);
60
+ fs.writeFileSync(filePath, content, 'utf-8');
61
+ }
62
+ catch (error) {
63
+ logger_1.Logger.error(`写入文件失败 ${filePath}: ${error.message}`);
64
+ throw error;
65
+ }
66
+ }
67
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/utils/file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,0CAOC;AAKD,4CASC;AA5BD,6CAA+B;AAC/B,2CAA6B;AAC7B,qCAAkC;AAElC;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAgB;IAC5C,IAAI,CAAC;QACD,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,eAAM,CAAC,KAAK,CAAC,UAAU,QAAQ,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,QAAgB,EAAE,OAAe;IAC9D,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACtB,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,eAAM,CAAC,KAAK,CAAC,UAAU,QAAQ,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './logger';
2
+ export * from './config';
3
+ export * from './file';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./logger"), exports);
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./file"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,yCAAuB"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 日志工具类
3
+ */
4
+ export declare class Logger {
5
+ static newLine(): void;
6
+ /**
7
+ * 输出信息日志
8
+ */
9
+ static info(...args: any[]): void;
10
+ /**
11
+ * 输出成功日志
12
+ */
13
+ static success(...args: any[]): void;
14
+ /**
15
+ * 输出警告日志
16
+ */
17
+ static warn(...args: any[]): void;
18
+ /**
19
+ * 输出错误日志
20
+ */
21
+ static error(...args: any[]): void;
22
+ /**
23
+ * 输出调试日志
24
+ */
25
+ static debug(...args: any[]): void;
26
+ }
27
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,MAAM;IACf,MAAM,CAAC,OAAO,IAAI,IAAI;IAItB;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAIjC;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAIpC;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAIjC;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAIlC;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;CAKrC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Logger = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ /**
9
+ * 日志工具类
10
+ */
11
+ class Logger {
12
+ static newLine() {
13
+ console.log();
14
+ }
15
+ /**
16
+ * 输出信息日志
17
+ */
18
+ static info(...args) {
19
+ console.log(chalk_1.default.blue('[INFO]'), ...args);
20
+ }
21
+ /**
22
+ * 输出成功日志
23
+ */
24
+ static success(...args) {
25
+ console.log(chalk_1.default.green('[SUCCESS]'), ...args);
26
+ }
27
+ /**
28
+ * 输出警告日志
29
+ */
30
+ static warn(...args) {
31
+ console.warn(chalk_1.default.yellow('[WARN]'), ...args);
32
+ }
33
+ /**
34
+ * 输出错误日志
35
+ */
36
+ static error(...args) {
37
+ console.error(chalk_1.default.red('[ERROR]'), ...args);
38
+ }
39
+ /**
40
+ * 输出调试日志
41
+ */
42
+ static debug(...args) {
43
+ if (process.env.DEBUG) {
44
+ console.log(chalk_1.default.gray('[DEBUG]'), ...args);
45
+ }
46
+ }
47
+ }
48
+ exports.Logger = Logger;
49
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B;;GAEG;AACH,MAAa,MAAM;IACf,MAAM,CAAC,OAAO;QACV,OAAO,CAAC,GAAG,EAAE,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,IAAW;QACtB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,IAAW;QACzB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,GAAG,IAAW;QACtB,OAAO,CAAC,IAAI,CAAC,eAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,IAAW;QACvB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,IAAW;QACvB,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;QAChD,CAAC;IACL,CAAC;CACJ;AAzCD,wBAyCC"}
@@ -0,0 +1,2 @@
1
+ export declare function truncate(str: string, maxLength: number): string;
2
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UAEtD"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.truncate = truncate;
4
+ function truncate(str, maxLength) {
5
+ return str.length > maxLength ? str.slice(0, maxLength) + '...' : str;
6
+ }
7
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":";;AAAA,4BAEC;AAFD,SAAgB,QAAQ,CAAC,GAAW,EAAE,SAAiB;IACnD,OAAO,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;AAC1E,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@nasl/cli",
3
+ "version": "0.1.0",
4
+ "description": "NASL (Next Application Specific Language) CLI tool for checking, compiling and developing NASL code",
5
+ "main": "out/index.js",
6
+ "bin": {
7
+ "nasl": "out/bin/nasl.js",
8
+ "naslc": "out/bin/naslc.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsc --watch",
13
+ "lint": "eslint src --ext .ts",
14
+ "lint:fix": "eslint src --ext .ts --fix",
15
+ "format": "prettier --write \"src/**/*.ts\"",
16
+ "prepublishOnly": "pnpm run build",
17
+ "release": "npm publish --access public"
18
+ },
19
+ "keywords": [
20
+ "nasl",
21
+ "cli",
22
+ "compiler",
23
+ "lcap"
24
+ ],
25
+ "author": "",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@types/node": "^20.0.0",
29
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
30
+ "@typescript-eslint/parser": "^8.0.0",
31
+ "eslint": "^8.0.0",
32
+ "typescript": "^5.9.0"
33
+ },
34
+ "dependencies": {
35
+ "@types/fs-extra": "^11.0.4",
36
+ "axios": "^1.13.2",
37
+ "chalk": "^4.1.2",
38
+ "commander": "^11.0.0",
39
+ "eslint-config-alloy": "^5.1.2",
40
+ "fs-extra": "^11.3.2",
41
+ "globby": "^11.1.0",
42
+ "prettier": "^3.6.2"
43
+ },
44
+ "engines": {
45
+ "node": ">=16.0.0"
46
+ }
47
+ }