-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.babel.js
124 lines (112 loc) · 2.85 KB
/
gulpfile.babel.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
import browserSyncModule from 'browser-sync';
import Builder from 'systemjs-builder';
import del from 'del';
import eslint from 'gulp-eslint';
import fse from 'fs-extra';
import gulp from 'gulp';
import jade from 'gulp-jade';
import notify from 'gulp-notify';
import modernizr from 'gulp-modernizr';
import uglify from 'gulp-uglify';
import tape from 'gulp-tape';
import tapColorize from 'tap-colorize';
const browserSync = browserSyncModule.create();
const bundle = (buildStatic = false) => {
const copyFiles = new Promise((resolve, reject) => {
fse.copy('src/config.js', '.tmp/config.js', err => {
if (err) {
reject(err);
} else {
fse.copy('src/jspm_packages/system.js', '.tmp/system.js', err2 => {
if (err2) {
reject(err2);
} else {
resolve();
}
});
}
});
});
const builder = new Builder('src', 'src/config.js');
const build = builder[buildStatic ? 'buildStatic' : 'bundle']('test/bundleme', '.tmp/bundle.js');
return Promise.all([build, copyFiles]);
};
gulp.task('clean', () => {
return del('.tmp');
});
gulp.task('jade', ['clean'], () => {
return gulp.src('test/*.jade')
.pipe(jade())
.pipe(gulp.dest('.tmp'));
});
gulp.task('bundle', ['clean'], () => {
return bundle();
});
gulp.task('bundleStatic', ['clean'], () => {
return bundle(true);
});
gulp.task('lint', () => {
const glob = [
'!src/config.js',
'!src/modernizr.js',
'!src/jspm_packages/**',
'src/**/*.js',
'test/**/*.spec.js',
];
return gulp.src(glob)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('modernizr', () => {
const glob = [
'!src/config.js',
'!src/modernizr.js',
'!src/jspm_packages/**',
'src/**/*.js',
];
return gulp.src(glob)
.pipe(modernizr())
.pipe(uglify())
.pipe(gulp.dest('src'));
});
gulp.task('test', () => {
return gulp.src('test/*.spec.js')
.pipe(tape({
reporter: tapColorize()
}));
});
gulp.task('test:runtime', ['jade', 'modernizr'], () => {
browserSync.init({
server: {
index: 'runtime-test.html',
baseDir: ['.tmp', 'src', 'test'],
},
});
gulp.watch('src/**.js').on('change', browserSync.reload);
});
gulp.task('test:bundle', ['jade', 'bundle'], () => {
browserSync.init({
server: {
baseDir: ['.tmp', 'test'],
index: 'bundle-test.html',
},
});
gulp.watch('src/**.js').on('change', browserSync.reload);
});
gulp.task('test:bundleStatic', ['jade', 'bundleStatic'], () => {
browserSync.init({
server: {
baseDir: ['.tmp', 'test'],
index: 'bundle-static-test.html',
},
});
gulp.watch('src/**.js').on('change', browserSync.reload);
});
gulp.task('default', ['lint', 'test'], () => {
return gulp.src('.')
.pipe(notify({
message: 'Successfully build',
onLast: true,
}));
});