Skip to content

Commit dd11895

Browse files
committed
build tools
1 parent b84dafb commit dd11895

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
syntaxes/
2+
tools/node_modules/
3+
tools/package-lock.json

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,49 @@ both VS Code and Sublime Text. There are a number of existing issues with the g
2222
that we need to track down and fix. Please see [issue #1](https://github.com/PowerShell/EditorSyntax/issues/1)
2323
for more details.
2424

25+
## Build and Import (VS Code)
26+
27+
### Prerequisites
28+
29+
- Python, >=2.7 (version 3 is not supported)
30+
- Node.JS, >= 8.9.1
31+
32+
### Build
33+
34+
1. Navigate via command line to the ./tools/` directory and install dependencies:
35+
36+
```
37+
npm install
38+
```
39+
40+
2. Run the `build-grammar` script to generate the json file.
41+
42+
```
43+
npm run build-grammar
44+
```
45+
46+
3. The .json file will be output to `./syntaxes/` at the root of the directory. You can use the vscode.ps1 script to load it or do it manually.
47+
48+
**Install - script**
49+
50+
```PowerShell
51+
PS tools> .\vscode.ps1 -InstallSyntax
52+
```
53+
54+
**Revert - script**
55+
56+
```PowerShell
57+
PS tools> .\vscode.ps1 -RevertSyntax
58+
```
59+
60+
**Install - manually**
61+
62+
1. Locate the VS Code installation directory and navigate to to `resources/app/extensions/powershell/syntaxes`
63+
64+
2. Rename `powershell.tmLanguage.json` to `powershell.tmLanguage.json_default`
65+
66+
3. Copy `powershell.tmLanguage.json` from `./syntaxes/` within this project folder to where you just renamed the file under VS Code's path.
67+
2568
## Contributing
2669
2770
We would love to have community contributions to this project to make PowerShell syntax

tools/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "EditorSyntax",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"fast-plist": "0.1.2"
6+
},
7+
"scripts": {
8+
"build-grammar": "node ./scripts/build-grammar.js ../PowerShellSyntax.tmLanguage ../syntaxes/powershell.tmLanguage.json"
9+
}
10+
}

tools/scripts/build-grammar.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

tools/vscode.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[cmdletbinding(DefaultParameterSetName='Install')]
2+
param(
3+
[Parameter(ParameterSetName='Install')]
4+
[switch]$InstallSyntax,
5+
6+
[Parameter(ParameterSetName='Revert')]
7+
[switch]$RevertSyntax
8+
)
9+
10+
$SyntaxPath = Join-Path $PSScriptRoot "..\syntaxes\powershell.tmLanguage.json"
11+
12+
if ($InstallSyntax) {
13+
if (-not(Test-Path $SyntaxPath)) {
14+
throw "No syntax to install. Please follow the build steps in the README.md"
15+
}
16+
17+
} elseif ($RevertSyntax) {
18+
19+
} else {
20+
throw "Please use either -InstallSyntax or -RevertSyntax"
21+
}

0 commit comments

Comments
 (0)