-
Notifications
You must be signed in to change notification settings - Fork 677
/
gulpfile.js
178 lines (146 loc) · 5.68 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*---------------------------------------------------------------------------------------------
* 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 fs = require('fs');
const path = require('path');
const del = require('del');
const gulp = require('gulp');
const gulpUtil = require('gulp-util');
const tslint = require('gulp-tslint');
const vsce = require('vsce');
const debugUtil = require('./out/coreclr-debug/util.js');
const debugInstall = require('./out/coreclr-debug/install.js');
const fs_extra = require('fs-extra-promise');
const omnisharp = require('./out/omnisharp/omnisharp');
const download = require('./out/omnisharp/download');
const platform = require('./out/platform');
const child_process = require('child_process');
const Flavor = omnisharp.Flavor;
const Platform = platform.Platform;
/// used in offline packaging run so does not clean .vsix
function clean() {
cleanDebugger();
return cleanOmnisharp();
}
gulp.task('clean', ['omnisharp:clean', 'debugger:clean', 'package:clean'], () => {
});
/// Omnisharp Tasks
function installOmnisharp(omnisharps) {
const logger = (message) => { console.log(message); };
const promises = omnisharps.map((omni) => download.go(omni.flavor, omni.platform, logger));
return Promise.all(promises);
}
function cleanOmnisharp() {
return del('.omnisharp');
}
gulp.task('omnisharp:clean', () => {
return cleanOmnisharp();
});
gulp.task('omnisharp:install', ['omnisharp:clean'], () => {
const flavor = gulpUtil.env.flavor || Flavor.CoreCLR;
const platform = gulpUtil.env.platform || platform.getCurrentPlatform();
return installOmnisharp([{flavor, platform}]);
});
/// Debugger Tasks
function getDebugInstaller() {
return new debugInstall.DebugInstaller(new debugUtil.CoreClrDebugUtil(path.resolve('.')), true);
}
function installDebugger(runtimeId) {
return getDebugInstaller().install(runtimeId);
}
function cleanDebugger() {
try {
getDebugInstaller().clean();
console.log('Cleaned Succesfully');
} catch (error) {
console.error(error);
}
}
gulp.task('debugger:install', ['debugger:clean'], () => {
installDebugger(gulp.env.runtimeId).then(() => {
console.log('Installed Succesfully');
}).catch((error) => {
console.error(error);
});
});
gulp.task('debugger:clean', () => {
cleanDebugger();
});
/// Packaging Tasks
function doPackageSync(packageName) {
var vsceArgs = [];
vsceArgs.push(path.join(__dirname, 'node_modules', 'vsce', 'out', 'vsce'))
vsceArgs.push('package'); // package command
if (packageName !== undefined) {
vsceArgs.push('-o');
vsceArgs.push(packageName);
}
var proc = child_process.spawnSync('node', vsceArgs);
if (proc.error) {
console.error(proc.error.toString());
}
}
function doOfflinePackage(runtimeId, omnisharps, packageName) {
return clean().then(() => {
return installDebugger(runtimeId);
}).then(() => {
return installOmnisharp(omnisharps);
}).then(() => {
doPackageSync(packageName + '-' + runtimeId + '.vsix');
});
}
gulp.task('package:clean', () => {
return del('*.vsix');
});
gulp.task('package:online', ['clean'], () => {
doPackageSync();
});
gulp.task('package:offline', ['clean'], () => {
var json = JSON.parse(fs.readFileSync('package.json'));
var name = json.name;
var version = json.version;
var packageName = name + '.' + version;
var packages = [];
packages.push({rid: 'win7-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.Windows}, {flavor: Flavor.Desktop, platform: Platform.Windows}]});
packages.push({rid: 'osx.10.11-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.OSX}]});
packages.push({rid: 'centos.7-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.CentOS}]});
packages.push({rid: 'debian.8-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.Debian}]});
packages.push({rid: 'fedora.23-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.Fedora}]});
packages.push({rid: 'opensuse.13.2-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.OpenSUSE}]});
packages.push({rid: 'rhel.7.2-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.RHEL}]});
packages.push({rid: 'ubuntu.14.04-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.Ubuntu14}]});
packages.push({rid: 'ubuntu.16.04-x64', omnisharps: [{flavor: Flavor.CoreCLR, platform: Platform.Ubuntu16}]});
var promise = Promise.resolve();
packages.forEach(data => {
promise = promise.then(() => {
return doOfflinePackage(data.rid, data.omnisharps, packageName);
})
});
return promise;
});
/// Misc Tasks
const allTypeScript = [
'src/**/*.ts',
'!**/*.d.ts',
'!**/typings**'
];
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(e => {
var message = relativeBase + e.name + ':' + (e.startPosition.line + 1) + ':' + (e.startPosition.character + 1) + ': ' + e.failure;
console.log('[tslint] ' + message);
});
};
gulp.task('tslint', () => {
gulp.src(allTypeScript)
.pipe(tslint({
rulesDirectory: "node_modules/tslint-microsoft-contrib"
}))
.pipe(tslint.report(lintReporter, {
summarizeFailureOutput: false,
emitError: false
}))
});