-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
164 lines (152 loc) · 4.47 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
// gulp
var gulp = require('gulp'),
// plugins
connect = require('gulp-connect'),
jshint = require('gulp-jshint'),
jscs = require('gulp-jscs'),
notify = require('gulp-notify'),
uglify = require('gulp-uglify'),
minifyCSS = require('gulp-minify-css'),
minifyHTML = require('gulp-minify-html'),
clean = require('gulp-clean'),
browserify = require('gulp-browserify'),
usemin = require('gulp-usemin'),
concat = require('gulp-concat'),
rev = require('gulp-rev'),
gulpif = require('gulp-if'),
livereload = require('gulp-livereload'),
watch = require('gulp-watch'),
git = require('gulp-git');
// tasks
gulp.task('lint', function() {
gulp.src(['./app/**/*.js', '!./app/bower_components/**'])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(notify({
title: 'Lint',
message: 'Lint Passed. All up to standards!'
}));
});
// Style Task
gulp.task('jscs', function() {
gulp.src(['app/js/**/*.js', '!./app/bower_components/**'])
.pipe(jscs())
.pipe(notify({
title: 'JSCS',
message: 'JSCS Passed. All up to standards!'
}));
});
// cleans the distribution folder
gulp.task('clean', function(cb) {
gulp.src('./dist/*')
.pipe(clean({force: true})).on('error', errorHandler);
cb()
});
// cleans the build folder
gulp.task('clean-build', function() {
gulp.src('./build/*')
.pipe(clean({force: true}));
});
// TODO leave task for now
gulp.task('minify-css', function() {
var opts = {comments: true, spare: true};
gulp.src(['./app/**/*.css', '!./app/bower_components/**'])
.pipe(minifyCSS(opts))
.pipe(gulp.dest('./dist/'))
});
//
gulp.task('copy-partial-html-files', ['usemin'], function(cb) {
gulp.src('./app/**/partials/*.html')
.pipe(gulp.dest('dist/'));
cb()
});
// browserify
gulp.task('browserify', function() {
gulp.src(['app/js/main.js'])
.pipe(browserify({
insertGlobals: true,
debug: true
}))
.pipe(concat('bundled.js'))
.pipe(gulp.dest('./app/js'))
});
/**
* CONNECTION
*/
gulp.task('connect', function() {
connect.server({
root: 'app/',
port: 8888,
livereload: true
});
});
gulp.task('connectDist', function() {
connect.server({
root: 'dist/',
port: 8001,
livereload: true
});
});
// need to add {maxListeners: 999},
gulp.task('usemin', ['clean'], function(cb) {
var condition = 'app.js';
return gulp.src('./app/**/*.html')
.pipe(usemin({
css: [minifyCSS()],
html: [minifyHTML({empty: true})]
}))
.pipe(gulpif(condition, uglify()))
.pipe(gulp.dest('dist/'));
cb()
});
// testing uglify
gulp.task('compress', function() {
gulp.src('app/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('test'))
});
// Create a new git branch
// Uses the default name as: dev-{YYMMDD}
gulp.task('branch', function() {
var today = new Date(),
month = String((today.getMonth() + 1 >= 10) ? (today.getMonth() + 1) : ('0' + String(today.getMonth() + 1))),
date = String((today.getDate() >= 10) ? (today.getDate()) : ('0' + (today.getDate()))),
year = String(today.getFullYear()),
shortYear = year.substr(year.length - 2, 2),
dateString = shortYear + month + date,
// branchName = 'dev-' + dateString,
branchName = dateString;
git.checkout(branchName, {args: '-b'}, function(err) {
if (err) {
throw err;
} else {
console.log('Git branch - ', branchName, ' created.');
}
});
});
// Watch Files For Changes
// Note use the maxListeners to avoid error - `possible EventEmitter memory leak detected`
gulp.task('watch', function() {
gulp.watch('app/js/**/*.js', {maxListeners: 999}, ['lint', 'jscs', 'build']);
});
// necessary to create a pipe to launch the relaod
gulp.task('watch-build', function() {
watch('dist/').pipe(connect.reload()).pipe(notify({
title: 'Reloaded',
message: '`Connect` Server has been reloaded!'
}));
});
// default task
gulp.task('default',
['lint', 'jscs', 'connect', 'watch', 'watch-build']
);
// build task
// TODO a bit hackey need a better way of moving the partials
gulp.task('build',
['clean', 'usemin', 'copy-partial-html-files']
);
// Handle errors
function errorHandler(error) {
console.log(error.toString());
this.emit('end');
}