occupant-website-auto-gen

1.1.2 • Public • Published

Occupant Website Auto-Gen

Auto-Gen is available as a Node.js function or command line interface. The input to these is a set of font file paths, which will produce a set of objects that describe metadata about the fonts. Designed to be plugged into the Occupant Website generation process, giving a programmatic interface into aspects of their fonts to be featured on their website.

Installation

npm install occupant-website-auto-gen

Usage

Node.js

const autoGen = require('occupant-website-auto-gen')
const { glob } = require('glob')

;(async () => {
  const cwd = '/path/to/fonts'
  const fontPaths = await glob('**/*.woff2', { cwd })
  const { docs, stats } = await autoGen({ fontPaths, cwd })
})()

The function signature is autoGen({ fontPaths, cwd, includeOptionalFeatures=false }).

fontPaths is an array of font file paths where the directory name is the font series, and all file paths within this directory are in the shape {name}-{width?,VF?}-{weight?}{italic?}. For example:

  • a variable font would be FontName-VF.woff2
  • a font series without widths would be FontName-Weight.woff2 for the roman and FontName-WeightItalic.woff2 for the italic.
  • a font series with widths would be FontName-Width-Weight.woff2 for the roman and FontName-Width-WeightItalic.woff2 for the italic.

cwd is the path where these fontPaths are all relative to.

The return value is { docs, stats }. docs is an array of metadata files. These are the primary output of the function. stats is an object that includes information around what the function saw across all font files processed. This includes useful debugging information like if there was a font weight encountered that was not accounted for in the sorting process done within font-name-parts

CLI

npx auto-gen {cwd} --help will give the command line interface usage information. It can also be read in the source

Development

To actively develop this repo you will need a Node.js environment. nvm is recommended for this, as it gives affordances for switching between versions of Node.js within your terminal. The current version that is being used for development is captured in the .nvmrc file. At the time or writing this is v20.4.0.

# Run these from within this repository
# Activate the correct verseion of Node.js
$ nvm use
# Install dependencies
$ npm install

There are many ways to test the output of this repository, but since it is destined for use with the Occupant Website, it can be best to use it directly. npm link allows one to use a local version of a module, we can use this to link our local module for use within the Occupant Website.

# Starting at the root of this package
# Give our npm a reference to our local package
$ npm link
# change directories to the Occupant Website,
$ cd ../_OccupantWebsite
# or from within another terminal window that
# has access to the same `npm` we can link
# our local package
$ npm link occupant-website-auto-gen

We can now run auto-gen commands that will use our local package.

# From _OccupantWebsite
# Run an auto-gen build looking at a single font series to increase our
# iteration cycle time
$ npx auto-gen src/fonts --match=Allium/*.woff2 --output=src/_data/fonts
# Alternatively we can run an entire build which lives behind this npm command
$ npm run build:auto-gen
# The above command is the same as the following
$ npx auto-gen src/fonts --match=**/*.woff2 --output=src/_data/fonts

/occupant-website-auto-gen/

    Package Sidebar

    Install

    npm i occupant-website-auto-gen

    Weekly Downloads

    4

    Version

    1.1.2

    License

    ISC

    Unpacked Size

    36.6 kB

    Total Files

    12

    Last publish

    Collaborators

    • rubenrodriguez