diff --git a/extensions/csharp-o/gulpfile.js b/extensions/csharp-o/gulpfile.js index e00fb8caa45..b78077bd37a 100644 --- a/extensions/csharp-o/gulpfile.js +++ b/extensions/csharp-o/gulpfile.js @@ -1,22 +1,60 @@ var gulp = require('gulp'); var decompress = require('gulp-decompress'); -var download = require('gulp-download'); +var es = require('event-stream'); +var GitHub = require('github-releases'); +var tmp = require('tmp'); +var vfs = require('vinyl-fs'); var del = require('del'); var fs = require('fs'); -var join = require('path').join; +var path = require('path'); +tmp.setGracefulCleanup(); + +function downloadOmnisharp(version) { + var result = es.through(); + + function onError(err) { + result.emit('error', err); + } + + var repo = new GitHub({ + repo: 'OmniSharp/omnisharp-roslyn', + token: process.env['GITHUB_TOKEN'] + }); + + repo.getReleases({ tag_name: version }, function (err, releases) { + if (err) { return onError(err); } + if (!releases.length) { return onError(new Error('Release not found')); } + if (!releases[0].assets.length) { return onError(new Error('Assets not found')); } + + repo.downloadAsset(releases[0].assets[0], function (err, istream) { + if (err) { return onError(err); } + + tmp.file(function (err, tmpPath, fd, cleanupCallback) { + if (err) { return onError(err); } + + var ostream = fs.createWriteStream(null, { fd: fd }); + ostream.once('error', onError); + istream.once('error', onError); + ostream.once('finish', function () { + vfs.src(tmpPath).pipe(result); + }); + istream.pipe(ostream); + }); + }); + }); + + return result; +} gulp.task('omnisharp:clean', function () { return del('bin'); }); gulp.task('omnisharp:fetch', ['omnisharp:clean'], function () { - - var release = 'https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.5.6/omnisharp.tar.gz'; - - return download(release) + return downloadOmnisharp('v1.5.6') .pipe(decompress({strip: 1})) - .pipe(gulp.dest('bin')) + .pipe(gulp.dest('bin')); }); gulp.task('omnisharp:fixscripts', ['omnisharp:fetch'], function () { @@ -38,7 +76,7 @@ exec "$DIR/packages/dnx-mono.1.0.0-beta4/bin/dnx" "$DNX_APPBASE" run "$@"\n\ var promises = Object.keys(_fixes).map(function (key) { return new Promise(function(resolve, reject) { - fs.writeFile(join(__dirname, key), _fixes[key], function (err) { + fs.writeFile(path.join(__dirname, key), _fixes[key], function (err) { if (err) { reject(err); } else { diff --git a/extensions/csharp-o/package.json b/extensions/csharp-o/package.json index 4f0bf6e7cda..a86fa4ed76b 100644 --- a/extensions/csharp-o/package.json +++ b/extensions/csharp-o/package.json @@ -1,101 +1,104 @@ { - "name": "csharp-o", - "version": "0.1.0", - "publisher": "vscode", - "engines": { - "node": "^4.0.0", - "vscode": "*" - }, - "activationEvents": [ - "onLanguage:csharp", - "onCommand:o.restart", - "onCommand:o.pickProjectAndStart", - "onCommand:o.restore", - "onCommand:o.execute", - "onCommand:o.showOutput", - "onCommand:o.execute", - "onCommand:o.execute-last-command" - ], - "main": "./out/omnisharpMain", - "scripts": { - "postinstall": "node ./node_modules/gulp/bin/gulp.js omnisharp", - "vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../gulpfile.plugins.js compile-plugin:csharp-o ./tsconfig.json" - }, - "dependencies": { - "applicationinsights": "0.15.6", - "run-in-terminal": "*", - "semver": "*" - }, - "devDependencies": { - "del": "^2.0.2", - "gulp": "^3.8.9", - "gulp-decompress": "^1.2.0", - "gulp-download": "^0.0.1", - "typescript": "^1.6.2" - }, - "extensionDependencies": [ - "vscode.csharp" - ], - "contributes": { - "commands": [ - { - "command": "o.restart", - "title": "Restart OmniSharp", - "category": "OmniSharp" - }, - { - "command": "o.pickProjectAndStart", - "title": "Select Project", - "category": "OmniSharp" - }, - { - "command": "o.restore", - "title": "Restore Packages", - "category": "dnx" - }, - { - "command": "o.execute", - "title": "Run Command", - "category": "dnx" - } - ], - "keybindings": [ - { - "command": "o.showOutput", - "key": "Ctrl+L L", - "mac": "Cmd+L L" - }, - { - "command": "o.execute", - "key": "Ctrl+L Shift+R", - "mac": "Cmd+L Shift+R" - }, - { - "command": "o.execute-last-command", - "key": "Ctrl+L R", - "mac": "Cmd+L R" - }, - { - "key": "shift+0", - "command": "^acceptSelectedSuggestion", - "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey" - }, - { - "key": "shift+9", - "command": "^acceptSelectedSuggestion", - "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey" - }, - { - "key": ".", - "command": "^acceptSelectedSuggestion", - "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey" - } - ], - "snippets": [ - { - "language": "csharp", - "path": "./snippets/csharp.json" - } - ] - } + "name": "csharp-o", + "version": "0.1.0", + "publisher": "vscode", + "engines": { + "node": "^4.0.0", + "vscode": "*" + }, + "activationEvents": [ + "onLanguage:csharp", + "onCommand:o.restart", + "onCommand:o.pickProjectAndStart", + "onCommand:o.restore", + "onCommand:o.execute", + "onCommand:o.showOutput", + "onCommand:o.execute", + "onCommand:o.execute-last-command" + ], + "main": "./out/omnisharpMain", + "scripts": { + "postinstall": "node ./node_modules/gulp/bin/gulp.js omnisharp", + "vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../gulpfile.plugins.js compile-plugin:csharp-o ./tsconfig.json" + }, + "dependencies": { + "applicationinsights": "0.15.6", + "run-in-terminal": "*", + "semver": "*" + }, + "devDependencies": { + "del": "^2.0.2", + "event-stream": "^3.3.2", + "github-releases": "^0.3.0", + "gulp": "^3.8.9", + "gulp-decompress": "^1.2.0", + "tmp": "0.0.28", + "typescript": "^1.6.2", + "vinyl-fs": "^2.2.1" + }, + "extensionDependencies": [ + "vscode.csharp" + ], + "contributes": { + "commands": [ + { + "command": "o.restart", + "title": "Restart OmniSharp", + "category": "OmniSharp" + }, + { + "command": "o.pickProjectAndStart", + "title": "Select Project", + "category": "OmniSharp" + }, + { + "command": "o.restore", + "title": "Restore Packages", + "category": "dnx" + }, + { + "command": "o.execute", + "title": "Run Command", + "category": "dnx" + } + ], + "keybindings": [ + { + "command": "o.showOutput", + "key": "Ctrl+L L", + "mac": "Cmd+L L" + }, + { + "command": "o.execute", + "key": "Ctrl+L Shift+R", + "mac": "Cmd+L Shift+R" + }, + { + "command": "o.execute-last-command", + "key": "Ctrl+L R", + "mac": "Cmd+L R" + }, + { + "key": "shift+0", + "command": "^acceptSelectedSuggestion", + "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey" + }, + { + "key": "shift+9", + "command": "^acceptSelectedSuggestion", + "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey" + }, + { + "key": ".", + "command": "^acceptSelectedSuggestion", + "when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey" + } + ], + "snippets": [ + { + "language": "csharp", + "path": "./snippets/csharp.json" + } + ] + } }