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