puff-pastry
Scaffolding for CLI tools
Usage
Install puff-pastry by running:
yarn add puff-pastry
Use it to create command-line executables like so:
#!/usr/bin/env node
import run from 'puff-pastry'
run('./cli.mjs', {
flags: ['--loader', 'hot-esm']
})
export default async function({cwd, env, argv, log}) {
log('Hello World!')
}
run()
takes the path to a CLI entry function and calls it with an object
containing:
-
cwd
: The current working directory -
env
: An object containing the environment variables -
argv
: The command-line arguments -
stdout
: A stream that writes to STDOUT -
stderr
: A stream that writes to STDERR
Also, if a .env.yml
file is present in the current working directory, it is
read and added to env
. See
vinsonchuong/envdotyml.
Encapsulating a CLI into a function that takes arguments instead of relying on
the process
global object allows for:
- Easier unit testing
- Easier composition of CLI tools from JavaScript