-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
105 lines (90 loc) · 2.55 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
const async = require('async');
const gulp = require('gulp');
const iconfont = require('gulp-iconfont');
const consolidate = require('gulp-consolidate');
const rename = require('gulp-rename');
const runTimestamp = Math.round(Date.now()/1000);
const clean = require('gulp-clean');
const browserSync = require('browser-sync');
const config = require('./config');
const src = './src/';
const dist = './dist/';
const path = {
svgs: src + 'svgs/*.svg',
fonts: dist + 'fonts/',
fontUrl: './fonts/'
};
const transform = (name, path, types) =>
types.reduce((obj, type) => {
obj[type] = `${path}${name}.${type}`
return obj
}, {});
const fontName = config.fontName;
const className = config.className;
const inputName = config.inputName;
const outputName = config.outputName;
const fileTypes = ['css', 'html', 'json'];
const inputs = transform(inputName, src, fileTypes);
const outputs = transform(outputName, '', fileTypes);
gulp.task('iconfont', function (done) {
const iconStream = gulp.src(path.svgs)
.pipe(iconfont({
fontName: fontName,
prependUnicode: true,
formats: ['ttf', 'woff', 'woff2'],
timestamp: runTimestamp,
normalize: true,
fontHeight: 1000,
startUnicode: 0xE000
}));
async.parallel([
function handleGlyphs (cb) {
iconStream.on('glyphs', function (glyphs) {
var options = {
glyphs: glyphs,
fontName: fontName,
outputName: outputName,
fontPath: path.fontUrl,
className: className,
};
gulp.src(inputs.css)
.pipe(consolidate('lodash', options))
.pipe(rename(outputs.css))
.pipe(gulp.dest(dist));
gulp.src(inputs.html)
.pipe(consolidate('lodash', options))
.pipe(rename(outputs.html))
.pipe(gulp.dest(dist));
gulp.src(inputs.json)
.pipe(consolidate('lodash', options))
.pipe(rename(outputs.json))
.pipe(gulp.dest(dist))
.on('finish', cb);
});
},
function handleFonts (cb) {
iconStream
.pipe(gulp.dest(path.fonts))
.on('finish', cb);
}
], done);
});
gulp.task('clean', function (cb) {
gulp.src(dist)
.pipe(clean({ force: true }));
cb();
});
gulp.task('server', ['iconfont'], function () {
browserSync.init({
server: {
baseDir: dist,
index: outputName + '.html'
}
});
gulp.watch('src/**/*.svg', {
interval: 500
},
['iconfont', browserSync.reload]);
});
gulp.task('dev', ['clean', 'iconfont', 'server']);
gulp.task('build', ['clean', 'iconfont']);