-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathgoogle-fonts-generator.js
62 lines (56 loc) · 1.72 KB
/
google-fonts-generator.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
// api-response.json retrieved from: https://www.googleapis.com/webfonts/v1/webfonts?fields=items(category%2Cfamily%2ClastModified%2Csubsets%2Cvariants%2Cversion)&key={YOUR_API_KEY}
// alternatively available from: https://developers.google.com/apis-explorer/?hl=en_US#p/webfonts/v1/webfonts.webfonts.list?fields=items(category%252Cfamily%252ClastModified%252Csubsets%252Cvariants%252Cversion)&_h=3&
const fs = require('fs');
const utils = require('./utils');
const fonts = require('./api-response.json');
const googleFonts = require('./google-fonts.json');
console.time('convert');
const actualizedFonts = process.argv[2]
? require(`./${process.argv[2]}`)
: fonts;
Promise.all([
utils.convertFontsOptions(
actualizedFonts,
({ family, variant }) => {
return `/css?subset=latin-ext&family=${family.replace(/\s/g, '+')}:${variant}`;
}
),
utils.convertFontsOptions(
[
{
"family": "Material Icons",
"category": "icon",
"variants": [
"regular",
],
"subsets": [
"latin"
],
}
],
() => {
return '/icon?family=Material+Icons';
}
)
])
.then(results => {
const combinedResults = {
...results[0],
...results[1]
}
fs.writeFile(
'google-fonts.json',
JSON.stringify(
utils.getSortedObject({
...googleFonts,
...combinedResults
}),
null,
'\t'
),
function() {
console.timeEnd('convert');
console.log('Operation complete.');
}
);
});