From 2656c38c2dc8642d032556f9bb1ebd3eb5b3186b Mon Sep 17 00:00:00 2001 From: Logan Graham Date: Sat, 15 Aug 2020 23:33:30 -0400 Subject: [PATCH] - Add check to determine user has either free or pro version installed. Add error / notice in console. - Update README with new installation requirements (defining a specific package) - Add upgrade guide for 1.x -> 2.0 users - Update changelog --- CHANGELOG.md | 4 ++-- README.md | 12 +++++++++--- UPGRADING.md | 13 +++++++++++++ package-lock.json | 12 +++--------- package.json | 8 ++------ src/index.ts | 10 ++++++++-- 6 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 UPGRADING.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f8cf3..f68c9ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [2.0.0](https://github.com/omacranger/fontawesome-subset/compare/1.1.0...2.0.0) +- Remove required `@fortawesome/fontawesome-free` dependency. Must install a needed version manually and define the package type in the options object. Defaults to `free`. See [the upgrade guide](UPGRADING.md) for further details. - Refactored module to TypeScript -- Remove required dependencies - must install a needed version manually and define the package type in the options object. Defaults to `free`. ## [1.1.0](https://github.com/omacranger/fontawesome-subset/compare/1.0.0...1.1.0) diff --git a/README.md b/README.md index 5a35d68..9dadb9c 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,18 @@ Love FontAwesome but don't need thousands of icons bundled on every page of the site? Me either. `fontawesome-subset` is a utility for creating subsets of FontAwesome for optimized use on the web. It works by taking glyph names that you've used (`angle-left`, `caret-up`, etc) and creating an optimized font with only the glyphs you need. Yes, SVG icons and fragments are fancier and more feature filled - but if you already have a website built using the webfont - why switch -- right? -## Usage -Install: -```bash +## Installation +First, install fontawesome-subset: +```sh npm install --save-dev fontawesome-subset ``` +Second, install the edition of FontAwesome you plan on using. If you're using the Pro version, see [below](#using-with-fontawesome-pro). For the free version, use the following: +```sh +npm install --save-dev @fortawesome/fontawesome-free +``` + +## Usage Run via your favorite task runner: ```javascript // Require fontawesome-subset diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 0000000..65aafae --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,13 @@ +# Upgrading Versions + +## 1.x to 2.0 +Version 2.0 of fontawesome-subset removes the required dependency for `@fortawesome/fontawesome-free`. + +### Pro Users +For Pro users, this release should be backwards compatible since we're only removing the required dependency for the free version. + +### Free Users +For Free users, this means you'll have to manually specify / save the dependency, as noted in the updated readme. +```sh +npm install --save-dev @fortawesome/fontawesome-free +``` \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d3df275..2d85356 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,12 +4,6 @@ "lockfileVersion": 1, "requires": true, "dependencies": { - "@fortawesome/fontawesome-free": { - "version": "5.14.0", - "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.14.0.tgz", - "integrity": "sha512-OfdMsF+ZQgdKHP9jUbmDcRrP0eX90XXrsXIdyjLbkmSBzmMXPABB8eobUJtivaupucYaByz6WNe1PI1JuYm3qA==", - "optional": true - }, "@types/mkdirp": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/mkdirp/-/mkdirp-1.0.1.tgz", @@ -31,9 +25,9 @@ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, "ajv": { - "version": "6.12.3", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.3.tgz", - "integrity": "sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA==", + "version": "6.12.4", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.4.tgz", + "integrity": "sha512-eienB2c9qVQs2KWexhkrdMLVDoIQCz5KSeLxwg9Lzk4DOfBtIK9PQwwufcsn1jjGuf9WZmqPMbGxOzfcuphJCQ==", "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", diff --git a/package.json b/package.json index d1fe5f5..64d93b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fontawesome-subset", - "version": "1.1.0", + "version": "2.0.0", "description": "Utility to create subsets for FontAwesome and FontAwesome Pro.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -8,7 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "tsc", "build-watch": "tsc -w", - "prepublish": "npm run build" + "prepublishOnly": "npm run build" }, "author": { "name": "Logan Graham", @@ -25,10 +25,6 @@ "ttf2woff": "^2.0.2", "ttf2woff2": "^3.0.0" }, - "optionalDependencies": { - "@fortawesome/fontawesome-pro": "^5.x", - "@fortawesome/fontawesome-free": "^5.x" - }, "license": "GPL-3.0-or-later", "repository": { "type": "git", diff --git a/src/index.ts b/src/index.ts index e75e3a2..aadb5f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ * Author: Logan Graham */ -import { readFileSync, existsSync, writeFileSync } from "fs"; +import { existsSync, readFileSync, writeFileSync } from "fs"; import { resolve } from "path"; import { sync as makeDirSync } from "mkdirp"; import { FontAwesomeOptions, Subset, SubsetOption } from "./types"; @@ -62,6 +62,12 @@ function fontawesomeSubset(subset: SubsetOption, outputDir: string, options: Fon }; const fontTypes = Object.keys(fontMap); + // Check to see if the user has either free, or pro installed. + if (!(existsSync("node_modules/@fortawesome/fontawesome-free") || existsSync("node_modules/@fortawesome/fontawesome-pro"))) { + console.error("Unable to find either the Free or Pro FontAwesome files in node_modules folder. Double-check that you have your preferred fontawesome package as a dependency in `package.json` and rerun the installation."); + return; + } + // If 'subset' is set to array, turn into object defaulted for 'solid' use (fontawesome free) if (Array.isArray(subset)) { subset = { solid: subset }; @@ -84,7 +90,7 @@ function fontawesomeSubset(subset: SubsetOption, outputDir: string, options: Fon const svgFilePath = `node_modules/@fortawesome/fontawesome-${options.package}/webfonts/${svgFileName}.svg`; if (!existsSync(svgFilePath)) { - console.error("Unable to find SVG file. Could be missing fontawesome dependencies. Make sure you have your preferred FontAwesome package in package.json and try running `npm install` or changing the font style."); + console.warn(`Unable to find SVG font file for requested font style '${fontFamily}'. Skipping.`); continue; }