-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
161 lines (132 loc) · 4.6 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// All used modules.
var gulp = require('gulp');
var babel = require('gulp-babel');
var runSeq = require('run-sequence');
var plumber = require('gulp-plumber');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var sass = require('gulp-sass');
var livereload = require('gulp-livereload');
var minifyCSS = require('gulp-minify-css');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var eslint = require('gulp-eslint');
var mocha = require('gulp-mocha');
var karma = require('karma').server;
var istanbul = require('gulp-istanbul');
var notify = require('gulp-notify');
// Development tasks
// --------------------------------------------------------------
// Live reload business.
gulp.task('reload', function () {
livereload.reload();
});
gulp.task('reloadCSS', function () {
return gulp.src('./public/style.css').pipe(livereload());
});
gulp.task('lintJS', function () {
return gulp.src(['./browser/js/**/*.js', './server/**/*.js'])
.pipe(plumber({
errorHandler: notify.onError('Linting FAILED! Check your gulp process.')
}))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('buildJS', ['lintJS'], function () {
return gulp.src(['./browser/js/app.js', './browser/js/**/*.js'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(concat('main.js'))
.pipe(babel({
presets: ['es2015']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public'));
});
gulp.task('testServerJS', function () {
require('babel-register');
return gulp.src('./tests/server/**/*.js', {
read: false
}).pipe(mocha({ reporter: 'spec' }));
});
gulp.task('testServerJSWithCoverage', function (done) {
gulp.src('./server/**/*.js')
.pipe(istanbul({
includeUntested: true
}))
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src('./tests/server/**/*.js', {read: false})
.pipe(mocha({reporter: 'spec'}))
.pipe(istanbul.writeReports({
dir: './coverage/server/',
reporters: ['html', 'text']
}))
.on('end', done);
});
});
gulp.task('testBrowserJS', function (done) {
karma.start({
configFile: __dirname + '/tests/browser/karma.conf.js',
singleRun: true
}, done);
});
gulp.task('buildCSS', function () {
var sassCompilation = sass();
sassCompilation.on('error', console.error.bind(console));
return gulp.src('./browser/scss/main.scss')
.pipe(plumber({
errorHandler: notify.onError('SASS processing failed! Check your gulp process.')
}))
.pipe(sassCompilation)
.pipe(rename('style.css'))
.pipe(gulp.dest('./public'));
});
// Production tasks
// --------------------------------------------------------------
gulp.task('buildCSSProduction', function () {
return gulp.src('./browser/scss/main.scss')
.pipe(sass())
.pipe(rename('style.css'))
.pipe(minifyCSS())
.pipe(gulp.dest('./public'))
});
gulp.task('buildJSProduction', function () {
return gulp.src(['./browser/js/app.js', './browser/js/**/*.js'])
.pipe(concat('main.js'))
.pipe(babel())
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(gulp.dest('./public'));
});
gulp.task('buildProduction', ['buildCSSProduction', 'buildJSProduction']);
// Composed tasks
// --------------------------------------------------------------
gulp.task('build', function () {
if (process.env.NODE_ENV === 'production') {
runSeq(['buildJSProduction', 'buildCSSProduction']);
} else {
runSeq(['buildJS', 'buildCSS']);
}
});
gulp.task('default', function () {
gulp.start('build');
// Run when anything inside of browser/js changes.
gulp.watch('browser/js/**', function () {
runSeq('buildJS', 'reload');
});
// Run when anything inside of browser/scss changes.
gulp.watch('browser/scss/**', function () {
runSeq('buildCSS', 'reloadCSS');
});
gulp.watch('server/**/*.js', ['lintJS']);
// Reload when a template (.html) file changes.
gulp.watch(['browser/**/*.html', 'server/app/views/*.html'], ['reload']);
// Run server tests when a server file or server test file changes.
gulp.watch(['tests/server/**/*.js'], ['testServerJS']);
// Run browser testing when a browser test file changes.
gulp.watch('tests/browser/**/*', ['testBrowserJS']);
livereload.listen();
});