[typescript] evolve update script, emit grammar as JSON

This commit is contained in:
Martin Aeschlimann 2016-08-02 17:20:04 +02:00
parent 847f78f6f4
commit fdcbf91f27
10 changed files with 2879 additions and 4374 deletions

View file

@ -4,10 +4,11 @@
// 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",
"license": "Apache2",
"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": [
// Reason: LICENSE file does not include Copyright statement
"Copyright (c) Microsoft Corporation. All rights reserved.",

View file

@ -6,20 +6,60 @@
var download = require('../../../build/lib/download');
var fs = require('fs');
var plist = require('plist');
var contentBaseLocation = 'https://raw.githubusercontent.com/Microsoft/TypeScript-TmLanguage/master/';
var lastCommit = 'https://api.github.com/repos/Microsoft/TypeScript-TmLanguage/git/refs/heads/master';
Promise.all([
download.toFile(contentBaseLocation + 'TypeScript.tmLanguage', './syntaxes/TypeScript.tmLanguage'),
download.toFile(contentBaseLocation + 'TypeScriptReact.tmLanguage', './syntaxes/TypeScriptReact.tmLanguage'),
download.toString(lastCommit).then(function (content) {
var commitInfo = JSON.parse(content);
fs.writeFileSync('./syntaxes/grammar-version.txt', commitInfo.object.url);
console.log('Update completed.');
console.log('New commit comment:');
console.log('[typescript] update grammar (Microsoft/TypeScript-TmLanguage@' + commitInfo.object.sha.substr(0, 7) + ')');
}, console.error)
]);
download.toString(lastCommit).then(function (content) {
var commitSha = JSON.parse(content).object.sha;
function writeJSON(fileName, modifyGrammar) {
return function(content) {
var grammar = plist.parse(content);
grammar.version = 'https://github.com/Microsoft/TypeScript-TmLanguage/commit/' + commitSha;
if (modifyGrammar) {
modifyGrammar(grammar);
}
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';
}
}

View file

@ -16,7 +16,7 @@
},
"scripts": {
"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": [
"onLanguage:javascript",
@ -57,12 +57,12 @@
{
"language": "typescript",
"scopeName": "source.ts",
"path": "./syntaxes/TypeScript.tmLanguage"
"path": "./syntaxes/TypeScript.tmLanguage.json"
},
{
"language": "typescriptreact",
"scopeName": "source.tsx",
"path": "./syntaxes/TypeScriptReact.tmLanguage"
"path": "./syntaxes/TypeScriptReact.tmLanguage.json"
}
],
"configuration": {

View 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

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
https://api.github.com/repos/Microsoft/TypeScript-TmLanguage/git/commits/1cf745cd5750d573f94f13bb9d95f4169c8a7841

View file

@ -77,6 +77,7 @@
"mocha": "^2.2.5",
"object-assign": "^4.0.1",
"optimist": "0.3.5",
"plist": "^1.2.0",
"queue": "3.0.6",
"rimraf": "^2.2.8",
"sinon": "^1.17.2",