-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
416 lines (366 loc) · 10.9 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
// Gulpfile
// ========
// Setup the CSS Compiler (rubysass / libsass)
var cssCompiler = 'rubysass';
var sassLoadPath = ['src/sass/'];
// Load Pathes
var sassSrc = [
'src/sass/**/*.scss',
'src/sass/**/*.sass'
];
// Setup what for JS Files you want to only copy it into dist/,
// and what for js files need to combined into scripts.js.
var sources = {
copyjs: [
{src:'src/stash/bower/conditionizr/dist/conditionizr.js'},
{src:'src/stash/bower/selectivizr/selectivizr.js'},
{src:'src/stash/bower/media-match/media.match.js'},
{src:'src/stash/bower/eq.js/build/eq.js'}
],
combinejs: [
'src/stash/bower/jquery/jquery.js'
]
};
// Place any font files into src/stash/fonts/ -
// the files would be copied to the dist directory
var fonts = {
files: [
{src: ''}
]
};
// DO NOT MODIFY BELOW THIS LINE ! ===============================================
// Config File
var pkg = require('./package.json');
var config = {
gitURL: pkg.repository.url,
gitBranch: 'master',
gitVersion: pkg.version
};
// Directory Routing
var targetDirBase = pkg.directory.base;
var targetDirCSS = pkg.directory.css;
var targetDirJS = pkg.directory.js;
var targetDirMarkup = pkg.directory.markup;
var targetDirCSSImg = pkg.directory.cssimg;
var targetDirHTMLImg = pkg.directory.htmlimg;
// Define the Header for the Files
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
// Define the Base Static Files and the Target
var build = {
files: [
{src:'src/stash/.system/.htaccess' , dest: ''},
{src:'src/stash/.system/404.html' , dest: ''},
{src:'src/stash/.system/robots.txt' , dest: ''},
{src:'src/stash/.system/favicon.png', dest: 'assets/img/system/'},
{src:'src/stash/.system/spinner.gif', dest: 'assets/img/system/'}
]
};
// Init grunt
var gulp = require('gulp');
require('gulp-grunt')(gulp);
// Init Gulp-Grunt
var gulp_grunt = require('gulp-grunt');
var tasks = gulp_grunt.tasks({
base: null,
prefix: 'grunt-',
verbose: false
});
// Set the Task Variables
var path = require('path'),
jade = require('gulp-jade'),
prettify = require('gulp-prettify'),
rubysass = require('gulp-ruby-sass'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
minifyCSS = require('gulp-minify-css'),
imagemin = require('gulp-imagemin'),
prefix = require('gulp-autoprefixer'),
plumber = require('gulp-plumber'),
header = require('gulp-header'),
notify = require('gulp-notify'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
bump = require('gulp-bump'),
changed = require('gulp-changed');
// --- Task Config --------------
// Ruby SASS
// TODO: Gulp Notify will not work right
gulp.task('rubysass', function () {
gulp.src(sassSrc)
.pipe(plumber())
.pipe(rubysass({
sourcemap : false,
style : 'nested',
precision : 6
}))
.on("error", notify.onError(function (error) {
return "SASS Compile Error: " + error.message;
}))
.pipe(prefix("last 2 version", "> 1%", "ie 9", "chrome 30", "firefox 24"))
.pipe(gulp.dest(targetDirCSS));
});
// Jade Compile Task only the Components
gulp.task('jade', function(){
gulp.src(['src/jade/*.jade','!src/jade/_*.jade'])
.pipe(changed(targetDirMarkup, { extension: '.html' }))
.pipe(plumber())
.pipe(jade({
pretty: true,
locals: {
siteTitle: pkg.name
}
}))
.on("error", notify.onError(function (error) {
return "JADE Compile Error!!";
}))
.on('error', function(err) {
console.log(err);
})
.pipe(prettify({
'indent_size': 2
}))
.pipe(gulp.dest(targetDirMarkup));
});
// Jade Compile Task for rebuilding all Files
gulp.task('jade-rebuild', function(){
gulp.src(['src/jade/*.jade','!src/jade/_*.jade'])
.pipe(plumber())
.pipe(jade({
pretty: true,
locals: {
siteTitle: pkg.name
}
}))
.on("error", notify.onError(function (error) {
return "JADE Compile Error!!";
}))
.on('error', function(err) {
console.log(err);
})
.pipe(prettify({
'indent_size': 2
}))
.pipe(gulp.dest(targetDirMarkup))
.pipe(notify({message: 'Jade Files rebuilded'}));
});
// Jade Compile Task only the Components
gulp.task('jade-components', function(){
gulp.src(['src/jade/components/*.jade', 'src/jade/templatepart/*.jade'])
.pipe(plumber())
.pipe(jade({
pretty: true,
locals: {
siteTitle: pkg.name
}
}))
.on("error", notify.onError(function (error) {
return "JADE Compile Error!!";
}))
.on('error', function(err) {
console.log(err);
})
.pipe(prettify({
collapseWhitespace: true,
'indent_size': 2
}))
.pipe(gulp.dest(targetDirMarkup + 'components/'))
.pipe(notify({message: 'Jade Components generated'}));
});
// Check written JS and move it into tmp
gulp.task('build-js', function() {
gulp.src(['src/js/*.js','!src/js/_*.js'])
.pipe(changed(targetDirJS, { extension: '.js' }))
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(gulp.dest(targetDirJS));
});
// Browser Sync Task
gulp.task('browser-sync', function() {
browserSync.init([
targetDirCSS +'**/*.css',
targetDirBase + '**/*.{html,php}',
targetDirCSSImg + '**/*.{jpg,gif,png,svg}',
targetDirJS + '**/*.js'],
{ options: {
debugInfo: true,
watchTask: true,
// proxy: 'domain',
ghostMode: {
clicks : true,
scroll : true,
links : true,
forms : true }
},
server: {
baseDir : 'dist/'
},
open: true
});
});
// --- Copy Tasks --------------
// Copy Bower Files to 'dist/assets/javascripts/'.
// Its a temporaly directory, the final JS files comes
// later in the 'js' directory
gulp.task('move-js', function () {
sources.copyjs.forEach(function(item) {
gulp.src(item.src)
.pipe(gulp.dest(targetDirJS));
});
});
// Copy the Default Build Files to 'tmp'
gulp.task('move-first', function () {
build.files.forEach(function(item) {
gulp.src(item.src)
.pipe(gulp.dest(targetDirBase + item.dest));
});
});
// Copy Image to the HTML Directory
gulp.task('move-images', function () {
gulp.src(['src/stash/images/html-images/html-assets/**'])
.pipe(changed(targetDirHTMLImg))
.pipe(gulp.dest(targetDirHTMLImg));
});
// Combine Scripts from Browser to script.js
gulp.task('combine-js', function() {
gulp.src(sources.combinejs)
.pipe(concat('scripts.js'))
.pipe(gulp.dest(targetDirJS));
});
// Code Quality
gulp.task('js-quality', function() {
gulp.src([targetDirJS + '*.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
// ---- PUBLISHING TASKS ----------------
// Compress CSS included Images and move it from tmp to dist
gulp.task('compress-css-images', function () {
gulp.src([
targetDirCSSImg + '**',
'!' + targetDirCSSImg + 'sprite_2x/',
'!' + targetDirCSSImg + 'sprite/',
])
.pipe(changed(targetDirCSSImg))
.pipe(imagemin({
optimizationLevel: 5,
pngquant: false,
progressive: true
}))
.pipe(gulp.dest(targetDirCSSImg));
});
// Compress HTML included images and move it from tmp to dist
gulp.task('compress-html-images', function () {
gulp.src([targetDirHTMLImg + '**'])
.pipe(changed(targetDirHTMLImg))
.pipe(imagemin({
optimizationLevel: 6,
pngquant: false
}))
.pipe(gulp.dest(targetDirHTMLImg));
});
// Comress all JS Files
gulp.task('compress-js', function() {
gulp.src([targetDirJS + '*.js'])
.pipe(uglify())
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest(targetDirJS));
});
// Minify CSS and copy it to dist/
gulp.task('minify-css', function() {
gulp.src(targetDirCSS + '*.css')
.pipe(minifyCSS({
keepSpecialComments: true,
keepBreaks: true,
removeEmpty: true,
debug: true
}))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest(targetDirCSS));
});
// ---- Version Bumper ---------------
// Update bower, component, npm at once:
gulp.task('bump', function(){
gulp.src(['bower.json', 'package.json'])
.pipe(bump({type:'patch'}))
.pipe(gulp.dest('./'));
});
gulp.task('bump-minor', function(){
gulp.src(['bower.json', 'package.json'])
.pipe(bump({type:'minor'}))
.pipe(gulp.dest('./'));
});
gulp.task('bump-major', function(){
gulp.src(['bower.json', 'package.json'])
.pipe(bump({type:'major'}))
.pipe(gulp.dest('./'));
});
// MAIN TASK BLOCK ------------------------------------------------------
// Starting Task for the first Build off the Project Structure
gulp.task('init', [
'grunt-modernizr-build',
'move-first',
'move-js',
'move-images',
'grunt-build-images',
cssCompiler,
'jade',
'build-js',
'combine-js'
]);
gulp.task('rebuild-js', [
'grunt-modernizr-build',
'move-js',
'build-js',
'combine-js'
]);
// Default Task - start the Watch Tasks for SASS,
// JADE, JS and activate the Browser Watch
gulp.task('watch-bin', function() {
// Watch the SCSS Folder for changes - compile CSS
gulp.watch(['src/sass/**/*.scss','src/sass/**/*.sass'], [cssCompiler]);
// Watch the JADE Folder for changes - compile HTML
gulp.watch(['src/jade/**/*.jade', 'src/markdown/**/*.md'], ['jade']);
// Watch the JS SRC Folder for Changes - Lint JS and copy it to tmp
gulp.watch('src/js/**/*.js', ['build-js']);
});
gulp.task('watch-images', function() {
// Watch SVGOnly Folder for changes - minify SVG and move it into tmp
gulp.watch('src/stash/images/css-images/svgonly/*.svg', ['grunt-minify-svg']);
// Watch SVG Folder for changes - build PNG Fallback and write the Imagemap
gulp.watch('src/stash/images/css-images/svg/*.svg', ['grunt-build-svg']);
// Watch the Single/Texture Folder - modify the Imagemap and move the Images to tmp folder
gulp.watch(
[
'src/stash/images/css-images/single-assets/*.{jpg,gif,png}',
'src/stash/images/css-images/texture-assets/*.{jpg,gif,png}'
],
['grunt-copy-images']
);
// Watch for Sprite Changes - modify the Spritemap and move the images (renamed) to tmp
gulp.watch('src/stash/images/css-images/sprite-assets/*.png', ['grunt-build-sprite']);
});
// Default gulp Task 'gulp' - watch the Binarys Directory, start the compile and browser-sync
gulp.task('default', ['browser-sync', 'watch-bin']);
// The Extended Watch Task - it watch additional image dirs
gulp.task('extended', ['browser-sync', 'watch-bin', 'watch-images']);
// Testing code quality
gulp.task('code-quality', [
'js-quality'
]);
// Publish Task
gulp.task('publish',[
'bump',
'minify-css',
'compress-js',
'compress-css-images',
'compress-html-images',
'grunt-documentation'
]);