0.0.9 • Published 6 months ago

@jliocsar/pipet v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

npm (scoped) npm package minimized gzipped size (select exports) GitHub last commit (branch)

Read the docs

Introduction

terminal pipe = pipet

Pipet is a zero dependency script-running framework; it provides an easy way to build different script inputs with different arguments/environment variables based on the output from previous scripts (or just pure JS/TS). It supports any kind of binary/executable, meaning you can use scripts for any language you'd like.

It acts as a pipeline with different ways of formatting/parsing the piped input values, also allowing you to manipulate the script behavior itself (i.e. aborting the script before it finishes whenever it matches a printed value).

It's also built with TypeScript, so Pipet is really easy to learn and master.

Example

const { Pipet, B, U } = require('@jliocsar/pipet')

const initialEnv = {
  count: 0,
}

new Pipet().run(
  [
    B.script('1st-script-path.js', {
      args: {
        version: {
          boolean: true,
        },
      },
    }),
    B.bin('jstr'),
    U.log('Hello world'),
    B.script('2nd-script-path.ts', {
      bin: 'tsx', // default is `"node"`
      args: {
        countResult: {
          match: /Count is (.+) and (.+)/,
          array: true,
        },
      },
    }),
    B.decorateEnv(env => {
      env.count = '20'
      return env
    }),
    B.decorateArgs(args => {
      console.log({ args })
      return args.concat('--title=hello')
    }),
    B.script('3rd-script-path.js', {
      bin: 'bun',
      binArgs: ['run', '--bun'],
      env: {
        countResult: {
          match: /Count is (.+) and (.+)/,
          array: true,
        },
      },
    }),
    U.tap(console.log),
    B.script('last-script.py', {
      bin: 'python',
      args: {
        $: {
          match: /Count is (.+) and (.+)/,
          array: true,
          separator: ' ',
        },
      },
    }),
  ],
  {
    initialEnv,
    binArgs: ['--title=hello'],
    async beforeRun() {
      // run any setup effect (like building)
    },
    async afterRun() {
      // run any clean up effect
    },
  },
)

Installation

# with npm
npm i -D @jliocsar/pipet

# with yarn
yarn add -D @jliocsar/pipet

# with bun
bun a -D @jliocsar/pipet

Usage

Builder (B)

The B namespace exports all utility functions used for building your scripts pipeline.

B.scripts

Builds the script definition object used in the script pipeline based on the script path.

B.bin

Builds the script definition object used in the script pipeline based on a CLI binary.

B.decorateEnv

Exposes an async injector function to decorate the env. variables of the next scripts.

B.decorateArgs

Exposes an async injector function to decorate the args array of the next script.

Utilities (U)

The U namespace exports all utility functions that can be used during your pipeline process (i.e. logging something before affecting the script environment).

U.log

Logs a message to the terminal between scripts in the pipeline.

U.tap

Runs a side-effect on the accumulated array of results.

U.sleep

Sleeps N seconds between scripts run.

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago