@nasl/cli 0.1.13 → 0.1.15
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/bin/nasl.mjs +265 -2
- package/dist/bin/nasl.mjs.map +1 -1
- package/dist/bin/naslc.mjs +6 -2
- package/dist/bin/naslc.mjs.map +1 -1
- package/dist/index.mjs +233 -2
- package/dist/index.mjs.map +1 -1
- package/out/apis/compileApi.d.ts +17 -0
- package/out/apis/compileApi.d.ts.map +1 -0
- package/out/apis/compileApi.js +83 -0
- package/out/apis/compileApi.js.map +1 -0
- package/out/apis/createAppApi.d.ts +31 -0
- package/out/apis/createAppApi.d.ts.map +1 -0
- package/out/apis/createAppApi.js +42 -0
- package/out/apis/createAppApi.js.map +1 -0
- package/out/apis/index.d.ts +2 -16
- package/out/apis/index.d.ts.map +1 -1
- package/out/apis/index.js +16 -80
- package/out/apis/index.js.map +1 -1
- package/out/apis/transformApi.d.ts +7 -0
- package/out/apis/transformApi.d.ts.map +1 -0
- package/out/apis/transformApi.js +20 -0
- package/out/apis/transformApi.js.map +1 -0
- package/out/bin/nasl.js +32 -0
- package/out/bin/nasl.js.map +1 -1
- package/out/commands/createAppInIde.d.ts +6 -0
- package/out/commands/createAppInIde.d.ts.map +1 -0
- package/out/commands/createAppInIde.js +128 -0
- package/out/commands/createAppInIde.js.map +1 -0
- package/out/commands/index.d.ts +2 -0
- package/out/commands/index.d.ts.map +1 -1
- package/out/commands/index.js +2 -0
- package/out/commands/index.js.map +1 -1
- package/out/commands/transform.d.ts +10 -0
- package/out/commands/transform.d.ts.map +1 -0
- package/out/commands/transform.js +134 -0
- package/out/commands/transform.js.map +1 -0
- package/out/services/resolve.d.ts.map +1 -1
- package/out/services/resolve.js +5 -1
- package/out/services/resolve.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ServerOptions, TranspileOptions, TranspileResult, FileInfo } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 编译 NASL 代码
|
|
4
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
5
|
+
*/
|
|
6
|
+
export declare function compileApi(fullNaturalTS: string, options: ServerOptions): Promise<FileInfo[]>;
|
|
7
|
+
/**
|
|
8
|
+
* 检查 NASL 代码
|
|
9
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
10
|
+
*/
|
|
11
|
+
export declare function checkApi(fullNaturalTS: string, options: ServerOptions): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* 转换 NASL 代码为 AST JSON
|
|
14
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
15
|
+
*/
|
|
16
|
+
export declare function transpile(files: FileInfo[], options: TranspileOptions): Promise<TranspileResult>;
|
|
17
|
+
//# sourceMappingURL=compileApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileApi.d.ts","sourceRoot":"","sources":["../../src/apis/compileApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,aAAa,EAAE,gBAAgB,EAA8B,eAAe,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKvI;;;GAGG;AACH,wBAAsB,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAiCnG;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAW7F;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAmBtG"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compileApi = compileApi;
|
|
4
|
+
exports.checkApi = checkApi;
|
|
5
|
+
exports.transpile = transpile;
|
|
6
|
+
const createAxios_1 = require("./createAxios");
|
|
7
|
+
const logger_1 = require("../utils/logger");
|
|
8
|
+
const string_1 = require("../utils/string");
|
|
9
|
+
/**
|
|
10
|
+
* 编译 NASL 代码
|
|
11
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
12
|
+
*/
|
|
13
|
+
async function compileApi(fullNaturalTS, options) {
|
|
14
|
+
// 这里需要调用实际的编译服务接口
|
|
15
|
+
// 示例实现:
|
|
16
|
+
const axios = (0, createAxios_1.createAxios)(options.serverBaseURL);
|
|
17
|
+
const res = await axios.post(`/compile/tsx?ideVersion=${options.ideVersion}&needAnnotation=true`, fullNaturalTS, {
|
|
18
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
19
|
+
});
|
|
20
|
+
const data = res.data;
|
|
21
|
+
if (data.code !== 200)
|
|
22
|
+
throw new Error(data.message);
|
|
23
|
+
const { bundle } = data.result;
|
|
24
|
+
const fileMap = bundle.frontendBundle.files;
|
|
25
|
+
const files = Object.keys(fileMap).map((key) => {
|
|
26
|
+
const fileInfo = {
|
|
27
|
+
path: key,
|
|
28
|
+
content: fileMap[key].code || '',
|
|
29
|
+
};
|
|
30
|
+
if (typeof fileInfo.content !== 'string') {
|
|
31
|
+
logger_1.defaultLogger.error(`文件 ${key} 内容不是字符串`, fileMap[key]);
|
|
32
|
+
}
|
|
33
|
+
return fileInfo;
|
|
34
|
+
});
|
|
35
|
+
files.push({
|
|
36
|
+
path: 'backendMock.js',
|
|
37
|
+
content: `(function () {
|
|
38
|
+
${bundle.backendBundle}
|
|
39
|
+
window.backendApp = app;
|
|
40
|
+
})();
|
|
41
|
+
`,
|
|
42
|
+
});
|
|
43
|
+
return files;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 检查 NASL 代码
|
|
47
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
48
|
+
*/
|
|
49
|
+
async function checkApi(fullNaturalTS, options) {
|
|
50
|
+
const axios = (0, createAxios_1.createAxios)(options.serverBaseURL);
|
|
51
|
+
const res = await axios.post(`/check/tsx?ideVersion=${options.ideVersion}`, fullNaturalTS, {
|
|
52
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
53
|
+
});
|
|
54
|
+
const result = res.data.result;
|
|
55
|
+
const errors = (result.errors || []);
|
|
56
|
+
console.log(`共检查到 ${errors.length} 个错误`);
|
|
57
|
+
if (errors.length > 0)
|
|
58
|
+
return (0, string_1.truncate)(result.errorStr, 10000);
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 转换 NASL 代码为 AST JSON
|
|
63
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
64
|
+
*/
|
|
65
|
+
async function transpile(files, options) {
|
|
66
|
+
// 这里需要调用实际的转换服务接口
|
|
67
|
+
// 示例实现:
|
|
68
|
+
throw new Error('transpile API 需要实现');
|
|
69
|
+
// 期望的实现逻辑:
|
|
70
|
+
// 1. 准备请求数据
|
|
71
|
+
// 2. 调用服务端接口
|
|
72
|
+
// 3. 返回 AST JSON 结果
|
|
73
|
+
// return {
|
|
74
|
+
// success: true,
|
|
75
|
+
// files: [
|
|
76
|
+
// {
|
|
77
|
+
// path: 'output.json',
|
|
78
|
+
// content: '{"type": "Program", ...}',
|
|
79
|
+
// },
|
|
80
|
+
// ],
|
|
81
|
+
// };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=compileApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compileApi.js","sourceRoot":"","sources":["../../src/apis/compileApi.ts"],"names":[],"mappings":";;AASA,gCAiCC;AAMD,4BAWC;AAMD,8BAmBC;AAnFD,+CAA4C;AAC5C,4CAAgD;AAChD,4CAA2C;AAE3C;;;GAGG;AACI,KAAK,UAAU,UAAU,CAAC,aAAqB,EAAE,OAAsB;IAC1E,kBAAkB;IAClB,QAAQ;IACR,MAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,OAAO,CAAC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M,KAAK,CAAC,IAAI,CAAC,yBAAyB,OAAO,CAAC,UAAU,EAAE,EAAE,aAAa,EAAE;QACvF,OAAO,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE;KAC5C,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;IAC/B,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAuD,CAAC;IAC3F,OAAO,CAAC,GAAG,CAAC,QAAQ,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC;IACzC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAA,iBAAQ,EAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,EAAE,CAAC;AACd,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,SAAS,CAAC,KAAiB,EAAE,OAAyB;IACxE,kBAAkB;IAClB,QAAQ;IACR,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAEtC,WAAW;IACX,YAAY;IACZ,aAAa;IACb,oBAAoB;IAEpB,WAAW;IACX,mBAAmB;IACnB,aAAa;IACb,QAAQ;IACR,6BAA6B;IAC7B,6CAA6C;IAC7C,SAAS;IACT,OAAO;IACP,KAAK;AACT,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建应用同步接口
|
|
3
|
+
*/
|
|
4
|
+
export interface CreateAppSyncOptions {
|
|
5
|
+
packageName: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
/** 服务器基础 URL */
|
|
8
|
+
serverBaseURL: string;
|
|
9
|
+
/** IDE 版本 */
|
|
10
|
+
ideVersion: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 创建应用同步结果
|
|
14
|
+
*/
|
|
15
|
+
export interface CreateAppSyncResult {
|
|
16
|
+
/** 是否成功 */
|
|
17
|
+
success: boolean;
|
|
18
|
+
/** 应用 ID */
|
|
19
|
+
appId?: string;
|
|
20
|
+
/** 应用 URL */
|
|
21
|
+
appURL?: string;
|
|
22
|
+
/** 消息 */
|
|
23
|
+
message?: string;
|
|
24
|
+
/** 错误信息 */
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 创建应用同步
|
|
29
|
+
*/
|
|
30
|
+
export declare function createAppSyncApi(fullNaturalTS: string, options: CreateAppSyncOptions): Promise<CreateAppSyncResult>;
|
|
31
|
+
//# sourceMappingURL=createAppApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAppApi.d.ts","sourceRoot":"","sources":["../../src/apis/createAppApi.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa;IACb,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,WAAW;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAClC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,oBAAoB,GAC9B,OAAO,CAAC,mBAAmB,CAAC,CAiC9B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAppSyncApi = createAppSyncApi;
|
|
4
|
+
const createAxios_1 = require("./createAxios");
|
|
5
|
+
/**
|
|
6
|
+
* 创建应用同步
|
|
7
|
+
*/
|
|
8
|
+
async function createAppSyncApi(fullNaturalTS, options) {
|
|
9
|
+
const url = new URL(options.serverBaseURL);
|
|
10
|
+
const origin = url.origin + '/app-ai-creator';
|
|
11
|
+
const axios = (0, createAxios_1.createAxios)(origin);
|
|
12
|
+
try {
|
|
13
|
+
const res = await axios.post('/api/createAppSync', {
|
|
14
|
+
fullNaturalTS,
|
|
15
|
+
packageName: options.packageName,
|
|
16
|
+
appName: options.appName,
|
|
17
|
+
hostname: url.hostname,
|
|
18
|
+
enableAuthTemplate: false,
|
|
19
|
+
ideVersion: options.ideVersion,
|
|
20
|
+
fullVersion: `${options.ideVersion}.0`,
|
|
21
|
+
});
|
|
22
|
+
if (res.data.success) {
|
|
23
|
+
return {
|
|
24
|
+
success: true,
|
|
25
|
+
appId: res.data.data?.appId,
|
|
26
|
+
appURL: res.data.data?.appURL,
|
|
27
|
+
message: res.data.data?.message,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: res.data.message || '应用创建失败',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.log(error);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=createAppApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAppApi.js","sourceRoot":"","sources":["../../src/apis/createAppApi.ts"],"names":[],"mappings":";;AAiCA,4CAoCC;AArED,+CAA4C;AA8B5C;;GAEG;AACI,KAAK,UAAU,gBAAgB,CAClC,aAAqB,EACrB,OAA6B;IAE7B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,iBAAiB,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,MAAM,CAAC,CAAC;IAElC,IAAI,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE;YAC/C,aAAa;YACb,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,kBAAkB,EAAE,KAAK;YACzB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,WAAW,EAAE,GAAG,OAAO,CAAC,UAAU,IAAI;SACzC,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK;gBAC3B,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM;gBAC7B,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO;aAClC,CAAC;QACN,CAAC;aAAM,CAAC;YACJ,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,QAAQ;aACtC,CAAC;QACN,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
package/out/apis/index.d.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* 编译 NASL 代码
|
|
4
|
-
* TODO: 实现具体的 API 调用逻辑
|
|
5
|
-
*/
|
|
6
|
-
export declare function compileApi(fullNaturalTS: string, options: ServerOptions): Promise<FileInfo[]>;
|
|
7
|
-
/**
|
|
8
|
-
* 检查 NASL 代码
|
|
9
|
-
* TODO: 实现具体的 API 调用逻辑
|
|
10
|
-
*/
|
|
11
|
-
export declare function checkApi(fullNaturalTS: string, options: ServerOptions): Promise<string>;
|
|
12
|
-
/**
|
|
13
|
-
* 转换 NASL 代码为 AST JSON
|
|
14
|
-
* TODO: 实现具体的 API 调用逻辑
|
|
15
|
-
*/
|
|
16
|
-
export declare function transpile(files: FileInfo[], options: TranspileOptions): Promise<TranspileResult>;
|
|
1
|
+
export * from './compileApi';
|
|
2
|
+
export * from './createAppApi';
|
|
17
3
|
//# sourceMappingURL=index.d.ts.map
|
package/out/apis/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
|
package/out/apis/index.js
CHANGED
|
@@ -1,83 +1,19 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
exports
|
|
5
|
-
exports.transpile = transpile;
|
|
6
|
-
const createAxios_1 = require("./createAxios");
|
|
7
|
-
const logger_1 = require("../utils/logger");
|
|
8
|
-
const string_1 = require("../utils/string");
|
|
9
|
-
/**
|
|
10
|
-
* 编译 NASL 代码
|
|
11
|
-
* TODO: 实现具体的 API 调用逻辑
|
|
12
|
-
*/
|
|
13
|
-
async function compileApi(fullNaturalTS, options) {
|
|
14
|
-
// 这里需要调用实际的编译服务接口
|
|
15
|
-
// 示例实现:
|
|
16
|
-
const axios = (0, createAxios_1.createAxios)(options.serverBaseURL);
|
|
17
|
-
const res = await axios.post(`/compile/tsx?ideVersion=${options.ideVersion}&needAnnotation=true`, fullNaturalTS, {
|
|
18
|
-
headers: { 'Content-Type': 'text/plain' },
|
|
19
|
-
});
|
|
20
|
-
const data = res.data;
|
|
21
|
-
if (data.code !== 200)
|
|
22
|
-
throw new Error(data.message);
|
|
23
|
-
const { bundle } = data.result;
|
|
24
|
-
const fileMap = bundle.frontendBundle.files;
|
|
25
|
-
const files = Object.keys(fileMap).map((key) => {
|
|
26
|
-
const fileInfo = {
|
|
27
|
-
path: key,
|
|
28
|
-
content: fileMap[key].code || '',
|
|
29
|
-
};
|
|
30
|
-
if (typeof fileInfo.content !== 'string') {
|
|
31
|
-
logger_1.defaultLogger.error(`文件 ${key} 内容不是字符串`, fileMap[key]);
|
|
32
|
-
}
|
|
33
|
-
return fileInfo;
|
|
34
|
-
});
|
|
35
|
-
files.push({
|
|
36
|
-
path: 'backendMock.js',
|
|
37
|
-
content: `(function () {
|
|
38
|
-
${bundle.backendBundle}
|
|
39
|
-
window.backendApp = app;
|
|
40
|
-
})();
|
|
41
|
-
`,
|
|
42
|
-
});
|
|
43
|
-
return files;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 检查 NASL 代码
|
|
47
|
-
* TODO: 实现具体的 API 调用逻辑
|
|
48
|
-
*/
|
|
49
|
-
async function checkApi(fullNaturalTS, options) {
|
|
50
|
-
const axios = (0, createAxios_1.createAxios)(options.serverBaseURL);
|
|
51
|
-
const res = await axios.post(`/check/tsx?ideVersion=${options.ideVersion}`, fullNaturalTS, {
|
|
52
|
-
headers: { 'Content-Type': 'text/plain' },
|
|
53
|
-
});
|
|
54
|
-
const result = res.data.result;
|
|
55
|
-
const errors = (result.errors || []);
|
|
56
|
-
console.log(`共检查到 ${errors.length} 个错误`);
|
|
57
|
-
if (errors.length > 0)
|
|
58
|
-
return (0, string_1.truncate)(result.errorStr, 10000);
|
|
59
|
-
return '';
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 转换 NASL 代码为 AST JSON
|
|
63
|
-
* TODO: 实现具体的 API 调用逻辑
|
|
64
|
-
*/
|
|
65
|
-
async function transpile(files, options) {
|
|
66
|
-
// 这里需要调用实际的转换服务接口
|
|
67
|
-
// 示例实现:
|
|
68
|
-
throw new Error('transpile API 需要实现');
|
|
69
|
-
// 期望的实现逻辑:
|
|
70
|
-
// 1. 准备请求数据
|
|
71
|
-
// 2. 调用服务端接口
|
|
72
|
-
// 3. 返回 AST JSON 结果
|
|
73
|
-
// return {
|
|
74
|
-
// success: true,
|
|
75
|
-
// files: [
|
|
76
|
-
// {
|
|
77
|
-
// path: 'output.json',
|
|
78
|
-
// content: '{"type": "Program", ...}',
|
|
79
|
-
// },
|
|
80
|
-
// ],
|
|
81
|
-
// };
|
|
82
|
-
}
|
|
17
|
+
__exportStar(require("./compileApi"), exports);
|
|
18
|
+
__exportStar(require("./createAppApi"), exports);
|
|
83
19
|
//# sourceMappingURL=index.js.map
|
package/out/apis/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,iDAA+B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ServerOptions, FileInfo } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 编译 NASL 代码
|
|
4
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
5
|
+
*/
|
|
6
|
+
export declare function transformJson2FilesApi(jsonContent: string, options: ServerOptions): Promise<FileInfo[]>;
|
|
7
|
+
//# sourceMappingURL=transformApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformApi.d.ts","sourceRoot":"","sources":["../../src/apis/transformApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,aAAa,EAAiE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGvI;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAS7G"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformJson2FilesApi = transformJson2FilesApi;
|
|
4
|
+
const createAxios_1 = require("./createAxios");
|
|
5
|
+
/**
|
|
6
|
+
* 编译 NASL 代码
|
|
7
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
8
|
+
*/
|
|
9
|
+
async function transformJson2FilesApi(jsonContent, options) {
|
|
10
|
+
// 示例实现:
|
|
11
|
+
const axios = (0, createAxios_1.createAxios)(options.serverBaseURL);
|
|
12
|
+
const res = await axios.post(`/transform/json2files?ideVersion=${options.ideVersion}`, jsonContent, {
|
|
13
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
14
|
+
});
|
|
15
|
+
const data = res.data;
|
|
16
|
+
if (data.code !== 200)
|
|
17
|
+
throw new Error(data.message);
|
|
18
|
+
return data.result;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=transformApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformApi.js","sourceRoot":"","sources":["../../src/apis/transformApi.ts"],"names":[],"mappings":";;AAOA,wDASC;AAfD,+CAA4C;AAE5C;;;GAGG;AACI,KAAK,UAAU,sBAAsB,CAAC,WAAmB,EAAE,OAAsB;IACpF,QAAQ;IACR,MAAM,KAAK,GAAG,IAAA,yBAAW,EAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,oCAAoC,OAAO,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE;QAChG,OAAO,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE;KAC5C,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IACtB,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC,MAAM,CAAC;AACvB,CAAC"}
|
package/out/bin/nasl.js
CHANGED
|
@@ -88,6 +88,38 @@ program
|
|
|
88
88
|
process.exit(1);
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
|
+
program
|
|
92
|
+
.command('create-app-in-ide [entry]')
|
|
93
|
+
.description('在 IDE 中创建应用')
|
|
94
|
+
.option('-v, --verbose', '显示详细信息,如依赖分析树')
|
|
95
|
+
.action(async (entry, options) => {
|
|
96
|
+
try {
|
|
97
|
+
await (0, commands_1.createAppInIde)(entry, options);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
logger_1.defaultLogger.error(`创建应用过程发生错误:${error.message}`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
program
|
|
105
|
+
.command('transform <transformType> [entry]')
|
|
106
|
+
.description('转换文件格式\n transformType: files2full (将 src 文件组合成 fullNaturalTS), json2files (将 JSON 转换为文件, 待实现), files2json (将 src 文件转换为 JSON)')
|
|
107
|
+
.option('-o, --output <outputPath>', '指定输出路径')
|
|
108
|
+
.option('-v, --verbose', '显示详细信息,如依赖分析树')
|
|
109
|
+
.action(async (transformType, entry, options) => {
|
|
110
|
+
try {
|
|
111
|
+
const validTypes = ['files2full', 'json2files', 'files2json'];
|
|
112
|
+
if (!validTypes.includes(transformType)) {
|
|
113
|
+
logger_1.defaultLogger.error(`无效的转换类型: ${transformType}。支持的类型: ${validTypes.join(', ')}`);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
await (0, commands_1.transform)(transformType, entry, options);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
logger_1.defaultLogger.error(`转换过程发生错误:${error.message}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
91
123
|
program.parse(process.argv);
|
|
92
124
|
// 如果没有提供任何命令,显示帮助信息
|
|
93
125
|
if (!process.argv.slice(2).length) {
|
package/out/bin/nasl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nasl.js","sourceRoot":"","sources":["../../src/bin/nasl.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AAEpC,
|
|
1
|
+
{"version":3,"file":"nasl.js","sourceRoot":"","sources":["../../src/bin/nasl.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AAEpC,0CAAsG;AAEtG,4CAAgD;AAChD,sEAAqC;AACrC,yCAAsC;AAGtC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAG9B,MAAM,gBAAgB,GAAG;;;;;yBAKA,CAAC;AAE1B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC;;;0BAGP,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,sBAAG,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAChG,OAAO;KACF,OAAO,CAAC,MAAM,CAAC;KACf,WA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AAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,OAAO,CAAC,UAAU,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAppInIde.d.ts","sourceRoot":"","sources":["../../src/commands/createAppInIde.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAwB/C;;GAEG;AACH,wBAAsB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,iBAkE5E"}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.createAppInIde = createAppInIde;
|
|
40
|
+
const utils_1 = require("../utils");
|
|
41
|
+
const apis_1 = require("../apis");
|
|
42
|
+
const compose_1 = require("../services/compose");
|
|
43
|
+
const resolve_1 = require("../services/resolve");
|
|
44
|
+
const fs = __importStar(require("fs-extra"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const config_1 = require("../utils/config");
|
|
47
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
48
|
+
/**
|
|
49
|
+
* 获取 specs 下第1个文件夹的名字
|
|
50
|
+
*/
|
|
51
|
+
function getFirstSpecFolderName(projectRoot) {
|
|
52
|
+
const dirname = path.basename(projectRoot);
|
|
53
|
+
const specsDir = path.join(projectRoot, 'specs');
|
|
54
|
+
if (!fs.existsSync(specsDir))
|
|
55
|
+
return dirname;
|
|
56
|
+
const entries = fs.readdirSync(specsDir, { withFileTypes: true });
|
|
57
|
+
const folders = entries
|
|
58
|
+
.filter(entry => entry.isDirectory())
|
|
59
|
+
.map(entry => entry.name);
|
|
60
|
+
if (folders.length === 0)
|
|
61
|
+
return dirname;
|
|
62
|
+
return folders[0];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 创建应用在 IDE 中
|
|
66
|
+
*/
|
|
67
|
+
async function createAppInIde(entry, options) {
|
|
68
|
+
const logger = options?.logger || utils_1.defaultLogger;
|
|
69
|
+
logger.info('开始创建应用在 IDE 中...');
|
|
70
|
+
// 收集需要处理的文件
|
|
71
|
+
const { collectedFiles, config } = await (0, resolve_1.resolveNASLFiles)(entry, logger, false, options?.verbose);
|
|
72
|
+
// 生成 fullNaturalTS
|
|
73
|
+
logger.newLine();
|
|
74
|
+
logger.info('正在生成 NaturalTS 代码...');
|
|
75
|
+
let fullNaturalTS = '';
|
|
76
|
+
try {
|
|
77
|
+
fullNaturalTS = (0, compose_1.composeToString)(collectedFiles);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
logger.error(`生成 NaturalTS 代码失败: ${error.message}`);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
// 获取 specs 下第1个文件夹
|
|
84
|
+
const projectRoot = (0, config_1.getProjectRoot)();
|
|
85
|
+
const firstSpecFolderName = getFirstSpecFolderName(projectRoot);
|
|
86
|
+
const suffix = (0, dayjs_1.default)().format('MMDDHHmmss');
|
|
87
|
+
const appName = `${firstSpecFolderName}_${suffix}`;
|
|
88
|
+
let cleaned = firstSpecFolderName.replace(/[^a-zA-Z0-9]/g, '').replace(/^\d+/, '');
|
|
89
|
+
if (!cleaned)
|
|
90
|
+
cleaned = 'app';
|
|
91
|
+
const packageName = `${cleaned}${suffix}`;
|
|
92
|
+
logger.info(`应用名称: ${appName}`);
|
|
93
|
+
logger.info(`包名: ${packageName}`);
|
|
94
|
+
logger.info(`IDE 版本: ${config.ideVersion}`);
|
|
95
|
+
logger.info(`完整版本: ${config.ideVersion}.0`);
|
|
96
|
+
// 调用创建应用 API
|
|
97
|
+
logger.newLine();
|
|
98
|
+
logger.info('正在调用创建应用服务...');
|
|
99
|
+
try {
|
|
100
|
+
const result = await (0, apis_1.createAppSyncApi)(fullNaturalTS, {
|
|
101
|
+
packageName: packageName,
|
|
102
|
+
appName: appName,
|
|
103
|
+
serverBaseURL: config.serverBaseURL,
|
|
104
|
+
ideVersion: config.ideVersion,
|
|
105
|
+
});
|
|
106
|
+
if (result.success) {
|
|
107
|
+
logger.success('应用创建成功!');
|
|
108
|
+
if (result.appURL) {
|
|
109
|
+
logger.info(`应用 URL: ${result.appURL}`);
|
|
110
|
+
}
|
|
111
|
+
if (result.appId) {
|
|
112
|
+
logger.info(`应用 ID: ${result.appId}`);
|
|
113
|
+
}
|
|
114
|
+
if (result.message) {
|
|
115
|
+
logger.info(result.message);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
logger.error(`应用创建失败: ${result.error || '未知错误'}`);
|
|
120
|
+
throw new Error(result.error || '应用创建失败');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger.error(`调用创建应用服务失败: ${error.message}`);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=createAppInIde.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAppInIde.js","sourceRoot":"","sources":["../../src/commands/createAppInIde.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,wCAkEC;AAjGD,oCAAyC;AACzC,kCAA2C;AAC3C,iDAAsD;AACtD,iDAAuD;AAEvD,6CAA+B;AAC/B,2CAA6B;AAC7B,4CAAiD;AACjD,kDAA0B;AAE1B;;GAEG;AACH,SAAS,sBAAsB,CAAC,WAAmB;IAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACjD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,OAAO,CAAC;IAE7C,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,I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,OAAO,EAAE,CAAC;gBACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAChC,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,KAAK,CAAC,WAAW,MAAM,CAAC,KAAK,IAAI,MAAM,EAAE,CAAC,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,QAAQ,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,eAAgB,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACxD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
package/out/commands/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
package/out/commands/index.js
CHANGED
|
@@ -20,4 +20,6 @@ __exportStar(require("./check"), exports);
|
|
|
20
20
|
__exportStar(require("./dep"), exports);
|
|
21
21
|
__exportStar(require("./dev"), exports);
|
|
22
22
|
__exportStar(require("./build"), exports);
|
|
23
|
+
__exportStar(require("./createAppInIde"), exports);
|
|
24
|
+
__exportStar(require("./transform"), exports);
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,4CAA0B;AAC1B,0CAAwB;AACxB,wCAAsB;AACtB,wCAAsB;AACtB,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,4CAA0B;AAC1B,0CAAwB;AACxB,wCAAsB;AACtB,wCAAsB;AACtB,0CAAwB;AACxB,mDAAiC;AACjC,8CAA4B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CommandOptions } from '../types';
|
|
2
|
+
export type TransformType = 'files2full' | 'json2files' | 'files2json';
|
|
3
|
+
export interface TransformOptions extends CommandOptions {
|
|
4
|
+
output?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 转换命令 - 支持多种文件转换格式
|
|
8
|
+
*/
|
|
9
|
+
export declare function transform(transformType: TransformType, entry?: string, options?: TransformOptions): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/commands/transform.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;AAEvE,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAkGD;;GAEG;AACH,wBAAsB,SAAS,CAC3B,aAAa,EAAE,aAAa,EAC5B,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,gBAAgB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAWf"}
|