@nasl/cli 0.1.19 → 0.2.1

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 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
  * 初始化命令 - 创建配置文件
@@ -29220,9 +29203,10 @@ async function checkApi(fullNaturalTS, options) {
29220
29203
  });
29221
29204
  const result = res.data.result;
29222
29205
  const errors = (result.errors || []);
29223
- console.log(`共检查到 ${errors.length} 个错误`);
29224
- if (errors.length > 0)
29206
+ if (errors.length > 0) {
29207
+ result.errorStr = `检查到以下错误(共 ${errors.length} 个):\n` + result.errorStr;
29225
29208
  return truncate(result.errorStr, 10000);
29209
+ }
29226
29210
  return '';
29227
29211
  }
29228
29212
 
@@ -29349,9 +29333,11 @@ function composeToString(files) {
29349
29333
  // 判断是否是特殊文件类型(variables 或 extensions)
29350
29334
  const isVariablesFile = nameFromPath === 'variables';
29351
29335
  const isExtensionsFile = arr[0] === 'extensions';
29352
- const isSpecialFile = isVariablesFile || isExtensionsFile;
29336
+ const isThemeCss = ext === 'css' && nameFromPath === 'theme';
29337
+ const isSpecialFile = isVariablesFile || isExtensionsFile || isThemeCss;
29353
29338
  // 特殊文件的 namespace 包含文件名,普通文件不包含
29354
29339
  const namespace = isSpecialFile ? [...arr, nameFromPath].join('.') : arr.join('.');
29340
+ let content = file.content;
29355
29341
  if (['ts', 'tsx'].includes(ext)) {
29356
29342
  if (isVariablesFile) {
29357
29343
  validateVariablesFile(file, errors);
@@ -29363,7 +29349,10 @@ function composeToString(files) {
29363
29349
  validateNormalFile(file, nameFromPath, namespace, errors);
29364
29350
  }
29365
29351
  }
29366
- return `namespace ${namespace} {\n${file.content}\n}\n`;
29352
+ else if (isThemeCss) {
29353
+ content = ` $theme\`${content}\`;`;
29354
+ }
29355
+ return `namespace ${namespace} {\n${content}\n}\n`;
29367
29356
  })
29368
29357
  .join('\n');
29369
29358
  if (errors.length > 0) {
@@ -37886,13 +37875,116 @@ function requireGlobby () {
37886
37875
  var globbyExports = requireGlobby();
37887
37876
  var globby = /*@__PURE__*/getDefaultExportFromCjs(globbyExports);
37888
37877
 
37878
+ /**
37879
+ * NASL 支持的所有文件类型配置
37880
+ */
37881
+ const NASL_FILE_TYPES = [
37882
+ {
37883
+ name: 'theme-css',
37884
+ description: '主题样式',
37885
+ fileNamePattern: 'app\\.frontendTypes\\.pc\\.frontends\\.pc\\.theme\\.css',
37886
+ codeRefPattern: 'app\\.frontendTypes\\.pc\\.frontends\\.pc\\.theme',
37887
+ extension: 'css',
37888
+ },
37889
+ {
37890
+ name: 'structures',
37891
+ description: '数据结构',
37892
+ fileNamePattern: 'app\\.structures\\.\\w+\\.ts',
37893
+ codeRefPattern: 'app\\.structures\\.\\w+(?:\\.\\w+)*',
37894
+ extension: 'ts',
37895
+ },
37896
+ {
37897
+ name: 'entities',
37898
+ description: '实体',
37899
+ fileNamePattern: 'app\\.dataSources\\.\\w+\\.entities\\.\\w+\\.ts',
37900
+ codeRefPattern: 'app\\.dataSources\\.\\w+\\.entities\\.\\w+(?:Entity)?(?:\\.\\w+)*',
37901
+ extension: 'ts',
37902
+ },
37903
+ {
37904
+ name: 'logics',
37905
+ description: '逻辑',
37906
+ fileNamePattern: 'app\\.logics\\.\\w+\\.ts',
37907
+ codeRefPattern: 'app\\.logics\\.\\w+(?:\\.\\w+)*',
37908
+ extension: 'ts',
37909
+ },
37910
+ {
37911
+ name: 'views',
37912
+ description: '视图',
37913
+ fileNamePattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+(?:\\.views\\.\\w+)+\\.tsx',
37914
+ codeRefPattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+(?:\\.views\\.\\w+)+(?:\\.\\w+)*',
37915
+ extension: 'tsx',
37916
+ },
37917
+ {
37918
+ name: 'backend-variables',
37919
+ description: '后端全局变量',
37920
+ fileNamePattern: 'app\\.backend\\.variables\\.ts',
37921
+ codeRefPattern: 'app\\.backend\\.variables(?:\\.\\w+)*',
37922
+ extension: 'ts',
37923
+ },
37924
+ {
37925
+ name: 'frontend-variables',
37926
+ description: '前端全局变量',
37927
+ fileNamePattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+\\.variables\\.ts',
37928
+ codeRefPattern: 'app\\.frontendTypes\\.\\w+\\.frontends\\.\\w+\\.variables(?:\\.\\w+)*',
37929
+ extension: 'ts',
37930
+ },
37931
+ {
37932
+ name: 'enums',
37933
+ description: '枚举',
37934
+ fileNamePattern: 'app\\.enums\\.\\w+\\.ts',
37935
+ codeRefPattern: 'app\\.enums\\.\\w+(?:\\.\\w+)*',
37936
+ extension: 'ts',
37937
+ },
37938
+ {
37939
+ name: 'extensions',
37940
+ description: '依赖库',
37941
+ fileNamePattern: 'extensions\\.\\w+\\.ts',
37942
+ codeRefPattern: 'extensions\\.\\w+(?:\\.\\w+)*',
37943
+ extension: 'ts',
37944
+ },
37945
+ ];
37946
+ /**
37947
+ * 获取用于验证文件名的正则表达式数组
37948
+ */
37949
+ function getFileNamePatterns() {
37950
+ return NASL_FILE_TYPES.map((type) => new RegExp(`^${type.fileNamePattern}$`));
37951
+ }
37952
+ const fileNamePatterns = getFileNamePatterns();
37953
+ /**
37954
+ * 获取用于提取代码引用的正则表达式数组
37955
+ */
37956
+ function getCodeRefPatterns() {
37957
+ return NASL_FILE_TYPES.map((type) => new RegExp(type.codeRefPattern, 'g'));
37958
+ }
37959
+ const codeRefPatterns = getCodeRefPatterns();
37960
+ /**
37961
+ * 判断文件路径是否为已知的 NASL 文件类型
37962
+ * 支持的类型:
37963
+ * - 数据结构 (structures): app.structures.{StructureName}.ts
37964
+ * - 实体 (entities): app.dataSources.{dsName}.entities.{EntityName}.ts
37965
+ * - 逻辑 (logics): app.logics.{logicName}.ts
37966
+ * - 视图 (views): app.frontendTypes.{type}.frontends.{name}.views.{viewName}.tsx
37967
+ * - 后端全局变量: app.backend.variables.ts
37968
+ * - 前端全局变量: app.frontendTypes.{type}.frontends.{name}.variables.ts
37969
+ * - 枚举 (enums): app.enums.{EnumName}.ts
37970
+ * - 依赖库 (extensions): extensions.{extensionName}.ts
37971
+ *
37972
+ * @param filePath 文件路径(绝对路径或相对路径)
37973
+ * @returns 是否为已知的 NASL 文件类型
37974
+ */
37975
+ function isKnownFileType(filePath) {
37976
+ // 提取文件名
37977
+ const fileName = sysPath.basename(filePath);
37978
+ return fileNamePatterns.some((pattern) => pattern.test(fileName));
37979
+ }
37980
+
37889
37981
  /**
37890
37982
  * 扫描目录下的所有 NASL 文件
37891
37983
  */
37892
37984
  async function scanNASLFiles(srcDir, representation, logger) {
37893
37985
  try {
37894
37986
  const pattern = representation === 'NaturalTS' ? '**/*.{ts,tsx}' : '**/*.nasl';
37895
- const files = await globby([pattern, '!**/*.css'], {
37987
+ const files = await globby([pattern, '**/app.frontendTypes.pc.frontends.pc.theme.css'], {
37896
37988
  cwd: srcDir,
37897
37989
  onlyFiles: true,
37898
37990
  absolute: false,
@@ -37906,7 +37998,6 @@ async function scanNASLFiles(srcDir, representation, logger) {
37906
37998
  }
37907
37999
  async function scanEntryFiles(projectRoot, patterns, logger) {
37908
38000
  try {
37909
- patterns.push('!**/*.css');
37910
38001
  const files = await globby(patterns, {
37911
38002
  cwd: projectRoot,
37912
38003
  onlyFiles: true,
@@ -37920,9 +38011,9 @@ async function scanEntryFiles(projectRoot, patterns, logger) {
37920
38011
  }
37921
38012
  }
37922
38013
  /**
37923
- * 从文件内容中提取 app.* 格式的依赖引用
38014
+ * 从文件内容中提取 指定 格式的依赖引用
37924
38015
  * @param content 文件内容
37925
- * @returns 依赖的 app.* 路径列表
38016
+ * @returns 依赖的 指定 路径列表
37926
38017
  */
37927
38018
  function extractDeps(content) {
37928
38019
  const deps = new Set();
@@ -37932,28 +38023,34 @@ function extractDeps(content) {
37932
38023
  .replace(/\/\*[\s\S]*?\*\//g, '') // 移除多行注释 /* ... */
37933
38024
  .replace(/'(?:[^'\\]|\\.)*'/g, '') // 移除单引号字符串 'xxx'
37934
38025
  .replace(/"(?:[^"\\]|\\.)*"/g, ''); // 移除双引号字符串 "xxx"
37935
- const allMatches = processedContent.matchAll(/(app|extensions)\.\w+\.[\w.]+/g); // 起码要2个点,支持 app.* 和 extensions.*
37936
- for (const match of allMatches) {
37937
- let dep = match[0];
37938
- if (/Entity$|Entity\./.test(dep)) {
37939
- dep = dep.replace(/Entity(\..*)?$/, '');
37940
- }
37941
- else if (/\.enums\.(\w+)\.(\w+)/.test(dep)) {
37942
- dep = dep.replace(/\.enums\.(\w+).+$/, '.enums.$1');
37943
- }
37944
- else if (/\.variables\.(\w+)/.test(dep)) {
37945
- // 处理 variables 依赖:app.backend.variables.xxx -> app.backend.variables
37946
- dep = dep.replace(/\.variables\..+$/, '.variables');
37947
- }
37948
- else if (/^extensions\.\w+\.\w+/.test(dep)) {
37949
- // 处理 extensions 依赖:extensions.lcap_auth.xxx -> extensions.lcap_auth
37950
- dep = dep.replace(/^(extensions\.\w+)\..+$/, '$1');
37951
- }
37952
- else if (/app\.dataSources\.\w+\.entities\.\w+\.\w+$/.test(dep)) {
37953
- continue; // 应该是写法有问题,跳过让后面的 checker 做检查
38026
+ for (const pattern of codeRefPatterns) {
38027
+ const matches = processedContent.matchAll(pattern);
38028
+ for (const match of matches) {
38029
+ let dep = match[0];
38030
+ // 处理 Entity 后缀:app.dataSources.ds.entities.EntityNameEntity -> app.dataSources.ds.entities.EntityName
38031
+ if (/Entity$|Entity\./.test(dep)) {
38032
+ dep = dep.replace(/Entity(\..*)?$/, '');
38033
+ }
38034
+ // 处理枚举:app.enums.EnumName.field -> app.enums.EnumName
38035
+ if (/^app\.enums\.\w+\./.test(dep)) {
38036
+ dep = dep.replace(/^(app\.enums\.\w+).+$/, '$1');
38037
+ }
38038
+ // 处理 variables:app.backend.variables.varName -> app.backend.variables
38039
+ if (/\.variables\.\w+/.test(dep)) {
38040
+ dep = dep.replace(/\.variables\..+$/, '.variables');
38041
+ }
38042
+ // 处理 extensions:extensions.lcap_auth.logics.getUser -> extensions.lcap_auth
38043
+ if (/^extensions\.\w+\./.test(dep)) {
38044
+ dep = dep.replace(/^(extensions\.\w+)\..+$/, '$1');
38045
+ }
38046
+ // 跳过不合法的实体引用(实体后还有字段的情况)
38047
+ if (/app\.dataSources\.\w+\.entities\.\w+\.\w+$/.test(dep)) {
38048
+ continue;
38049
+ }
38050
+ // 添加文件扩展名
38051
+ dep = `${dep}.${dep.includes('.views.') ? 'tsx' : 'ts'}`;
38052
+ deps.add(dep);
37954
38053
  }
37955
- dep = `${dep}.${dep.includes('.views.') ? 'tsx' : 'ts'}`;
37956
- deps.add(dep);
37957
38054
  }
37958
38055
  return Array.from(deps);
37959
38056
  }
@@ -38199,7 +38296,7 @@ async function compile(entry, options) {
38199
38296
  logger.success(`所有文件已输出到: ${outDir}`);
38200
38297
  }
38201
38298
  catch (error) {
38202
- logger.error(`编译失败:\n${error.message}`);
38299
+ logger.error(`编译过程发生错误:\n${error.message}`);
38203
38300
  logger.exit(1);
38204
38301
  }
38205
38302
  return { config, outDir };
@@ -38666,7 +38763,7 @@ async function transform(transformType, entry, options) {
38666
38763
  await transformFn(entry, options);
38667
38764
  }
38668
38765
 
38669
- var version = "0.1.19";
38766
+ var version = "0.2.1";
38670
38767
  var pkg = {
38671
38768
  version: version};
38672
38769