-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
140 lines (120 loc) · 3.28 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
var gulp = require('gulp'),
usemin = require('gulp-usemin'),
wrap = require('gulp-wrap'),
connect = require('gulp-connect'),
watch = require('gulp-watch'),
minifyCss = require('gulp-cssnano'),
minifyJs = require('gulp-uglify'),
concat = require('gulp-concat'),
less = require('gulp-less'),
rename = require('gulp-rename'),
minifyHTML = require('gulp-htmlmin'),
fs = require('fs'),
server = require('gulp-express'),
forever = require('forever-monitor');
var paths = {
scripts: 'client/js/**/*.*',
styles: 'client/less/**/*.*',
images: 'client/img/**/*.*',
templates: 'client/templates/**/*.html',
index: 'client/index.html',
bower_fonts: 'client/components/**/*.{ttf,woff,eof,svg}',
};
var process = null;
/**
* Handle bower components from index
*/
gulp.task('usemin', function() {
return gulp.src(paths.index)
.pipe(usemin({
js: [minifyJs(), 'concat'],
css: [minifyCss({keepSpecialComments: 0}), 'concat'],
}))
.pipe(gulp.dest('dist/'));
});
/**
* Copy assets
*/
gulp.task('build-assets', ['copy-bower_fonts']);
gulp.task('copy-bower_fonts', function() {
return gulp.src(paths.bower_fonts)
.pipe(rename({
dirname: '/fonts'
}))
.pipe(gulp.dest('dist/lib'));
});
/**
* Handle custom files
*/
gulp.task('build-custom', ['custom-images', 'custom-js', 'custom-less', 'custom-templates']);
gulp.task('custom-images', function() {
return gulp.src(paths.images)
.pipe(gulp.dest('dist/img'));
});
gulp.task('custom-js', function() {
return gulp.src(paths.scripts)
.pipe(minifyJs())
.pipe(concat('dashboard.min.js'))
.pipe(gulp.dest('dist/js'));
});
gulp.task('custom-less', function() {
return gulp.src(paths.styles)
.pipe(less())
.pipe(gulp.dest('dist/css'));
});
gulp.task('custom-templates', function() {
return gulp.src(paths.templates)
.pipe(minifyHTML())
.pipe(gulp.dest('dist/templates'));
});
/**
* Watch custom files
*/
gulp.task('watch', function() {
gulp.watch([paths.images], ['custom-images']);
gulp.watch([paths.styles], ['custom-less']);
gulp.watch([paths.scripts], ['custom-js']);
gulp.watch([paths.templates], ['custom-templates']);
gulp.watch([paths.index], ['usemin']);
});
/**
* Live reload server
*/
gulp.task('webserver', function() {
connect.server({
root: 'dist',
livereload: true,
port: 8888
});
});
gulp.task('run', function () {
server.run(['./bin/www']);
});
gulp.task('forever', function () {
process = new forever.Monitor('./bin/www').start();
});
gulp.task('foreverstop', function () {
if (process) {
process.stop();
} else {
console.log('The process is not up and running now!')
}
});
gulp.task('livereload', function() {
gulp.src(['dist/**/*.*'])
.pipe(watch(['dist/**/*.*']))
.pipe(connect.reload());
});
gulp.task('log', function () {
var dir = './logs';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
});
/**
* Gulp tasks
*/
gulp.task('build', ['usemin', 'build-assets', 'build-custom']);
gulp.task('prod', ['build', 'log', 'run']);
gulp.task('stop', ['foreverstop']);
gulp.task('default', ['build', 'log', 'run', 'watch']);