scancscode 1.0.9 → 1.0.11
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/CSCodeScanner.js +10 -3
- package/dist/CmdExecutor.js +3 -1
- package/dist/LiteralCollector.js +4 -4
- package/package.json +1 -1
- package/src/CSCodeScanner.ts +10 -3
- package/src/CmdExecutor.ts +3 -1
- package/src/LiteralCollector.ts +4 -4
package/dist/CSCodeScanner.js
CHANGED
|
@@ -35,7 +35,14 @@ class CSCodeScanner {
|
|
|
35
35
|
let lineColumn = content.lastIndexOf('\n', index);
|
|
36
36
|
return [lineIndex + 1, index - lineColumn];
|
|
37
37
|
}
|
|
38
|
-
static scanFile(filePath, content) {
|
|
38
|
+
static scanFile(filePath, content, trmethod) {
|
|
39
|
+
let trmethodParts = trmethod.split(".");
|
|
40
|
+
let trclassname = "Tr";
|
|
41
|
+
let trmethodname = "TR";
|
|
42
|
+
if (trmethodParts.length == 2) {
|
|
43
|
+
trclassname = trmethodParts[0];
|
|
44
|
+
trmethodname = trmethodParts[1];
|
|
45
|
+
}
|
|
39
46
|
const snippets = [];
|
|
40
47
|
const assignMatches = [...content.matchAll(CSCodeScanner.assignmentPattern)];
|
|
41
48
|
for (let j = 0; j < assignMatches.length; j++) {
|
|
@@ -74,7 +81,7 @@ class CSCodeScanner {
|
|
|
74
81
|
convertedAssignLine = assignMatch[1] + prefix + stringMatchFirst[0] + ";";
|
|
75
82
|
}
|
|
76
83
|
else {
|
|
77
|
-
convertedAssignLine = assignMatch[1] + prefix + stringMatchFirst[0] +
|
|
84
|
+
convertedAssignLine = assignMatch[1] + prefix + stringMatchFirst[0] + `.${trmethodname}();`;
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
else {
|
|
@@ -177,7 +184,7 @@ class CSCodeScanner {
|
|
|
177
184
|
else {
|
|
178
185
|
convertedAssignLine = assignLine;
|
|
179
186
|
}
|
|
180
|
-
let convertedAssignLine2 = convertedAssignLine.replaceAll(this.stringFormatPattern,
|
|
187
|
+
let convertedAssignLine2 = convertedAssignLine.replaceAll(this.stringFormatPattern, `${trclassname}.Format`);
|
|
181
188
|
snippets.push({
|
|
182
189
|
originalIndex: assignMatch.index,
|
|
183
190
|
originalCode: assignLine,
|
package/dist/CmdExecutor.js
CHANGED
|
@@ -29,6 +29,7 @@ class CmdExecutor {
|
|
|
29
29
|
{ name: "langs", type: String, multiple: true, defaultOption: true },
|
|
30
30
|
{ name: "verbose", alias: 'v', type: Boolean },
|
|
31
31
|
{ name: "scanonly", type: Boolean, defaultOption: false },
|
|
32
|
+
{ name: "trmethod", type: String }
|
|
32
33
|
];
|
|
33
34
|
const options = (0, command_line_args_1.default)(optionDefinitions);
|
|
34
35
|
let cscodedir = options.cscodedir ?? [];
|
|
@@ -37,6 +38,7 @@ class CmdExecutor {
|
|
|
37
38
|
let langs = options.langs ?? ["zh_cn"];
|
|
38
39
|
let verbose = options.verbose ?? false;
|
|
39
40
|
let scanonly = options.scanonly ?? false;
|
|
41
|
+
let trmethod = options.trmethod ?? "Tr.TR";
|
|
40
42
|
let argv = process.argv;
|
|
41
43
|
if (isNullOrEmpty(cscodedir) && isNullOrEmpty(configdir)) {
|
|
42
44
|
if (isNullOrEmpty(cscodedir)) {
|
|
@@ -58,7 +60,7 @@ class CmdExecutor {
|
|
|
58
60
|
}
|
|
59
61
|
console.log(`convert cmd options: `, cscodedir, configdir, outcsv, langs, verbose);
|
|
60
62
|
let literalCollector = new LiteralCollector_1.LiteralCollector();
|
|
61
|
-
await literalCollector.convert(cscodedir, configdir, outcsv, langs, scanonly, verbose);
|
|
63
|
+
await literalCollector.convert(cscodedir, configdir, outcsv, langs, trmethod, scanonly, verbose);
|
|
62
64
|
console.log("convert done.");
|
|
63
65
|
}
|
|
64
66
|
static testSlimCsv() {
|
package/dist/LiteralCollector.js
CHANGED
|
@@ -40,7 +40,7 @@ const CSCodeScanner_1 = require("./CSCodeScanner");
|
|
|
40
40
|
const CSVUtils_1 = require("./CSVUtils");
|
|
41
41
|
const TableScanner_1 = require("./TableScanner");
|
|
42
42
|
class LiteralCollector {
|
|
43
|
-
scanCodeInFolder(folder, literals, unexpects, scanonly, verbose) {
|
|
43
|
+
scanCodeInFolder(folder, literals, unexpects, trmethod, scanonly, verbose) {
|
|
44
44
|
if (fs.existsSync(folder) == false) {
|
|
45
45
|
console.warn(`代码目录不存在: ${folder}`);
|
|
46
46
|
return;
|
|
@@ -57,7 +57,7 @@ class LiteralCollector {
|
|
|
57
57
|
console.log(`处理文件: ${filePath}`);
|
|
58
58
|
}
|
|
59
59
|
const content = fs.readFileSync(fullPath, "utf-8");
|
|
60
|
-
const snippets = CSCodeScanner_1.CSCodeScanner.scanFile(fullPath, content);
|
|
60
|
+
const snippets = CSCodeScanner_1.CSCodeScanner.scanFile(fullPath, content, trmethod);
|
|
61
61
|
if (snippets.length > 0) {
|
|
62
62
|
if (!scanonly) {
|
|
63
63
|
let convertedContent = CSCodeScanner_1.CSCodeScanner.replaceInFile(content, snippets);
|
|
@@ -94,11 +94,11 @@ class LiteralCollector {
|
|
|
94
94
|
literals.length = 0;
|
|
95
95
|
literals.push(...literalsSet);
|
|
96
96
|
}
|
|
97
|
-
async convert(cscodeFolders, gameConfigFolders, outCsvFile, langs, scanonly = false, verbose = false) {
|
|
97
|
+
async convert(cscodeFolders, gameConfigFolders, outCsvFile, langs, trmethod = "Tr.TR", scanonly = false, verbose = false) {
|
|
98
98
|
let literals = [];
|
|
99
99
|
let unexpects = [];
|
|
100
100
|
for (const cscodeFolder of cscodeFolders) {
|
|
101
|
-
this.scanCodeInFolder(cscodeFolder, literals, unexpects, scanonly, verbose);
|
|
101
|
+
this.scanCodeInFolder(cscodeFolder, literals, unexpects, trmethod, scanonly, verbose);
|
|
102
102
|
}
|
|
103
103
|
for (const gameConfigFolder of gameConfigFolders) {
|
|
104
104
|
this.scanTablesInFolder(gameConfigFolder, literals, verbose);
|
package/package.json
CHANGED
package/src/CSCodeScanner.ts
CHANGED
|
@@ -41,7 +41,14 @@ export class CSCodeScanner {
|
|
|
41
41
|
return [lineIndex + 1, index - lineColumn];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
public static scanFile(filePath: string, content: string): CodeSnippet[] {
|
|
44
|
+
public static scanFile(filePath: string, content: string, trmethod: string): CodeSnippet[] {
|
|
45
|
+
let trmethodParts = trmethod.split(".");
|
|
46
|
+
let trclassname = "Tr"
|
|
47
|
+
let trmethodname = "TR"
|
|
48
|
+
if (trmethodParts.length == 2) {
|
|
49
|
+
trclassname = trmethodParts[0];
|
|
50
|
+
trmethodname = trmethodParts[1];
|
|
51
|
+
}
|
|
45
52
|
const snippets: CodeSnippet[] = [];
|
|
46
53
|
|
|
47
54
|
const assignMatches = [...content.matchAll(CSCodeScanner.assignmentPattern)];
|
|
@@ -81,7 +88,7 @@ export class CSCodeScanner {
|
|
|
81
88
|
if (this.isNativeString(stringLineFirst)) {
|
|
82
89
|
convertedAssignLine = assignMatch[1] + prefix + stringMatchFirst[0] + ";";
|
|
83
90
|
} else {
|
|
84
|
-
convertedAssignLine = assignMatch[1] + prefix + stringMatchFirst[0] +
|
|
91
|
+
convertedAssignLine = assignMatch[1] + prefix + stringMatchFirst[0] + `.${trmethodname}();`;
|
|
85
92
|
}
|
|
86
93
|
} else {
|
|
87
94
|
let stringLines: string[] = [];
|
|
@@ -186,7 +193,7 @@ export class CSCodeScanner {
|
|
|
186
193
|
convertedAssignLine = assignLine;
|
|
187
194
|
}
|
|
188
195
|
|
|
189
|
-
let convertedAssignLine2 = convertedAssignLine.replaceAll(this.stringFormatPattern,
|
|
196
|
+
let convertedAssignLine2 = convertedAssignLine.replaceAll(this.stringFormatPattern, `${trclassname}.Format`);
|
|
190
197
|
snippets.push({
|
|
191
198
|
originalIndex: assignMatch.index,
|
|
192
199
|
originalCode: assignLine,
|
package/src/CmdExecutor.ts
CHANGED
|
@@ -25,6 +25,7 @@ export class CmdExecutor {
|
|
|
25
25
|
{ name: "langs", type: String, multiple: true, defaultOption: true },
|
|
26
26
|
{ name: "verbose", alias: 'v', type: Boolean },
|
|
27
27
|
{ name: "scanonly", type: Boolean, defaultOption: false },
|
|
28
|
+
{ name: "trmethod", type: String }
|
|
28
29
|
]
|
|
29
30
|
const options = commandLineArgs(optionDefinitions)
|
|
30
31
|
let cscodedir: string[] = options.cscodedir ?? []
|
|
@@ -33,6 +34,7 @@ export class CmdExecutor {
|
|
|
33
34
|
let langs: string[] = options.langs ?? ["zh_cn"]
|
|
34
35
|
let verbose: boolean = options.verbose ?? false
|
|
35
36
|
let scanonly: boolean = options.scanonly ?? false
|
|
37
|
+
let trmethod: string = options.trmethod ?? "Tr.TR"
|
|
36
38
|
|
|
37
39
|
let argv = process.argv
|
|
38
40
|
if (isNullOrEmpty(cscodedir) && isNullOrEmpty(configdir)) {
|
|
@@ -55,7 +57,7 @@ export class CmdExecutor {
|
|
|
55
57
|
}
|
|
56
58
|
console.log(`convert cmd options: `, cscodedir, configdir, outcsv, langs, verbose)
|
|
57
59
|
let literalCollector = new LiteralCollector();
|
|
58
|
-
await literalCollector.convert(cscodedir, configdir, outcsv, langs, scanonly, verbose)
|
|
60
|
+
await literalCollector.convert(cscodedir, configdir, outcsv, langs, trmethod, scanonly, verbose)
|
|
59
61
|
console.log("convert done.")
|
|
60
62
|
}
|
|
61
63
|
static testSlimCsv() {
|
package/src/LiteralCollector.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { TableScanner } from "./TableScanner";
|
|
|
7
7
|
|
|
8
8
|
export class LiteralCollector {
|
|
9
9
|
|
|
10
|
-
scanCodeInFolder(folder: string, literals: string[], unexpects: string[], scanonly: boolean, verbose: boolean) {
|
|
10
|
+
scanCodeInFolder(folder: string, literals: string[], unexpects: string[], trmethod: string, scanonly: boolean, verbose: boolean) {
|
|
11
11
|
if (fs.existsSync(folder) == false) {
|
|
12
12
|
console.warn(`代码目录不存在: ${folder}`);
|
|
13
13
|
return;
|
|
@@ -25,7 +25,7 @@ export class LiteralCollector {
|
|
|
25
25
|
console.log(`处理文件: ${filePath}`);
|
|
26
26
|
}
|
|
27
27
|
const content = fs.readFileSync(fullPath, "utf-8");
|
|
28
|
-
const snippets = CSCodeScanner.scanFile(fullPath, content);
|
|
28
|
+
const snippets = CSCodeScanner.scanFile(fullPath, content, trmethod);
|
|
29
29
|
if (snippets.length > 0) {
|
|
30
30
|
if (!scanonly) {
|
|
31
31
|
let convertedContent = CSCodeScanner.replaceInFile(content, snippets);
|
|
@@ -69,12 +69,12 @@ export class LiteralCollector {
|
|
|
69
69
|
literals.push(...literalsSet);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
async convert(cscodeFolders: string[], gameConfigFolders: string[], outCsvFile: string, langs: string[], scanonly: boolean = false, verbose: boolean = false) {
|
|
72
|
+
async convert(cscodeFolders: string[], gameConfigFolders: string[], outCsvFile: string, langs: string[], trmethod: string = "Tr.TR", scanonly: boolean = false, verbose: boolean = false) {
|
|
73
73
|
|
|
74
74
|
let literals: string[] = [];
|
|
75
75
|
let unexpects: string[] = [];
|
|
76
76
|
for (const cscodeFolder of cscodeFolders) {
|
|
77
|
-
this.scanCodeInFolder(cscodeFolder, literals, unexpects, scanonly, verbose);
|
|
77
|
+
this.scanCodeInFolder(cscodeFolder, literals, unexpects, trmethod, scanonly, verbose);
|
|
78
78
|
}
|
|
79
79
|
for (const gameConfigFolder of gameConfigFolders) {
|
|
80
80
|
this.scanTablesInFolder(gameConfigFolder, literals, verbose);
|