-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (64 loc) · 2.03 KB
/
index.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
'use strict';
const PLUGIN_NAME = 'gulp-font-blast';
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var path = require('path');
var extractor = require('./lib/glyph-extractor');
/**
* Hint for the configuration from the original font-blast sources
*
* type UserConf = {
* png?: Boolean,
* filenames?: Object,
* icons?: Array<string>,
* cleanCharacter?: Function
* };
*
* const defaultConfig: UserConf = {};
*/
var defaultConfig = {};
function gulpBlaster (userConfig) {
var config = Object.assign({}, defaultConfig, userConfig || {});
var stream = through.obj(function (file, enc, cb) {
var f = path.parse(file.path);
var self = this;
// extract glyphs and make new file objects
extractor(
file.contents.toString(),
config.filenames,
function (characterSvgs) {
console.info(
'Found ' + characterSvgs.length + ' available icons in the <' + f.name + '> font'
);
console.info('Generating SVG content for each character...');
var savedIcons = [];
characterSvgs.forEach(function (char) {
var filename = char.name ? char.name : char.code;
// if a subset of icons set was requested, ignore any others
// that are not within the subset
if (
config.icons &&
config.icons.length &&
config.icons.indexOf(char.code) === -1 &&
config.icons.indexOf(filename) === -1
) {
return;
}
savedIcons.push(char);
var glyph = file.clone();
glyph.path = path.join(glyph.base, filename + f.ext);
glyph.contents = Buffer.from(String(char.svg));
self.push(glyph);
});
console.info('Saved ' + savedIcons.length + ' files from the <' + f.name + '> font');
// TODO: png images?
// TODO: verify?
},
config.cleanCharacter
);
return cb(); // discard original file
});
return stream;
}
module.exports = gulpBlaster;