@@ -18,6 +18,13 @@ function main(): void {
1818 return ;
1919 }
2020
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+
2128 var inputFilePath = sys . args [ 0 ] . replace ( / \\ / g, "/" ) ;
2229 var inputStr = sys . readFile ( inputFilePath ) ;
2330
@@ -28,11 +35,10 @@ function main(): void {
2835
2936 var infoFileOutput = buildInfoFileOutput ( diagnosticMessages , nameMap ) ;
3037 checkForUniqueCodes ( names , diagnosticMessages ) ;
38+ writeFile ( "diagnosticInformationMap.generated.ts" , infoFileOutput ) ;
3139
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 ) ;
3642}
3743
3844function checkForUniqueCodes ( messages : string [ ] , diagnosticTable : InputDiagnosticMessageTable ) {
@@ -85,12 +91,14 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
8591 for ( var i = 0 ; i < names . length ; i ++ ) {
8692 var name = names [ i ] ;
8793 var diagnosticDetails = messageTable [ name ] ;
94+ var propName = convertPropertyName ( nameMap [ name ] ) ;
8895
8996 result +=
90- ' ' + convertPropertyName ( nameMap [ name ] ) +
97+ ' ' + propName +
9198 ': { code: ' + diagnosticDetails . code +
9299 ', category: DiagnosticCategory.' + diagnosticDetails . category +
93- ', key: "' + name . replace ( / [ \" ] / g, '\\"' ) + '"' +
100+ ', key: "' + createKey ( propName , diagnosticDetails . code ) + '"' +
101+ ', message: "' + name . replace ( / [ \" ] / g, '\\"' ) + '"' +
94102 ' },\r\n' ;
95103 }
96104
@@ -99,6 +107,30 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap:
99107 return result ;
100108}
101109
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 += ' "' + createKey ( propName , diagnosticDetails . code ) + '"' + ' : "' + name . replace ( / [ \" ] / g, '\\"' ) + '"' ;
120+ if ( i !== names . length - 1 ) {
121+ result += ',' ;
122+ }
123+ }
124+
125+ result += '}' ;
126+
127+ return result ;
128+ }
129+
130+ function createKey ( name : string , code : number ) : string {
131+ return name . slice ( 0 , 100 ) + '_' + code ;
132+ }
133+
102134function convertPropertyName ( origName : string ) : string {
103135 var result = origName . split ( "" ) . map ( char => {
104136 if ( char === '*' ) { return "_Asterisk" ; }
0 commit comments