1.0.3 • Published 4 years ago

@oauthanon/scripting v1.0.3

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
4 years ago

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 and STDERR.
    • Writes to process.stdout and process.stderr.
    • Returns captured STDOUT and STDERR strings.
  • 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
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago