forked from OfficeDev/Microsoft-Teams-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
237 lines (214 loc) · 6.72 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
var gulp = require('gulp');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var del = require('del');
var server = require('gulp-develop-server');
var mocha = require('gulp-spawn-mocha');
var sourcemaps = require('gulp-sourcemaps');
var zip = require('gulp-zip');
var browserify = require('browserify');
var tsify = require("tsify");
var source = require('vinyl-source-stream');
var path = require('path');
var minimist = require('minimist');
var fs = require('fs');
var _ = require('lodash');
var knownOptions = {
string: 'packageName',
string: 'packagePath',
string: 'specFilter',
default: {packageName: 'Package.zip', packagePath: path.join(__dirname, '_package'), specFilter: '*'}
};
var options = minimist(process.argv.slice(2), knownOptions);
var filesToWatch = ['**/*.ts', '!node_modules/**'];
var filesToLint = ['**/*.ts', '!src/typings/**', '!node_modules/**'];
var staticFiles = ['src/**/*.json', 'src/**/*.pug', '!src/manifest.json'];
var clientJS = 'src/TaskModuleTab.ts';
var bundledJS = 'bundle.js';
var msTeamsLib = './node_modules/@microsoft/teams-js/dist/MicrosoftTeams.min.js';
/**
* Clean build output.
*/
gulp.task('clean', (done) => {
del([
'build/**/*',
// Azure doesn't like it when we delete build/src
'!build/src'
// 'manifest/**/*'
]);
done();
});
/**
* Lint all TypeScript files.
*/
gulp.task('ts:lint', (done) => {
if (!process.env.GLITCH_NO_LINT) {
gulp.src(filesToLint)
.pipe(tslint({
formatter: 'verbose'
}))
.pipe(tslint.report({
summarizeFailureOutput: true
}));
done();
} else {
done();
}
});
/**
* Compile TypeScript and include references to library.
*/
gulp.task('ts', gulp.series("clean", (done) => {
var tsProject = ts.createProject('./tsconfig.json', {
// Point to the specific typescript package we pull in, not a machine-installed one
typescript: require('typescript'),
});
tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js
.pipe(sourcemaps.write('.', { sourceRoot: function(file) { return file.cwd + '/build'; }}))
.pipe(gulp.dest('build/src'));
done();
}));
/**
* Copy statics to build directory.
*/
gulp.task('statics:copy', gulp.series("clean", (done) => {
gulp.src(staticFiles, { base: '.' })
.pipe(gulp.dest('./build'));
done();
}));
/**
* Copy (generated) client TypeScript files to the /scripts directory
*/
gulp.task('client-js', gulp.series("ts", (done) => {
var bundler = browserify({
basedir: ".",
entries: clientJS,
ignoreMissing: true,
debug: false
});
var bundle = function() {
return bundler
.plugin(tsify)
.bundle()
.on('.error', function() {})
.pipe(source(bundledJS))
.pipe(gulp.dest('./public/scripts'));
};
if (global.isWatching) {
bundler = watchify(bundler);
bundler.on('update', bundle)
}
bundle();
done();
}));
/**
* Build application.
*/
gulp.task('build', gulp.series("clean", "ts:lint", "ts", "client-js", "statics:copy"));
/**
* Build manifest
*/
gulp.task('generate-manifest', (done) => {
gulp.src(['./public/images/*_icon.png', 'src/manifest.json'])
.pipe(zip('TaskModule.zip'))
.pipe(gulp.dest('manifest'));
done();
});
/**
* Build debug version of the manifest -
*/
gulp.task('generate-manifest-debug', (done) => {
gulp.src(['./public/images/*_icon.png', 'manifest/debug/manifest.json'])
.pipe(zip('TaskModuleDebug.zip'))
.pipe(gulp.dest('manifest/debug'));
done();
});
/**
* Run tests.
*/
gulp.task('test', gulp.series("ts", "statics:copy", (done) => {
gulp
.src('build/test/' + options.specFilter + '.spec.js', {read: false})
.pipe(mocha({cwd: 'build/src'}))
.once('error', function () {
process.exit(1);
})
.once('end', function () {
process.exit();
});
done();
}));
/**
* Package up app into a ZIP file for Azure deployment.
*/
gulp.task('package', gulp.series("build", (done) => {
var packagePaths = [
'build/**/*',
'public/**/*',
'web.config',
'package.json',
'**/node_modules/**',
'!build/src/**/*.js.map',
'!build/test/**/*',
'!build/test',
'!build/src/typings/**/*'];
//add exclusion patterns for all dev dependencies
var packageJSON = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
var devDeps = packageJSON.devDependencies;
for (var propName in devDeps) {
var excludePattern1 = '!**/node_modules/' + propName + '/**';
var excludePattern2 = '!**/node_modules/' + propName;
packagePaths.push(excludePattern1);
packagePaths.push(excludePattern2);
}
gulp.src(packagePaths, { base: '.' })
.pipe(zip(options.packageName))
.pipe(gulp.dest(options.packagePath));
done();
}));
gulp.task('server:start', gulp.series("build", (done) => {
server.listen({path: 'build/src/app.js'}, function(error) {
console.log(error);
});
done();
}));
gulp.task('server:restart', gulp.series("build", (done) => {
server.restart();
done();
}));
gulp.task('default', gulp.series("server:start", (done) => {
gulp.watch(filesToWatch, ['server:restart']);
done();
}));
gulp.task('default', gulp.series("clean", "generate-manifest", (done) => {
console.log('Build completed. Output in manifest folder');
done();
}));