-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·38 lines (32 loc) · 978 Bytes
/
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
const c = require('ansi-colors')
const fs = require('fs/promises')
const readdirp = require('readdirp')
const ttf2woff2 = require('ttf2woff2-no-gyp')
require('ansi-colors')
async function start(dir) {
await convertToWoff2Recursively(dir)
}
async function convertFileToWoff2(file) {
try {
const pathWithoutExtension = file.fullPath.substring(
0,
file.fullPath.lastIndexOf('.ttf')
)
const newFilePath = pathWithoutExtension + '.woff2'
const oldFileData = await fs.readFile(file.fullPath)
await fs.writeFile(newFilePath, ttf2woff2(oldFileData))
console.log(c.green(`✔ Converted to ${newFilePath}`))
} catch (err) {
console.log(
c.red(`✖ conversion of ${file.basename} to woff2 failed: ${err.message}`)
)
}
}
async function convertToWoff2Recursively(dir) {
for await (const entry of readdirp(dir)) {
if (entry.path.endsWith('.ttf')) {
await convertFileToWoff2(entry)
}
}
}
start(process.argv[2])