-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
106 lines (89 loc) · 2.53 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
const gulp = require('gulp');
const nodemon = require('nodemon');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const watch = require('gulp-watch');
const mocha = require('gulp-mocha');
const spawnMocha = require('gulp-spawn-mocha');
const tslint = require('gulp-tslint');
const tsSrcPath = 'src/**/*.ts';
const compiledTestsPath = 'build/**/*.spec.js';
gulp.task('default', ['scripts'], runNodemonAndWatch);
gulp.task('compile-typescript', runTSCompiler);
gulp.task('scripts', ['compile-typescript']);
gulp.task('generate-secrets', ['compile-typescript'], () => {
require('./build/generateSecrets');
});
gulp.task('test', ['scripts'], getTestsTaskBodyForWatch);
gulp.task('test:validate', ['scripts'], getTestsTaskBodyForValidation);
gulp.task('build-and-validate', ['lint:validate', 'test:validate']);
gulp.task('lint', getTsLintTaskBody(false));
gulp.task('lint:validate', getTsLintTaskBody(true));
gulp.task('watch', ['lint', 'test'], () => {
watch(tsSrcPath, () => {
gulp.start('lint', 'test');
});
});
gulp.task('pre-commit', ['build-and-validate']);
/// Implementation below ///
const mochaTimeout = process.env.RL_MOCHA_TIMEOUT || 200;
function runTSCompiler () {
const tsProject = ts.createProject('tsconfig.json');
const tsResult = gulp
.src(tsSrcPath)
.pipe(sourcemaps.init())
.pipe(tsProject(ts.reporter.longReporter()));
return tsResult.js
.pipe(sourcemaps.write())
.pipe(gulp.dest('build'));
}
function runNodemonAndWatch () {
return nodemon({
script: 'build/index.js',
ext: 'js',
env: {
PORT: process.env.PORT || 9000,
NODE_ENV: process.env.NODE_ENV || 'development'
},
watch: 'build'
});
}
function getTsLintTaskBody (emitError) {
return () => {
gulp
.src(tsSrcPath)
.pipe(tslint({
formatter: 'codeFrame'
}))
.pipe(tslint.report({
summarizeFailureOutput: true,
emitError: emitError
}));
};
}
function getTestsTaskBodyForWatch () {
return gulp
.src(compiledTestsPath, {read: false})
.pipe(spawnMocha({
timeout: mochaTimeout,
R: 'progress',
env: {'NODE_ENV': 'test'}
}));
}
function getTestsTaskBodyForValidation () {
process.env.NODE_ENV = 'test';
return gulp
.src(compiledTestsPath, {read: false})
.pipe(mocha({
reporter: 'spec',
ui: 'bdd',
timeout: mochaTimeout
}))
.once('error', (error) => {
console.error(error);
process.exit(-1);
})
.once('end', () => {
process.exit();
});
}