1.0.3 • Published 4 years ago
@oauthanon/scripting v1.0.3
OAuthAnon: Scripting
Collection of utilities used to make TypeScript CLI applications and "shell" scripts.
Function: main
Simple async main function for CLIs.
- Provides an async closure.
- Prints simple error message and exits with a non-zero exit code on errors.
import { main } from '@oauthanon/utils';
main(async () => {
await someAsyncFunction();
});
Function: exec
Simple async child process execution to enable Javascript as a scripting language.
- Prints out the executed command.
- Inherits
STDIN
. - Forks
STDOUT
andSTDERR
.- Writes to
process.stdout
andprocess.stderr
. - Returns captured
STDOUT
andSTDERR
strings.
- Writes to
- Exits immediately on non-zero exit code!
import { main, exec } from '@oauthanon/utils';
main(async () => {
const [stdout] = await exec('echo', 'Hello, world!');
});
Function: sigint
Add a SIGINT
handler which invokes an async handler for graceful shutdown.
- Only calls the handler once.
- Calls
process.exit()
when the handler promise resolves. - Exits immediately on subsequent signals.
import { sigint } from '@oauthanon/utils';
sigint(async () => {
await doShutdownStuff();
});
CLI: chmodx <glob> [<globs...>]
Utility to make files matching one or more glob patterns, executable.
chmodx lib/**/*-cli.js