Skip to content

Commit

Permalink
- Ensure a package type is set - defaulting to 'free'
Browse files Browse the repository at this point in the history
- Add additional npm scripts
  • Loading branch information
omacranger committed Aug 15, 2020
1 parent eb5b9d6 commit 11a7fbe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
"build": "tsc",
"build-watch": "tsc -w",
"prepublish": "npm run build"
},
"author": {
"name": "Logan Graham",
Expand Down
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ function findGlyphsToRemove(svgFile: string, fontFamily: Subset, icons: string[]
* @param outputDir Directory output generated webfonts.
* @param options Object of options / tweaks for further customization. Defaults to 'Free' package.
*/
function fontawesomeSubset(subset: SubsetOption, outputDir: string, options: FontAwesomeOptions = {}) {
const opts = {
package: "free",
...options
};

function fontawesomeSubset(subset: SubsetOption, outputDir: string, options: FontAwesomeOptions = { package: "free" }) {
// Maps style to actual font name / file name.
const fontMap: Record<Subset, string> = {
solid: "fa-solid-900",
Expand Down Expand Up @@ -86,7 +81,7 @@ function fontawesomeSubset(subset: SubsetOption, outputDir: string, options: Fon

const fontFamily = key as keyof typeof fontMap;
const svgFileName = fontMap[fontFamily];
const svgFilePath = `node_modules/@fortawesome/fontawesome-${opts.package}/webfonts/${svgFileName}.svg`;
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.");
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface FontAwesomeOptions {
package?: "free" | "pro";
package: "free" | "pro";
}

export type Subset = "solid" | "light" | "regular" | "brands" | "duotone";
Expand Down

0 comments on commit 11a7fbe

Please sign in to comment.