@nasl/cli 0.3.4 → 0.3.5
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/README.md +24 -3
- package/dist/bin/nasl.mjs +37 -15
- package/dist/bin/nasl.mjs.map +1 -1
- package/dist/bin/naslc.mjs +37 -15
- package/dist/bin/naslc.mjs.map +1 -1
- package/dist/index.mjs +36 -14
- package/dist/index.mjs.map +1 -1
- package/out/constants/nasl-file-types.d.ts +1 -1
- package/out/constants/nasl-file-types.d.ts.map +1 -1
- package/out/constants/nasl-file-types.js +8 -1
- package/out/constants/nasl-file-types.js.map +1 -1
- package/out/services/compose.d.ts.map +1 -1
- package/out/services/compose.js +21 -8
- package/out/services/compose.js.map +1 -1
- package/out/services/resolve.d.ts.map +1 -1
- package/out/services/resolve.js +7 -5
- package/out/services/resolve.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -39,7 +39,18 @@ const DEFAULT_CONFIG = {
|
|
|
39
39
|
const CONFIG_FILE_NAME = 'nasl.config.json';
|
|
40
40
|
|
|
41
41
|
function createSorter() {
|
|
42
|
-
const priorityOrder = [
|
|
42
|
+
const priorityOrder = [
|
|
43
|
+
'extensions',
|
|
44
|
+
'apis',
|
|
45
|
+
'connectors',
|
|
46
|
+
'app.backend.variables',
|
|
47
|
+
'app.roles',
|
|
48
|
+
'app.enums',
|
|
49
|
+
'app.dataSources',
|
|
50
|
+
'app.structures',
|
|
51
|
+
'app.logics',
|
|
52
|
+
'app.frontendTypes',
|
|
53
|
+
];
|
|
43
54
|
// 获取优先级索引
|
|
44
55
|
const getPriority = (str) => {
|
|
45
56
|
const prefixIndex = priorityOrder.findIndex((p) => str.startsWith(p));
|
|
@@ -53,13 +64,11 @@ function createSorter() {
|
|
|
53
64
|
return aPriority - bPriority;
|
|
54
65
|
}
|
|
55
66
|
// 如果是frontendTypes,按字母顺序排序
|
|
56
|
-
if (
|
|
67
|
+
if (a.startsWith('app.frontendTypes') && b.startsWith('app.frontendTypes')) {
|
|
57
68
|
return a.localeCompare(b);
|
|
58
69
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return 0;
|
|
62
|
-
}
|
|
70
|
+
// 其他情况保持原顺序
|
|
71
|
+
return 0;
|
|
63
72
|
};
|
|
64
73
|
}
|
|
65
74
|
const sorter = createSorter();
|
|
@@ -127,11 +136,15 @@ function composeToString(files, options) {
|
|
|
127
136
|
const isVariablesFile = nameFromPath === 'variables';
|
|
128
137
|
const isExtensionsFile = arr[0] === 'extensions';
|
|
129
138
|
const isThemeCss = ext === 'css' && nameFromPath === 'theme';
|
|
130
|
-
const
|
|
139
|
+
const isRolesJson = file.path === 'app.roles.json';
|
|
140
|
+
const isSpecialFile = isVariablesFile || isExtensionsFile || isThemeCss || isRolesJson;
|
|
131
141
|
// 特殊文件的 namespace ${包含文件名,普通文件不包含
|
|
132
142
|
const namespace = isSpecialFile ? [...arr, nameFromPath].join('.') : arr.join('.');
|
|
133
143
|
let content = file.content;
|
|
134
|
-
if (
|
|
144
|
+
if (isRolesJson) {
|
|
145
|
+
content = ` $roles(${content});`;
|
|
146
|
+
}
|
|
147
|
+
else if (['ts', 'tsx'].includes(ext)) {
|
|
135
148
|
if (isVariablesFile) {
|
|
136
149
|
validateVariablesFile(file, errors);
|
|
137
150
|
}
|
|
@@ -13754,6 +13767,13 @@ function writeFileWithLog(filePath, content, logger) {
|
|
|
13754
13767
|
* NASL 支持的所有文件类型配置
|
|
13755
13768
|
*/
|
|
13756
13769
|
const NASL_FILE_TYPES = [
|
|
13770
|
+
{
|
|
13771
|
+
name: 'roles',
|
|
13772
|
+
description: '角色',
|
|
13773
|
+
fileNamePattern: 'app\\.roles\\.json',
|
|
13774
|
+
codeRefPattern: '',
|
|
13775
|
+
extension: 'json',
|
|
13776
|
+
},
|
|
13757
13777
|
{
|
|
13758
13778
|
name: 'theme-css',
|
|
13759
13779
|
description: '主题样式',
|
|
@@ -13850,7 +13870,7 @@ const fileNamePatterns = getFileNamePatterns();
|
|
|
13850
13870
|
* 获取用于提取代码引用的正则表达式数组
|
|
13851
13871
|
*/
|
|
13852
13872
|
function getCodeRefPatterns() {
|
|
13853
|
-
return NASL_FILE_TYPES.map((type) => new RegExp(type.codeRefPattern, 'g'));
|
|
13873
|
+
return NASL_FILE_TYPES.filter((type) => type.codeRefPattern).map((type) => new RegExp(type.codeRefPattern, 'g'));
|
|
13854
13874
|
}
|
|
13855
13875
|
const codeRefPatterns = getCodeRefPatterns();
|
|
13856
13876
|
/**
|
|
@@ -13885,7 +13905,7 @@ function shouldSkipDependencyTraversal(depPath) {
|
|
|
13885
13905
|
async function scanNASLFiles(srcDir, representation, logger) {
|
|
13886
13906
|
try {
|
|
13887
13907
|
const pattern = representation === 'NaturalTS' ? '**/*.{ts,tsx}' : '**/*.nasl';
|
|
13888
|
-
const files = await globby([pattern, '
|
|
13908
|
+
const files = await globby([pattern, 'app.frontendTypes.pc.frontends.pc.theme.css', 'app.roles.json'], {
|
|
13889
13909
|
cwd: srcDir,
|
|
13890
13910
|
onlyFiles: true,
|
|
13891
13911
|
absolute: false,
|
|
@@ -14119,9 +14139,9 @@ function buildExternalDependencies(refs, mergedDeps, logger) {
|
|
|
14119
14139
|
function replaceViewAsSignature(content, hasSubViews = false) {
|
|
14120
14140
|
if (hasSubViews) {
|
|
14121
14141
|
// 如果有子页面,替换为返回 ElRouterView 的函数
|
|
14122
|
-
return content.replace(/export function ((\w+)\([
|
|
14142
|
+
return content.replace(/export function ((\w+)\([\s\S]*?\)) \{[\s\S]+$/, 'export function $1 {\n return <ElRouterView />\n}');
|
|
14123
14143
|
}
|
|
14124
|
-
return content.replace(/export function ((\w+)\([
|
|
14144
|
+
return content.replace(/export function ((\w+)\([\s\S]*?\)) \{[\s\S]+$/, 'export declare function $1;');
|
|
14125
14145
|
}
|
|
14126
14146
|
/**
|
|
14127
14147
|
* 处理单个文件的依赖
|
|
@@ -14163,8 +14183,10 @@ function processFileDeps(pathRelativeToSrc, srcDir, matchedFileSet, processedFil
|
|
|
14163
14183
|
processedFileMap.set(pathRelativeToSrc, fileInfo);
|
|
14164
14184
|
// 提取依赖
|
|
14165
14185
|
// extensions/connectors/apis/uilibs 作为叶子节点,不再向下递归查找依赖
|
|
14186
|
+
// JSON 文件(如 app.roles.json)无代码引用,跳过依赖分析
|
|
14166
14187
|
const isExternalDep = shouldSkipDependencyTraversal(pathRelativeToSrc);
|
|
14167
|
-
const
|
|
14188
|
+
const isRolesJson = pathRelativeToSrc === 'app.roles.json';
|
|
14189
|
+
const deps = isExternalDep || isRolesJson ? [] : extractDeps(fileInfo.content);
|
|
14168
14190
|
// 查找依赖文件
|
|
14169
14191
|
if (isView) {
|
|
14170
14192
|
const pathArr = pathRelativeToSrc.split('.');
|
|
@@ -14290,7 +14312,7 @@ async function resolveNASLFiles(entry, logger, depMode, verbose) {
|
|
|
14290
14312
|
}
|
|
14291
14313
|
let externalRefs = null;
|
|
14292
14314
|
if (!entry && depMode)
|
|
14293
|
-
entry = 'src/**/app.*.{ts,tsx,css}';
|
|
14315
|
+
entry = ['src/**/app.*.{ts,tsx,css}', 'src/app.roles.json'];
|
|
14294
14316
|
if (entry) {
|
|
14295
14317
|
// 检查入口路径是否在源代码目录外面
|
|
14296
14318
|
// if (entry.startsWith('..')) throw new Error('入口路径不能在源代码目录外面');
|