diff --git a/build/lib/download.js b/build/lib/download.js new file mode 100644 index 0000000000000000000000000000000000000000..07abe533382d4ffdd1ca7cf5c1dc740bf06a2808 --- /dev/null +++ b/build/lib/download.js @@ -0,0 +1,52 @@ +/*--------------------------------------------------------------------------------------------- + * 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 https = require('https'); +var fs = require('fs'); +var url = require('url'); + +function getOptions(urlString) { + var _url = url.parse(urlString); + return { + host: _url.host, + port: _url.port, + path: _url.pathname, + headers: { + 'User-Agent': 'NodeJS' + } + } +} + +exports.toFile = function (url, dest) { + return new Promise((c, e) => { + var file = fs.createWriteStream(dest); + var request = https.get(getOptions(url), function (response) { + response.pipe(file); + file.on('finish', function () { + var cb = (err, result) => err ? e(err) : c(result); + file.close(cb); + }); + }).on('error', function (err) { // Handle errors + fs.unlink(dest); // Delete the file async, don't check the result + e(err.message); + }); + }); +}; + +exports.toString = function(url) { + return new Promise((c, e) => { + var content = ''; + var request = https.get(getOptions(url), function (response) { + response.on('data', function (data) { + content += data.toString(); + }).on('end', function () { + c(content); + }); + }).on('error', function (err) { + e(err.message); + }); + }); +} \ No newline at end of file diff --git a/extensions/typescript/build/update-grammars.js b/extensions/typescript/build/update-grammars.js new file mode 100644 index 0000000000000000000000000000000000000000..c8a3ef443ea20db994f4a5c65aacac5edda561ae --- /dev/null +++ b/extensions/typescript/build/update-grammars.js @@ -0,0 +1,22 @@ +/*--------------------------------------------------------------------------------------------- + * 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('../../../build/lib/download'); +var fs = require('fs'); + +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) { + fs.writeFileSync('./syntaxes/grammar-version.txt', JSON.parse(content).object.url); + console.log('Update completed.') + }, console.error) +]); + + + diff --git a/extensions/typescript/package.json b/extensions/typescript/package.json index 319e46a8460417051806983b26a39cb1fa0a5980..ee5e64c156740ab5dc7dd84086c5f2a9e0f46bb3 100644 --- a/extensions/typescript/package.json +++ b/extensions/typescript/package.json @@ -15,7 +15,8 @@ "vscode-nls": "^1.0.4" }, "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" }, "activationEvents": [ "onLanguage:javascript",