From e882d502883e6cc1b6dfdc2f72ddba565b22dc11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sat, 14 Jul 2018 22:45:39 +0200 Subject: [PATCH] improvements --- .gitignore | 3 +++ README.md | 21 +++++----------- build.sh | 16 +++++++++--- install.sh | 4 +++ patcher/apply-filter.js | 39 +++++++++++++---------------- patcher/refresh-wanted-templates.js | 11 ++++++++ refresh-templates.sh | 1 + update-fa.sh | 12 --------- wanted.full.ini | 2 -- 9 files changed, 54 insertions(+), 55 deletions(-) delete mode 100755 update-fa.sh delete mode 100644 wanted.full.ini diff --git a/.gitignore b/.gitignore index 19f93ec..3044a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ wanted.all.ini wanted.none.ini wanted.ini + +fontcustom.yml +fontcustom.default.yml diff --git a/README.md b/README.md index cda5128..b988d5f 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,12 @@ This is a little hack to let you generate custom Fork-Awesome builds with only a - 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. + - You can update Fork-Awesome and these files at any time by running `./install.sh` again. +4. Copy either of the "wanted" templates 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 -``` - - - +Note: The "woff" file may fail to build, resulting in the make target in `Fork-Awesome/src/icons` failing. +This shouldn't be a problem, as the fonts are already built. diff --git a/build.sh b/build.sh index 93f88ab..6ae1b9d 100755 --- a/build.sh +++ b/build.sh @@ -20,12 +20,20 @@ if [ ! -d "./Fork-Awesome/node_modules" ]; then exit fi -bash ./refresh-templates.sh - echo "=== Starting a build... ===" (cd patcher && node ./apply-filter.js) (cd "./Fork-Awesome/src/icons/" && make) +echo -e "\x1b[33mIf the make target failed at a \"cp\" statement, that is most likely safe to ignore\x1b[m" + +fontname=$(cat fontcustom.yml | head -n1 | sed "s/font_name: //") + +if [ ! -f "./Fork-Awesome/src/icons/$fontname/$fontname-preview.html" ]; then + echo -e "\x1b[31;1mBuild failed, output directory is empty.\x1b[m" + exit +fi -cp ./Fork-Awesome/src/icons/forkawesome/* ./output +rm ./output/* +cp "./Fork-Awesome/src/icons/$fontname/"* ./output -echo "=== Your font is ready in the output/ directory ===" +echo +echo "=== Your font \"$fontname\" is ready in the output/ directory ===" diff --git a/install.sh b/install.sh index 76f72f3..9f18967 100755 --- a/install.sh +++ b/install.sh @@ -7,6 +7,9 @@ fi cd Fork-Awesome +echo "=== Ensuring FA is up-to-date ===" +git fetch && git reset --hard origin/master + echo "=== Installing ruby dependencies ===" bundle install --path vendor/bundle @@ -18,4 +21,5 @@ 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" +cd .. bash ./refresh-templates.sh diff --git a/patcher/apply-filter.js b/patcher/apply-filter.js index 88a3b99..28dbc4c 100755 --- a/patcher/apply-filter.js +++ b/patcher/apply-filter.js @@ -27,31 +27,16 @@ function cp(src, dest) { } -let manifest = JSON.parse(fs.readFileSync('templates/.fontcustom-manifest.json', 'utf-8')) +// 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] !== '#') -// 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') @@ -60,7 +45,7 @@ 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/ +let pattern = /id:\s+([a-z_0-9-]+)\n/ pieces = pieces.filter((x) => { let ar = pattern.exec(x) @@ -69,15 +54,25 @@ pieces = pieces.filter((x) => { let combined = 'icons:\n - name:' + pieces.join(' - name:') -console.log('\x1b[32m[Writing]\x1b[m icons.yml') +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 files in svg/ ...') +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 from svg-all/ to svg/ ...') + +console.log('Copying desired files to FA~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 index 5155341..24a9991 100755 --- a/patcher/refresh-wanted-templates.js +++ b/patcher/refresh-wanted-templates.js @@ -2,7 +2,9 @@ const fs = require('fs') +// the manifest file is easier to parse for us, but the actual source file is icons.yml let manifest = JSON.parse(fs.readFileSync('./templates/.fontcustom-manifest.json', 'utf-8')) +let fcyml = fs.readFileSync('./templates/fontcustom.yml', 'utf-8') let all_enabled = [] let all_disabled = [] @@ -21,3 +23,12 @@ 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') + + +console.log(`\x1b[32m[Writing]\x1b[m fontcustom.default.yml`) +fs.writeFileSync('../fontcustom.default.yml', fcyml) + +if (!fs.existsSync('../fontcustom.yml')) { + console.log(`\x1b[32m[Writing]\x1b[m fontcustom.yml (did not exist)`) +fs.writeFileSync('../fontcustom.yml', fcyml) +} diff --git a/refresh-templates.sh b/refresh-templates.sh index fcccda7..e41d546 100755 --- a/refresh-templates.sh +++ b/refresh-templates.sh @@ -9,6 +9,7 @@ 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/fontcustom.yml" "./patcher/templates" cp "./Fork-Awesome/src/icons/icons.yml" "./patcher/templates" cp -R "./Fork-Awesome/src/icons/svg" "./patcher/templates" diff --git a/update-fa.sh b/update-fa.sh deleted file mode 100755 index 8ad3bec..0000000 --- a/update-fa.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/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 deleted file mode 100644 index 1181382..0000000 --- a/wanted.full.ini +++ /dev/null @@ -1,2 +0,0 @@ -star -table