Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 41 additions & 76 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,35 @@
var gulp = require('gulp');
var decompress = require('gulp-decompress');
var tslint = require("gulp-tslint");
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 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 () {
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

const decompress = require('gulp-decompress');
const del = require('del');
const fs = require('fs-extra-promise');
const gulp = require('gulp');
const path = require('path');
const tslint = require('gulp-tslint');
const omnisharpInstall = require('./out/omnisharpInstall');

gulp.task('omnisharp:clean', () => {
return del('bin');
});

gulp.task('omnisharp:fetch', ['omnisharp:clean'], function () {
return downloadOmnisharp('v1.6.7.9')
gulp.task('omnisharp:fetch', ['omnisharp:clean'], () => {
return omnisharpInstall.downloadOmnisharp('v1.6.7.9')
.pipe(decompress({strip: 1}))
.pipe(gulp.dest('bin'));
});

var allTypeScript = [
const allTypeScript = [
'src/**/*.ts',
'!**/*.d.ts',
'!**/typings**'
];

var lintReporter = function (output, file, options) {
const lintReporter = (output, file, options) => {
//emits: src/helloWorld.c:5:3: warning: implicit declaration of function ‘prinft’
var relativeBase = file.base.substring(file.cwd.length + 1).replace('\\', '/');
output.forEach(function(e) {
Expand All @@ -73,7 +38,7 @@ var lintReporter = function (output, file, options) {
});
};

gulp.task('tslint', function () {
gulp.task('tslint', () => {
gulp.src(allTypeScript)
.pipe(tslint({
rulesDirectory: "node_modules/tslint-microsoft-contrib"
Expand All @@ -84,37 +49,37 @@ gulp.task('tslint', function () {
}))
});

gulp.task('omnisharp:fixscripts', ['omnisharp:fetch'], function () {
gulp.task('omnisharp:fixscripts', ['omnisharp:fetch'], () => {

var _fixes = Object.create(null);
_fixes['./bin/omnisharp.cmd'] = '@"%~dp0packages\\dnx-clr-win-x86.1.0.0-beta4\\bin\\dnx.exe" "%~dp0packages\\OmniSharp\\1.0.0\\root" run %*';
_fixes['./bin/omnisharp'] = '#!/bin/bash\n\
SOURCE="${BASH_SOURCE[0]}"\n\
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink\n\
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"\n\
SOURCE="$(readlink "$SOURCE")"\n\
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located\n\
done\n\
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"\n\
export SET DNX_APPBASE="$DIR/packages/OmniSharp/1.0.0/root"\n\
export PATH=/usr/local/bin:/Library/Frameworks/Mono.framework/Commands:$PATH # this is required for the users of the Homebrew Mono package\n\
exec "$DIR/packages/dnx-mono.1.0.0-beta4/bin/dnx" "$DNX_APPBASE" run "$@"\n\
\n';

var promises = Object.keys(_fixes).map(function (key) {
return new Promise(function(resolve, reject) {
fs.writeFile(path.join(__dirname, key), _fixes[key], function (err) {
_fixes['./bin/omnisharp'] = '#!/bin/bash\n'
+ 'SOURCE="${BASH_SOURCE[0]}"\n'
+ 'while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink\n'
+ 'DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"\n'
+ 'SOURCE="$(readlink "$SOURCE")"\n'
+ '[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located\n'
+ 'done\n'
+ 'DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"\n'
+ 'export SET DNX_APPBASE="$DIR/packages/OmniSharp/1.0.0/root"\n'
+ 'export PATH=/usr/local/bin:/Library/Frameworks/Mono.framework/Commands:$PATH # this is required for the users of the Homebrew Mono package\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still want this line?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I guess this code is still using mono dnx.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed until I roll us forward to the new OmniSharp.

+ 'exec "$DIR/packages/dnx-mono.1.0.0-beta4/bin/dnx" "$DNX_APPBASE" run "$@"\n'
+ '\n';

const promises = Object.keys(_fixes).map(key => {
return new Promise((resolve, reject) => {
fs.writeFile(path.join(__dirname, key), _fixes[key], err => {
if (err) {
reject(err);
} else {
}
else {
resolve();
}
})
});
});
});

return Promise.all(promises)
});


gulp.task('omnisharp', ['omnisharp:fixscripts']);
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
],
"main": "./out/omnisharpMain",
"scripts": {
"postinstall": "gulp omnisharp && tsc"
"postinstall": "tsc && gulp omnisharp"
},
"dependencies": {
"del": "^2.0.2",
"event-stream": "^3.3.2",
"fs-extra-promise": "^0.3.1",
"github-releases": "^0.3.0",
"run-in-terminal": "*",
"semver": "*",
"vscode-extension-telemetry": "0.0.4"
"vscode-extension-telemetry": "0.0.4",
"tmp": "0.0.28",
"vinyl-fs": "^2.2.1"
},
"devDependencies": {
"del": "^2.0.2",
"event-stream": "^3.3.2",
"github-releases": "^0.3.0",
"gulp": "^3.8.9",
"gulp-decompress": "^1.2.0",
"gulp-tslint": "^4.3.0",
"tmp": "0.0.28",
"tslint": "^3.3.0",
"tslint-microsoft-contrib": "^2.0.0",
"typescript": "^1.7.3",
"vinyl-fs": "^2.2.1",
"vscode": "^0.10.1"
},
"engines": {
Expand Down
65 changes: 65 additions & 0 deletions src/omnisharpInstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import * as fs from 'fs-extra-promise';
import * as tmp from 'tmp';
import * as vfs from 'vinyl-fs';

const es = require('event-stream');
const github = require('github-releases');

tmp.setGracefulCleanup();

export function downloadOmnisharp(version: string) {
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;
}
28 changes: 28 additions & 0 deletions src/typings/del/del.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Type definitions for del v2.2.0
// Project: https://github.com/sindresorhus/del
// Definitions by: Asana <https://asana.com>, Aya Morisawa <https://github.com/AyaMorisawa>

// /// <reference path="../glob/glob.d.ts"/>
// /// <reference path="../es6-promise/es6-promise.d.ts" />

declare module "del" {
import glob = require("glob");

function Del(pattern: string): Promise<string[]>;
function Del(pattern: string, options: Del.Options): Promise<string[]>;

function Del(patterns: string[]): Promise<string[]>;
function Del(patterns: string[], options: Del.Options): Promise<string[]>;

module Del {
function sync(pattern: string, options?: Options): string[];
function sync(patterns: string[], options?: Options): string[];

interface Options extends glob.IOptions {
force?: boolean;
dryRun?: boolean;
}
}

export = Del;
}
13 changes: 8 additions & 5 deletions src/typings/fs-extra-promise/fs-extra-promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

// Imported from: https://github.com/soywiz/typescript-node-definitions/fs-extra.d.ts via TSD fs-extra definition

// ///<reference path="../node/node.d.ts"/>
// ///<reference path="../bluebird/bluebird.d.ts"/>
///<reference path="../bluebird/bluebird.d.ts"/>
///<reference path="../ref.d.ts"/>

declare module "fs-extra-promise" {
import stream = require("stream");
Expand Down Expand Up @@ -177,13 +177,16 @@ declare module "fs-extra-promise" {
encoding?: string;
fd?: number;
mode?: number;
bufferSize?: number;
autoClose?: boolean;
}

export interface WriteStreamOptions {
flags?: string;
encoding?: string;
string?: string;
defaultEncounding?: string;
fd?: number;
mode?: number;
}

export function createReadStream(path: string, options?: ReadStreamOptions): ReadStream;
export function createWriteStream(path: string, options?: WriteStreamOptions): WriteStream;

Expand Down
3 changes: 2 additions & 1 deletion src/typings/ref.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/// <reference path='../../node_modules/vscode/typings/index.d.ts'/>
/// <reference path='../../node_modules/vscode/typings/index.d.ts'/>
/// <reference path='../../node_modules/vscode/typings/glob.d.ts'/>
47 changes: 47 additions & 0 deletions src/typings/tmp/tmp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Type definitions for tmp v0.0.28
// Project: https://www.npmjs.com/package/tmp
// Definitions by: Jared Klopper <https://github.com/optical>

declare module "tmp" {

module tmp {
interface Options extends SimpleOptions {
mode?: number;
}

interface SimpleOptions {
prefix?: string;
postfix?: string;
template?: string;
dir?: string;
tries?: number;
keep?: boolean;
unsafeCleanup?: boolean;
}

interface SynchrounousResult {
name: string;
fd: number;
removeCallback: () => void;
}

function file(callback: (err: any, path: string, fd: number, cleanupCallback: () => void) => void): void;
function file(config: Options, callback?: (err: any, path: string, fd: number, cleanupCallback: () => void) => void): void;

function fileSync(config?: Options): SynchrounousResult;

function dir(callback: (err: any, path: string, cleanupCallback: () => void) => void): void;
function dir(config: Options, callback?: (err: any, path: string, cleanupCallback: () => void) => void): void;

function dirSync(config?: Options): SynchrounousResult;

function tmpName(callback: (err: any, path: string) => void): void;
function tmpName(config: SimpleOptions, callback?: (err: any, path: string) => void): void;

function tmpNameSync(config?: SimpleOptions): string;

function setGracefulCleanup(): void;
}

export = tmp;
}
Loading