forked from OfficeDev/Microsoft-Teams-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
131 lines (116 loc) · 3.61 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
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 sourcemaps = require('gulp-sourcemaps');
var zip = require('gulp-zip');
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 tsProject = ts.createProject('./tsconfig.json', {
// Point to the specific typescript package we pull in, not a machine-installed one
typescript: require('typescript'),
});
var filesToWatch = ['**/*.ts', '!node_modules/**'];
var filesToLint = ['**/*.ts', '!src/typings/**', '!node_modules/**'];
var staticFiles = ['**/*.json', '**/*.hbs'];
/**
* Clean build output.
*/
gulp.task('clean', function () {
return del([
'build/**/*',
// Azure doesn't like it when we delete build/src
'!build/src'
]);
});
/**
* Lint all TypeScript files.
*/
gulp.task('ts:lint', function () {
if (!process.env.GLITCH_NO_LINT) {
return gulp
.src(filesToLint)
.pipe(tslint({
formatter: 'verbose'
}))
.pipe(tslint.report({
summarizeFailureOutput: true
}));
}
});
/**
* Compile TypeScript and include references to library.
*/
gulp.task('ts', function() {
return tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: '.'}))
.pipe(gulp.dest('build'));
});
/**
* Copy statics to build directory.
*/
gulp.task('statics:copy', function () {
return gulp.src(staticFiles, { base: 'src' })
.pipe(gulp.dest('./build'));
});
/**
* Build application.
*/
gulp.task('build', gulp.parallel('ts:lint', 'ts', 'statics:copy'));
gulp.task('rebuild', gulp.series('clean', gulp.parallel('ts:lint', 'ts', 'statics:copy')));
/**
* Build manifest
*/
gulp.task('generate-manifest', function() {
gulp.src(['./manifest/*.png', 'manifest/manifest.json'])
.pipe(zip('AuthBot.zip'))
.pipe(gulp.dest('manifest'));
});
/**
* Package up app into a ZIP file for Azure deployment.
*/
gulp.task('package', gulp.series('rebuild', function () {
var packagePaths = [
'build/**/*',
'public/**/*',
'web.config',
'package.json',
'**/node_modules/**',
'!build/**/*.js.map'];
//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);
}
return gulp.src(packagePaths, { base: '.' })
.pipe(zip(options.packageName))
.pipe(gulp.dest(options.packagePath));
}));
gulp.task('server:start', gulp.series('build', function() {
server.listen({path: 'app.js', cwd: 'build/src'}, function(error) {
console.error(error);
});
}));
gulp.task('server:restart', gulp.series('build', function() {
server.restart();
}));
gulp.task('default', gulp.series('server:start', function() {
gulp.watch(filesToWatch, ['server:restart']);
}));