Skip to content

Commit

Permalink
- Add check to determine user has either free or pro version installe…
Browse files Browse the repository at this point in the history
…d. 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
  • Loading branch information
omacranger committed Aug 16, 2020
1 parent 11a7fbe commit 2656c38
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -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
```
12 changes: 3 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"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",
"scripts": {
"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",
Expand All @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Author: Logan Graham <[email protected]>
*/

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";
Expand Down Expand Up @@ -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 };
Expand All @@ -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;
}

Expand Down

0 comments on commit 2656c38

Please sign in to comment.