diff --git a/README.md b/README.md index 9299ae7fb..ecdbb6ed6 100644 --- a/README.md +++ b/README.md @@ -281,8 +281,8 @@ Please note that, due to the complex interactions when forming ligations, cherry To build Iosevka you should: -1. Ensure that [`nodejs`](http://nodejs.org) (≥ 12.16.0) and [`ttfautohint`](http://www.freetype.org/ttfautohint/) are present. -2. Install necessary libs by `npm install`. If you’ve installed them, upgrade to the latest. +1. Ensure that [`nodejs`](http://nodejs.org) (≥ 12.16.0) and [`ttfautohint`](http://www.freetype.org/ttfautohint/) are present, and accessible from `PATH`. +2. Run `npm install`. This command will install **all** the NPM dependenceis, and will also validate whether external dependencies are present. 3. `npm run build -- contents::iosevka`. You will find TTFs, as well as WOFF(2) web fonts and one Webfont CSS in the `dist/` directory. diff --git a/package.json b/package.json index d0edae585..4df84c016 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,9 @@ "version": "4.0.0", "main": "./font-src/index.js", "scripts": { - "build": "verda -f verdafile.js", + "build": "node utility/ensure-verda-exists && verda -f verdafile.js", "bump-ver": "node utility/update-package-json-version/index", - "clean": "verda -f verdafile.js clean", - "install": "node utility/check-env" + "clean": "node utility/ensure-verda-exists && verda -f verdafile.js clean" }, "dependencies": { "@iarna/toml": "^2.2.5", @@ -23,7 +22,7 @@ "stylus": "^0.54.8", "toposort": "^2.0.2", "typo-geom": "^0.11.0", - "verda": "^1.1.2", + "verda": "^1.2.0", "wawoff2": "^1.0.2", "which": "^2.0.2" }, diff --git a/utility/check-env.js b/utility/check-env.js deleted file mode 100644 index 1df9ff20b..000000000 --- a/utility/check-env.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; - -const which = require("which"); -const FgRed = "\x1b[31m"; -const FgGreen = "\x1b[32m"; -const FgYellow = "\x1b[33m"; -const Reset = "\x1b[0m"; - -console.log("Checking External Dependencies"); -check("ttfautohint"); - -function check(util) { - try { - which.sync(util); - console.error(FgGreen + ` * External dependency <${util}> is present.` + Reset); - } catch (e) { - console.error(FgRed + ` * External dependency <${util}> is not found.` + Reset); - } -} diff --git a/utility/ensure-verda-exists.js b/utility/ensure-verda-exists.js new file mode 100644 index 000000000..2feea79cd --- /dev/null +++ b/utility/ensure-verda-exists.js @@ -0,0 +1,23 @@ +"use strict"; + +const FgRed = "\x1b[31m"; +const FgYellow = "\x1b[33m"; +const Reset = "\x1b[0m"; + +const os = require("os"); +const shellWord = os.platform() === "win32" ? "command prompt" : "shell"; + +// Check packages are present +try { + require("verda/package.json"); + require("semver/package.json"); + require("which/package.json"); + require("@iarna/toml/package.json"); +} catch (e) { + console.error(`${FgRed}It looks like you forgot to run "npm install" before building.${Reset}`); + console.error(`"npm install" sets up dependencies required to build the fonts.`); + console.error(`Run the following command in your ${shellWord} and retry:`); + console.error(` ${FgYellow}npm install${Reset}`); + console.error(); + process.exit(1); +} diff --git a/verdafile.js b/verdafile.js index e3a92cbe1..56755fef4 100644 --- a/verdafile.js +++ b/verdafile.js @@ -2,26 +2,27 @@ const fs = require("fs"); const build = require("verda").create(); +const which = require("which"); +const Path = require("path"); +const toml = require("@iarna/toml"); + +/////////////////////////////////////////////////////////// + const { task, file, oracle, computed, phony } = build.ruleTypes; const { de, fu, sfu, ofu } = build.rules; -const { run, node, cd, cp, rm, mv, fail, echo } = build.actions; +const { run, node, cd, cp, rm, mv, fail, echo, silently } = build.actions; const { FileList } = build.predefinedFuncs; -const which = require("which"); module.exports = build; /////////////////////////////////////////////////////////// -const Path = require("path"); -const toml = require("@iarna/toml"); - const BUILD = ".build"; const DIST = "dist"; const SNAPSHOT_TMP = ".build/snapshot"; const DIST_SUPER_TTC = "dist/.super-ttc"; const ARCHIVE_DIR = "release-archives"; -const TTX = "ttx"; const PATEL_C = ["node", "./node_modules/patel/bin/patel-c"]; const TTCIZE = ["node", "node_modules/otb-ttc-bundle/bin/otb-ttc-bundle"]; const webfontFormats = [ @@ -52,6 +53,14 @@ const Version = oracle(`oracle:version`, async target => { return package_json.version; }); +const CheckTtfAutoHintExists = oracle(`oracle:check-ttfautohint-exists`, async target => { + try { + return await which("ttfautohint"); + } catch (e) { + fail("External dependency , needed for building hinted font, does not exist."); + } +}); + /////////////////////////////////////////////////////////// ////// Plans ////// /////////////////////////////////////////////////////////// @@ -309,9 +318,9 @@ const DistUnhintedTTF = file.make( const DistHintedTTF = file.make( (gr, fn) => `${DIST}/${gr}/ttf/${fn}.ttf`, async (target, path, gr, f) => { - const [{ hintParams }] = await target.need(FontInfoOf(f)); + const [{ hintParams }, hint] = await target.need(FontInfoOf(f), CheckTtfAutoHintExists); const [from] = await target.need(BuildTTF(gr, f), de`${path.dir}`); - await run("ttfautohint", hintParams, from.full, path.full); + await silently.run(hint, hintParams, from.full, path.full); } ); const DistWoff2 = file.make(