forked from coollabsio/fonts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gather-fonts.mjs
34 lines (30 loc) · 1.14 KB
/
gather-fonts.mjs
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
import got from 'got';
import { promises as fs } from 'fs';
import { promisify } from 'node:util';
import stream from 'node:stream';
import 'dotenv/config'
const data = await got.get(`https://google-webfonts-helper.herokuapp.com/api/fonts/`).json()
const pipeline = promisify(stream.pipeline);
const families = data.map(d => d.id).filter(n => n)
const storageZoneName = 'coolfonts'
for (const family of families) {
console.log('Doing: ', family)
const { variants } = await got.get(`https://google-webfonts-helper.herokuapp.com/api/fonts/${family}`).json();
for (const variant of variants) {
const id = variant.fontWeight
const dir = `./${family}/${variant.fontStyle}/`
try {
await pipeline(
got.stream(`${variant.woff2}`),
await got.stream.put(`https://storage.bunnycdn.com/${storageZoneName}/${dir}/${id}.woff2`, {
headers: {
AccessKey: process.env.BUNNYCDN_ACCESS_KEY,
}
}),
new stream.PassThrough()
);
} catch (err) {
console.log(err)
}
}
}