@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/naslc.mjs
CHANGED
|
@@ -8385,23 +8385,6 @@ function writeFileWithLog(filePath, content, logger) {
|
|
|
8385
8385
|
throw error;
|
|
8386
8386
|
}
|
|
8387
8387
|
}
|
|
8388
|
-
/**
|
|
8389
|
-
* 判断文件路径是否为已知的 NASL 文件类型
|
|
8390
|
-
* 支持的类型:
|
|
8391
|
-
* - 枚举 (enums)
|
|
8392
|
-
* - 实体 (entities)
|
|
8393
|
-
* - 数据结构 (structures)
|
|
8394
|
-
* - 逻辑 (logics)
|
|
8395
|
-
* - 页面 (views)
|
|
8396
|
-
* - 前端/服务端全局变量 (variables)
|
|
8397
|
-
* - 依赖库 (extensions)
|
|
8398
|
-
*/
|
|
8399
|
-
function isKnownFileType(filePath) {
|
|
8400
|
-
return (/\.(enums|entities|structures|logics|views)\.\w+\.(ts|tsx)$/.test(filePath) || // 枚举、实体、数据结构、逻辑、页面
|
|
8401
|
-
/^app\..*\.variables\.ts$/.test(filePath) || // 前端/服务端全局变量 (以app开头,以variables.ts结尾)
|
|
8402
|
-
/^extensions\.\w+\.(ts|tsx)$/.test(filePath) // 依赖库
|
|
8403
|
-
);
|
|
8404
|
-
}
|
|
8405
8388
|
|
|
8406
8389
|
/**
|
|
8407
8390
|
* Create a bound version of a function with a specified `this` context
|
|
@@ -29222,9 +29205,11 @@ function composeToString(files) {
|
|
|
29222
29205
|
// 判断是否是特殊文件类型(variables 或 extensions)
|
|
29223
29206
|
const isVariablesFile = nameFromPath === 'variables';
|
|
29224
29207
|
const isExtensionsFile = arr[0] === 'extensions';
|
|
29225
|
-
const
|
|
29208
|
+
const isThemeCss = ext === 'css' && nameFromPath === 'theme';
|
|
29209
|
+
const isSpecialFile = isVariablesFile || isExtensionsFile || isThemeCss;
|
|
29226
29210
|
// 特殊文件的 namespace 包含文件名,普通文件不包含
|
|
29227
29211
|
const namespace = isSpecialFile ? [...arr, nameFromPath].join('.') : arr.join('.');
|
|
29212
|
+
let content = file.content;
|
|
29228
29213
|
if (['ts', 'tsx'].includes(ext)) {
|
|
29229
29214
|
if (isVariablesFile) {
|
|
29230
29215
|
validateVariablesFile(file, errors);
|
|
@@ -29236,7 +29221,10 @@ function composeToString(files) {
|
|
|
29236
29221
|
validateNormalFile(file, nameFromPath, namespace, errors);
|
|
29237
29222
|
}
|
|
29238
29223
|
}
|
|
29239
|
-
|
|
29224
|
+
else if (isThemeCss) {
|
|
29225
|
+
content = ` $theme\`${content}\`;`;
|
|
29226
|
+
}
|
|
29227
|
+
return `namespace ${namespace} {\n${content}\n}\n`;
|
|
29240
29228
|
})
|
|
29241
29229
|
.join('\n');
|
|
29242
29230
|
if (errors.length > 0) {
|
|
@@ -37759,13 +37747,116 @@ function requireGlobby () {
|
|
|
37759
37747
|
var globbyExports = requireGlobby();
|
|
37760
37748
|
var globby = /*@__PURE__*/getDefaultExportFromCjs(globbyExports);
|
|
37761
37749
|
|
|
37750
|
+
/**
|
|
37751
|
+
* NASL 支持的所有文件类型配置
|
|
37752
|
+
*/
|
|
37753
|
+
const NASL_FILE_TYPES = [
|
|
37754
|
+
{
|
|
37755
|
+
name: 'theme-css',
|
|
37756
|
+
description: '主题样式',
|
|
37757
|
+
fileNamePattern: 'app\\.frontendTypes\\.pc\\.frontends\\.pc\\.theme\\.css',
|
|
37758
|
+
codeRefPattern: 'app\\.frontendTypes\\.pc\\.frontends\\.pc\\.theme',
|
|
37759
|
+
extension: 'css',
|
|
37760
|
+
},
|
|
37761
|
+
{
|
|
37762
|
+
name: 'structures',
|
|
37763
|
+
description: '数据结构',
|
|
37764
|
+
fileNamePattern: 'app\\.structures\\.\\w+\\.ts',
|
|
37765
|
+
codeRefPattern: 'app\\.structures\\.\\w+(?:\\.\\w+)*',
|
|
37766
|
+
extension: 'ts',
|
|
37767
|
+
},
|
|
37768
|
+
{
|
|
37769
|
+
name: 'entities',
|
|
37770
|
+
description: '实体',
|
|
37771
|
+
fileNamePattern: 'app\\.dataSources\\.\\w+\\.entities\\.\\w+\\.ts',
|
|
37772
|
+
codeRefPattern: 'app\\.dataSources\\.\\w+\\.entities\\.\\w+(?:Entity)?(?:\\.\\w+)*',
|
|
37773
|
+
extension: 'ts',
|
|
37774
|
+
},
|
|
37775
|
+
{
|
|
37776
|
+
name: 'logics',
|
|
37777
|
+
description: '逻辑',
|
|
37778
|
+
fileNamePattern: 'app\\.logics\\.\\w+\\.ts',
|
|
37779
|
+
codeRefPattern: 'app\\.logics\\.\\w+(?:\\.\\w+)*',
|
|
37780
|
+
extension: 'ts',
|
|
37781
|
+
},
|
|
37782
|
+
{
|
|
37783
|
+
name: 'views',
|
|
37784
|
+
description: '视图',
|
|
37785
|
+
fileNamePattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+(?:\\.views\\.\\w+)+\\.tsx',
|
|
37786
|
+
codeRefPattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+(?:\\.views\\.\\w+)+(?:\\.\\w+)*',
|
|
37787
|
+
extension: 'tsx',
|
|
37788
|
+
},
|
|
37789
|
+
{
|
|
37790
|
+
name: 'backend-variables',
|
|
37791
|
+
description: '后端全局变量',
|
|
37792
|
+
fileNamePattern: 'app\\.backend\\.variables\\.ts',
|
|
37793
|
+
codeRefPattern: 'app\\.backend\\.variables(?:\\.\\w+)*',
|
|
37794
|
+
extension: 'ts',
|
|
37795
|
+
},
|
|
37796
|
+
{
|
|
37797
|
+
name: 'frontend-variables',
|
|
37798
|
+
description: '前端全局变量',
|
|
37799
|
+
fileNamePattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+\\.variables\\.ts',
|
|
37800
|
+
codeRefPattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+\\.variables(?:\\.\\w+)*',
|
|
37801
|
+
extension: 'ts',
|
|
37802
|
+
},
|
|
37803
|
+
{
|
|
37804
|
+
name: 'enums',
|
|
37805
|
+
description: '枚举',
|
|
37806
|
+
fileNamePattern: 'app\\.enums\\.\\w+\\.ts',
|
|
37807
|
+
codeRefPattern: 'app\\.enums\\.\\w+(?:\\.\\w+)*',
|
|
37808
|
+
extension: 'ts',
|
|
37809
|
+
},
|
|
37810
|
+
{
|
|
37811
|
+
name: 'extensions',
|
|
37812
|
+
description: '依赖库',
|
|
37813
|
+
fileNamePattern: 'extensions\\.\\w+\\.ts',
|
|
37814
|
+
codeRefPattern: 'extensions\\.\\w+(?:\\.\\w+)*',
|
|
37815
|
+
extension: 'ts',
|
|
37816
|
+
},
|
|
37817
|
+
];
|
|
37818
|
+
/**
|
|
37819
|
+
* 获取用于验证文件名的正则表达式数组
|
|
37820
|
+
*/
|
|
37821
|
+
function getFileNamePatterns() {
|
|
37822
|
+
return NASL_FILE_TYPES.map((type) => new RegExp(`^${type.fileNamePattern}$`));
|
|
37823
|
+
}
|
|
37824
|
+
const fileNamePatterns = getFileNamePatterns();
|
|
37825
|
+
/**
|
|
37826
|
+
* 获取用于提取代码引用的正则表达式数组
|
|
37827
|
+
*/
|
|
37828
|
+
function getCodeRefPatterns() {
|
|
37829
|
+
return NASL_FILE_TYPES.map((type) => new RegExp(type.codeRefPattern, 'g'));
|
|
37830
|
+
}
|
|
37831
|
+
const codeRefPatterns = getCodeRefPatterns();
|
|
37832
|
+
/**
|
|
37833
|
+
* 判断文件路径是否为已知的 NASL 文件类型
|
|
37834
|
+
* 支持的类型:
|
|
37835
|
+
* - 数据结构 (structures): app.structures.{StructureName}.ts
|
|
37836
|
+
* - 实体 (entities): app.dataSources.{dsName}.entities.{EntityName}.ts
|
|
37837
|
+
* - 逻辑 (logics): app.logics.{logicName}.ts
|
|
37838
|
+
* - 视图 (views): app.frontendTypes.{type}.frontends.{name}.views.{viewName}.tsx
|
|
37839
|
+
* - 后端全局变量: app.backend.variables.ts
|
|
37840
|
+
* - 前端全局变量: app.frontendTypes.{type}.frontends.{name}.variables.ts
|
|
37841
|
+
* - 枚举 (enums): app.enums.{EnumName}.ts
|
|
37842
|
+
* - 依赖库 (extensions): extensions.{extensionName}.ts
|
|
37843
|
+
*
|
|
37844
|
+
* @param filePath 文件路径(绝对路径或相对路径)
|
|
37845
|
+
* @returns 是否为已知的 NASL 文件类型
|
|
37846
|
+
*/
|
|
37847
|
+
function isKnownFileType(filePath) {
|
|
37848
|
+
// 提取文件名
|
|
37849
|
+
const fileName = sysPath.basename(filePath);
|
|
37850
|
+
return fileNamePatterns.some((pattern) => pattern.test(fileName));
|
|
37851
|
+
}
|
|
37852
|
+
|
|
37762
37853
|
/**
|
|
37763
37854
|
* 扫描目录下的所有 NASL 文件
|
|
37764
37855
|
*/
|
|
37765
37856
|
async function scanNASLFiles(srcDir, representation, logger) {
|
|
37766
37857
|
try {
|
|
37767
37858
|
const pattern = representation === 'NaturalTS' ? '**/*.{ts,tsx}' : '**/*.nasl';
|
|
37768
|
-
const files = await globby([pattern, '
|
|
37859
|
+
const files = await globby([pattern, '**/app.frontendTypes.pc.frontends.pc.theme.css'], {
|
|
37769
37860
|
cwd: srcDir,
|
|
37770
37861
|
onlyFiles: true,
|
|
37771
37862
|
absolute: false,
|
|
@@ -37779,7 +37870,6 @@ async function scanNASLFiles(srcDir, representation, logger) {
|
|
|
37779
37870
|
}
|
|
37780
37871
|
async function scanEntryFiles(projectRoot, patterns, logger) {
|
|
37781
37872
|
try {
|
|
37782
|
-
patterns.push('!**/*.css');
|
|
37783
37873
|
const files = await globby(patterns, {
|
|
37784
37874
|
cwd: projectRoot,
|
|
37785
37875
|
onlyFiles: true,
|
|
@@ -37793,9 +37883,9 @@ async function scanEntryFiles(projectRoot, patterns, logger) {
|
|
|
37793
37883
|
}
|
|
37794
37884
|
}
|
|
37795
37885
|
/**
|
|
37796
|
-
* 从文件内容中提取
|
|
37886
|
+
* 从文件内容中提取 指定 格式的依赖引用
|
|
37797
37887
|
* @param content 文件内容
|
|
37798
|
-
* @returns 依赖的
|
|
37888
|
+
* @returns 依赖的 指定 路径列表
|
|
37799
37889
|
*/
|
|
37800
37890
|
function extractDeps(content) {
|
|
37801
37891
|
const deps = new Set();
|
|
@@ -37805,28 +37895,34 @@ function extractDeps(content) {
|
|
|
37805
37895
|
.replace(/\/\*[\s\S]*?\*\//g, '') // 移除多行注释 /* ... */
|
|
37806
37896
|
.replace(/'(?:[^'\\]|\\.)*'/g, '') // 移除单引号字符串 'xxx'
|
|
37807
37897
|
.replace(/"(?:[^"\\]|\\.)*"/g, ''); // 移除双引号字符串 "xxx"
|
|
37808
|
-
const
|
|
37809
|
-
|
|
37810
|
-
|
|
37811
|
-
|
|
37812
|
-
|
|
37813
|
-
|
|
37814
|
-
|
|
37815
|
-
|
|
37816
|
-
|
|
37817
|
-
|
|
37818
|
-
|
|
37819
|
-
|
|
37820
|
-
|
|
37821
|
-
|
|
37822
|
-
|
|
37823
|
-
|
|
37824
|
-
|
|
37825
|
-
|
|
37826
|
-
|
|
37898
|
+
for (const pattern of codeRefPatterns) {
|
|
37899
|
+
const matches = processedContent.matchAll(pattern);
|
|
37900
|
+
for (const match of matches) {
|
|
37901
|
+
let dep = match[0];
|
|
37902
|
+
// 处理 Entity 后缀:app.dataSources.ds.entities.EntityNameEntity -> app.dataSources.ds.entities.EntityName
|
|
37903
|
+
if (/Entity$|Entity\./.test(dep)) {
|
|
37904
|
+
dep = dep.replace(/Entity(\..*)?$/, '');
|
|
37905
|
+
}
|
|
37906
|
+
// 处理枚举:app.enums.EnumName.field -> app.enums.EnumName
|
|
37907
|
+
if (/^app\.enums\.\w+\./.test(dep)) {
|
|
37908
|
+
dep = dep.replace(/^(app\.enums\.\w+).+$/, '$1');
|
|
37909
|
+
}
|
|
37910
|
+
// 处理 variables:app.backend.variables.varName -> app.backend.variables
|
|
37911
|
+
if (/\.variables\.\w+/.test(dep)) {
|
|
37912
|
+
dep = dep.replace(/\.variables\..+$/, '.variables');
|
|
37913
|
+
}
|
|
37914
|
+
// 处理 extensions:extensions.lcap_auth.logics.getUser -> extensions.lcap_auth
|
|
37915
|
+
if (/^extensions\.\w+\./.test(dep)) {
|
|
37916
|
+
dep = dep.replace(/^(extensions\.\w+)\..+$/, '$1');
|
|
37917
|
+
}
|
|
37918
|
+
// 跳过不合法的实体引用(实体后还有字段的情况)
|
|
37919
|
+
if (/app\.dataSources\.\w+\.entities\.\w+\.\w+$/.test(dep)) {
|
|
37920
|
+
continue;
|
|
37921
|
+
}
|
|
37922
|
+
// 添加文件扩展名
|
|
37923
|
+
dep = `${dep}.${dep.includes('.views.') ? 'tsx' : 'ts'}`;
|
|
37924
|
+
deps.add(dep);
|
|
37827
37925
|
}
|
|
37828
|
-
dep = `${dep}.${dep.includes('.views.') ? 'tsx' : 'ts'}`;
|
|
37829
|
-
deps.add(dep);
|
|
37830
37926
|
}
|
|
37831
37927
|
return Array.from(deps);
|
|
37832
37928
|
}
|
|
@@ -38086,7 +38182,7 @@ async function tryCompile(entry, options) {
|
|
|
38086
38182
|
}
|
|
38087
38183
|
}
|
|
38088
38184
|
|
|
38089
|
-
var version = "0.
|
|
38185
|
+
var version = "0.2.0";
|
|
38090
38186
|
var pkg = {
|
|
38091
38187
|
version: version};
|
|
38092
38188
|
|