-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
173 lines (153 loc) · 4.25 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
var gulp = require('gulp'),
args = require('yargs').argv,
autoprefixer = require('gulp-autoprefixer'),
bump = require('gulp-bump'),
imagemin = require('gulp-imagemin'),
livereload = require('gulp-livereload'),
minifyCSS = require('gulp-minify-css'),
mocha = require('gulp-mocha'),
nib = require('nib'),
nodemon = require('gulp-nodemon'),
plumber = require('gulp-plumber'),
rimraf = require('gulp-rimraf'),
runSequence = require('run-sequence'),
shell = require('gulp-shell'),
size = require('gulp-size'),
stylus = require('gulp-stylus'),
git = require('gulp-git'),
pngquant = require('imagemin-pngquant'),
webpack = require('gulp-webpack');
var VERSION;
var paths = {
scriptsFrontend: ['./client/js/**/*.js'],
scripts: [
'./client/js/**/*.js',
'!./client/js/lib/**/*.js',
'!./client/js/bower_components/**/*.js',
'./server/**/*.js'
],
images: './client/img/**/*.{png,jpg,jpeg,gif}',
stylus: ['./client/css/app.styl'],
css: ['./build/css/app.css']
};
gulp.task('clean', function() {
return gulp.src(['./build/js', './build/css', './build/deps.js'], {
read: false
})
.pipe(rimraf({
force: true
}));
});
gulp.task('imagemin', function() {
return gulp.src(paths.images)
.pipe(imagemin({
progressive: true,
use: [pngquant()]
}))
.pipe(gulp.dest('./build/img'));
});
gulp.task('image-copy', function() {
return gulp.src(paths.images)
.pipe(gulp.dest('./build/img'));
});
gulp.task('stylus', function() {
return gulp.src(paths.stylus)
.pipe(plumber())
.pipe(stylus({
errors: true,
use: [nib()],
'include css': true
}))
.pipe(autoprefixer(['> 1%', 'last 2 versions', 'ie 8', 'ie 9']))
.pipe(minifyCSS())
.pipe(size({
showFiles: true
}))
.pipe(size({
showFiles: true,
gzip: true
}))
.pipe(gulp.dest('./build/css'));
});
gulp.task('set-ulimit', shell.task([
'ulimit -n 10240'
]));
gulp.task('test', function() {
return gulp.src('test/**/*.test.js', {
read: false
})
.pipe(mocha({
reporter: 'spec'
}));
});
gulp.task('test-deployed', function() {
return gulp.src('test/**/*.test.js', {
read: false
})
.pipe(mocha({
reporter: 'spec'
}))
.once('end', function() {
process.exit();
});
});
gulp.task('webpack', function() {
return gulp.src('./client/js/main.js')
.pipe(webpack(require("./webpack.config.js")))
.pipe(gulp.dest('./build/js/'));
});
gulp.task('git-commit', function() {
var packageJSON = require('./package.json');
return gulp.src(['./build/*', './package.json', './bower.json'])
.pipe(git.add({
args: '-A'
}))
.pipe(git.commit('Release v' + packageJSON.version));
});
gulp.task('git-push', function() {
return git.push('origin', 'master', function(err) {
if (err) {
throw err;
}
process.exit();
});
});
gulp.task('bump', function() {
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({
type: VERSION
}))
.pipe(gulp.dest('./'));
});
gulp.task('dev', ['stylus', 'test']);
gulp.task('build', function() {
runSequence('clean', 'stylus', 'test', 'webpack', 'imagemin');
});
/**
* gulp release --version major|minor|patch
* gulp release -v major|minor|patch
*/
gulp.task('release', function() {
VERSION = args.v || args.version;
if (typeof VERSION !== 'undefined') {
runSequence('clean', 'stylus', 'test', 'webpack', 'imagemin', 'bump', 'git-commit', 'git-push');
} else {
console.log('SORRY, app --version parameter missing.');
}
});
gulp.task('start-server', function() {
nodemon({
script: 'server/app.js',
exec: 'node',
watch: ['server/**/*.js']
}).on('start');
livereload.listen();
gulp.watch(['client/css/**/*.styl'], ['stylus']);
gulp.watch(['client/js/**/*.js', '!./client/js/bower_components/**/*.js', '!/client/js/build.js'], ['webpack']);
gulp.watch(['test/**/*.js'], ['test']);
gulp.watch(['build/css/app.css', 'build/img/**', 'server/views/**/*.jade']).on('change', livereload.changed);
gulp.watch(['build/js/build-dev.js']).on('change', livereload.reload);
gulp.watch(['client/img/**/*'], ['image-copy']);
});
gulp.task('server', ['dev', 'start-server']);
gulp.task('default', ['set-ulimit', 'dev', 'start-server']);