-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
89 lines (81 loc) · 2.23 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
'use strict';
const gulp = require('gulp');
const iconfont = require('gulp-iconfont');
const exec = require('child_process').exec;
const fs = require('fs');
gulp.task('icons', function(done) {
var glyphs;
const fontName = 'vaadin-rte-icons';
const fileName = 'vcf-enhanced-rich-text-editor-icons';
gulp.src('icons/*.svg')
.pipe(iconfont({
fontName: fileName,
formats: ['woff'],
fontHeight: 1000,
ascent: 850,
descent: 150,
fixedWidth: true,
normalize: true,
}))
.on('glyphs', function(glyphData) {
// Store for later use
glyphs = glyphData;
})
.pipe(gulp.dest('.'))
.on('finish', function() {
// Generate base64 version of the font
exec(`base64 ${fileName}.woff`, function(err, stdout) {
var output = `<!-- NOTE: Auto generated with 'gulp icons', do not edit -->
<link rel="import" href="../../polymer/lib/elements/custom-style.html">
<custom-style>
<style>
@font-face {
font-family: '${fontName}';
src: url(data:application/font-woff;charset=utf-8;base64,${stdout.trim()}) format('woff');
font-weight: normal;
font-style: normal;
}
html {
`;
glyphs.forEach(g => {
var name = g.name.replace(/\s/g, '-').toLowerCase();
var unicode = '\\' + g.unicode[0].charCodeAt(0).toString(16);
output += ` --${fontName}-${name}: "${unicode}";\n`;
});
output += ` }
</style>
</custom-style>
<dom-module id="${fileName}">
<template>
<style>
`;
glyphs.forEach((g, index) => {
var name = g.name.replace(/\s/g, '-').toLowerCase();
output += ` [part~="toolbar-button-${name}"]::before {
content: var(--${fontName}-${name});
}`;
if (index < glyphs.length - 1) {
output += `
`;
}
});
output += `
</style>
</template>
</dom-module>
`;
fs.writeFile(`src/${fileName}.html`, output, function(err) {
if (err) {
return console.error(err);
}
});
// Cleanup
fs.unlink(`${fileName}.woff`, function(err) {
if (err) {
return console.error(err);
}
done();
});
});
});
});