-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
executable file
·68 lines (64 loc) · 3.06 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
/* eslint-env node, es6 */
/* global require */
'use strict';
/**
* Configuration
*/
const
{
// parallel,
// series,
src,
dest,
task,
// watch,
} = require('gulp'),
svgo = require('gulp-svgo'),
replace = require('gulp-replace');
const
svgSource = 'source/**/*.svg',
svgDestination = 'for-web';
const optimizeSvgs = () =>
src(svgSource)
// Replace any font declarations with CSS fallback fonts
.pipe(replace(/font-family:.*?;/g, (match) => {
match = match.toLowerCase();
// Matching something like: "font-family: LiberationMono, Liberation Mono;"
if (match.indexOf('mono') >= 0) {
// Matching something like: "font-family: LiberationMono-Italic, Liberation Mono;"
if (match.indexOf('italic') >= 0) {
return 'font-family: LiberationMono, "Liberation Mono", Consolas, Monaco, "Andale Mono", monospace; font-style: italic;';
}
return 'font-family: LiberationMono, "Liberation Mono", Consolas, Monaco, "Andale Mono", monospace;';
}
if (match.indexOf('redhattext') >= 0 || match.indexOf('red hat text') >= 0) {
// Matching something like "font-family: RedHatText-Bold, Red Hat Text;"
if (match.indexOf('bold') >= 0) {
if (match.indexOf('italic') >= 0) {
return 'font-family: RedHatText, "Red Hat Text", Overpass,"Helvetica Neue", Arial, sans-serif; font-weight: bold; font-style: italic;';
}
return 'font-family: RedHatText, "Red Hat Text", Overpass,"Helvetica Neue", Arial, sans-serif; font-weight: bold;';
}
// Matching something like: "font-family: RedHatText-Medium, Red Hat Text;"
if (match.indexOf('medium') >= 0) {
if (match.indexOf('italic') >= 0) {
return 'font-family: RedHatText, "Red Hat Text", Overpass,"Helvetica Neue", Arial, sans-serif; font-weight: 500; font-style: italic;';
}
return 'font-family: RedHatText, "Red Hat Text", Overpass,"Helvetica Neue", Arial, sans-serif; font-weight: 500;';
}
// Matching something like "font-family: RedHatText-Italic, Red Hat Text;"
if (match.indexOf('italic') >= 0) {
return 'font-family: RedHatText, "Red Hat Text", Overpass,"Helvetica Neue", Arial, sans-serif; font-style: italic;';
}
// Matching something like "font-family: RedHatText-Regular, Red Hat Text;"
if (match.indexOf('regular') >= 0) {
return 'font-family: RedHatText, "Red Hat Text", Overpass,"Helvetica Neue", Arial, sans-serif;';
}
console.warn('Couldn\'t find a matching rule for the Red Hat Text variation, if it\'s not Regular non-italic, contact [email protected]', `CSS from Illustrator was ${match}`);
return 'font-family: RedHatText, "Red Hat Text", Overpass,"Helvetica Neue", Arial, sans-serif;';
}
console.error('Found a font face that couldn\'t be optimized, please notify [email protected] to add coverage for it. Found: ', `CSS from Illustrator was ${match}`);
}))
.pipe(svgo())
.pipe(dest(svgDestination));
task('default', optimizeSvgs);