@nasl/cli 0.3.2 → 0.3.4
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 +157 -111
- package/dist/bin/nasl.mjs.map +1 -1
- package/dist/bin/naslc.mjs +3 -2
- package/dist/bin/naslc.mjs.map +1 -1
- package/dist/index.mjs +144 -84
- package/dist/index.mjs.map +1 -1
- package/out/apis/appApi.d.ts +17 -0
- package/out/apis/appApi.d.ts.map +1 -0
- package/out/apis/appApi.js +36 -0
- package/out/apis/appApi.js.map +1 -0
- package/out/apis/createAxios.js +1 -1
- package/out/apis/index.d.ts +1 -1
- package/out/apis/index.d.ts.map +1 -1
- package/out/apis/index.js +1 -1
- package/out/apis/index.js.map +1 -1
- package/out/bin/nasl.js +14 -61
- package/out/bin/nasl.js.map +1 -1
- package/out/commands/createAppInIde.d.ts +0 -3
- package/out/commands/createAppInIde.d.ts.map +1 -1
- package/out/commands/createAppInIde.js +26 -93
- package/out/commands/createAppInIde.js.map +1 -1
- package/out/commands/index.d.ts +1 -0
- package/out/commands/index.d.ts.map +1 -1
- package/out/commands/index.js +1 -0
- package/out/commands/index.js.map +1 -1
- package/out/commands/updateAppInIde.d.ts +3 -0
- package/out/commands/updateAppInIde.d.ts.map +1 -0
- package/out/commands/updateAppInIde.js +59 -0
- package/out/commands/updateAppInIde.js.map +1 -0
- package/out/utils/appName.d.ts +8 -0
- package/out/utils/appName.d.ts.map +1 -0
- package/out/utils/appName.js +71 -0
- package/out/utils/appName.js.map +1 -0
- package/out/utils/prompt.d.ts +5 -0
- package/out/utils/prompt.d.ts.map +1 -0
- package/out/utils/prompt.js +54 -0
- package/out/utils/prompt.js.map +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import crypto$1, { createHash } from 'crypto';
|
|
|
15
15
|
import http2 from 'http2';
|
|
16
16
|
import zlib from 'zlib';
|
|
17
17
|
import { spawn, spawnSync } from 'child_process';
|
|
18
|
+
import * as readline from 'readline';
|
|
18
19
|
import { realpath as realpath$1, stat as stat$2, lstat as lstat$1, open, readdir as readdir$1 } from 'fs/promises';
|
|
19
20
|
import { lstat, stat as stat$1, readdir, realpath } from 'node:fs/promises';
|
|
20
21
|
import { Readable as Readable$1 } from 'node:stream';
|
|
@@ -35086,7 +35087,7 @@ async function createAxios(options) {
|
|
|
35086
35087
|
const instance = axios.create({
|
|
35087
35088
|
baseURL,
|
|
35088
35089
|
headers,
|
|
35089
|
-
timeout:
|
|
35090
|
+
timeout: 480000,
|
|
35090
35091
|
});
|
|
35091
35092
|
const oldPost = instance.post;
|
|
35092
35093
|
instance.post = async (url, data, config) => {
|
|
@@ -35191,41 +35192,33 @@ async function parseApi(fullNaturalTS, options) {
|
|
|
35191
35192
|
}
|
|
35192
35193
|
|
|
35193
35194
|
/**
|
|
35194
|
-
*
|
|
35195
|
+
* 创建应用(POST /nasl/app/create)
|
|
35195
35196
|
*/
|
|
35196
|
-
async function
|
|
35197
|
-
const
|
|
35198
|
-
const
|
|
35199
|
-
|
|
35200
|
-
|
|
35201
|
-
|
|
35202
|
-
|
|
35203
|
-
|
|
35204
|
-
|
|
35205
|
-
|
|
35206
|
-
|
|
35207
|
-
|
|
35208
|
-
|
|
35209
|
-
|
|
35210
|
-
|
|
35211
|
-
|
|
35212
|
-
|
|
35213
|
-
|
|
35214
|
-
|
|
35215
|
-
|
|
35216
|
-
|
|
35217
|
-
|
|
35218
|
-
|
|
35219
|
-
|
|
35220
|
-
|
|
35221
|
-
error: res.data.message || '应用创建失败',
|
|
35222
|
-
};
|
|
35223
|
-
}
|
|
35224
|
-
}
|
|
35225
|
-
catch (error) {
|
|
35226
|
-
console.log(error);
|
|
35227
|
-
throw error;
|
|
35228
|
-
}
|
|
35197
|
+
async function createApp(fullNaturalTS, options, appName, packageName) {
|
|
35198
|
+
const axiosInstance = await createAxios(options);
|
|
35199
|
+
const res = await axiosInstance.post('/app/create', {
|
|
35200
|
+
fullNaturalTS,
|
|
35201
|
+
packageName,
|
|
35202
|
+
appName,
|
|
35203
|
+
ideVersion: options.ideVersion,
|
|
35204
|
+
}, {
|
|
35205
|
+
headers: { ...buildNaslHeaders(options), 'Content-Type': 'application/json' },
|
|
35206
|
+
});
|
|
35207
|
+
return res.data.result;
|
|
35208
|
+
}
|
|
35209
|
+
/**
|
|
35210
|
+
* 更新应用(POST /nasl/app/update)
|
|
35211
|
+
*/
|
|
35212
|
+
async function updateApp(fullNaturalTS, options, appId) {
|
|
35213
|
+
const axiosInstance = await createAxios(options);
|
|
35214
|
+
const res = await axiosInstance.post('/app/update', {
|
|
35215
|
+
fullNaturalTS,
|
|
35216
|
+
appId,
|
|
35217
|
+
ideVersion: options.ideVersion,
|
|
35218
|
+
}, {
|
|
35219
|
+
headers: { ...buildNaslHeaders(options), 'Content-Type': 'application/json' },
|
|
35220
|
+
});
|
|
35221
|
+
return res.data.result;
|
|
35229
35222
|
}
|
|
35230
35223
|
|
|
35231
35224
|
async function installDependenciesApi(dependenciesJSON, options) {
|
|
@@ -35632,78 +35625,94 @@ async function build(entry, options) {
|
|
|
35632
35625
|
}
|
|
35633
35626
|
|
|
35634
35627
|
/**
|
|
35635
|
-
*
|
|
35628
|
+
* 从 specs/ 目录取第一个子文件夹名;若无则退回项目根目录名
|
|
35636
35629
|
*/
|
|
35637
|
-
function
|
|
35638
|
-
const dirname = path$1.basename(projectRoot);
|
|
35630
|
+
function getSpecBaseName(projectRoot) {
|
|
35639
35631
|
const specsDir = path$1.join(projectRoot, 'specs');
|
|
35640
|
-
if (
|
|
35641
|
-
|
|
35642
|
-
|
|
35643
|
-
|
|
35644
|
-
.
|
|
35645
|
-
|
|
35646
|
-
|
|
35647
|
-
|
|
35648
|
-
|
|
35632
|
+
if (libExports.existsSync(specsDir)) {
|
|
35633
|
+
const folders = libExports.readdirSync(specsDir, { withFileTypes: true })
|
|
35634
|
+
.filter(e => e.isDirectory())
|
|
35635
|
+
.map(e => e.name);
|
|
35636
|
+
if (folders.length > 0)
|
|
35637
|
+
return folders[0];
|
|
35638
|
+
}
|
|
35639
|
+
return path$1.basename(projectRoot);
|
|
35640
|
+
}
|
|
35641
|
+
/**
|
|
35642
|
+
* 从项目目录推导出合法的应用名称和包名
|
|
35643
|
+
*/
|
|
35644
|
+
function deriveAppNames(projectRoot) {
|
|
35645
|
+
const baseName = getSpecBaseName(projectRoot);
|
|
35646
|
+
const suffix = dayjs().format('MMDDHHmmss');
|
|
35647
|
+
let cleaned = baseName.replace(/[^a-zA-Z0-9]/g, '').replace(/^\d+/, '').slice(0, 12);
|
|
35648
|
+
if (!cleaned)
|
|
35649
|
+
cleaned = 'app';
|
|
35650
|
+
return {
|
|
35651
|
+
appName: `${cleaned}_${suffix}`,
|
|
35652
|
+
packageName: `${cleaned}${suffix}`,
|
|
35653
|
+
};
|
|
35649
35654
|
}
|
|
35655
|
+
|
|
35650
35656
|
/**
|
|
35651
|
-
*
|
|
35657
|
+
* 使用 readline 询问用户确认
|
|
35652
35658
|
*/
|
|
35659
|
+
function askForConfirmation(question) {
|
|
35660
|
+
const rl = readline.createInterface({
|
|
35661
|
+
input: process.stdin,
|
|
35662
|
+
output: process.stdout,
|
|
35663
|
+
});
|
|
35664
|
+
return new Promise((resolve) => {
|
|
35665
|
+
rl.question(question, (answer) => {
|
|
35666
|
+
rl.close();
|
|
35667
|
+
const a = answer.trim().toLowerCase();
|
|
35668
|
+
resolve(!a || a === 'y' || a === 'yes' || a === '是');
|
|
35669
|
+
});
|
|
35670
|
+
});
|
|
35671
|
+
}
|
|
35672
|
+
|
|
35653
35673
|
async function createAppInIde(entry, options) {
|
|
35654
35674
|
const logger = options?.logger || defaultLogger;
|
|
35655
|
-
|
|
35656
|
-
|
|
35657
|
-
|
|
35658
|
-
|
|
35659
|
-
|
|
35660
|
-
|
|
35675
|
+
// ── 扫描 ─────────────────────────────────────────────
|
|
35676
|
+
const { collectedFiles, config, mergedDependencies } = await resolveNASLFiles(entry, logger, false, options?.verbose);
|
|
35677
|
+
// ── 展示参数 ──────────────────────────────────────────
|
|
35678
|
+
const { appName, packageName } = deriveAppNames(getProjectRoot());
|
|
35679
|
+
logger.newLine();
|
|
35680
|
+
logger.info(`应用名称: ${appName}`);
|
|
35681
|
+
logger.info(`包名: ${packageName}`);
|
|
35682
|
+
logger.info(`IDE 版本: ${config.ideVersion}`);
|
|
35683
|
+
logger.info(`租户名称: ${config.tenantName || 'defaulttenant'}`);
|
|
35684
|
+
// ── 确认 ──────────────────────────────────────────────
|
|
35685
|
+
if (!options?.quiet) {
|
|
35686
|
+
logger.newLine();
|
|
35687
|
+
const confirmed = await askForConfirmation('即将在 IDE 中创建新的应用,请确认是否继续?(Y/n): ');
|
|
35688
|
+
if (!confirmed) {
|
|
35689
|
+
logger.info('已取消操作');
|
|
35690
|
+
process.exit(0);
|
|
35691
|
+
}
|
|
35661
35692
|
}
|
|
35662
|
-
//
|
|
35693
|
+
// ── 执行 ──────────────────────────────────────────────
|
|
35663
35694
|
logger.newLine();
|
|
35664
35695
|
logger.info('正在生成 NaturalTS 代码...');
|
|
35665
|
-
let fullNaturalTS
|
|
35696
|
+
let fullNaturalTS;
|
|
35666
35697
|
try {
|
|
35667
35698
|
fullNaturalTS = composeToString(collectedFiles);
|
|
35699
|
+
fullNaturalTS = prependDependencies(fullNaturalTS, mergedDependencies);
|
|
35668
35700
|
}
|
|
35669
35701
|
catch (error) {
|
|
35670
35702
|
logger.error(`生成 NaturalTS 代码失败: ${error.message}`);
|
|
35671
35703
|
throw error;
|
|
35672
35704
|
}
|
|
35673
|
-
// 获取 specs 下第1个文件夹
|
|
35674
|
-
const projectRoot = getProjectRoot();
|
|
35675
|
-
const firstSpecFolderName = getFirstSpecFolderName(projectRoot);
|
|
35676
|
-
const suffix = dayjs().format('MMDDHHmmss');
|
|
35677
|
-
let cleaned = firstSpecFolderName.replace(/[^a-zA-Z0-9]/g, '').replace(/^\d+/, '').slice(0, 12);
|
|
35678
|
-
if (!cleaned)
|
|
35679
|
-
cleaned = 'app';
|
|
35680
|
-
const appName = `${cleaned}_${suffix}`;
|
|
35681
|
-
const packageName = `${cleaned}${suffix}`;
|
|
35682
|
-
logger.info(`应用名称: ${appName}`);
|
|
35683
|
-
logger.info(`包名: ${packageName}`);
|
|
35684
|
-
logger.info(`IDE 版本: ${config.ideVersion}`);
|
|
35685
|
-
logger.info(`完整版本: ${config.ideVersion}.0`);
|
|
35686
|
-
// 调用创建应用 API
|
|
35687
|
-
logger.newLine();
|
|
35688
35705
|
logger.info('正在调用创建应用服务...');
|
|
35689
35706
|
try {
|
|
35690
|
-
const result = await
|
|
35691
|
-
packageName: packageName,
|
|
35692
|
-
appName: appName,
|
|
35693
|
-
serverBaseURL: config.serverBaseURL,
|
|
35694
|
-
ideVersion: config.ideVersion,
|
|
35695
|
-
});
|
|
35707
|
+
const result = await createApp(fullNaturalTS, config, appName, packageName);
|
|
35696
35708
|
if (result.success) {
|
|
35697
35709
|
logger.success('应用创建成功!');
|
|
35698
|
-
if (result.appURL)
|
|
35710
|
+
if (result.appURL)
|
|
35699
35711
|
logger.info(`应用 URL: ${result.appURL}`);
|
|
35700
|
-
|
|
35701
|
-
if (result.appId) {
|
|
35712
|
+
if (result.appId)
|
|
35702
35713
|
logger.info(`应用 ID: ${result.appId}`);
|
|
35703
|
-
|
|
35704
|
-
if (result.message) {
|
|
35714
|
+
if (result.message)
|
|
35705
35715
|
logger.info(result.message);
|
|
35706
|
-
}
|
|
35707
35716
|
}
|
|
35708
35717
|
else {
|
|
35709
35718
|
logger.error(`应用创建失败: ${result.error || '未知错误'}`);
|
|
@@ -35716,6 +35725,57 @@ async function createAppInIde(entry, options) {
|
|
|
35716
35725
|
}
|
|
35717
35726
|
}
|
|
35718
35727
|
|
|
35728
|
+
async function updateAppInIde(appId, entry, options) {
|
|
35729
|
+
const logger = options?.logger || defaultLogger;
|
|
35730
|
+
// ── 扫描 ─────────────────────────────────────────────
|
|
35731
|
+
const { collectedFiles, config, mergedDependencies } = await resolveNASLFiles(entry, logger, false, options?.verbose);
|
|
35732
|
+
// ── 展示参数 ──────────────────────────────────────────
|
|
35733
|
+
logger.newLine();
|
|
35734
|
+
logger.info(`应用 ID: ${appId}`);
|
|
35735
|
+
logger.info(`IDE 版本: ${config.ideVersion}`);
|
|
35736
|
+
logger.info(`租户名称: ${config.tenantName || 'defaulttenant'}`);
|
|
35737
|
+
// ── 确认 ──────────────────────────────────────────────
|
|
35738
|
+
if (!options?.quiet) {
|
|
35739
|
+
logger.newLine();
|
|
35740
|
+
const confirmed = await askForConfirmation(`即将更新应用 ${appId},请确认是否继续?(Y/n): `);
|
|
35741
|
+
if (!confirmed) {
|
|
35742
|
+
logger.info('已取消操作');
|
|
35743
|
+
process.exit(0);
|
|
35744
|
+
}
|
|
35745
|
+
}
|
|
35746
|
+
// ── 执行 ──────────────────────────────────────────────
|
|
35747
|
+
logger.newLine();
|
|
35748
|
+
logger.info('正在生成 NaturalTS 代码...');
|
|
35749
|
+
let fullNaturalTS;
|
|
35750
|
+
try {
|
|
35751
|
+
fullNaturalTS = composeToString(collectedFiles);
|
|
35752
|
+
fullNaturalTS = prependDependencies(fullNaturalTS, mergedDependencies);
|
|
35753
|
+
}
|
|
35754
|
+
catch (error) {
|
|
35755
|
+
logger.error(`生成 NaturalTS 代码失败: ${error.message}`);
|
|
35756
|
+
throw error;
|
|
35757
|
+
}
|
|
35758
|
+
logger.info('正在调用更新应用服务...');
|
|
35759
|
+
try {
|
|
35760
|
+
const result = await updateApp(fullNaturalTS, config, appId);
|
|
35761
|
+
if (result.success) {
|
|
35762
|
+
logger.success('应用更新成功!');
|
|
35763
|
+
if (result.appURL)
|
|
35764
|
+
logger.info(`应用 URL: ${result.appURL}`);
|
|
35765
|
+
if (result.message)
|
|
35766
|
+
logger.info(result.message);
|
|
35767
|
+
}
|
|
35768
|
+
else {
|
|
35769
|
+
logger.error(`应用更新失败: ${result.error || '未知错误'}`);
|
|
35770
|
+
throw new Error(result.error || '应用更新失败');
|
|
35771
|
+
}
|
|
35772
|
+
}
|
|
35773
|
+
catch (error) {
|
|
35774
|
+
logger.error(`调用更新应用服务失败: ${error.message}`);
|
|
35775
|
+
throw error;
|
|
35776
|
+
}
|
|
35777
|
+
}
|
|
35778
|
+
|
|
35719
35779
|
/**
|
|
35720
35780
|
* 编译 NASL 代码
|
|
35721
35781
|
* TODO: 实现具体的 API 调用逻辑
|
|
@@ -37764,5 +37824,5 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
37764
37824
|
watch: watch
|
|
37765
37825
|
});
|
|
37766
37826
|
|
|
37767
|
-
export { BaseLogger, CONFIG_FILE_NAME, ConsoleLogger, ConsoleLoggerWithoutExit, DEFAULT_CONFIG, MemoryLogger, build, check, compile, composeToString, createAppInIde, createSorter, defaultLogger, dep, dev, docCheck, extractFullNaturalTS, fastAppendLogToFile, fastLogToFile, init, installAuto, installByJSON, installByKind, loadAppDependencies, loadMergedDependencies, mergeDependenciesIntoApp, prependDependencies, resolveNASLFiles, scanEntryFiles, scanNASLFiles, sorter, transform, tryCompile };
|
|
37827
|
+
export { BaseLogger, CONFIG_FILE_NAME, ConsoleLogger, ConsoleLoggerWithoutExit, DEFAULT_CONFIG, MemoryLogger, build, check, compile, composeToString, createAppInIde, createSorter, defaultLogger, dep, dev, docCheck, extractFullNaturalTS, fastAppendLogToFile, fastLogToFile, init, installAuto, installByJSON, installByKind, loadAppDependencies, loadMergedDependencies, mergeDependenciesIntoApp, prependDependencies, resolveNASLFiles, scanEntryFiles, scanNASLFiles, sorter, transform, tryCompile, updateAppInIde };
|
|
37768
37828
|
//# sourceMappingURL=index.mjs.map
|