scancscode 1.0.30 → 1.0.33

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.
Files changed (55) hide show
  1. package/.trae/specs/fix-doc-comment-boundary/checklist.md +7 -0
  2. package/.trae/specs/fix-doc-comment-boundary/spec.md +52 -0
  3. package/.trae/specs/fix-doc-comment-boundary/tasks.md +34 -0
  4. package/.trae/specs/fix-interpolated-string-nested-literals/checklist.md +7 -0
  5. package/.trae/specs/fix-interpolated-string-nested-literals/spec.md +55 -0
  6. package/.trae/specs/fix-interpolated-string-nested-literals/tasks.md +25 -0
  7. package/.trae/specs/fix-remaining-interpolated-string-index/checklist.md +9 -0
  8. package/.trae/specs/fix-remaining-interpolated-string-index/spec.md +59 -0
  9. package/.trae/specs/fix-remaining-interpolated-string-index/tasks.md +41 -0
  10. package/.trae/specs/fix-return-interpolated-string/checklist.md +8 -0
  11. package/.trae/specs/fix-return-interpolated-string/spec.md +60 -0
  12. package/.trae/specs/fix-return-interpolated-string/tasks.md +39 -0
  13. package/.trae/specs/handle-interpolated-string-double-braces/checklist.md +9 -0
  14. package/.trae/specs/handle-interpolated-string-double-braces/spec.md +61 -0
  15. package/.trae/specs/handle-interpolated-string-double-braces/tasks.md +41 -0
  16. package/.trae/specs/handle-return-statement/checklist.md +11 -0
  17. package/.trae/specs/handle-return-statement/spec.md +76 -0
  18. package/.trae/specs/handle-return-statement/tasks.md +44 -0
  19. package/.trae/specs/handle-special-string-characters/checklist.md +13 -0
  20. package/.trae/specs/handle-special-string-characters/spec.md +94 -0
  21. package/.trae/specs/handle-special-string-characters/tasks.md +74 -0
  22. package/.trae/specs/unify-return-statement-string-extraction/checklist.md +10 -0
  23. package/.trae/specs/unify-return-statement-string-extraction/spec.md +70 -0
  24. package/.trae/specs/unify-return-statement-string-extraction/tasks.md +54 -0
  25. package/bin/scanliterals.js +3 -3
  26. package/bin/slimlangs.js +3 -3
  27. package/dist/src/CSharpStringExtractor.js +1755 -358
  28. package/dist/src/CmdExecutor.js +6 -8
  29. package/dist/test/CSharpStringExtractor.test.js +1484 -207
  30. package/docs/CSharpStringExtractor/344/273/243/347/240/201/347/224/237/346/210/220/346/217/220/347/244/272/350/257/215.txt +73 -0
  31. package/jest.config.js +9 -9
  32. package/package.json +1 -1
  33. package/src/CSCodeScanner.ts +305 -305
  34. package/src/CSVUtils.ts +181 -181
  35. package/src/CSharpStringExtractor.ts +2019 -479
  36. package/src/CmdExecutor.ts +107 -106
  37. package/src/LiteralCollector.ts +143 -143
  38. package/src/RunConvert.ts +3 -3
  39. package/src/RunSlimLangs.ts +3 -3
  40. package/src/TableScanner.ts +92 -92
  41. package/test/CSharpStringExtractor.test.ts +1564 -208
  42. package/test/KeeperDialog.cs +114 -0
  43. package/test/TestSpecialString.cs +24 -0
  44. package/tsconfig.json +109 -109
  45. package/dist/CSCodeScanner.js +0 -271
  46. package/dist/CSVUtils.js +0 -218
  47. package/dist/CmdExecutor.js +0 -101
  48. package/dist/CodeSnippet.js +0 -2
  49. package/dist/LiteralCollector.js +0 -124
  50. package/dist/RunConvert.js +0 -4
  51. package/dist/RunSlimLangs.js +0 -4
  52. package/dist/TableScanner.js +0 -107
  53. package/dist/TestConvert.test.js +0 -10
  54. package/dist/TestSlimCsv.test.js +0 -10
  55. package/dist/index.js +0 -4
@@ -1,92 +1,92 @@
1
- import * as fs from "fs";
2
- import { glob } from "glob";
3
-
4
-
5
- export class TableScanner {
6
- parseTrStrFields(content: string) {
7
- let m = content.match(/\/\/ NeedTranslateFields\: \[([a-zA-Z_,\s0-9]*)\]$/m);
8
- if (m != null) {
9
- let wordsContent = m[1];
10
- let words = wordsContent.split(", ");
11
- return words;
12
- } else {
13
- return [];
14
- }
15
- }
16
- scanJsonWords(jsonContent: string, fields: string[], literals: string[]) {
17
- try {
18
- let arr = JSON.parse(jsonContent);
19
- for (const jsonRow of arr) {
20
- for (const key of fields) {
21
- let value = jsonRow[key];
22
- if (typeof (value) == "string") {
23
- literals.push(value);
24
- } else if (Array.isArray(value)) {
25
- literals.push(...value);
26
- }
27
- }
28
- }
29
- } catch (error) {
30
- console.error(`解析JSON失败: ${error}`);
31
- }
32
- }
33
- async scanTableLiterals(csFullPath: string, literals: string[], verbose: boolean) {
34
- // csFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/GameConfigs/Main/RefinerTable-RefinerEventTable.cs";
35
- let jsonFullPath = csFullPath.replace("/Main/", "/Auto/").replace(/\.cs$/, ".json");
36
- try {
37
- const [csExists, jsonExists] = await Promise.all([
38
- fs.promises.access(csFullPath).then(() => true).catch(() => false),
39
- fs.promises.access(jsonFullPath).then(() => true).catch(() => false)
40
- ]);
41
-
42
- if (jsonExists && csExists) {
43
- const [csContent, jsonContent] = await Promise.all([
44
- fs.promises.readFile(csFullPath, "utf-8"),
45
- fs.promises.readFile(jsonFullPath, "utf-8")
46
- ]);
47
-
48
- let trstrFields = this.parseTrStrFields(csContent);
49
- if (trstrFields.length > 0) {
50
- if (verbose) {
51
- console.log(`扫描表格: ${csFullPath} , 需要翻译字段: ${trstrFields}`);
52
- }
53
- this.scanJsonWords(jsonContent, trstrFields, literals);
54
- } else {
55
- if (verbose) {
56
- console.log(`跳过表格: ${csFullPath}`);
57
- }
58
- }
59
- } else {
60
- if (verbose) {
61
- if (!csExists) {
62
- console.warn(`表格 CS 文件不存在: ${jsonFullPath}`);
63
- }
64
- if (!jsonExists) {
65
- console.warn(`表格 JSON 文件不存在: ${csFullPath}`);
66
- }
67
- }
68
- }
69
- } catch (error) {
70
- console.error(`处理表格文件失败: ${csFullPath}`, error);
71
- }
72
- }
73
- /**
74
- * 扫描
75
- */
76
- async scanTablesLiterals(folder: string, literals: string[], verbose: boolean) {
77
- let dir = folder;
78
- let files = glob.sync("*.cs", { cwd: dir });
79
-
80
- // 限制并行处理的文件数量,避免内存占用过高
81
- const batchSize = 10;
82
- for (let i = 0; i < files.length; i += batchSize) {
83
- const batchFiles = files.slice(i, i + batchSize).reverse();
84
- const batchPromises = batchFiles.map(async (filePath) => {
85
- let csFullPath = folder + filePath;
86
- await this.scanTableLiterals(csFullPath, literals, verbose);
87
- });
88
-
89
- await Promise.all(batchPromises);
90
- }
91
- }
92
- }
1
+ import * as fs from "fs";
2
+ import { glob } from "glob";
3
+
4
+
5
+ export class TableScanner {
6
+ parseTrStrFields(content: string) {
7
+ let m = content.match(/\/\/ NeedTranslateFields\: \[([a-zA-Z_,\s0-9]*)\]$/m);
8
+ if (m != null) {
9
+ let wordsContent = m[1];
10
+ let words = wordsContent.split(", ");
11
+ return words;
12
+ } else {
13
+ return [];
14
+ }
15
+ }
16
+ scanJsonWords(jsonContent: string, fields: string[], literals: string[]) {
17
+ try {
18
+ let arr = JSON.parse(jsonContent);
19
+ for (const jsonRow of arr) {
20
+ for (const key of fields) {
21
+ let value = jsonRow[key];
22
+ if (typeof (value) == "string") {
23
+ literals.push(value);
24
+ } else if (Array.isArray(value)) {
25
+ literals.push(...value);
26
+ }
27
+ }
28
+ }
29
+ } catch (error) {
30
+ console.error(`解析JSON失败: ${error}`);
31
+ }
32
+ }
33
+ async scanTableLiterals(csFullPath: string, literals: string[], verbose: boolean) {
34
+ // csFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/GameConfigs/Main/RefinerTable-RefinerEventTable.cs";
35
+ let jsonFullPath = csFullPath.replace("/Main/", "/Auto/").replace(/\.cs$/, ".json");
36
+ try {
37
+ const [csExists, jsonExists] = await Promise.all([
38
+ fs.promises.access(csFullPath).then(() => true).catch(() => false),
39
+ fs.promises.access(jsonFullPath).then(() => true).catch(() => false)
40
+ ]);
41
+
42
+ if (jsonExists && csExists) {
43
+ const [csContent, jsonContent] = await Promise.all([
44
+ fs.promises.readFile(csFullPath, "utf-8"),
45
+ fs.promises.readFile(jsonFullPath, "utf-8")
46
+ ]);
47
+
48
+ let trstrFields = this.parseTrStrFields(csContent);
49
+ if (trstrFields.length > 0) {
50
+ if (verbose) {
51
+ console.log(`扫描表格: ${csFullPath} , 需要翻译字段: ${trstrFields}`);
52
+ }
53
+ this.scanJsonWords(jsonContent, trstrFields, literals);
54
+ } else {
55
+ if (verbose) {
56
+ console.log(`跳过表格: ${csFullPath}`);
57
+ }
58
+ }
59
+ } else {
60
+ if (verbose) {
61
+ if (!csExists) {
62
+ console.warn(`表格 CS 文件不存在: ${jsonFullPath}`);
63
+ }
64
+ if (!jsonExists) {
65
+ console.warn(`表格 JSON 文件不存在: ${csFullPath}`);
66
+ }
67
+ }
68
+ }
69
+ } catch (error) {
70
+ console.error(`处理表格文件失败: ${csFullPath}`, error);
71
+ }
72
+ }
73
+ /**
74
+ * 扫描
75
+ */
76
+ async scanTablesLiterals(folder: string, literals: string[], verbose: boolean) {
77
+ let dir = folder;
78
+ let files = glob.sync("*.cs", { cwd: dir });
79
+
80
+ // 限制并行处理的文件数量,避免内存占用过高
81
+ const batchSize = 10;
82
+ for (let i = 0; i < files.length; i += batchSize) {
83
+ const batchFiles = files.slice(i, i + batchSize).reverse();
84
+ const batchPromises = batchFiles.map(async (filePath) => {
85
+ let csFullPath = folder + filePath;
86
+ await this.scanTableLiterals(csFullPath, literals, verbose);
87
+ });
88
+
89
+ await Promise.all(batchPromises);
90
+ }
91
+ }
92
+ }