@nasl/cli 0.1.14 → 0.1.16
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/build/nasl.bundle.js +4970 -4941
- package/dist/bin/nasl.mjs +272 -1
- package/dist/bin/nasl.mjs.map +1 -1
- package/dist/bin/naslc.mjs +1 -1
- package/dist/bin/naslc.mjs.map +1 -1
- package/dist/index.mjs +211 -1
- 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 +94 -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 +117 -0
- package/out/commands/transform.js.map +1 -0
- package/out/types/command.d.ts +1 -0
- package/out/types/command.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/bin/nasl.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import require$$0$6 from 'url';
|
|
|
18
18
|
import require$$8 from 'crypto';
|
|
19
19
|
import http2 from 'http2';
|
|
20
20
|
import zlib from 'zlib';
|
|
21
|
+
import * as readline from 'readline';
|
|
21
22
|
import { realpath as realpath$1, stat as stat$2, lstat as lstat$1, open, readdir as readdir$1 } from 'fs/promises';
|
|
22
23
|
import { lstat, stat as stat$1, readdir, realpath } from 'node:fs/promises';
|
|
23
24
|
import { Readable as Readable$1 } from 'node:stream';
|
|
@@ -28906,6 +28907,44 @@ async function checkApi(fullNaturalTS, options) {
|
|
|
28906
28907
|
return '';
|
|
28907
28908
|
}
|
|
28908
28909
|
|
|
28910
|
+
/**
|
|
28911
|
+
* 创建应用同步
|
|
28912
|
+
*/
|
|
28913
|
+
async function createAppSyncApi(fullNaturalTS, options) {
|
|
28914
|
+
const url = new URL(options.serverBaseURL);
|
|
28915
|
+
const origin = url.origin + '/app-ai-creator';
|
|
28916
|
+
const axios = createAxios(origin);
|
|
28917
|
+
try {
|
|
28918
|
+
const res = await axios.post('/api/createAppSync', {
|
|
28919
|
+
fullNaturalTS,
|
|
28920
|
+
packageName: options.packageName,
|
|
28921
|
+
appName: options.appName,
|
|
28922
|
+
hostname: url.hostname,
|
|
28923
|
+
enableAuthTemplate: false,
|
|
28924
|
+
ideVersion: options.ideVersion,
|
|
28925
|
+
fullVersion: `${options.ideVersion}.0`,
|
|
28926
|
+
});
|
|
28927
|
+
if (res.data.success) {
|
|
28928
|
+
return {
|
|
28929
|
+
success: true,
|
|
28930
|
+
appId: res.data.data?.appId,
|
|
28931
|
+
appURL: res.data.data?.appURL,
|
|
28932
|
+
message: res.data.data?.message,
|
|
28933
|
+
};
|
|
28934
|
+
}
|
|
28935
|
+
else {
|
|
28936
|
+
return {
|
|
28937
|
+
success: false,
|
|
28938
|
+
error: res.data.message || '应用创建失败',
|
|
28939
|
+
};
|
|
28940
|
+
}
|
|
28941
|
+
}
|
|
28942
|
+
catch (error) {
|
|
28943
|
+
console.log(error);
|
|
28944
|
+
throw error;
|
|
28945
|
+
}
|
|
28946
|
+
}
|
|
28947
|
+
|
|
28909
28948
|
function createSorter() {
|
|
28910
28949
|
const priorityOrder = ['app.dataSources', 'app.enums', 'app.structures', 'app.logics', 'app.frontendTypes'];
|
|
28911
28950
|
// 获取优先级索引
|
|
@@ -38065,11 +38104,199 @@ async function build(entry, options) {
|
|
|
38065
38104
|
await justExecCommandSync(webpackArgs, outDir);
|
|
38066
38105
|
}
|
|
38067
38106
|
|
|
38068
|
-
|
|
38107
|
+
/**
|
|
38108
|
+
* 获取 specs 下第1个文件夹的名字
|
|
38109
|
+
*/
|
|
38110
|
+
function getFirstSpecFolderName(projectRoot) {
|
|
38111
|
+
const dirname = sysPath.basename(projectRoot);
|
|
38112
|
+
const specsDir = sysPath.join(projectRoot, 'specs');
|
|
38113
|
+
if (!libExports.existsSync(specsDir))
|
|
38114
|
+
return dirname;
|
|
38115
|
+
const entries = libExports.readdirSync(specsDir, { withFileTypes: true });
|
|
38116
|
+
const folders = entries
|
|
38117
|
+
.filter(entry => entry.isDirectory())
|
|
38118
|
+
.map(entry => entry.name);
|
|
38119
|
+
if (folders.length === 0)
|
|
38120
|
+
return dirname;
|
|
38121
|
+
return folders[0];
|
|
38122
|
+
}
|
|
38123
|
+
/**
|
|
38124
|
+
* 创建应用在 IDE 中
|
|
38125
|
+
*/
|
|
38126
|
+
async function createAppInIde(entry, options) {
|
|
38127
|
+
const logger = options?.logger || defaultLogger;
|
|
38128
|
+
logger.info('开始创建应用在 IDE 中...');
|
|
38129
|
+
// 收集需要处理的文件
|
|
38130
|
+
const { collectedFiles, config } = await resolveNASLFiles(entry, logger, false, options?.verbose);
|
|
38131
|
+
// 生成 fullNaturalTS
|
|
38132
|
+
logger.newLine();
|
|
38133
|
+
logger.info('正在生成 NaturalTS 代码...');
|
|
38134
|
+
let fullNaturalTS = '';
|
|
38135
|
+
try {
|
|
38136
|
+
fullNaturalTS = composeToString(collectedFiles);
|
|
38137
|
+
}
|
|
38138
|
+
catch (error) {
|
|
38139
|
+
logger.error(`生成 NaturalTS 代码失败: ${error.message}`);
|
|
38140
|
+
throw error;
|
|
38141
|
+
}
|
|
38142
|
+
// 获取 specs 下第1个文件夹
|
|
38143
|
+
const projectRoot = getProjectRoot();
|
|
38144
|
+
const firstSpecFolderName = getFirstSpecFolderName(projectRoot);
|
|
38145
|
+
const suffix = dayjs().format('MMDDHHmmss');
|
|
38146
|
+
const appName = `${firstSpecFolderName}_${suffix}`;
|
|
38147
|
+
let cleaned = firstSpecFolderName.replace(/[^a-zA-Z0-9]/g, '').replace(/^\d+/, '');
|
|
38148
|
+
if (!cleaned)
|
|
38149
|
+
cleaned = 'app';
|
|
38150
|
+
const packageName = `${cleaned}${suffix}`;
|
|
38151
|
+
logger.info(`应用名称: ${appName}`);
|
|
38152
|
+
logger.info(`包名: ${packageName}`);
|
|
38153
|
+
logger.info(`IDE 版本: ${config.ideVersion}`);
|
|
38154
|
+
logger.info(`完整版本: ${config.ideVersion}.0`);
|
|
38155
|
+
// 调用创建应用 API
|
|
38156
|
+
logger.newLine();
|
|
38157
|
+
logger.info('正在调用创建应用服务...');
|
|
38158
|
+
try {
|
|
38159
|
+
const result = await createAppSyncApi(fullNaturalTS, {
|
|
38160
|
+
packageName: packageName,
|
|
38161
|
+
appName: appName,
|
|
38162
|
+
serverBaseURL: config.serverBaseURL,
|
|
38163
|
+
ideVersion: config.ideVersion,
|
|
38164
|
+
});
|
|
38165
|
+
if (result.success) {
|
|
38166
|
+
logger.success('应用创建成功!');
|
|
38167
|
+
if (result.appURL) {
|
|
38168
|
+
logger.info(`应用 URL: ${result.appURL}`);
|
|
38169
|
+
}
|
|
38170
|
+
if (result.appId) {
|
|
38171
|
+
logger.info(`应用 ID: ${result.appId}`);
|
|
38172
|
+
}
|
|
38173
|
+
if (result.message) {
|
|
38174
|
+
logger.info(result.message);
|
|
38175
|
+
}
|
|
38176
|
+
}
|
|
38177
|
+
else {
|
|
38178
|
+
logger.error(`应用创建失败: ${result.error || '未知错误'}`);
|
|
38179
|
+
throw new Error(result.error || '应用创建失败');
|
|
38180
|
+
}
|
|
38181
|
+
}
|
|
38182
|
+
catch (error) {
|
|
38183
|
+
logger.error(`调用创建应用服务失败: ${error.message}`);
|
|
38184
|
+
throw error;
|
|
38185
|
+
}
|
|
38186
|
+
}
|
|
38187
|
+
|
|
38188
|
+
/**
|
|
38189
|
+
* 编译 NASL 代码
|
|
38190
|
+
* TODO: 实现具体的 API 调用逻辑
|
|
38191
|
+
*/
|
|
38192
|
+
async function transformJson2FilesApi(jsonContent, options) {
|
|
38193
|
+
// 示例实现:
|
|
38194
|
+
const axios = createAxios(options.serverBaseURL);
|
|
38195
|
+
const res = await axios.post(`/transform/json2files?ideVersion=${options.ideVersion}`, jsonContent, {
|
|
38196
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
38197
|
+
});
|
|
38198
|
+
const data = res.data;
|
|
38199
|
+
if (data.code !== 200)
|
|
38200
|
+
throw new Error(data.message);
|
|
38201
|
+
return data.result;
|
|
38202
|
+
}
|
|
38203
|
+
|
|
38204
|
+
const transformFns = {
|
|
38205
|
+
/**
|
|
38206
|
+
* 将 src 中的文件组合成 fullNaturalTS
|
|
38207
|
+
*/
|
|
38208
|
+
async files2full(entry, options) {
|
|
38209
|
+
const logger = options?.logger || defaultLogger;
|
|
38210
|
+
// 收集需要处理的文件
|
|
38211
|
+
const { collectedFiles, projectRoot } = await resolveNASLFiles(entry, logger, false, options?.verbose);
|
|
38212
|
+
if (collectedFiles.length === 0) {
|
|
38213
|
+
logger.error('未找到需要转换的文件');
|
|
38214
|
+
logger.exit(1);
|
|
38215
|
+
}
|
|
38216
|
+
logger.info(`找到 ${collectedFiles.length} 个文件`);
|
|
38217
|
+
// 组合成 fullNaturalTS
|
|
38218
|
+
logger.newLine();
|
|
38219
|
+
logger.info('正在组合文件...');
|
|
38220
|
+
const fullNaturalTS = composeToString(collectedFiles);
|
|
38221
|
+
// 确定输出路径
|
|
38222
|
+
const outputPath = options?.output
|
|
38223
|
+
? sysPath.resolve(projectRoot, options.output)
|
|
38224
|
+
: sysPath.join(projectRoot, './full-natural.ts');
|
|
38225
|
+
// 写入文件
|
|
38226
|
+
writeFileWithLog(outputPath, fullNaturalTS, logger);
|
|
38227
|
+
logger.success(`文件已输出到: ${outputPath}`);
|
|
38228
|
+
},
|
|
38229
|
+
/**
|
|
38230
|
+
* 将 JSON 文件转换成 src 的 files
|
|
38231
|
+
* TODO: 待实现
|
|
38232
|
+
*/
|
|
38233
|
+
async json2files(entry, options) {
|
|
38234
|
+
const logger = options?.logger || defaultLogger;
|
|
38235
|
+
// 加载配置
|
|
38236
|
+
const config = loadConfig();
|
|
38237
|
+
const projectRoot = getProjectRoot();
|
|
38238
|
+
logger.info(`项目根目录: ${projectRoot}`);
|
|
38239
|
+
logger.info(`源代码目录: ${config.srcDir}`);
|
|
38240
|
+
let jsonContent = '';
|
|
38241
|
+
if (!entry) {
|
|
38242
|
+
logger.warn('没有指定 JSON 文件路径,按照默认 IDE 版本的基础模板转换');
|
|
38243
|
+
}
|
|
38244
|
+
else {
|
|
38245
|
+
jsonContent = libExports.readFileSync(entry, 'utf-8');
|
|
38246
|
+
}
|
|
38247
|
+
const files = await transformJson2FilesApi(jsonContent, {
|
|
38248
|
+
serverBaseURL: config.serverBaseURL,
|
|
38249
|
+
ideVersion: config.ideVersion,
|
|
38250
|
+
});
|
|
38251
|
+
await Promise.all(files.map(async (file) => {
|
|
38252
|
+
const outputPath = sysPath.join(projectRoot, config.srcDir, file.path);
|
|
38253
|
+
await libExports.writeFile(outputPath, file.content);
|
|
38254
|
+
}));
|
|
38255
|
+
logger.success(`JSON 文件已转换为 ${files.length} 个文件,输出到 ${config.srcDir}`);
|
|
38256
|
+
},
|
|
38257
|
+
/**
|
|
38258
|
+
* 将 src 中的文件转换成一个 JSON
|
|
38259
|
+
*/
|
|
38260
|
+
async files2json(entry, options) {
|
|
38261
|
+
options?.logger || defaultLogger;
|
|
38262
|
+
throw new Error('files2json 转换类型尚未实现');
|
|
38263
|
+
},
|
|
38264
|
+
};
|
|
38265
|
+
/**
|
|
38266
|
+
* 转换命令 - 支持多种文件转换格式
|
|
38267
|
+
*/
|
|
38268
|
+
async function transform(transformType, entry, options) {
|
|
38269
|
+
const logger = options?.logger || defaultLogger;
|
|
38270
|
+
logger.info(`开始执行转换: ${transformType}`);
|
|
38271
|
+
const transformFn = transformFns[transformType];
|
|
38272
|
+
if (!transformFn) {
|
|
38273
|
+
logger.error(`不支持的转换类型: ${transformType}`);
|
|
38274
|
+
logger.exit(1);
|
|
38275
|
+
}
|
|
38276
|
+
await transformFn(entry, options);
|
|
38277
|
+
}
|
|
38278
|
+
|
|
38279
|
+
var version = "0.1.16";
|
|
38069
38280
|
var pkg = {
|
|
38070
38281
|
version: version};
|
|
38071
38282
|
|
|
38072
38283
|
const program = new Command();
|
|
38284
|
+
/**
|
|
38285
|
+
* 使用 readline 询问用户确认
|
|
38286
|
+
*/
|
|
38287
|
+
function askForConfirmation(question) {
|
|
38288
|
+
const rl = readline.createInterface({
|
|
38289
|
+
input: process.stdin,
|
|
38290
|
+
output: process.stdout,
|
|
38291
|
+
});
|
|
38292
|
+
return new Promise((resolve) => {
|
|
38293
|
+
rl.question(question, (answer) => {
|
|
38294
|
+
rl.close();
|
|
38295
|
+
const normalizedAnswer = answer.trim().toLowerCase();
|
|
38296
|
+
resolve(normalizedAnswer === 'y' || normalizedAnswer === 'yes' || normalizedAnswer === '是');
|
|
38297
|
+
});
|
|
38298
|
+
});
|
|
38299
|
+
}
|
|
38073
38300
|
const entryDescription = `是相对于项目根目录的路径,支持 glob 模式(注意要用引号包裹),例如:
|
|
38074
38301
|
- src/app.enums.Status.ts 支持具体文件
|
|
38075
38302
|
- "src/app.enums.*.ts" 表示所有枚举
|
|
@@ -38148,6 +38375,50 @@ program
|
|
|
38148
38375
|
process.exit(1);
|
|
38149
38376
|
}
|
|
38150
38377
|
});
|
|
38378
|
+
program
|
|
38379
|
+
.command('create-app-in-ide [entry]')
|
|
38380
|
+
.description('在 IDE 中创建应用')
|
|
38381
|
+
.option('-v, --verbose', '显示详细信息,如依赖分析树')
|
|
38382
|
+
.option('-q, --quiet', '不询问问题')
|
|
38383
|
+
.action(async (entry, options) => {
|
|
38384
|
+
try {
|
|
38385
|
+
// 如果不是 quiet 模式,询问用户确认
|
|
38386
|
+
if (!options?.quiet) {
|
|
38387
|
+
defaultLogger.newLine();
|
|
38388
|
+
defaultLogger.info('即将在 IDE 中创建应用,此操作将调用远程服务。');
|
|
38389
|
+
const confirmed = await askForConfirmation('是否继续?(y/n): ');
|
|
38390
|
+
if (!confirmed) {
|
|
38391
|
+
defaultLogger.info('已取消操作');
|
|
38392
|
+
process.exit(0);
|
|
38393
|
+
}
|
|
38394
|
+
defaultLogger.newLine();
|
|
38395
|
+
}
|
|
38396
|
+
await createAppInIde(entry, options);
|
|
38397
|
+
}
|
|
38398
|
+
catch (error) {
|
|
38399
|
+
defaultLogger.error(`创建应用过程发生错误:${error.message}`);
|
|
38400
|
+
process.exit(1);
|
|
38401
|
+
}
|
|
38402
|
+
});
|
|
38403
|
+
program
|
|
38404
|
+
.command('transform <transformType> [entry]')
|
|
38405
|
+
.description('转换文件格式\n transformType: files2full (将 src 文件组合成 fullNaturalTS), json2files (将 JSON 转换为文件, 待实现), files2json (将 src 文件转换为 JSON)')
|
|
38406
|
+
.option('-o, --output <outputPath>', '指定输出路径')
|
|
38407
|
+
.option('-v, --verbose', '显示详细信息,如依赖分析树')
|
|
38408
|
+
.action(async (transformType, entry, options) => {
|
|
38409
|
+
try {
|
|
38410
|
+
const validTypes = ['files2full', 'json2files', 'files2json'];
|
|
38411
|
+
if (!validTypes.includes(transformType)) {
|
|
38412
|
+
defaultLogger.error(`无效的转换类型: ${transformType}。支持的类型: ${validTypes.join(', ')}`);
|
|
38413
|
+
process.exit(1);
|
|
38414
|
+
}
|
|
38415
|
+
await transform(transformType, entry, options);
|
|
38416
|
+
}
|
|
38417
|
+
catch (error) {
|
|
38418
|
+
defaultLogger.error(`转换过程发生错误:${error.message}`);
|
|
38419
|
+
process.exit(1);
|
|
38420
|
+
}
|
|
38421
|
+
});
|
|
38151
38422
|
program.parse(process.argv);
|
|
38152
38423
|
// 如果没有提供任何命令,显示帮助信息
|
|
38153
38424
|
if (!process.argv.slice(2).length) {
|