-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
118 lines (85 loc) · 2.76 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
/** @fileoverview gulpfile.js
If needed: npm install
To see targets: gulp -T
=============================================================================*/
"use strict";
const
gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
clear = require('clear');
const
SRC_DIR = 'src',
TEST_DIR = 'test',
BUILD_DIR = 'build',
JS_FILES = SRC_DIR+'/**/*.js',
TEST_FILES = TEST_DIR+'/**/{test_*,*Test}.js',
RESOURCES=['package.json','README.md','static/**/*'];
// Primitive targets
// -----------------
gulp.task('clean', ['clean-test', 'clean-coverage'], () => {
return gulp.src(BUILD_DIR)
.pipe($.rimraf());
});
gulp.task('clean-test', $.shell.task([
`echo Removing ${TEST_DIR}/index.js`,
`rm -f ${TEST_DIR}/index.js`
]));
gulp.task('clean-coverage', () => {
return gulp.src(['coverage'])
.pipe($.rimraf());
});
gulp.task('very-clean', ['clean'], () => {
return gulp.src(['*~',SRC_DIR+'/**/*~',TEST_DIR+'/**/*~','dump.rdb'])
.pipe($.rimraf());
});
gulp.task('dist-clean', ['very-clean'], () => {
console.log("Hope you know what you are doing...");
return gulp.src('node_modules')
.pipe($.rimraf());
});
gulp.task('build', ['xpile','resources']);
gulp.task('xpile', () => {
return gulp.src(JS_FILES)
.pipe($.newer(BUILD_DIR))
.pipe($.shell([ 'echo "Transpile src/<%= file.relative %> -> build/"' ],
{ verbose: false }))
.pipe($.babel()) // See .babelrc
.pipe(gulp.dest(BUILD_DIR));
});
gulp.task('prep-test', ['clean-test'], () => {
console.log('Constructing test/index.js file');
return gulp.src(TEST_FILES)
.pipe($.shell([
`echo "require('./<%= file.relative %>');" >> ${TEST_DIR}/index.js`
], { verbose: false }))
});
gulp.task('test', ['prep-test'], $.shell.task([
'echo Running unit tests',
`BABEL_ENV=test babel-node ${TEST_DIR}/index.js | tap-colorize`
], { verbose: true }));
gulp.task('cover', ['prep-test'], $.shell.task([
'echo Running code coverage analysis',
`BABEL_ENV=test babel-node ./node_modules/.bin/babel-istanbul cover ${TEST_DIR}/index.js | tap-colorize`,
'babel-istanbul report html',
'echo Check coverage/index.html report'
], { verbose: true }));
gulp.task('clear', (next) => {
clear();
return next();
});
gulp.task('watch', ['build', 'test'], () => {
return gulp.watch([JS_FILES,TEST_FILES,RESOURCES], ['clear','build','test']);
});
gulp.task('resources', () => {
return gulp.src(RESOURCES,{base:'.'})
.pipe($.newer(BUILD_DIR))
.pipe($.shell([ 'echo "Copy <%= file.relative %> -> build/"' ],
{ verbose: false }))
.pipe(gulp.dest(BUILD_DIR));
});
// Convenience targets
// -------------------
// watch-run: run via supervisor or: npm run run
// clean-build: gulp clean && gulp build
gulp.task('default', ['watch']);
// EOF