-
Notifications
You must be signed in to change notification settings - Fork 47
/
gulpfile.js
151 lines (135 loc) · 4.08 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
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 rename = require('gulp-rename');
var jsonTransform = require('gulp-json-transform');
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 = ['src/**/*.json', 'src/**/*.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', ['clean'], 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', ['clean'], function () {
return gulp.src(staticFiles, { base: '.' })
.pipe(gulp.dest('./build'));
});
/**
* Build application.
*/
gulp.task('build', ['clean', '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'));
});
/**
* Run tests.
*/
gulp.task('test', ['ts', 'statics:copy'], function() {
return 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();
});
});
/**
* Package up app into a ZIP file for Azure deployment.
*/
gulp.task('package', ['build'], function () {
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);
}
return gulp.src(packagePaths, { base: '.' })
.pipe(zip(options.packageName))
.pipe(gulp.dest(options.packagePath));
});
gulp.task('server:start', ['build'], function() {
server.listen({path: 'app.js', cwd: 'build/src'}, function(error) {
console.error(error);
});
});
gulp.task('server:restart', ['build'], function() {
server.restart();
});
gulp.task('default', ['server:start'], function() {
gulp.watch(filesToWatch, ['server:restart']);
});