Socket
Book a DemoInstallSign in
Socket

@bconnorwhite/exec

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bconnorwhite/exec

Execute commands while keeping flags easily configurable as an object.

Source
npmnpm
Version
3.1.2
Version published
Weekly downloads
83
15.28%
Maintainers
1
Weekly downloads
 
Created
Source

@bconnorwhite/exec

dependencies minzipped size typescript npm

Execute commands while keeping flags easily configurable as an object.

yarn add @bconnorwhite/exec
  • Run one or multiple commands
  • Easily define arguments and flags
  • Run commands in parallel or series
  • Inject environment variables
  • Set verbose to pass through output

API

exec

Types
exec(command: Command) => ChildProcess | SpawnSyncReturns<Buffer>

type Command = {
  command: string;
  args?: string | string[];
  flags?: Flags;
  env?: NodeJS.ProcessEnv;
  verbose?: boolean;
}

type Flags = {
  [flag: string]: string | boolean | string[] | undefined;
}
Usage
import exec from "@bconnorwhite/exec";

exec({
  command: "babel",
  args: "./src", // for multiple args, use an array instead
  flags: {
    "out-dir": "./build",
    "config-file": "./babel.config.json",
    "w": true // single character flags will be set using a single dash
  }
});

// Equivalent of:
// babel ./src --out-dir ./build --config-file ./babel.config.json -w

execAll

Types
execAll(
  commands: Command[],
  options: Options
) => Promise<(ChildProcess | SpawnSyncReturns<Buffer>)[]>

type Command = {
  command: string;
  args?: string | string[];
  flags?: Flags;
  env?: NodeJS.ProcessEnv;
  verbose?: boolean;
}

type Options = {
  env?: NodeJS.ProcessEnv; // default, will not override individual commands
  verbose?: boolean; // default, will not override individual commands
  parallel?: boolean;
}
Usage
import { execAll } from "@bconnorwhite/exec";

execAll([{
  command: "babel",
  args: ["./src"],
  flags: {
    "out-dir": "./build",
    "config-file": "./babel.config.json",
    "watch": true
  }
}, {
  command: "tsc",
  flags: {
    "emitDeclarationOnly": true
  }
}], {
  env: {
    NODE_ENV: "development"
  },
  verbose: true,
  parallel: false
});
// Equivalent of:
// NODE_ENV=development babel ./src --out-dir ./build --config-file ./babel.config.json --watch && tsc --emitDeclarationOnly

flagsToArgs

Types
flagsToArgs(flags?: Flags) => string[]

type Flags = {
  [flag: string]: string | boolean | string[] | undefined;
}
Usage
import { flagsToArgs } from "@bconnorwhite/exec";

flagsToArgs({
  "out-dir": "./build",
  "config-file": "./babel.config.json",
  "watch": true
});
// ["--out-dir", "./build", "--config-file", "./babel.config.json", "--watch"]

flagsToArgs is useful for adding flags that must preceed later arguments. For example:

import { flagsToArgs } from "@bconnorwhite/exec";

const files = [...];

exec({
  command: "wc",
  args: flagsToArgs({ l: true }).concat(files)
});
// Equivalent of:
// wc -l [FILES]...

Keywords

exec

FAQs

Package last updated on 12 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts