forked from gesteves/denali
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGulpfile.js
More file actions
60 lines (54 loc) · 1.61 KB
/
Gulpfile.js
File metadata and controls
60 lines (54 loc) · 1.61 KB
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
'use strict';
var cheerio = require('gulp-cheerio');
var gulp = require('gulp');
var rename = require('gulp-rename');
var scsslint = require('gulp-scss-lint');
var scssstylish = require('gulp-scss-lint-stylish');
var svgmin = require('gulp-svgmin');
var replace = require('gulp-replace');
var paths = {
svg: ['app/assets/images/svg/*.svg'],
sass: ['app/assets/stylesheets/**/*.scss', '!app/assets/stylesheets/vendors/*.scss']
};
// Lint Sass
gulp.task('sass', function() {
return gulp.src(paths.sass)
.pipe(scsslint({
config: '.scss-lint.yml',
bundleExec: true,
customReport: scssstylish
}));
});
// Minify and concatenate SVGs
// and save as a Rails partial
gulp.task('svg', function () {
return gulp.src(paths.svg)
.pipe(svgmin())
.pipe(cheerio({
run: function ($) {
$('[style]').removeAttr('style');
$('[fill]').removeAttr('fill');
$('[stroke]').removeAttr('stroke');
},
parserOptions: { xmlMode: true }
}))
.pipe(cheerio({
run: function ($) {
$('svg').attr({
'class': '{{{%= class_name %}}}',
'aria-hidden': '{{{%= aria_hidden %}}}'
});
$('svg').removeAttr('xmlns');
},
parserOptions: { xmlMode: true }
}))
.pipe(replace('{{{', '<'))
.pipe(replace('}}}', '>'))
.pipe(rename({ extname: '.html.erb', prefix: '_' }))
.pipe(gulp.dest('app/views/partials/svg'));
});
gulp.task('watch', function () {
gulp.watch(paths.svg, gulp.series('svg'));
gulp.watch(paths.sass, gulp.series('sass'));
});
gulp.task('default', gulp.series('watch'));