-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
182 lines (158 loc) · 4.69 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
174
175
176
177
178
179
180
181
182
var gulp = require('gulp')
, gutil = require('gulp-util')
, del = require('del')
, concat = require('gulp-concat')
, rename = require('gulp-rename')
, minifycss = require('gulp-minify-css')
, minifyhtml = require('gulp-minify-html')
, processhtml = require('gulp-processhtml')
, jshint = require('gulp-jshint')
, uglify = require('gulp-uglify')
, connect = require('gulp-connect')
, nodemon = require('gulp-nodemon')
, clean = require('gulp-clean')
, runSequence = require('run-sequence')
, mocha = require('gulp-mocha')
, cover = require('gulp-coverage')
, browserSync = require('browser-sync')
, paths;
paths = {
css: ['src/css/*.css'],
html: ['src/html/*'],
node: [
'server.js',
'app/**/*.js',
'config/**/*.js',
'tests/**/*.js'
],
libs: [
'./bower_components/angular/angular.min.js',
'./bower_components/jquery/dist/jquery.min.js',
'./bower_components/bootstrap/dist/css/bootstrap.min.css',
'./bower_components/bootstrap/dist/js/bootstrap.min.js',
'./bower_components/highcharts/highcharts.js',
'./bower_components/highcharts/js/modules/exporting.js',
'./bower_components/angular-route/angular-route.min.js',
'./bower_components/angular-loading-overlay/dist/angular-loading-overlay.js',
'./bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'./bower_components/angular/angular.min.js.map',
'./bower_components/angular-route/angular-route.min.js.map'
],
js: ['src/js/**/*.js'],
dist: './dist/',
favicon:'src/favicon.ico',
src: './src/',
tests: './tests/*.js'
};
//CLEAN
gulp.task('clean', function () {
return gulp
.src(paths.dist)
.pipe(clean({force: true}));
});
//Copy all bower dependencies
gulp.task('bower', function () {
gulp.src(paths.favicon)
.pipe(gulp.dest(paths.dist, {overwrite: true}))
.on('error', gutil.log);
return gulp.src(paths.libs)
.pipe(gulp.dest(paths.dist))
.on('error', gutil.log);
});
//Static files
gulp.task('html', function () {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.dist, {overwrite: true}))
.on('error', gutil.log);
});
gulp.task('js', function () {
return gulp.src(paths.js)
.pipe(concat('main.min.js'))
// .pipe(uglify({outSourceMaps: false}))
.pipe(gulp.dest(paths.dist, {overwrite: true}));
});
gulp.task('css', function () {
return gulp.src(paths.css)
.pipe(minifycss({
keepSpecialComments: false,
removeEmpty: true
}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.dist, {overwrite: true}))
.on('error', gutil.log);
});
//Static Analysis
gulp.task('jshint', function () {
return gulp
.src(paths.js.concat(paths.node)) //All javascript
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
//Test suite
gulp.task('test', function () {
return gulp.src('tests/**/*.js', { read: false })
.pipe(cover.instrument({
pattern: paths.node,
debugDirectory: 'debug'
}))
.pipe(mocha())
.pipe(cover.gather())
.pipe(cover.format())
.pipe(gulp.dest('reports'));
});
gulp.task('build', ['jshint', 'bower', 'html', 'js', 'css']);
gulp.task('develop', function(done) {
return runSequence('clean', 'build', function() {
return done();
});
});
//Live development
// we'd need a slight delay to reload browsers
// connected to browser-sync after restarting nodemon
var BROWSER_SYNC_RELOAD_DELAY = 500;
gulp.task('nodemon', ['develop'], function (cb) {
gulp.doneCallback = function (err) { };
var called = false;
return nodemon({
// nodemon our expressjs server
script: 'server.js',
// watch core server file(s) that require server restart on change
watch: paths.node
})
.on('start', function onStart() {
// ensure start only got called once
if (!called) { cb(); }
called = true;
})
.on('restart', function onRestart() {
// reload connected browsers after a slight delay
setTimeout(function reload() {
browserSync.reload({
stream: false
});
}, BROWSER_SYNC_RELOAD_DELAY);
});
});
gulp.task('browser-sync', ['nodemon'], function () {
// for more browser-sync config options: http://www.browsersync.io/docs/options/
browserSync({
// informs browser-sync to proxy our expressjs app which would run at the following location
proxy: 'http://localhost:3002',
// informs browser-sync to use the following port for the proxied app
// notice that the default port is 3000, which would clash with our expressjs
port: 4000,
// open the proxied app in chrome
browser: ['firefox']
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.doneCallback = function (err) {
process.exit(err ? 1 : 0);
};
gulp.task('default', ['browser-sync'], function () {
gulp.watch(paths.js, ['js', browserSync.reload]);
gulp.watch(paths.css, ['css']);
gulp.watch(paths.html, ['html', 'bs-reload']);
});