commit 0a0c1915233bed01bbc657d516fe8816dc8b04e2 Author: Ondřej Hruška Date: Sat Jul 14 21:53:42 2018 +0200 customizer initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19f93ec --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +wanted.all.ini +wanted.none.ini +wanted.ini diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9392795 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Fork-Awesome"] + path = Fork-Awesome + url = https://github.com/ForkAwesome/Fork-Awesome.git diff --git a/Fork-Awesome b/Fork-Awesome new file mode 160000 index 0000000..2850081 --- /dev/null +++ b/Fork-Awesome @@ -0,0 +1 @@ +Subproject commit 285008117b87520930524b332dbbfad1cc26cc2c diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..cda5128 --- /dev/null +++ b/README.txt @@ -0,0 +1,30 @@ +# Fork-Awesome customizer + +This is a little hack to let you generate custom Fork-Awesome builds with only a subset of icons. + +![screenshot](screenshot.png) + +## How to use + +1. Make sure you cloned this repository recursively, i.e. the `Fork-Awesome/` folder is not empty. + - You can fix that by running `git submodule init` and `git submodule update` +2. Run `./install.sh`. This should prepare the FA submodule for building the font. +3. Verify that files `wanted.all.ini` and `wanted.none.ini` have been created. +4. Copy either of the "wanted" template files to `wanted.ini`, and customize it as needed. + Lines starting with `#` will be excluded. Use the [FA icons page](https://forkawesome.github.io/Fork-Awesome/icons/) for reference. +5. Run `./build.sh` to build your customized font. +6. Retrieve your output files from the `output/` directory. + +Note: The "woff" file may fail to build, resulting in the make target in `Fork-Awesome/src/icons` failing, in which case you get no files. +A workaround is to comment out that line by prepending it with `#`, and trying to build again. + +```patch + cp ${FA_FONTCUSTOM_OUTPUT_DIR}/forkawesome.svg ${FA_ROOT_FONTS_DIR}/forkawesome-webfont.svg + cp ${FA_FONTCUSTOM_OUTPUT_DIR}/forkawesome.ttf ${FA_ROOT_FONTS_DIR}/forkawesome-webfont.ttf +- cp ${FA_FONTCUSTOM_OUTPUT_DIR}/forkawesome.woff ${FA_ROOT_FONTS_DIR}/forkawesome-webfont.woff ++ #cp ${FA_FONTCUSTOM_OUTPUT_DIR}/forkawesome.woff ${FA_ROOT_FONTS_DIR}/forkawesome-webfont.woff + cp ${FA_FONTCUSTOM_OUTPUT_DIR}/forkawesome.woff2 ${FA_ROOT_FONTS_DIR}/forkawesome-webfont.woff2 +``` + + + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..93f88ab --- /dev/null +++ b/build.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +if [ ! -f "./Fork-Awesome/.git" ]; then + echo -e "\x1b[31;1mFA submodule is not initialized, exit...\x1b[m" + exit +fi + +if [ ! -f "./wanted.ini" ]; then + echo -e "\x1b[31;1mMissing customization file './wanted.ini'!\x1b[m" + exit +fi + +if [ ! -d "./Fork-Awesome/.bundle" ]; then + echo -e "\x1b[31;1mGems not installed in the FA submodule, cannot build. Did you run install.sh?\x1b[m" + exit +fi + +if [ ! -d "./Fork-Awesome/node_modules" ]; then + echo -e "\x1b[31;1mNode modules not installed in the FA submodule, cannot build. Did you run install.sh?\x1b[m" + exit +fi + +bash ./refresh-templates.sh + +echo "=== Starting a build... ===" +(cd patcher && node ./apply-filter.js) +(cd "./Fork-Awesome/src/icons/" && make) + +cp ./Fork-Awesome/src/icons/forkawesome/* ./output + +echo "=== Your font is ready in the output/ directory ===" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..76f72f3 --- /dev/null +++ b/install.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ ! -f "./Fork-Awesome/.git" ]; then + echo -e "\x1b[31;1mFA submodule is not initialized, exit...\x1b[m" + exit +fi + +cd Fork-Awesome + +echo "=== Installing ruby dependencies ===" +bundle install --path vendor/bundle + +echo +echo "=== Installing NODE dependencies ===" +npm install + +echo +echo ">>> If no errors occured, FA should be ready to build." +echo -e "\x1b[90m(npm complaining about vulnerabilities is probably okay)\x1b[m" + +bash ./refresh-templates.sh diff --git a/output/.gitignore b/output/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/patcher/apply-filter.js b/patcher/apply-filter.js new file mode 100755 index 0000000..88a3b99 --- /dev/null +++ b/patcher/apply-filter.js @@ -0,0 +1,83 @@ +#!/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`) +} diff --git a/patcher/refresh-wanted-templates.js b/patcher/refresh-wanted-templates.js new file mode 100755 index 0000000..5155341 --- /dev/null +++ b/patcher/refresh-wanted-templates.js @@ -0,0 +1,23 @@ +#!/usr/bin/env node + +const fs = require('fs') + +let manifest = JSON.parse(fs.readFileSync('./templates/.fontcustom-manifest.json', 'utf-8')) + +let all_enabled = [] +let all_disabled = [] + +for (var key in manifest.glyphs){ + if (manifest.glyphs.hasOwnProperty(key)) { + all_enabled.push(key) + all_disabled.push(`#${key}`) + } +} + +console.log(`Found ${all_enabled.length} icons in manifest, writing template files`) + +console.log(`\x1b[32m[Writing]\x1b[m wanted.all.ini`) +fs.writeFileSync('../wanted.all.ini', all_enabled.join('\n') + '\n') + +console.log(`\x1b[32m[Writing]\x1b[m wanted.none.ini`) +fs.writeFileSync('../wanted.none.ini', all_disabled.join('\n') + '\n') diff --git a/patcher/templates/.gitignore b/patcher/templates/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/patcher/templates/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/refresh-templates.sh b/refresh-templates.sh new file mode 100755 index 0000000..fcccda7 --- /dev/null +++ b/refresh-templates.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ ! -f "./Fork-Awesome/.git" ]; then + echo -e "\x1b[31;1mFA submodule is not initialized, exit...\x1b[m" + exit +fi + +echo "=== Refreshing templates for building a customized font ===" +rm -rf "./patcher/templates/*" + +cp "./Fork-Awesome/src/icons/.fontcustom-manifest.json" "./patcher/templates" +cp "./Fork-Awesome/src/icons/icons.yml" "./patcher/templates" +cp -R "./Fork-Awesome/src/icons/svg" "./patcher/templates" + +(cd ./patcher && node ./refresh-wanted-templates.js) diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..743f245 Binary files /dev/null and b/screenshot.png differ diff --git a/update-fa.sh b/update-fa.sh new file mode 100755 index 0000000..8ad3bec --- /dev/null +++ b/update-fa.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ ! -f "./Fork-Awesome/.git" ]; then + echo -e "\x1b[31;1mFA submodule is not initialized, exit...\x1b[m" + exit +fi + +echo "=== Updating the Fork-Awesome submodule... ===" +(cd Fork-Awesome && git fetch && git reset --hard origin/master) +echo "=== Fork-Awesome updated ===" + +bash ./refresh-templates.sh diff --git a/wanted.full.ini b/wanted.full.ini new file mode 100644 index 0000000..1181382 --- /dev/null +++ b/wanted.full.ini @@ -0,0 +1,2 @@ +star +table