diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cc668c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +syntaxes/ +tools/node_modules/ +tools/package-lock.json \ No newline at end of file diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..f184e96 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,38 @@ + + +### Environment + +- Editor and Version (VS Code, Atom, Sublime): +- Your primary theme: + +### Issue Description + + + +#### Screenshots + + + +### Expected Behavior + + + +### Code Samples + + + +```PowerShell + + +``` diff --git a/README.md b/README.md index bab6c15..b7fc145 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,36 @@ both VS Code and Sublime Text. There are a number of existing issues with the g that we need to track down and fix. Please see [issue #1](https://github.com/PowerShell/EditorSyntax/issues/1) for more details. +## Build and Import (VS Code) + +### Prerequisites + +- Node.JS, >= 8.9.1 + +### Build + +1. Navigate via command line to the `./tools/` directory and install dependencies: + + ``` + npm install + ``` + +2. Run the `build-grammar` script to generate the json file. + + ``` + npm run build-grammar + ``` + +3. The .json file will be generated in `./syntaxes/` at the root of the project. You will need to copy it in to VS Code manually. + + 1. Locate the VS Code installation directory and navigate to to `resources/app/extensions/powershell/syntaxes` + + 2. Rename `powershell.tmLanguage.json` to `powershell.tmLanguage.json_default` + + 3. Copy `powershell.tmLanguage.json` from `./syntaxes/` within the project folder to where you just renamed the file under VS Code's path. + +4. If VS Code is already running you will need to run "Reload Window" from the command pallete. + ## Contributing We would love to have community contributions to this project to make PowerShell syntax diff --git a/tools/package.json b/tools/package.json new file mode 100644 index 0000000..a824bb4 --- /dev/null +++ b/tools/package.json @@ -0,0 +1,16 @@ +{ + "name": "editorsyntax", + "license" : "MIT", + "description": "PowerShell language syntax", + "repository": { + "type": "git", + "url": "https://github.com/PowerShell/EditorSyntax.git" + }, + "version": "1.0.0", + "dependencies": { + "fast-plist": "0.1.2" + }, + "scripts": { + "build-grammar": "node ./scripts/build-grammar.js ../PowerShellSyntax.tmLanguage ../syntaxes/powershell.tmLanguage.json" + } +} \ No newline at end of file diff --git a/tools/scripts/build-grammar.js b/tools/scripts/build-grammar.js new file mode 100644 index 0000000..e422a20 --- /dev/null +++ b/tools/scripts/build-grammar.js @@ -0,0 +1,55 @@ +/*--------------------------------------------------------------------------------------------- + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Modified for PowerShell\EditorSyntax from Microsoft\vscode (update-grammar.js) + * This script generates the JSON file using the same tools as vscode's build. + *--------------------------------------------------------------------------------------------*/ + + 'use strict'; + +var path = require('path'); +var fs = require('fs'); +var plist = require('fast-plist'); + +exports.update = function (tmlPath, dest) { + console.log('... Reading source file.'); + var content = fs.readFileSync(tmlPath).toString(); + + console.log('... Parsing content.'); + var grammar; + grammar = plist.parse(content); + + console.log('... Building contents.'); + let result = { + information_for_contributors: [ + 'This file has been converted from source and may not be in line with the official build.', + 'The current master branch for this syntax can be found here: https://github.com/PowerShell/EditorSyntax', + 'If you want to provide a fix or improvement, please create a pull request against the original repository.' + ] + }; + + result.version = require('child_process') + .execSync('git rev-parse HEAD') + .toString().trim() + + let keys = ['name', 'scopeName', 'comment', 'injections', 'patterns', 'repository']; + for (let key of keys) { + if (grammar.hasOwnProperty(key)) { + result[key] = grammar[key]; + } + } + + var dirname = path.dirname(dest); + if (!fs.existsSync(dirname)) { + console.log('... Creating directory: ' + dirname); + fs.mkdirSync(dirname); + } + + fs.writeFileSync(dest, JSON.stringify(result, null, '\t')); + console.log('[Finished] File written to: ' + dest); +}; + +if (path.basename(process.argv[1]) === 'build-grammar.js') { + console.log('[Starting] Converting ' + process.argv[2] + ' to json.'); + exports.update(process.argv[2], process.argv[3]); +}