-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
52 lines (40 loc) · 1.47 KB
/
cli.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
const { execSync } = require("child_process")
const parsePlist = require("plist").parse
const fs = require("fs")
const path = require("path")
const pluralizeFont = require("./lib/pluralize-font")
const untildify = require("./lib/untildify")
const fontName = process.argv[2]
const outputDirectory = process.argv[3]
if (fontName === undefined) {
console.log("A font name to search for is required.")
process.exit(1)
}
if (outputDirectory === undefined) {
console.log("A directory to output matching fonts to is required.")
process.exit(1)
}
console.log("Raiding fonts…")
let plist = execSync("system_profiler -xml SPFontsDataType").toString()
let data = parsePlist(plist)
let fonts = data[0]._items
console.log(`${fonts.length} ${pluralizeFont(fonts.length)} found…`)
let matchingFonts = fonts.filter((font) => {
return font.typefaces.find((typeface) => {
return typeface.family.match(new RegExp(fontName, "i"))
})
})
if (!matchingFonts.length) {
console.log("No matching fonts found.")
process.exit(0)
}
console.log(`${matchingFonts.length} matching ${pluralizeFont(matchingFonts.length)} found, locations are:`)
let fontPaths = matchingFonts.map((font) => font.path)
console.log("")
fontPaths.forEach((fontPath) => console.log(fontPath))
console.log("")
fontPaths.forEach((fontPath) => {
let filename = path.basename(fontPath)
fs.copyFileSync(fontPath, untildify(path.join(outputDirectory, filename)))
})
console.log(`Copied fonts to “${outputDirectory}”!`)