mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
grammar update script: Generalize as /build/npm/update-grammar
This commit is contained in:
parent
5341c17cca
commit
c5fc19d474
|
@ -11,9 +11,10 @@ var url = require('url');
|
|||
function getOptions(urlString) {
|
||||
var _url = url.parse(urlString);
|
||||
return {
|
||||
protocol: _url.protocol,
|
||||
host: _url.host,
|
||||
port: _url.port,
|
||||
path: _url.pathname,
|
||||
path: _url.path,
|
||||
headers: {
|
||||
'User-Agent': 'NodeJS'
|
||||
}
|
||||
|
|
74
build/npm/update-grammar.js
Normal file
74
build/npm/update-grammar.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var download = require('../lib/download');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var plist = require('plist');
|
||||
var cson = require('cson-parser');
|
||||
|
||||
function getCommitSha(repoId, repoPath) {
|
||||
var commitInfo = 'https://api.github.com/repos/' + repoId + '/commits?path=' + repoPath;
|
||||
return download.toString(commitInfo).then(function (content) {
|
||||
try {
|
||||
let lastCommit = JSON.parse(content)[0];
|
||||
return Promise.resolve({
|
||||
commitSha : lastCommit.sha,
|
||||
commitDate : lastCommit.commit.author.date
|
||||
});
|
||||
} catch (e) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
}, function () {
|
||||
console.err('Failed loading ' + commitInfo);
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
}
|
||||
|
||||
exports.update = function (repoId, repoPath, dest, modifyGrammar) {
|
||||
var contentPath = 'https://raw.githubusercontent.com/' + repoId + '/master/' + repoPath;
|
||||
console.log('Reading from ' + contentPath);
|
||||
return download.toString(contentPath).then(function (content) {
|
||||
var ext = path.extname(repoPath);
|
||||
var grammar;
|
||||
if (ext === '.tmLanguage' || ext === '.plist') {
|
||||
grammar = plist.parse(content);
|
||||
} else if (ext === '.cson') {
|
||||
grammar = cson.parse(content);
|
||||
} else if (ext === '.json') {
|
||||
grammar = JSON.parse(content);
|
||||
} else {
|
||||
console.error('Unknown file extension: ' + ext);
|
||||
return;
|
||||
}
|
||||
if (modifyGrammar) {
|
||||
modifyGrammar(grammar);
|
||||
}
|
||||
return getCommitSha(repoId, repoPath).then(function (info) {
|
||||
if (info) {
|
||||
grammar.version = 'https://github.com/' + repoId + '/commit/' + info.commitSha;
|
||||
}
|
||||
try {
|
||||
fs.writeFileSync(dest, JSON.stringify(grammar, null, '\t'));
|
||||
if (info) {
|
||||
console.log('Updated ' + path.basename(dest) + ' to ' + repoId + '@' + info.commitSha.substr(0, 7) + ' (' + info.commitDate.substr(0, 10) + ')');
|
||||
} else {
|
||||
console.log('Updated ' + path.basename(dest));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
}, console.error);
|
||||
}
|
||||
if (path.basename(process.argv[1]) === 'update-grammar.js') {
|
||||
exports.update(process.argv[2], process.argv[3], process.argv[4]);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1522,5 +1522,5 @@
|
|||
},
|
||||
"scopeName": "source.js",
|
||||
"uuid": "805375ec-d614-41f5-8993-5843fe63ea82",
|
||||
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/1cf745cd5750d573f94f13bb9d95f4169c8a7841"
|
||||
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/55b86614037e8c754c0657b0cd03f4f90c9498db"
|
||||
}
|
|
@ -4,35 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
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';
|
||||
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);
|
||||
var updateGrammar = require('../../../build/npm/update-grammar');
|
||||
|
||||
function adaptToJavaScript(grammar) {
|
||||
grammar.name = 'JavaScript (with React support)';
|
||||
|
@ -60,6 +32,11 @@ function adaptToJavaScript(grammar) {
|
|||
repository['type-parameters']['begin'] = 'DO_NOT_MATCH';
|
||||
}
|
||||
}
|
||||
var tsGrammarRepo = 'Microsoft/TypeScript-TmLanguage';
|
||||
updateGrammar.update(tsGrammarRepo, 'TypeScript.tmLanguage', './syntaxes/TypeScript.tmLanguage.json');
|
||||
updateGrammar.update(tsGrammarRepo, 'TypeScriptReact.tmLanguage', './syntaxes/TypeScriptReact.tmLanguage.json');
|
||||
updateGrammar.update(tsGrammarRepo, 'TypeScriptReact.tmLanguage', '../javascript/syntaxes/JavaScript.tmLanguage.json', adaptToJavaScript);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1288,5 +1288,5 @@
|
|||
},
|
||||
"scopeName": "source.ts",
|
||||
"uuid": "ef98eb90-bf9b-11e4-bb52-0800200c9a66",
|
||||
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/1cf745cd5750d573f94f13bb9d95f4169c8a7841"
|
||||
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/55b86614037e8c754c0657b0cd03f4f90c9498db"
|
||||
}
|
|
@ -1521,5 +1521,5 @@
|
|||
},
|
||||
"scopeName": "source.tsx",
|
||||
"uuid": "805375ec-d614-41f5-8993-5843fe63ea82",
|
||||
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/1cf745cd5750d573f94f13bb9d95f4169c8a7841"
|
||||
"version": "https://github.com/Microsoft/TypeScript-TmLanguage/commit/55b86614037e8c754c0657b0cd03f4f90c9498db"
|
||||
}
|
|
@ -38,6 +38,7 @@
|
|||
"azure-storage": "^0.3.1",
|
||||
"clean-css": "3.4.6",
|
||||
"clone": "^1.0.2",
|
||||
"cson-parser": "^1.3.3",
|
||||
"debounce": "^1.0.0",
|
||||
"documentdb": "^1.5.1",
|
||||
"event-stream": "^3.1.7",
|
||||
|
|
Loading…
Reference in a new issue