-
Notifications
You must be signed in to change notification settings - Fork 76
/
gulpfile.js
78 lines (71 loc) · 2.26 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
const gulp = require('gulp')
const rename = require('gulp-rename')
const sketch = require('gulp-sketch')
const iconfont = require('gulp-iconfont')
const consolidate = require('gulp-consolidate')
const bs = require('browser-sync').create()
/**
* Font settings
*/
const fontName = 'symbols' // set name of your symbol font
const className = 's' // set class name in your CSS
const template = 'fontawesome-style' // or 'foundation-style'
const skethcFileName = 'symbol-font-14px.sketch' // or 'symbol-font-16px.sketch'
/**
* Recommended to get consistent builds when watching files
* See https://github.com/nfroidure/gulp-iconfont
*/
const timestamp = Math.round(Date.now() / 1000)
gulp.task('symbols', () =>
gulp.src(skethcFileName)
.pipe(sketch({
export: 'artboards',
formats: 'svg'
}))
.pipe(iconfont({
fontName,
formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'],
timestamp,
log: () => {} // suppress unnecessary logging
}))
.on('glyphs', (glyphs) => {
const options = {
className,
fontName,
fontPath: '../fonts/', // set path to font (from your CSS file if relative)
glyphs: glyphs.map(mapGlyphs)
}
gulp.src(`templates/${template}.css`)
.pipe(consolidate('lodash', options))
.pipe(rename({ basename: fontName }))
.pipe(gulp.dest('dist/css/')) // set path to export your CSS
// if you don't need sample.html, remove next 4 lines
gulp.src(`templates/${template}.html`)
.pipe(consolidate('lodash', options))
.pipe(rename({ basename: 'sample' }))
.pipe(gulp.dest('dist/')) // set path to export your sample HTML
})
.pipe(gulp.dest('dist/fonts/')) // set path to export your fonts
)
gulp.task('watch', ['symbols'], () => {
bs.init({
files: 'dist/sample.html',
server: 'dist/',
startPath: '/sample.html',
middleware: cacheControl
})
gulp.watch('*.sketch', ['symbols'])
})
/**
* This is needed for mapping glyphs and codepoints.
*/
function mapGlyphs (glyph) {
return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
}
/**
* This keeps browser from caching fonts for your testing environment
*/
function cacheControl (req, res, next) {
res.setHeader('Cache-control', 'no-store')
next()
}