puff-pastry
v1.3.2
Published
Scaffolding for CLI tools
Downloads
263
Readme
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 directoryenv
: An object containing the environment variablesargv
: The command-line argumentsstdout
: A stream that writes to STDOUTstderr
: 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