-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
83 lines (74 loc) · 2.58 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
var _ = require('underscore');
var fs = require('fs-extra');
var gulp = require('gulp');
var del = require('del');
var consolidate = require('gulp-consolidate');
var sass = require('gulp-dart-sass');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
// task to remove images and fonts to clean directories
gulp.task('clean-assets', function () {
return del([
'./public/img/*',
'./public/fonts/*'
]);
});
// get the latest images and fonts
gulp.task('copy-images', function() {
return gulp.src(['./node_modules/fec-cms/fec/fec/static/img/**/*'])
.pipe(gulp.dest('./public/img'));
});
gulp.task('copy-fonts', function() {
return gulp.src(['./node_modules/fec-cms/fec/fec/static/fonts/*'])
.pipe(gulp.dest('./public/fonts'));
});
// build stylesheet of classes for all icons
gulp.task('build-icon-classes', function() {
// get the list of icons from fec-cms
function getIconNames() {
return _(fs.readdirSync('./node_modules/fec-cms/fec/fec/static/icons/output/'))
.chain()
.filter(function (filename) {
return filename.slice(-4) === '.svg';
}).map(function (filename) {
return {
name: filename.split('.')[0],
};
}).value();
}
// generate css classes for icons from getIconNames list from icon-template.scss template
return gulp.src('./static/templates/icon-classes.scss')
.pipe(consolidate('underscore', {
icons: getIconNames()
}))
.pipe(rename({basename: '_icon-classes'}))
.pipe(gulp.dest('./static/scss'));
});
// build custom icons stylesheet, refresh images and fonts, and then build our complete stylesheet
gulp.task('build-sass', gulp.series(['build-icon-classes', 'clean-assets', 'copy-images', 'copy-fonts'], function() {
return gulp.src('./static/scss/styles.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS())
.pipe(rename('styles.css'))
.pipe(gulp.dest('./public/css'));
}));
// generate HTML template for icons documentation component
gulp.task('build-icons-component', function() {
function getIconNames() {
return _(fs.readdirSync('./node_modules/fec-cms/fec/fec/static/icons/output/'))
.chain()
.filter(function (filename) {
return filename.slice(-4) === '.svg';
}).map(function (filename) {
return {
name: filename.split('.')[0],
};
}).value();
}
return gulp.src('./static/templates/icons-component.html')
.pipe(consolidate('underscore', {
icons: getIconNames()
}))
.pipe(rename({basename: '_icons'}))
.pipe(gulp.dest('./components/01-basics/'));
});