forked from rsuite/rsuite-icon-font
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
138 lines (127 loc) · 3.36 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
const fs = require('fs');
const gulp = require('gulp');
const iconfont = require('gulp-iconfont');
const consolidate = require('gulp-consolidate');
const { fontName, className, svgSrc, lessClassNamePrev } = JSON.parse(
fs.readFileSync(__dirname + '/package.json', 'utf8')
).CONFIG;
const { mtime } = fs.statSync('./package.json');
// Use package.json edit time as timestamp;
const timestamp = +mtime;
const rename = require('gulp-rename');
const generateComponents = require('./generateReactComponent');
/**
* This is needed for mapping glyphs and codepoints.
*/
function mapGlyphs(glyph) {
return {
name: glyph.name,
codepoint: glyph.unicode[0].charCodeAt(0),
};
}
function defaultTask() {
return gulp
.src(svgSrc)
.pipe(
iconfont({
fontName, // required
prependUnicode: true, // recommended option
formats: ['ttf', 'eot', 'woff', 'svg'],
timestamp, // recommended to get consistent builds when watching files
descent: 143, // The same to font-awesome?v4.7.0
fontHeight: 1000,
normalize: true,
})
)
.on('glyphs', function (glyphs) {
const options = {
className,
lessClassNamePrev,
fontName,
fontPath: 'fonts/', // set path to font (from your CSS file if relative)
glyphs: glyphs
.sort((a, b) => {
return a.name.localeCompare(b.name);
})
.map(mapGlyphs),
};
gulp
.src('src/tpl/css.tpl')
.pipe(consolidate('lodash', options))
.pipe(
rename({
basename: fontName,
extname: '.css',
})
)
.pipe(gulp.dest('dist/'));
gulp
.src('src/tpl/iconfont-less.tpl')
.pipe(consolidate('lodash', options))
.pipe(
rename({
basename: 'iconfont',
extname: '.less',
})
)
.pipe(gulp.dest('dist/'));
gulp
.src('src/tpl/iconfont-variables-less.tpl')
.pipe(consolidate('lodash', options))
.pipe(
rename({
basename: 'iconfont-variables',
extname: '.less',
})
)
.pipe(gulp.dest('dist/'));
gulp
.src('src/tpl/html.tpl')
.pipe(consolidate('lodash', options))
.pipe(
rename({
basename: 'index',
extname: '.html',
})
)
.pipe(gulp.dest('dist/'));
gulp
.src('src/tpl/json.tpl')
.pipe(consolidate('lodash', options))
.pipe(
rename({
basename: 'icons',
extname: '.json',
})
)
.pipe(gulp.dest('dist/'));
gulp
.src('src/tpl/d.ts.tpl')
.pipe(consolidate('lodash', options))
.pipe(
rename({
basename: 'icons.d',
extname: '.ts',
})
)
.pipe(gulp.dest('dist/'));
})
.pipe(gulp.dest('dist/fonts/'));
}
function renameTask() {
return gulp
.src(svgSrc)
.pipe(
rename((path) => {
path.basename = path.basename.replace(/^.*-/, '');
})
)
.pipe(gulp.dest('./svgs'));
}
function buildToLib(cb) {
generateComponents();
cb();
}
exports.buildToLib = gulp.series(buildToLib);
exports.default = gulp.series(defaultTask, buildToLib);
exports.prepublish = gulp.series(defaultTask, buildToLib, renameTask);