Hack to customize fork awesome
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
fork-awesome-customizer/patcher/apply-filter.js

90 lines
2.5 KiB

#!/usr/bin/env node
const fs = require('fs')
function rmInDir(dirPath) {
try { var files = fs.readdirSync(dirPath) }
catch(e) { return }
if (files.length > 0) {
for (var i = 0; i < files.length; i++) {
var filePath = dirPath + '/' + files[i]
if (fs.statSync(filePath).isFile())
fs.unlinkSync(filePath)
else
rmDir(filePath)
}
}
}
function cp(src, dest) {
if (!fs.existsSync(src)) {
return false;
}
var data = fs.readFileSync(src, 'utf-8');
fs.writeFileSync(dest, data);
return true
}
// let manifest = JSON.parse(fs.readFileSync('templates/.fontcustom-manifest.json', 'utf-8'))
let fcyml = fs.readFileSync('../fontcustom.yml', 'utf-8')
let desired = fs.readFileSync('../wanted.ini', 'utf-8').split('\n')
.filter((x) => x.length && x[0] !== '#')
.map((x) => x.trim().replace(/\s*#.*/, ''))
// TODO deal with aliases properly
console.log(`Including ${desired.length} icons`)
console.log('Preparing icons.yml...')
// this would be prettier with some yaml module, but to avoid installing anything...
let iconsy = fs.readFileSync('templates/icons.yml', 'utf-8')
let pieces = iconsy.substring(iconsy.indexOf('\n')+1).split(' - name:')
pieces.shift() // remove first
// now we have the entries, without leading ' - name'
let pattern = /id:\s+([a-z_0-9-]+)\n/
pieces = pieces.filter((x) => {
let ar = pattern.exec(x)
return ar !== null && desired.indexOf(ar[1]) !== -1
})
let combined = 'icons:\n - name:' + pieces.join(' - name:')
console.log('\x1b[32m[Writing]\x1b[m FA~icons.yml')
fs.writeFileSync('../Fork-Awesome/src/icons/icons.yml', combined)
console.log('\x1b[32m[Writing]\x1b[m FA~fontcustom.yml')
fs.writeFileSync('../Fork-Awesome/src/icons/fontcustom.yml', fcyml)
console.log('Deleting FA~.fontcustom-manifest.json, to force a rebuilt ...')
if (fs.existsSync('../Fork-Awesome/src/icons/.fontcustom-manifest.json')) {
fs.unlinkSync('../Fork-Awesome/src/icons/.fontcustom-manifest.json')
}
console.log('Deleting files in FA~svg/ ...')
rmInDir('../Fork-Awesome/src/icons/svg')
console.log('Copying desired files to FA~svg/ ...')
let any_bad = false
for (let a of desired) {
if (!cp(`./templates/svg/${a}.svg`, `../Fork-Awesome/src/icons/svg/${a}.svg`)) {
console.log(`- \x1b[33mFile \x1b[31m"${a}.svg"\x1b[33m not found, probably a typo or alias\x1b[m`)
any_bad = true
}
}
if (any_bad) {
console.log(`\x1b[31mSome files were not found. If you included their aliases (e.g. save -> floppy-o), this is correct.\x1b[m`)
}