Created
August 6, 2018 11:24
-
-
Save screeny05/06b383ddbfee4f11e21e76d0bd7c4507 to your computer and use it in GitHub Desktop.
Rename webfonts from fontforge according to their ps-name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const xml2js = require('xml2js'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const fontsXmlPath = process.argv[2]; | |
const fontsFolderPath = path.resolve(fontsXmlPath, '..', 'Fonts'); | |
const tryRename = (filename, psName) => { | |
try { | |
fs.renameSync(path.resolve(fontsFolderPath, filename), path.resolve(fontsFolderPath, psName + path.extname(filename))); | |
} catch (e) { | |
console.log('file', filename, 'not found'); | |
} | |
} | |
const xml = xml2js.parseString(fs.readFileSync(fontsXmlPath, 'utf8'), (err, dom) => { | |
if(err) return console.log(err); | |
dom.fonts.font.forEach(font => { | |
tryRename(font.$.woff, font.$.psName); | |
tryRename(font.$.eot, font.$.psName); | |
tryRename(font.$.ttf, font.$.psName); | |
tryRename(font.$.svg, font.$.psName); | |
tryRename(font.$.woff2, font.$.psName); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment