-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
174 lines (128 loc) · 4.52 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
'use strict';
var gulp = require('gulp'),
del = require('del'),
fs = require('fs'),
glob = require('glob'),
util = require('gulp-util'),
clean = require('gulp-clean'),
path = require('path'),
msbuild = require('gulp-msbuild'),
xunit = require('gulp-xunit-runner'),
Nuget = require('nuget-runner'),
assemblyInfo = require('gulp-dotnet-assembly-info');
var paths = {};
paths.root = __dirname;
paths.artifactsDirectory = path.join(paths.root, 'artifacts');
paths.sourceDirectory = path.join(paths.root, 'src');
paths.solutionDirectory = paths.sourceDirectory;
paths.solutionFilePattern = path.join(paths.solutionDirectory, '*.sln');
paths.nugetDirectory = path.join(paths.solutionDirectory, '.nuget');
paths.nugetPackagesDirectory = path.join(paths.solutionDirectory, 'packages');
paths.nugetNuspecPattern = path.join(paths.solutionDirectory, '**/*.nuspec');
paths.nugetExeFile = path.join(paths.nugetDirectory, 'NuGet.exe');
paths.nugetConfigFile = path.join(paths.nugetDirectory, 'NuGet.config');
paths.projectLicenceUrl = '';
var buildinfo = {};
buildinfo.configuration = 'Release';
buildinfo.number = process.env.BUILD_NUMBER || 0;
buildinfo.version = '1.0.0.' + buildinfo.number;
var nuget = new Nuget({
nugetPath: paths.nugetExeFile,
apiKey: '',
verbosity: 'normal',
configFile: paths.nugetConfigFile
});
// Return a stream so gulp can determine completion
gulp.task('clean', function (done) {
del([paths.artifactsDirectory, paths.nugetPackagesDirectory], function (err, paths) {
console.log('Deleted files/folders:\n', paths.join('\n'));
done();
});
});
gulp.task('nuget-restore', ['clean'], function () {
nuget
.restore({
packages: paths.solutionDirectory
});
});
gulp.task('configuration', function () {
});
gulp.task('package', ['nuget-pack'], function () {});
gulp.task('nuget-pack', ['nuget-restore', 'build', 'test'], function () {
var nuspecProperties = {
authors: 'Nicholas Hammond',
owners: 'Nicholas Hammond',
licenseUrl: 'http://github.com',
projectUrl: 'http://github.com',
iconUrl: 'http://github.com',
requireLicenseAcceptance: false,
releaseNotes: '',
copyright: 'Copyright (2015)',
configuration: buildinfo.configuration
};
fs.mkdirSync(paths.artifactsDirectory);
var options = {
nonull: false
};
glob(paths.nugetNuspecPattern, options, function (error, nuspecFiles) {
if (nuspecFiles.length === 0) {
util.log('NuGet: No nuspec files found in projects to pack');
return;
}
for (var index = 0; index < nuspecFiles.length; index++) {
var nuspecFile = nuspecFiles[index];
var projectFile = nuspecFile.replace('.nuspec', '.csproj');
nuget.pack({
spec: projectFile,
outputDirectory: paths.artifactsDirectory,
version: buildinfo.version,
symbols: true,
includeReferencedProjects: true,
properties: nuspecProperties
});
}
})
});
gulp.task('xunit-test', ['build'], function () {
var files = glob.sync('**/Xunit.console.exe');
if (files.length === 0) {
throw new Error('XUnit console is not installed, Please install package xunit.runner.console using nuget');
}
var unitTestsPath = path.join(path.join('**/bin', buildinfo.configuration), '*UnitTests*.dll');
return gulp.src([unitTestsPath], {
read: false
})
.pipe(xunit({
executable: files[0]
}));
});
gulp.task('test', ['xunit-test']);
gulp.task('assemblyInfo', function () {
var replacements = {
configuration: buildinfo.configuration,
copyright: 'Copyright 2015',
version: buildinfo.version,
fileVersion: buildinfo.version,
};
gulp.src('**/AssemblyInfo.cs')
.pipe(assemblyInfo(replacements))
.pipe(gulp.dest('.'));
});
gulp.task('build', ['assemblyInfo', 'nuget-restore'], function () {
var options = {
configuration: buildinfo.configuration,
toolsVersion: 12.0,
targets: ['Clean', 'Build'],
errorOnFail: true,
stdout: true,
verbosity: 'quiet',
properties: {
clp: 'ErrorsOnly'
}
};
return gulp
.src('**/*.sln')
.pipe(msbuild(options));
});
gulp.task('default', ['clean', 'build', 'test', 'package']);
gulp.task('ci', ['clean', 'build', 'test', 'package']);