[typescript] evolve update script, emit grammar as JSON
This commit is contained in:
parent
847f78f6f4
commit
fdcbf91f27
|
@ -4,10 +4,11 @@
|
||||||
// DO NOT USE OR SHARE THIS CODE WITHOUT APPROVAL PURSUANT TO THE MICROSOFT OPEN SOURCE SOFTWARE APPROVAL POLICY.
|
// DO NOT USE OR SHARE THIS CODE WITHOUT APPROVAL PURSUANT TO THE MICROSOFT OPEN SOURCE SOFTWARE APPROVAL POLICY.
|
||||||
|
|
||||||
[{
|
[{
|
||||||
"name": "typescript-sublime-plugin",
|
"name": "TypeScript-TmLanguage",
|
||||||
"version": "0.1.8",
|
"version": "0.1.8",
|
||||||
"license": "Apache2",
|
"license": "Apache2",
|
||||||
"repositoryURL": "https://github.com/Microsoft/TypeScript-TmLanguage",
|
"repositoryURL": "https://github.com/Microsoft/TypeScript-TmLanguage",
|
||||||
|
"description": "The files syntaxes/TypeScript.tmLanguage.json and syntaxes/TypeScriptReact.tmLanguage.json were derived from TypeScript.tmLanguage and TypeScriptReact.tmLanguage in https://github.com/Microsoft/TypeScript-TmLanguage.",
|
||||||
"licenseDetail": [
|
"licenseDetail": [
|
||||||
// Reason: LICENSE file does not include Copyright statement
|
// Reason: LICENSE file does not include Copyright statement
|
||||||
"Copyright (c) Microsoft Corporation. All rights reserved.",
|
"Copyright (c) Microsoft Corporation. All rights reserved.",
|
||||||
|
|
|
@ -6,20 +6,60 @@
|
||||||
|
|
||||||
var download = require('../../../build/lib/download');
|
var download = require('../../../build/lib/download');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var plist = require('plist');
|
||||||
|
|
||||||
var contentBaseLocation = 'https://raw.githubusercontent.com/Microsoft/TypeScript-TmLanguage/master/';
|
var contentBaseLocation = 'https://raw.githubusercontent.com/Microsoft/TypeScript-TmLanguage/master/';
|
||||||
|
|
||||||
var lastCommit = 'https://api.github.com/repos/Microsoft/TypeScript-TmLanguage/git/refs/heads/master';
|
var lastCommit = 'https://api.github.com/repos/Microsoft/TypeScript-TmLanguage/git/refs/heads/master';
|
||||||
Promise.all([
|
download.toString(lastCommit).then(function (content) {
|
||||||
download.toFile(contentBaseLocation + 'TypeScript.tmLanguage', './syntaxes/TypeScript.tmLanguage'),
|
var commitSha = JSON.parse(content).object.sha;
|
||||||
download.toFile(contentBaseLocation + 'TypeScriptReact.tmLanguage', './syntaxes/TypeScriptReact.tmLanguage'),
|
function writeJSON(fileName, modifyGrammar) {
|
||||||
download.toString(lastCommit).then(function (content) {
|
return function(content) {
|
||||||
var commitInfo = JSON.parse(content);
|
var grammar = plist.parse(content);
|
||||||
fs.writeFileSync('./syntaxes/grammar-version.txt', commitInfo.object.url);
|
grammar.version = 'https://github.com/Microsoft/TypeScript-TmLanguage/commit/' + commitSha;
|
||||||
console.log('Update completed.');
|
if (modifyGrammar) {
|
||||||
console.log('New commit comment:');
|
modifyGrammar(grammar);
|
||||||
console.log('[typescript] update grammar (Microsoft/TypeScript-TmLanguage@' + commitInfo.object.sha.substr(0, 7) + ')');
|
}
|
||||||
}, console.error)
|
fs.writeFileSync(fileName, JSON.stringify(grammar, null, '\t'));
|
||||||
]);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
download.toString(contentBaseLocation + 'TypeScript.tmLanguage').then(writeJSON('./syntaxes/TypeScript.tmLanguage.json'), console.error),
|
||||||
|
download.toString(contentBaseLocation + 'TypeScriptReact.tmLanguage').then(writeJSON('./syntaxes/TypeScriptReact.tmLanguage.json'), console.error),
|
||||||
|
download.toString(contentBaseLocation + 'TypeScriptReact.tmLanguage').then(writeJSON('../javascript/syntaxes/JavaScript.tmLanguage.json', adaptToJavaScript), console.error)
|
||||||
|
]).then(function() {
|
||||||
|
console.log('Update complete.');
|
||||||
|
console.log('[typescript] update grammar (Microsoft/TypeScript-TmLanguage@' + commitSha.substr(0, 7) + ')');
|
||||||
|
});
|
||||||
|
}, console.error);
|
||||||
|
|
||||||
|
function adaptToJavaScript(grammar) {
|
||||||
|
grammar.name = 'JavaScript (with React support)';
|
||||||
|
grammar.fileTypes = ['.js', '.jsx' ];
|
||||||
|
grammar.scopeName = 'source.js';
|
||||||
|
|
||||||
|
var fixScopeNames = function(rule) {
|
||||||
|
if (typeof rule.name === 'string') {
|
||||||
|
rule.name = rule.name.replace(/\.tsx/g, '.js');
|
||||||
|
}
|
||||||
|
for (var property in rule) {
|
||||||
|
var value = rule[property];
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
fixScopeNames(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var repository = grammar.repository;
|
||||||
|
for (var key in repository) {
|
||||||
|
fixScopeNames(repository[key]);
|
||||||
|
}
|
||||||
|
// disable type parameters
|
||||||
|
if (repository['type-parameters']) {
|
||||||
|
repository['type-parameters']['begin'] = 'DO_NOT_MATCH';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:typescript ./tsconfig.json",
|
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:typescript ./tsconfig.json",
|
||||||
"update-grammar": "node ./build/update-grammars.js"
|
"update-grammars": "node ./build/update-grammars.js"
|
||||||
},
|
},
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"onLanguage:javascript",
|
"onLanguage:javascript",
|
||||||
|
@ -57,12 +57,12 @@
|
||||||
{
|
{
|
||||||
"language": "typescript",
|
"language": "typescript",
|
||||||
"scopeName": "source.ts",
|
"scopeName": "source.ts",
|
||||||
"path": "./syntaxes/TypeScript.tmLanguage"
|
"path": "./syntaxes/TypeScript.tmLanguage.json"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"language": "typescriptreact",
|
"language": "typescriptreact",
|
||||||
"scopeName": "source.tsx",
|
"scopeName": "source.tsx",
|
||||||
"path": "./syntaxes/TypeScriptReact.tmLanguage"
|
"path": "./syntaxes/TypeScriptReact.tmLanguage.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"configuration": {
|
"configuration": {
|
||||||
|
|
5
extensions/typescript/syntaxes/Readme.md
Normal file
5
extensions/typescript/syntaxes/Readme.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
The file `TypeScript.tmLanguage.json` and `TypeScriptReact.tmLanguage.json` are derived from [TypeScript.tmLanguage](https://github.com/Microsoft/TypeScript-TmLanguage/blob/master/TypeScript.tmLanguage) and [TypeScriptReact.tmLanguage](https://github.com/Microsoft/TypeScript-TmLanguage/blob/master/TypeScriptReact.tmLanguage).
|
||||||
|
|
||||||
|
To update to the latest version:
|
||||||
|
- `cd extensions/typescript` and run `npm run update-grammars`
|
||||||
|
- don't forget to run the integration tests at `./scripts/test-integration.sh`
|
File diff suppressed because it is too large
Load diff
1292
extensions/typescript/syntaxes/TypeScript.tmLanguage.json
Normal file
1292
extensions/typescript/syntaxes/TypeScript.tmLanguage.json
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
1525
extensions/typescript/syntaxes/TypeScriptReact.tmLanguage.json
Normal file
1525
extensions/typescript/syntaxes/TypeScriptReact.tmLanguage.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1 +0,0 @@
|
||||||
https://api.github.com/repos/Microsoft/TypeScript-TmLanguage/git/commits/1cf745cd5750d573f94f13bb9d95f4169c8a7841
|
|
|
@ -77,6 +77,7 @@
|
||||||
"mocha": "^2.2.5",
|
"mocha": "^2.2.5",
|
||||||
"object-assign": "^4.0.1",
|
"object-assign": "^4.0.1",
|
||||||
"optimist": "0.3.5",
|
"optimist": "0.3.5",
|
||||||
|
"plist": "^1.2.0",
|
||||||
"queue": "3.0.6",
|
"queue": "3.0.6",
|
||||||
"rimraf": "^2.2.8",
|
"rimraf": "^2.2.8",
|
||||||
"sinon": "^1.17.2",
|
"sinon": "^1.17.2",
|
||||||
|
|
Loading…
Reference in a new issue