forked from nette/sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
162 lines (136 loc) · 3.6 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
/* jshint node: true */
'use strict';
var del = require('del');
var g = require('gulp-load-plugins')();
var gulp = require('gulp');
var neat = require('node-neat').includePaths; // http:neat.bourbon.io
var runSequence = require('run-sequence');
var isBuild;
// === Development ===
gulp.task('clean', function(cb) {
return del([
'.sass-cache',
'build/*',
'log/*',
'temp/btfj.dat',
'temp/cache',
'temp/sessions/*',
'www/css/*',
], cb);
});
gulp.task('styles', function() {
var style = (isBuild) ? 'compressed' : 'nested';
var dest = (isBuild) ? 'build/www/css' : 'www/css';
return gulp.src('www/scss/**/*.{sass,scss}')
.pipe(g.sass({
includePaths: ['www/scss'].concat(neat), // add bourbon neat
style: style,
quiet: true
})).on('error', g.util.log)
.pipe(g.autoprefixer())
.pipe(gulp.dest(dest));
});
gulp.task('jshint', function() {
return gulp.src([
'www/js/**/*.js',
'!www/js/netteForms.js',
])
.pipe(g.jshint())
.pipe(g.jshint.reporter('jshint-stylish'));
});
gulp.task('watch', function() {
g.livereload.listen();
// compile handlers
gulp.watch('www/scss/**/*.{sass,scss}', ['compass']);
gulp.watch('www/js/**/*.js', ['jshint']);
// livereload handlers
gulp.watch([
'app/**/*.latte',
'app/config/*.neon',
'app/**/*.php',
'www/css/**/*.css',
'www/js/**/*.js',
]).on('change', g.livereload.changed);
});
// === Build ===
gulp.task('buildImages', function() {
return gulp.src('www/images/**/*.{gif,jpg,jpeg,png,webp}')
.pipe(g.imagemin({
optimizationLevel: 7,
progressive: true,
interlaced: true,
}))
.pipe(gulp.dest('build/www/images'));
});
gulp.task('buildWrapper', function() {
var assets = g.useref.assets({
searchPath: ['build/www', 'www']
});
var app = g.filter('js/app.js');
var wrapper = g.filter('@wrapper.latte');
return gulp.src('app/templates/@wrapper.latte')
.pipe(g.replace(new RegExp('vendor\\/([\\w\\-\\.\\/]+).((js|css))', 'g'), 'vendor/$1.min.$2'))
.pipe(g.replace('{$basePath}/', ''))
.pipe(assets) // concatenate assets defined in HTML build blocks
.pipe(g.rev())
.pipe(assets.restore())
.pipe(g.useref())
.pipe(wrapper)
.pipe(g.rename({
extname: '.html'
}))
.pipe(wrapper.restore())
.pipe(g.revReplace())
.pipe(wrapper)
.pipe(g.rename({
extname: '.latte'
}))
.pipe(g.replace(/(href|src)="(\w)/g, '$1="{$baseUrl}/$2'))
.pipe(wrapper.restore())
.pipe(gulp.dest('build/app/templates'));
});
gulp.task('copyApp', function() {
return gulp.src([
'app/**/*',
'!app/templates/@layout.latte',
'bin/**/*',
'log/.*',
'temp/**/.*',
'vendor/**/*',
'www/*.*',
'www/.*',
], {base: './'})
.pipe(gulp.dest('build'));
});
gulp.task('copyRevedAssets', function() {
return gulp.src([
'build/app/templates/css/*',
'build/app/templates/js/*',
], {base: './build/app/templates'})
.pipe(gulp.dest('build/www'));
});
gulp.task('cleanBuild', function(cb) {
return del([
'build/app/templates/css',
'build/app/templates/js',
], cb);
});
gulp.task('jsMaps', function() {
return gulp.src([
'www/vendor/jquery/dist/jquery.min.map',
])
.pipe(gulp.dest('build/www/js'));
});
// === Main tasks definitions ===
//
gulp.task('build', function() {
isBuild = true;
return runSequence(
'clean',
['buildImages', 'styles', 'copyApp', 'jsMaps'],
'buildWrapper',
'copyRevedAssets',
'cleanBuild'
);
});
gulp.task('default', ['styles', 'jshint', 'watch']);