@nasl/cli 0.1.19 → 0.2.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.
- package/dist/bin/nasl.mjs +141 -45
- package/dist/bin/nasl.mjs.map +1 -1
- package/dist/bin/naslc.mjs +141 -45
- package/dist/bin/naslc.mjs.map +1 -1
- package/dist/index.mjs +134 -38
- package/dist/index.mjs.map +1 -1
- package/out/constants/index.d.ts +2 -0
- package/out/constants/index.d.ts.map +1 -0
- package/out/constants/index.js +18 -0
- package/out/constants/index.js.map +1 -0
- package/out/constants/nasl-file-types.d.ts +47 -0
- package/out/constants/nasl-file-types.d.ts.map +1 -0
- package/out/constants/nasl-file-types.js +143 -0
- package/out/constants/nasl-file-types.js.map +1 -0
- package/out/services/compose.d.ts.map +1 -1
- package/out/services/compose.js +7 -2
- package/out/services/compose.js.map +1 -1
- package/out/services/resolve.d.ts.map +1 -1
- package/out/services/resolve.js +33 -27
- package/out/services/resolve.js.map +1 -1
- package/out/utils/file.d.ts +0 -12
- package/out/utils/file.d.ts.map +1 -1
- package/out/utils/file.js +0 -18
- package/out/utils/file.js.map +1 -1
- package/package.json +1 -1
package/dist/bin/nasl.mjs
CHANGED
|
@@ -8419,23 +8419,6 @@ function writeFileWithLog(filePath, content, logger) {
|
|
|
8419
8419
|
throw error;
|
|
8420
8420
|
}
|
|
8421
8421
|
}
|
|
8422
|
-
/**
|
|
8423
|
-
* 判断文件路径是否为已知的 NASL 文件类型
|
|
8424
|
-
* 支持的类型:
|
|
8425
|
-
* - 枚举 (enums)
|
|
8426
|
-
* - 实体 (entities)
|
|
8427
|
-
* - 数据结构 (structures)
|
|
8428
|
-
* - 逻辑 (logics)
|
|
8429
|
-
* - 页面 (views)
|
|
8430
|
-
* - 前端/服务端全局变量 (variables)
|
|
8431
|
-
* - 依赖库 (extensions)
|
|
8432
|
-
*/
|
|
8433
|
-
function isKnownFileType(filePath) {
|
|
8434
|
-
return (/\.(enums|entities|structures|logics|views)\.\w+\.(ts|tsx)$/.test(filePath) || // 枚举、实体、数据结构、逻辑、页面
|
|
8435
|
-
/^app\..*\.variables\.ts$/.test(filePath) || // 前端/服务端全局变量 (以app开头,以variables.ts结尾)
|
|
8436
|
-
/^extensions\.\w+\.(ts|tsx)$/.test(filePath) // 依赖库
|
|
8437
|
-
);
|
|
8438
|
-
}
|
|
8439
8422
|
|
|
8440
8423
|
/**
|
|
8441
8424
|
* 初始化命令 - 创建配置文件
|
|
@@ -29349,9 +29332,11 @@ function composeToString(files) {
|
|
|
29349
29332
|
// 判断是否是特殊文件类型(variables 或 extensions)
|
|
29350
29333
|
const isVariablesFile = nameFromPath === 'variables';
|
|
29351
29334
|
const isExtensionsFile = arr[0] === 'extensions';
|
|
29352
|
-
const
|
|
29335
|
+
const isThemeCss = ext === 'css' && nameFromPath === 'theme';
|
|
29336
|
+
const isSpecialFile = isVariablesFile || isExtensionsFile || isThemeCss;
|
|
29353
29337
|
// 特殊文件的 namespace 包含文件名,普通文件不包含
|
|
29354
29338
|
const namespace = isSpecialFile ? [...arr, nameFromPath].join('.') : arr.join('.');
|
|
29339
|
+
let content = file.content;
|
|
29355
29340
|
if (['ts', 'tsx'].includes(ext)) {
|
|
29356
29341
|
if (isVariablesFile) {
|
|
29357
29342
|
validateVariablesFile(file, errors);
|
|
@@ -29363,7 +29348,10 @@ function composeToString(files) {
|
|
|
29363
29348
|
validateNormalFile(file, nameFromPath, namespace, errors);
|
|
29364
29349
|
}
|
|
29365
29350
|
}
|
|
29366
|
-
|
|
29351
|
+
else if (isThemeCss) {
|
|
29352
|
+
content = ` $theme\`${content}\`;`;
|
|
29353
|
+
}
|
|
29354
|
+
return `namespace ${namespace} {\n${content}\n}\n`;
|
|
29367
29355
|
})
|
|
29368
29356
|
.join('\n');
|
|
29369
29357
|
if (errors.length > 0) {
|
|
@@ -37886,13 +37874,116 @@ function requireGlobby () {
|
|
|
37886
37874
|
var globbyExports = requireGlobby();
|
|
37887
37875
|
var globby = /*@__PURE__*/getDefaultExportFromCjs(globbyExports);
|
|
37888
37876
|
|
|
37877
|
+
/**
|
|
37878
|
+
* NASL 支持的所有文件类型配置
|
|
37879
|
+
*/
|
|
37880
|
+
const NASL_FILE_TYPES = [
|
|
37881
|
+
{
|
|
37882
|
+
name: 'theme-css',
|
|
37883
|
+
description: '主题样式',
|
|
37884
|
+
fileNamePattern: 'app\\.frontendTypes\\.pc\\.frontends\\.pc\\.theme\\.css',
|
|
37885
|
+
codeRefPattern: 'app\\.frontendTypes\\.pc\\.frontends\\.pc\\.theme',
|
|
37886
|
+
extension: 'css',
|
|
37887
|
+
},
|
|
37888
|
+
{
|
|
37889
|
+
name: 'structures',
|
|
37890
|
+
description: '数据结构',
|
|
37891
|
+
fileNamePattern: 'app\\.structures\\.\\w+\\.ts',
|
|
37892
|
+
codeRefPattern: 'app\\.structures\\.\\w+(?:\\.\\w+)*',
|
|
37893
|
+
extension: 'ts',
|
|
37894
|
+
},
|
|
37895
|
+
{
|
|
37896
|
+
name: 'entities',
|
|
37897
|
+
description: '实体',
|
|
37898
|
+
fileNamePattern: 'app\\.dataSources\\.\\w+\\.entities\\.\\w+\\.ts',
|
|
37899
|
+
codeRefPattern: 'app\\.dataSources\\.\\w+\\.entities\\.\\w+(?:Entity)?(?:\\.\\w+)*',
|
|
37900
|
+
extension: 'ts',
|
|
37901
|
+
},
|
|
37902
|
+
{
|
|
37903
|
+
name: 'logics',
|
|
37904
|
+
description: '逻辑',
|
|
37905
|
+
fileNamePattern: 'app\\.logics\\.\\w+\\.ts',
|
|
37906
|
+
codeRefPattern: 'app\\.logics\\.\\w+(?:\\.\\w+)*',
|
|
37907
|
+
extension: 'ts',
|
|
37908
|
+
},
|
|
37909
|
+
{
|
|
37910
|
+
name: 'views',
|
|
37911
|
+
description: '视图',
|
|
37912
|
+
fileNamePattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+(?:\\.views\\.\\w+)+\\.tsx',
|
|
37913
|
+
codeRefPattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+(?:\\.views\\.\\w+)+(?:\\.\\w+)*',
|
|
37914
|
+
extension: 'tsx',
|
|
37915
|
+
},
|
|
37916
|
+
{
|
|
37917
|
+
name: 'backend-variables',
|
|
37918
|
+
description: '后端全局变量',
|
|
37919
|
+
fileNamePattern: 'app\\.backend\\.variables\\.ts',
|
|
37920
|
+
codeRefPattern: 'app\\.backend\\.variables(?:\\.\\w+)*',
|
|
37921
|
+
extension: 'ts',
|
|
37922
|
+
},
|
|
37923
|
+
{
|
|
37924
|
+
name: 'frontend-variables',
|
|
37925
|
+
description: '前端全局变量',
|
|
37926
|
+
fileNamePattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+\\.variables\\.ts',
|
|
37927
|
+
codeRefPattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+\\.variables(?:\\.\\w+)*',
|
|
37928
|
+
extension: 'ts',
|
|
37929
|
+
},
|
|
37930
|
+
{
|
|
37931
|
+
name: 'enums',
|
|
37932
|
+
description: '枚举',
|
|
37933
|
+
fileNamePattern: 'app\\.enums\\.\\w+\\.ts',
|
|
37934
|
+
codeRefPattern: 'app\\.enums\\.\\w+(?:\\.\\w+)*',
|
|
37935
|
+
extension: 'ts',
|
|
37936
|
+
},
|
|
37937
|
+
{
|
|
37938
|
+
name: 'extensions',
|
|
37939
|
+
description: '依赖库',
|
|
37940
|
+
fileNamePattern: 'extensions\\.\\w+\\.ts',
|
|
37941
|
+
codeRefPattern: 'extensions\\.\\w+(?:\\.\\w+)*',
|
|
37942
|
+
extension: 'ts',
|
|
37943
|
+
},
|
|
37944
|
+
];
|
|
37945
|
+
/**
|
|
37946
|
+
* 获取用于验证文件名的正则表达式数组
|
|
37947
|
+
*/
|
|
37948
|
+
function getFileNamePatterns() {
|
|
37949
|
+
return NASL_FILE_TYPES.map((type) => new RegExp(`^${type.fileNamePattern}$`));
|
|
37950
|
+
}
|
|
37951
|
+
const fileNamePatterns = getFileNamePatterns();
|
|
37952
|
+
/**
|
|
37953
|
+
* 获取用于提取代码引用的正则表达式数组
|
|
37954
|
+
*/
|
|
37955
|
+
function getCodeRefPatterns() {
|
|
37956
|
+
return NASL_FILE_TYPES.map((type) => new RegExp(type.codeRefPattern, 'g'));
|
|
37957
|
+
}
|
|
37958
|
+
const codeRefPatterns = getCodeRefPatterns();
|
|
37959
|
+
/**
|
|
37960
|
+
* 判断文件路径是否为已知的 NASL 文件类型
|
|
37961
|
+
* 支持的类型:
|
|
37962
|
+
* - 数据结构 (structures): app.structures.{StructureName}.ts
|
|
37963
|
+
* - 实体 (entities): app.dataSources.{dsName}.entities.{EntityName}.ts
|
|
37964
|
+
* - 逻辑 (logics): app.logics.{logicName}.ts
|
|
37965
|
+
* - 视图 (views): app.frontendTypes.{type}.frontends.{name}.views.{viewName}.tsx
|
|
37966
|
+
* - 后端全局变量: app.backend.variables.ts
|
|
37967
|
+
* - 前端全局变量: app.frontendTypes.{type}.frontends.{name}.variables.ts
|
|
37968
|
+
* - 枚举 (enums): app.enums.{EnumName}.ts
|
|
37969
|
+
* - 依赖库 (extensions): extensions.{extensionName}.ts
|
|
37970
|
+
*
|
|
37971
|
+
* @param filePath 文件路径(绝对路径或相对路径)
|
|
37972
|
+
* @returns 是否为已知的 NASL 文件类型
|
|
37973
|
+
*/
|
|
37974
|
+
function isKnownFileType(filePath) {
|
|
37975
|
+
// 提取文件名
|
|
37976
|
+
const fileName = sysPath.basename(filePath);
|
|
37977
|
+
return fileNamePatterns.some((pattern) => pattern.test(fileName));
|
|
37978
|
+
}
|
|
37979
|
+
|
|
37889
37980
|
/**
|
|
37890
37981
|
* 扫描目录下的所有 NASL 文件
|
|
37891
37982
|
*/
|
|
37892
37983
|
async function scanNASLFiles(srcDir, representation, logger) {
|
|
37893
37984
|
try {
|
|
37894
37985
|
const pattern = representation === 'NaturalTS' ? '**/*.{ts,tsx}' : '**/*.nasl';
|
|
37895
|
-
const files = await globby([pattern, '
|
|
37986
|
+
const files = await globby([pattern, '**/app.frontendTypes.pc.frontends.pc.theme.css'], {
|
|
37896
37987
|
cwd: srcDir,
|
|
37897
37988
|
onlyFiles: true,
|
|
37898
37989
|
absolute: false,
|
|
@@ -37906,7 +37997,6 @@ async function scanNASLFiles(srcDir, representation, logger) {
|
|
|
37906
37997
|
}
|
|
37907
37998
|
async function scanEntryFiles(projectRoot, patterns, logger) {
|
|
37908
37999
|
try {
|
|
37909
|
-
patterns.push('!**/*.css');
|
|
37910
38000
|
const files = await globby(patterns, {
|
|
37911
38001
|
cwd: projectRoot,
|
|
37912
38002
|
onlyFiles: true,
|
|
@@ -37920,9 +38010,9 @@ async function scanEntryFiles(projectRoot, patterns, logger) {
|
|
|
37920
38010
|
}
|
|
37921
38011
|
}
|
|
37922
38012
|
/**
|
|
37923
|
-
* 从文件内容中提取
|
|
38013
|
+
* 从文件内容中提取 指定 格式的依赖引用
|
|
37924
38014
|
* @param content 文件内容
|
|
37925
|
-
* @returns 依赖的
|
|
38015
|
+
* @returns 依赖的 指定 路径列表
|
|
37926
38016
|
*/
|
|
37927
38017
|
function extractDeps(content) {
|
|
37928
38018
|
const deps = new Set();
|
|
@@ -37932,28 +38022,34 @@ function extractDeps(content) {
|
|
|
37932
38022
|
.replace(/\/\*[\s\S]*?\*\//g, '') // 移除多行注释 /* ... */
|
|
37933
38023
|
.replace(/'(?:[^'\\]|\\.)*'/g, '') // 移除单引号字符串 'xxx'
|
|
37934
38024
|
.replace(/"(?:[^"\\]|\\.)*"/g, ''); // 移除双引号字符串 "xxx"
|
|
37935
|
-
const
|
|
37936
|
-
|
|
37937
|
-
|
|
37938
|
-
|
|
37939
|
-
|
|
37940
|
-
|
|
37941
|
-
|
|
37942
|
-
|
|
37943
|
-
|
|
37944
|
-
|
|
37945
|
-
|
|
37946
|
-
|
|
37947
|
-
|
|
37948
|
-
|
|
37949
|
-
|
|
37950
|
-
|
|
37951
|
-
|
|
37952
|
-
|
|
37953
|
-
|
|
38025
|
+
for (const pattern of codeRefPatterns) {
|
|
38026
|
+
const matches = processedContent.matchAll(pattern);
|
|
38027
|
+
for (const match of matches) {
|
|
38028
|
+
let dep = match[0];
|
|
38029
|
+
// 处理 Entity 后缀:app.dataSources.ds.entities.EntityNameEntity -> app.dataSources.ds.entities.EntityName
|
|
38030
|
+
if (/Entity$|Entity\./.test(dep)) {
|
|
38031
|
+
dep = dep.replace(/Entity(\..*)?$/, '');
|
|
38032
|
+
}
|
|
38033
|
+
// 处理枚举:app.enums.EnumName.field -> app.enums.EnumName
|
|
38034
|
+
if (/^app\.enums\.\w+\./.test(dep)) {
|
|
38035
|
+
dep = dep.replace(/^(app\.enums\.\w+).+$/, '$1');
|
|
38036
|
+
}
|
|
38037
|
+
// 处理 variables:app.backend.variables.varName -> app.backend.variables
|
|
38038
|
+
if (/\.variables\.\w+/.test(dep)) {
|
|
38039
|
+
dep = dep.replace(/\.variables\..+$/, '.variables');
|
|
38040
|
+
}
|
|
38041
|
+
// 处理 extensions:extensions.lcap_auth.logics.getUser -> extensions.lcap_auth
|
|
38042
|
+
if (/^extensions\.\w+\./.test(dep)) {
|
|
38043
|
+
dep = dep.replace(/^(extensions\.\w+)\..+$/, '$1');
|
|
38044
|
+
}
|
|
38045
|
+
// 跳过不合法的实体引用(实体后还有字段的情况)
|
|
38046
|
+
if (/app\.dataSources\.\w+\.entities\.\w+\.\w+$/.test(dep)) {
|
|
38047
|
+
continue;
|
|
38048
|
+
}
|
|
38049
|
+
// 添加文件扩展名
|
|
38050
|
+
dep = `${dep}.${dep.includes('.views.') ? 'tsx' : 'ts'}`;
|
|
38051
|
+
deps.add(dep);
|
|
37954
38052
|
}
|
|
37955
|
-
dep = `${dep}.${dep.includes('.views.') ? 'tsx' : 'ts'}`;
|
|
37956
|
-
deps.add(dep);
|
|
37957
38053
|
}
|
|
37958
38054
|
return Array.from(deps);
|
|
37959
38055
|
}
|
|
@@ -38666,7 +38762,7 @@ async function transform(transformType, entry, options) {
|
|
|
38666
38762
|
await transformFn(entry, options);
|
|
38667
38763
|
}
|
|
38668
38764
|
|
|
38669
|
-
var version = "0.
|
|
38765
|
+
var version = "0.2.0";
|
|
38670
38766
|
var pkg = {
|
|
38671
38767
|
version: version};
|
|
38672
38768
|
|