#!/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); } let manifest = JSON.parse(fs.readFileSync('templates/.fontcustom-manifest.json', 'utf-8')) let desired = fs.readFileSync('../wanted.ini', 'utf-8').split('\n').filter((x) => x.length && x[0] !== '#') // This forces a rebuild manifest.checksum.previous = 'asdf' console.log('Preparing fontcustom manifest...') console.log(`Including ${desired.length} icons`) const orig_glyphs = manifest.glyphs manifest.glyphs = Object.keys(orig_glyphs) .filter(key => desired.includes(key)) .reduce((obj, key) => { obj[key] = orig_glyphs[key] return obj }, {}) console.log('\x1b[32m[Writing]\x1b[m .fontcustom-manifest.json') fs.writeFileSync('../Fork-Awesome/src/icons/.fontcustom-manifest.json', JSON.stringify(manifest, null, 2)) 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+(\w+)\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 icons.yml') fs.writeFileSync('../Fork-Awesome/src/icons/icons.yml', combined) console.log('Deleting files in svg/ ...') rmInDir('../Fork-Awesome/src/icons/svg') console.log('Copying desired files from svg-all/ to svg/ ...') for (let a of desired) { cp(`./templates/svg/${a}.svg`, `../Fork-Awesome/src/icons/svg/${a}.svg`) }