-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
138 lines (113 loc) · 3.21 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
var gulp = require('gulp');
var async = require('async');
var base64 = require('gulp-base64');
var consolidate = require('gulp-consolidate');
var del = require('del');
var fs = require('fs');
var iconfont = require('gulp-iconfont');
var path = require('path');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
// Methods
function getFolders(dir) {
return fs.readdirSync(dir)
.filter(function(file) {
return fs.statSync(path.join(dir, file)).isDirectory();
});
}
// Clean
gulp.task('clean', function(fn) {
return del(['dist/**/*'], fn);
});
gulp.task('clean-woff', function(fn) {
return del(['dist/**/*.woff'], fn);
});
// Font Icon Building
gulp.task('font-icon', function(fn) {
var directories= getFolders('src');
directories.forEach(function(dir, index) {
var iconName = dir;
var srcPath = path.join('src', dir, '*.svg');
var destPath = path.join('dist', dir);
var iconStream = gulp.src(srcPath)
.pipe(iconfont({
fontHeight: 1200,
fontName: iconName,
formats: ['ttf', 'woff', 'eot'],
prependUnicode: true,
normalize: true
}));
async.parallel([
function handleGlyphs (cb) {
// HTML + MD
iconStream.on('glyphs', function(glyphs, options) {
// SCSS
gulp.src('templates/_icons.scss')
.pipe(consolidate('lodash', {
glyphs: glyphs,
fontName: iconName,
fontDir: dir,
cssClass: 'icon'
}))
.pipe(gulp.dest(destPath));
// CSS
gulp.src('templates/icons.css')
.pipe(consolidate('lodash', {
glyphs: glyphs,
fontName: iconName,
fontDir: dir,
cssClass: 'icon'
}))
.pipe(gulp.dest(destPath));
// HTML
gulp.src('templates/preview.html')
.pipe(consolidate('lodash', {
glyphs: glyphs,
fontName: iconName
}))
.pipe(gulp.dest(destPath));
// MD
gulp.src('templates/icons.md')
.pipe(consolidate('lodash', {
glyphs: glyphs
}))
.pipe(gulp.dest(destPath));
});
},
function handleFonts(cb) {
iconStream
.pipe(gulp.dest(destPath + '/fonts'))
.on('end', function() {
// Base64 font injection
var _destPath = destPath + '/';
generateBase64(_destPath, '*.css');
generateBase64(_destPath, '*.scss');
gulp.start('clean-woff');
});
}
]);
});
});
// Generate Base64
var generateBase64 = function(path, file) {
if(!path || !file) {
return false;
}
return gulp.src(path + file)
.pipe(base64({
extensions: ['ttf', 'woff', 'eot'],
maxImageSize: 500000
}))
.pipe(gulp.dest(path));
};
// Watch
gulp.task('watch', function() {
gulp.watch(['src/**/*.svg'],
['generate-font']);
});
// Build tasks
gulp.task('generate-font', function(fn) {
runSequence('clean', 'font-icon', fn);
});
// Tasks
gulp.task('default', ['generate-font']);