@@ -18,6 +18,13 @@ function main(): void {
18
18
return ;
19
19
}
20
20
21
+ function writeFile ( fileName : string , contents : string ) {
22
+ // TODO: Fix path joining
23
+ var inputDirectory = inputFilePath . substr ( 0 , inputFilePath . lastIndexOf ( "/" ) ) ;
24
+ var fileOutputPath = inputDirectory + "/" + fileName ;
25
+ sys . writeFile ( fileOutputPath , contents ) ;
26
+ }
27
+
21
28
var inputFilePath = sys . args [ 0 ] . replace ( / \\ / g, "/" ) ;
22
29
var inputStr = sys . readFile ( inputFilePath ) ;
23
30
@@ -28,11 +35,10 @@ function main(): void {
28
35
29
36
var infoFileOutput = buildInfoFileOutput ( diagnosticMessages , nameMap ) ;
30
37
checkForUniqueCodes ( names , diagnosticMessages ) ;
38
+ writeFile ( "diagnosticInformationMap.generated.ts" , infoFileOutput ) ;
31
39
32
- // TODO: Fix path joining
33
- var inputDirectory = inputFilePath . substr ( 0 , inputFilePath . lastIndexOf ( "/" ) ) ;
34
- var fileOutputPath = inputDirectory + "/diagnosticInformationMap.generated.ts" ;
35
- sys . writeFile ( fileOutputPath , infoFileOutput ) ;
40
+ var messageOutput = buildDiagnosticMessageOutput ( diagnosticMessages , nameMap ) ;
41
+ writeFile ( "diagnosticMessages.generated.json" , messageOutput ) ;
36
42
}
37
43
38
44
function checkForUniqueCodes ( messages : string [ ] , diagnosticTable : InputDiagnosticMessageTable ) {
@@ -85,12 +91,14 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
85
91
for ( var i = 0 ; i < names . length ; i ++ ) {
86
92
var name = names [ i ] ;
87
93
var diagnosticDetails = messageTable [ name ] ;
94
+ var propName = convertPropertyName ( nameMap [ name ] ) ;
88
95
89
96
result +=
90
- ' ' + convertPropertyName ( nameMap [ name ] ) +
97
+ ' ' + propName +
91
98
': { code: ' + diagnosticDetails . code +
92
99
', category: DiagnosticCategory.' + diagnosticDetails . category +
93
- ', key: "' + name . replace ( / [ \" ] / g, '\\"' ) + '"' +
100
+ ', key: "' + createKey ( propName , diagnosticDetails . code ) + '"' +
101
+ ', message: "' + name . replace ( / [ \" ] / g, '\\"' ) + '"' +
94
102
' },\r\n' ;
95
103
}
96
104
@@ -99,6 +107,30 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
99
107
return result ;
100
108
}
101
109
110
+ function buildDiagnosticMessageOutput ( messageTable : InputDiagnosticMessageTable , nameMap : ts . Map < string > ) : string {
111
+ var result =
112
+ '{' ;
113
+ var names = Utilities . getObjectKeys ( messageTable ) ;
114
+ for ( var i = 0 ; i < names . length ; i ++ ) {
115
+ var name = names [ i ] ;
116
+ var diagnosticDetails = messageTable [ name ] ;
117
+ var propName = convertPropertyName ( nameMap [ name ] ) ;
118
+
119
+ result += '\r\n "' + createKey ( propName , diagnosticDetails . code ) + '"' + ' : "' + name . replace ( / [ \" ] / g, '\\"' ) + '"' ;
120
+ if ( i !== names . length - 1 ) {
121
+ result += ',' ;
122
+ }
123
+ }
124
+
125
+ result += '\r\n}' ;
126
+
127
+ return result ;
128
+ }
129
+
130
+ function createKey ( name : string , code : number ) : string {
131
+ return name . slice ( 0 , 100 ) + '_' + code ;
132
+ }
133
+
102
134
function convertPropertyName ( origName : string ) : string {
103
135
var result = origName . split ( "" ) . map ( char => {
104
136
if ( char === '*' ) { return "_Asterisk" ; }
0 commit comments