-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
75 lines (69 loc) · 2.27 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
var gulp = require('gulp'),
consolidate = require('gulp-consolidate'),
iconfont = require('gulp-iconfont'),
rename = require('gulp-rename'),
del = require('del'),
runSequence = require('run-sequence'),
iconConfig = require('./icons.json');
gulp.task('generate', function () {
return gulp.src('tmp/*.svg')
.pipe(iconfont({
fontName: iconConfig['font-name'],
formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'],
appendCodepoints: true,
appendUnicode: false,
normalize: true,
fontHeight: 1000,
descent: 170,
centerHorizontally: true
}))
.on('glyphs', function (glyphs, options) {
gulp.src('template/iconfont.css')
.pipe(consolidate('underscore', {
glyphs: glyphs,
className: iconConfig['class-name'],
fontName: options.fontName,
fontVersion: iconConfig['version'],
fontDate: new Date().getTime()
}))
.pipe(rename(options.fontName + '.css'))
.pipe(gulp.dest('dist'));
gulp.src('template/index.html')
.pipe(consolidate('underscore', {
glyphs: glyphs,
className: iconConfig['class-name'],
fontName: options.fontName
}))
.pipe(gulp.dest('dist'));
})
.pipe(gulp.dest('dist'));
});
gulp.task('clean-dist', function () {
return del(['dist']);
})
gulp.task('clean-tmp', function () {
return del(['tmp']);
})
gulp.task('copy', function () {
let total = iconConfig.icons.length;
return new Promise(function (resolve, reject) {
iconConfig.icons.forEach(function (icon) {
gulp.src(icon.svg)
.pipe(rename(icon.name + '.svg'))
.pipe(gulp.dest('./tmp'))
.on('end', function () {
if (--total == 0) {
reject();
}
})
.on('error', reject);
});
});
});
gulp.task('default', function () {
return runSequence(
['clean-dist', 'copy'],
'generate',
'clean-tmp'
);
})