forked from exodus4d/pathfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
198 lines (164 loc) · 4.41 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* GULP itself */
var gulp = require('gulp-param')(require('gulp'), process.argv);
var jshint = require('gulp-jshint');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var gulpif = require('gulp-if');
var clean = require('gulp-clean');
var runSequence = require('run-sequence');
var exec = require('child_process').exec;
var path = require('path');
var stylish = require('jshint-stylish');
/*******************************************/
// Source and destination file paths
var _src = {
GULP: './gulpfile.js',
ICON: './public/img/notifications/logo.png',
JS_SRC: './js/**/*',
JS_LIBS: './js/lib/**/*',
JS_BUILD: './build_js',
JS_DIST: './public/js',
PACKAGE: './package.json'
};
// Gulp plumber error handler
var onError = function(err) {
console.log(err);
};
/*******************************************/
// Build Configuration
var isProductionBuild = false;
/**
* Version nr (e.g. v0.0.4)
* required for "production" task
* @type {null}
*/
var tagVersion = null;
/**
* RequireJS build task using the r.js optimizer.
*/
gulp.task('requirejs', ['jshint'], function() {
var rjsPath = path.resolve(__dirname, './node_modules/requirejs/bin/r.js');
var oPath = path.resolve(__dirname, './build.js');
exec('node ' + rjsPath + ' -o ' + oPath, function(error, stdout, stderr) {
var success = true;
console.log('[RequireJS]', stderr);
if (error !== null) {
console.log('[RequireJS]', error);
success = false;
}
runSequence(
'copyBuildFiles',
'removeBuildFiles'
);
});
});
/*******************************************/
/**
* JSHint JavaScript and JSON
* see .jshintrc for configuration
* http://jshint.com/docs/
* http://jshint.com/docs/options/
*/
gulp.task('jshint', function(){
return gulp.src([
_src.JS_SRC,
'!' + _src.JS_LIBS
])
.pipe(plumber({
errorHandler: onError
}))
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(notify({
icon: path.resolve(__dirname, _src.ICON),
title: 'JSHint',
message: 'Task complete',
onLast: true
}));
// .pipe(jshint.reporter('fail')); // uncomment this line to stop build on error
});
/**
* Copy optimized/uglyfied js files from "js_build" folder to "public/js/x.x.x/*" folder
* for release deployment (cache busting)
*/
gulp.task('copyBuildFiles', ['removeDistFiles'], function () {
// raw files
var source = _src.JS_SRC;
if(isProductionBuild){
// build files
source = _src.JS_BUILD + '/**/*';
}
return gulp
.src( source )
.pipe(
gulpif(
tagVersion !== null,
gulp.dest( _src.JS_DIST + '/' + tagVersion )
)
).pipe(notify({
icon: path.resolve(__dirname, _src.ICON),
title: 'Copy JS to dist',
message: 'Task complete',
onLast: true
}));
});
/**
* task removes temp build js files
*/
gulp.task('removeBuildFiles', function () {
'use strict';
return gulp.src( _src.JS_BUILD ).pipe( clean( _src.JS_BUILD ) );
});
/**
* task removes "dist" js files
*/
gulp.task('removeDistFiles', function () {
'use strict';
var dist = _src.JS_DIST + '/' + tagVersion;
return gulp.src(dist).pipe( clean(dist) );
});
/*******************************************/
// Watch
// execute only during continuous development!
gulp.task('watch', function(tag) {
if(tag){
tagVersion = tag;
}
gulp.watch([
_src.JS_SRC,
'!' + _src.JS_LIBS,
], ['jshint', 'copyBuildFiles']);
});
/*******************************************/
// Default Tasks
/**
* Production task for deployment.
* Triggered by Maven Plugin.
* $ gulp production --tag v0.0.9
* WARNING: DO NOT REMOVE THIS TASK!!!
*/
gulp.task('production', function(tag) {
if(tag !== null){
tagVersion = tag;
isProductionBuild = true;
// use run-sequence until gulp v4.0 is released
runSequence(
'requirejs'
);
}
});
/**
* Default task for continuous development.
* $ gulp default --tag v0.0.9
* WARNING: DO NOT REMOVE THIS TASK!!!
*/
gulp.task('default', function(tag) {
if(tag){
tagVersion = tag;
}
runSequence(
'jshint',
'copyBuildFiles',
'watch'
);
});