|
| 1 | +import path = require("path"); |
| 2 | +import fs = require("fs"); |
| 3 | + |
1 | 4 | interface DiagnosticDetails { |
2 | 5 | category: string; |
3 | 6 | code: number; |
4 | 7 | reportsUnnecessary?: {}; |
5 | 8 | isEarly?: boolean; |
6 | 9 | } |
7 | 10 |
|
8 | | -type InputDiagnosticMessageTable = ts.Map<DiagnosticDetails>; |
| 11 | +type InputDiagnosticMessageTable = Map<string, DiagnosticDetails>; |
9 | 12 |
|
10 | 13 | function main(): void { |
11 | | - const sys = ts.sys; |
12 | | - if (sys.args.length < 1) { |
13 | | - sys.write("Usage:" + sys.newLine); |
14 | | - sys.write("\tnode processDiagnosticMessages.js <diagnostic-json-input-file>" + sys.newLine); |
| 14 | + if (process.argv.length < 3) { |
| 15 | + console.log("Usage:"); |
| 16 | + console.log("\tnode processDiagnosticMessages.js <diagnostic-json-input-file>"); |
15 | 17 | return; |
16 | 18 | } |
17 | 19 |
|
18 | 20 | function writeFile(fileName: string, contents: string) { |
19 | | - const inputDirectory = ts.getDirectoryPath(inputFilePath); |
20 | | - const fileOutputPath = ts.combinePaths(inputDirectory, fileName); |
21 | | - sys.writeFile(fileOutputPath, contents); |
| 21 | + fs.writeFile(path.join(path.dirname(inputFilePath), fileName), contents, { encoding: "utf-8" }, err => { |
| 22 | + if (err) throw err; |
| 23 | + }) |
22 | 24 | } |
23 | 25 |
|
24 | | - const inputFilePath = sys.args[0].replace(/\\/g, "/"); |
25 | | - const inputStr = sys.readFile(inputFilePath)!; |
| 26 | + const inputFilePath = process.argv[2].replace(/\\/g, "/"); |
| 27 | + console.log(`Reading diagnostics from ${inputFilePath}`); |
| 28 | + const inputStr = fs.readFileSync(inputFilePath, { encoding: "utf-8" }); |
26 | 29 |
|
27 | 30 | const diagnosticMessagesJson: { [key: string]: DiagnosticDetails } = JSON.parse(inputStr); |
28 | 31 |
|
29 | | - const diagnosticMessages: InputDiagnosticMessageTable = ts.createMapFromTemplate(diagnosticMessagesJson); |
| 32 | + const diagnosticMessages: InputDiagnosticMessageTable = new Map(); |
| 33 | + for (const key in diagnosticMessagesJson) { |
| 34 | + if (Object.hasOwnProperty.call(diagnosticMessagesJson, key)) { |
| 35 | + diagnosticMessages.set(key, diagnosticMessagesJson[key]); |
| 36 | + } |
| 37 | + } |
30 | 38 |
|
31 | | - const outputFilesDir = ts.getDirectoryPath(inputFilePath); |
32 | | - const thisFilePathRel = ts.getRelativePathToDirectoryOrUrl(outputFilesDir, sys.getExecutingFilePath(), |
33 | | - sys.getCurrentDirectory(), ts.createGetCanonicalFileName(sys.useCaseSensitiveFileNames), /* isAbsolutePathAnUrl */ false); |
| 39 | + const outputFilesDir = path.dirname(inputFilePath); |
| 40 | + const thisFilePathRel = path.relative(process.cwd(), outputFilesDir); |
34 | 41 |
|
35 | 42 | const infoFileOutput = buildInfoFileOutput(diagnosticMessages, "./diagnosticInformationMap.generated.ts", thisFilePathRel); |
36 | 43 | checkForUniqueCodes(diagnosticMessages); |
|
0 commit comments