-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
67 lines (53 loc) · 1.58 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
require('babel-core/register');
const babel = require('gulp-babel');
const execSync = require('child_process').execSync;
const gulp = require('gulp');
const del = require('del');
const jasmine = require('gulp-jasmine');
const toFilePath = file => {
return file.split('/src')[1].split('/');
};
const toTranspile = file => {
let filePath = toFilePath(file);
return `transpile:${filePath.join('/')}`;
};
const toDirectory = file => {
let filePath = toFilePath(file).slice(0, -1);
return filePath.join('/');
};
const testError = exit => function(err) {
if (err.name && err.message && err.codeFrame) {
console.error(err.name + ':', err.message);
console.error(err.codeFrame, '\n');
} else {
console.log('An error occurred', err);
}
if (exit) process.exit(1);
this.emit('end');
};
const test = exit => () => {
return gulp.src('spec/**/*.js')
.pipe(jasmine().on('error', testError(exit)));
};
let srcFiles = String(execSync(`ls -1 ${__dirname}/src/**/*`))
.split('\n')
.filter(Boolean);
srcFiles.forEach(file => {
var taskName = toTranspile(file);
console.log('adding task:', taskName);
gulp.task(taskName, () => gulp.src(file)
.pipe(babel())
.pipe(gulp.dest(`lib/${toDirectory(file)}`)));
});
gulp.task('clean', () => {
return del('lib');
});
gulp.task('transpile:all', ['clean'], () => {
return gulp.start(srcFiles.map(toTranspile));
});
gulp.task('test:continue', test());
gulp.task('test', test(true));
gulp.task('test:watch', ['test:continue'], () => {
return gulp.watch(['spec/**/*.js', 'src/**/*.js'], test());
});
gulp.task('default', ['test']);