1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *
5+ * Modified for PowerShell\EditorSyntax from MicroSoft\vscode (update-grammar.js)
6+ * This script generates the JSON file using the same tools as vscode's build.
7+ *--------------------------------------------------------------------------------------------*/
8+
9+ 'use strict' ;
10+
11+ var path = require ( 'path' ) ;
12+ var fs = require ( 'fs' ) ;
13+ var plist = require ( 'fast-plist' ) ;
14+
15+ exports . update = function ( tmlPath , dest ) {
16+
17+ var content = fs . readFileSync ( tmlPath ) . toString ( ) ;
18+
19+ var grammar ;
20+ grammar = plist . parse ( content ) ;
21+
22+ let result = {
23+ information_for_contributors : [
24+ 'This file has been converted from source and may not be in line with the official build.' ,
25+ 'The current master branch for this syntax can be found here: https://github.com/PowerShell/EditorSyntax' ,
26+ 'If you want to provide a fix or improvement, please create a pull request against the original repository.'
27+ ]
28+ } ;
29+
30+ result . version = require ( 'child_process' )
31+ . execSync ( 'git rev-parse HEAD' )
32+ . toString ( ) . trim ( )
33+
34+ let keys = [ 'name' , 'scopeName' , 'comment' , 'injections' , 'patterns' , 'repository' ] ;
35+ for ( let key of keys ) {
36+ if ( grammar . hasOwnProperty ( key ) ) {
37+ result [ key ] = grammar [ key ] ;
38+ }
39+ }
40+
41+ var dirname = path . dirname ( dest ) ;
42+ if ( ! fs . existsSync ( dirname ) ) {
43+ fs . mkdirSync ( dirname ) ;
44+ }
45+
46+ fs . writeFileSync ( dest , JSON . stringify ( result , null , '\t' ) ) ;
47+ } ;
48+
49+ if ( path . basename ( process . argv [ 1 ] ) === 'build-grammar.js' ) {
50+ exports . update ( process . argv [ 2 ] , process . argv [ 3 ] ) ;
51+ }
0 commit comments