-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
173 lines (139 loc) · 4.75 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
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
// All used modules.
var babel = require('gulp-babel');
var gulp = require('gulp');
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');
// 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(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())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public'));
});
gulp.task('testServerJS', function () {
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 () {
return gulp.src('./browser/scss/main.scss')
.pipe(sass({
errLogToConsole: true
}))
.pipe(rename('style.css'))
.pipe(gulp.dest('./public'));
});
gulp.task('seedDB', function () {
var users = [
{ email: '[email protected]', password: 'testing123' },
{ email: '[email protected]', password: 'rainbowkicks' },
{ email: '[email protected]', password: 'potus' }
];
var dbConnected = require('./server/db');
return dbConnected.then(function () {
var User = require('mongoose').model('User');
return User.create(users);
}).then(function () {
process.kill(0);
}).catch(function (err) {
console.error(err);
});
});
// --------------------------------------------------------------
// 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 () {
livereload.listen();
gulp.start('build');
gulp.watch('browser/js/**', function () {
runSeq('buildJS', 'reload');
});
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']);
});