@@ -3,6 +3,22 @@ import path = require('path');
33import yaml = require( 'js-yaml' ) ;
44import plist = require( 'plist' ) ;
55
6+ enum Language {
7+ TypeScript = "TypeScript" ,
8+ TypeScriptReact = "TypeScriptReact"
9+ }
10+
11+ enum Extension {
12+ TmLanguage = "tmLanguage" ,
13+ TmTheme = "tmTheme" ,
14+ YamlTmLangauge = "YAML-tmLanguage" ,
15+ YamlTmTheme = "YAML-tmTheme"
16+ }
17+
18+ function file ( language : Language , extension : Extension ) {
19+ return path . join ( __dirname , '..' , `${ language } .${ extension } ` ) ;
20+ }
21+
622function writePlistFile ( grammar : any , fileName : string ) {
723 const text = plist . build ( grammar ) ;
824 fs . writeFileSync ( fileName , text ) ;
@@ -40,7 +56,7 @@ function transformGrammarRepository(grammar: any, propertyNames: string[], trans
4056}
4157
4258function changeTsToTsxGrammar ( grammar : any , variables : any ) {
43- const tsxUpdates = updateGrammarVariables ( readYaml ( "../ TypeScriptReact.YAML-tmLanguage" ) , variables ) ;
59+ const tsxUpdates = updateGrammarVariables ( readYaml ( file ( Language . TypeScriptReact , Extension . YamlTmLangauge ) ) , variables ) ;
4460
4561 // Update name, file types, scope name and uuid
4662 for ( let key in tsxUpdates ) {
@@ -96,21 +112,21 @@ function updateGrammarVariables(grammar: any, variables: any) {
96112}
97113
98114function buildGrammar ( ) {
99- const tsGrammarBeforeTransformation = readYaml ( "../ TypeScript.YAML-tmLanguage" ) ;
115+ const tsGrammarBeforeTransformation = readYaml ( file ( Language . TypeScript , Extension . YamlTmLangauge ) ) ;
100116 const variables = tsGrammarBeforeTransformation . variables ;
101117
102118 const tsGrammar = updateGrammarVariables ( tsGrammarBeforeTransformation , variables ) ;
103119
104120 // Write TypeScript.tmLanguage
105- writePlistFile ( tsGrammar , "../ TypeScript.tmLanguage" ) ;
121+ writePlistFile ( tsGrammar , file ( Language . TypeScript , Extension . TmLanguage ) ) ;
106122
107123 // Write TypeScriptReact.tmLangauge
108124 const tsxGrammar = changeTsToTsxGrammar ( tsGrammar , variables ) ;
109- writePlistFile ( tsxGrammar , "../ TypeScriptReact.tmLanguage" ) ;
125+ writePlistFile ( tsxGrammar , file ( Language . TypeScriptReact , Extension . TmLanguage ) ) ;
110126}
111127
112128function changeTsToTsxTheme ( theme : any ) {
113- const tsxUpdates = readYaml ( "../ TypeScriptReact.YAML-tmTheme" ) ;
129+ const tsxUpdates = readYaml ( file ( Language . TypeScriptReact , Extension . YamlTmTheme ) ) ;
114130
115131 // Update name, uuid
116132 for ( let key in tsxUpdates ) {
@@ -132,14 +148,14 @@ function changeTsToTsxTheme(theme: any) {
132148}
133149
134150function buildTheme ( ) {
135- const tsTheme = readYaml ( "../ TypeScript.YAML-tmTheme" ) ;
151+ const tsTheme = readYaml ( file ( Language . TypeScript , Extension . YamlTmTheme ) ) ;
136152
137153 // Write TypeScript.tmTheme
138- writePlistFile ( tsTheme , "../ TypeScript.tmTheme" ) ;
154+ writePlistFile ( tsTheme , file ( Language . TypeScript , Extension . TmTheme ) ) ;
139155
140156 // Write TypeScriptReact.thTheme
141157 const tsxTheme = changeTsToTsxTheme ( tsTheme ) ;
142- writePlistFile ( tsxTheme , "../ TypeScriptReact.tmTheme" ) ;
158+ writePlistFile ( tsxTheme , file ( Language . TypeScriptReact , Extension . TmTheme ) ) ;
143159}
144160
145161buildGrammar ( ) ;
0 commit comments