1.2.0 • Published 4 years ago

egzek v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

egzek

Build, Test and Release npm semantic-release Gitmoji

An opinionated wrapper around child_process.execSync.


Installation

yarn add --dev egzek

Example

import { exec } from "egzek";

exec(`
  echo "commands are run sequentially" > ${filepath}
  cat ${filepath}
  rm ${filepath}
`);

Output:

 ➡ echo "commands are run sequentially" > /test-1.txt

 ➡ cat /test-1.txt
"commands are run sequentially"

 ➡ rm /test-1.txt

Why?

  • Bash is a hell to maintain. Node is a great alternative for utility scripts
  • I wanted something smaller and simpler than executive and execa.
    • small
      • 4.5kB unpacked
      • 479B gzipped, 428B Brotli.
      • 831B of uncompressed JavaScript code, 1.2kB of types.
    • simple
      • one exported function and one exported type
      • almost the same public API as child_process.execSync
        • common defaults for stdio and encoding options

Public API

import { ExecSyncOptions, StdioOptions } from "child_process";
export interface ExecOptions extends Omit<ExecSyncOptions, "encoding"> {
  /**
   * A directory in which the commands are run.
   */
  dir?: string;
  /**
   * The encoding used for all stdio inputs and outputs.
   * @default "utf-8"
   * @see https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options
   */
  encoding?: BufferEncoding;
  /**
   * Child's stdio configuration.
   * @default "inherit"
   */
  stdio?: StdioOptions;
}
export declare namespace ExecOptions {
  interface Pipe extends ExecOptions {
    stdio: "pipe" | [any, "pipe", any?];
  }
  interface Inherit extends ExecOptions {
    stdio?: "inherit" | [any, "inherit", any?];
  }
}
/**
 * @example
 *  exec(`
 *    echo "commands are run sequentially" > ${filepath}
 *    cat ${filepath}
 *  `);
 *
 * @returns array of strings when options.stdio is `pipe`, otherwise undefined
 */
export declare function exec(
  commands: string,
  options: ExecOptions.Pipe
): string[];
export declare function exec(
  commands: string,
  options?: ExecOptions.Inherit
): undefined;

Types from @types/node

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago