This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
294 lines (256 loc) · 8.08 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
var gulp = require('gulp'),
sketch = require('gulp-sketch'),
fm = require('front-matter'),
data = require('gulp-data'),
jade = require('gulp-jade'),
libsass = require('gulp-sass'),
minifycss= require('gulp-minify-css'),
notify = require('gulp-notify'),
newer = require('gulp-newer'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
path = require('path'),
bower = require('gulp-bower'),
preen = require('preen'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
del = require('del'),
iconfont = require('gulp-iconfont'),
rename = require('gulp-rename'),
consolidate = require('gulp-consolidate'),
sourcemaps = require('gulp-sourcemaps'),
cache = require('gulp-cached'),
jadeAffected = require('gulp-jade-find-affected'),
postcss = require('gulp-postcss'),
minimist = require('minimist'),
mqpacker = require('css-mqpacker'),
prefix = require('autoprefixer-core'),
pixrem = require('gulp-pixrem');
var paths = {
templates: './src/jade/',
sass: './src/css/',
sketch: './src/sketch/',
images: './src/images/**/*',
scripts: './src/js/'
};
// ******************************
// CLI argumenten
// ******************************
var knownOptions = {
string: 'env',
default: { env: 'development' }
};
var options = minimist(process.argv.slice(2), knownOptions);
// ******************************
// Dist map leegmaken
// ******************************
gulp.task('clean', function(cb) {
// You can use multiple globbing patterns as you would with `gulp.src`
del(['dist'], cb);
});
// ******************************
// Bower componenten installeren
// ******************************
gulp.task('bower', function() {
return bower()
});
gulp.task('preen', ['bower'], function(cb) {
preen.preen({}, cb);
});
// ******************************
// Custom Javascripts
// ******************************
gulp.task('scripts', function() {
return gulp.src(path.join(paths.scripts, '**/*.js'))
.pipe(sourcemaps.init())
.pipe(concat('scripts.min.js'))
.pipe(uglify())
.on('error', function(error) {
console.log(error);
this.emit('end');
})
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/js'))
.pipe(notify({ title: 'Gulp: scripts updated', message: '<%= file.relative %>' }));
});
// ******************************
// Jade (HTML) templates
// ******************************
gulp.task('jade', function() {
return gulp.src('./src/jade/**/*.jade')
// Front matter
.pipe(data(function(file) {
var content = fm(String(file.contents));
file.contents = new Buffer(content.body);
return content.attributes;
}))
.on('error', function(error) {
console.log(error);
this.emit('end');
})
// Parse jade
.pipe(jade({
pretty: true,
basedir: paths.templates
}))
.on('error', function(error) {
console.log(error);
this.emit('end');
})
// Output
.pipe(gulp.dest('./dist/'))
.pipe(reload({stream:true}))
.pipe(notify({ title: 'Gulp: Jade compiled', message: '<%= file.relative %>' }));
});
// ******************************
// Statische plaatjes
// ******************************
gulp.task('images', function() {
return gulp.src(paths.images)
// Pass in options to the task
.pipe(cache('images'))
.pipe(newer('./dist/images/'))
.pipe(gulp.dest('./dist/images/'))
.pipe(reload({stream:true}));
});
// ******************************
// Sass (SCSS)
// ******************************
gulp.task('sass', function() {
var stream = gulp.src(path.join(paths.sass, '**/*.scss'));
if (options.env !== 'production') {
stream = stream.pipe(sourcemaps.init());
}
stream = stream.pipe(libsass({includePaths: require('node-bourbon').with('./node_modules/susy/sass/'),
errLogToConsole: true,
outputStyle: 'nested',
sourceComments: false
}))
.on('error', function(error) {
// Would like to catch the error here
console.log(error);
this.emit('end');
});
if (options.env !== 'production') {
stream = stream.pipe(postcss([prefix]))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/css/'));
}
else {
stream = stream.pipe(postcss([prefix, mqpacker]))
.pipe(minifycss())
.pipe(gulp.dest('./dist/css/'))
.pipe(pixrem())
.pipe(rename({suffix: ".old"}))
.pipe(gulp.dest('./dist/css/'));
}
return stream.pipe(reload({stream:true}))
.pipe(notify({ title: 'Gulp: Sass compiled', message: '<%= file.relative %> <%= options.env %>' }));
});
// ******************************
// Lokale webserver
// ******************************
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: './dist/'
}
});
});
// ******************************
// Sketch
// ******************************
// Install http://bohemiancoding.com/sketch/tool/
// sketchtool export slices ./src/sketch/design.sketch --output=./dist/images
gulp.task('sketch', function(){
return gulp.src(path.join(paths.sketch, '*.sketch'))
.pipe(sketch({
export: 'slices',
clean: true
}))
.pipe(gulp.dest('./dist/images/'));
});
// ******************************
// Icon font
// ******************************
gulp.task('icon-font', function(){
var template = 'sass-style';
return gulp.src('./dist/images/icons/*.svg')
.pipe(iconfont({ fontName: 'icons' }))
.on('codepoints', function(codepoints) {
var options = {
glyphs: codepoints,
fontName: 'icons',
fontPath: '/fonts/', // set path to font (from your CSS file if relative)
className: 'icon' // set class name in your CSS
};
gulp.src('./src/sketch/iconfont-templates/' + template + '.scss')
.pipe(consolidate('lodash', options))
.pipe(rename({ basename: '_icons' }))
.pipe(gulp.dest('./src/css/base/'))
.on('error', function(error) {
console.log(error);
this.emit('end');
})
gulp.src('./src/sketch/iconfont-templates/partial.jade')
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:'icons' }))
.pipe(gulp.dest('./src/jade/partials/'))
.on('error', function(error) {
console.log(error);
this.emit('end');
})
gulp.src('./src/sketch/iconfont-templates/' + template + '.html')
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:'index' }))
.pipe(gulp.dest('./dist/fonts/'))
.on('error', function(error) {
console.log(error);
this.emit('end');
})
})
.on('error', function(error) {
console.log(error);
this.emit('end');
})
.pipe(gulp.dest('./dist/fonts/'));
});
// ******************************
// Default Gulp Task
// ******************************
gulp.task('default', ['scripts',
'jade',
'sass',
'browser-sync',
'images'], function() {
// Watchers
gulp.watch('./src/jade/**/*.jade', ['jade']);
gulp.watch(path.join(paths.sass, '**/*.scss'), ['sass']);
gulp.watch(path.join(paths.scripts, '**/*.js'), ['scripts']);
gulp.watch(paths.images, ['images']);
});
// ******************************
// Export sketch Gulp Task
// ******************************
gulp.task('export-sketch', ['sketch',
'icon-font'], function() {
});
// ******************************
// Install components task
// ******************************
gulp.task('install', ['bower',
'preen'], function() {
});
// ******************************
// CSS Lint task
// ******************************
var csslint = require('gulp-csslint');
gulp.task('css', function() {
/*csslint adjoining-classes:false */
gulp.src('dist/css/*.css')
.pipe(csslint({
'adjoining-classes': false,
'box-sizing': false
}))
.pipe(csslint.reporter());
});