-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.babel.js
132 lines (111 loc) · 2.45 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
125
126
127
128
129
130
131
132
/*global __dirname */
import babelify from 'babelify';
import browserify from 'browserify';
import buffer from 'vinyl-buffer';
import eslint from 'gulp-eslint';
import gulp from 'gulp';
import gulpwatch from 'gulp-watch';
import gutil from 'gulp-util';
import historyApiFallback from 'connect-history-api-fallback';
import sequence from 'run-sequence';
import source from 'vinyl-source-stream';
import stringify from 'stringify';
import watchify from 'watchify';
import {server as karma} from 'karma';
import browsersync from 'browser-sync';
function handleError(task){
return function(err) {
gutil.beep();
gutil.log(err);
this.emit('end');
};
}
function Build(watch, done){
var b;
function transform(){
if( !b ){
b = browserify('./app/index.js', {
debug: true,
paths: ['./node_modules', './app/'],
cache: {},
packageCache: {},
fullPaths: true
});
if(watch){
b = watchify(b);
}
b.transform(babelify.configure({
stage: 0
}));
b.transform(stringify(['.html']));
}
function bundle(){
let stream = b.bundle()
.on('error', handleError('Browserify'))
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist'));
stream.on('end', browsersync.reload);
return stream;
}
return bundle();
}
gulp.task('bundle', ['lint'], function bundleTask(){
return transform();
});
gulp.task('bundle-light', function bundleLightTask(){
return transform();
});
gulp.task('test', function(done){
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done);
});
function tdd(){
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: false,
reporters: ['mocha']
});
}
gulp.task('setup-watchers', function(){
gulpwatch(['app/**/*.js', 'app/**/*.html', 'node_modules/ng-forward/**/*.js'], function(){
gulp.run('bundle');
});
gulp.run('serve');
tdd();
});
if(watch)
{
sequence('bundle', 'setup-watchers', done);
}
else
{
sequence('bundle', 'test', done);
}
}
function serve(){
browsersync.init({
port: 2000,
ui: {
port: 2001
},
server: {
baseDir: './dist',
middleware: [historyApiFallback]
}
});
}
gulp.task('serve', serve);
gulp.task('default', function(done){
Build(true, done);
});
gulp.task('build', function(done){
Build(false, done);
});
gulp.task('lint', function(){
return gulp.src(['app/**/*.js', '!app/**/*.spec.js', '!app/**/*.e2e.js'])
.pipe(eslint())
.pipe(eslint.format());
});