-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
97 lines (86 loc) · 2.65 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
/// <reference path="typings/node/node.d.ts"/>
/**
* Dependencies.
*/
var gulp = require('gulp');
var config = require('./gulp.config')();
var $ = require('gulp-load-plugins')(); //Automatically load gulp plugins
var port = process.env.PORT || config.defaultPort;
// the default task that is run with the command 'gulp'
gulp.task('default', function () {
// assets is where you define your application assets and you can pass them into gulp.
var assets = require('./src/assets');
// change the working directory to the public folder, where your assets are located.
var gulpFileCwd = __dirname + '/src/public';
process.chdir(gulpFileCwd);
// print the working directory
$.util.log('Working directory changed to', $.util.colors.magenta(gulpFileCwd));
// concat and minify your css
gulp.src(assets.development.css)
.pipe($.concat('styles.css'))
.pipe($.minifyCss())
.pipe(gulp.dest('./css/'));
// concat and minify your js
gulp.src(assets.development.js)
.pipe($.concat('scripts.js'))
.pipe($.uglify())
.pipe(gulp.dest('./js/'));
// optimize your images
gulp.src('./images/*')
.pipe($.imagemin())
.pipe(gulp.dest('./images/'));
});
/**
* serve the dev environment
*/
gulp.task('serve-dev', function () {
serve(true /*isDev*/);
});
/**
* serve the code
* --debug-brk or --debug
* --nosync
* @param {Boolean} isDev - dev or build mode
* @param {Boolean} specRunner - server spec runner html
*/
function serve(isDev) {
var nodeOptions = {
script: isDev ? config.nodeServer.dev : config.nodeServer.build
, delayTime: 1
, ext: 'html'
, env: {
'PORT': port,
'NODE_ENV': isDev ? 'development' : 'build'
}
, watch: config.server
};
return $.nodemon(nodeOptions)
.on('restart', function (ev) {
log('*** nodemon restart');
log('files changed on restart:\n' + ev)
})
.on('start', function () {
log('*** nodemon started');
})
.on('crash', function () {
log('*** nodemon crashed: script crashed for some reason');
})
.on('exit', function () {
log('*** nodemon exited cleanly');
})
}
/**
* Log a message or series of messages using chalk's blue color.
* Can pass in a string, object or array.
*/
function log(msg) {
if (typeof (msg) === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(msg[item]));
}
}
} else {
$.util.log($.util.colors.blue(msg));
}
}