bash-fool
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

run a sequence of bash commands as specified by a json

codecov Version Downloads/week License

Geenee Template

Why

Frequently you need to have a cli execute several commands. The tools execa and listr make this easy, but why go to the trouble of repeating the same boilerplate each time?

What

A function that generates a listr for execution of a set of bash commands using execa. You just pass in an array of commands and a listr is generated for it. You can also have:

  • targetDir a string indicating the directory that you can use in commands. Anywhere that you use a $codeDir placeholder, it will be dynamically replaced by targetDir.
  • session an object that lets you dynamically replace other strings in your commands. You must insert a key keyName into session, and then you can use it by placing into a command specification that string __session.keyName__. For instance, __session.lastName__ could be used in a command, and session could be `{lastName: 'jones'}.

Usage

First, install the package:

npm i bash-fool

Here is a sample usage:

const bashFool = require('bash-fool')

const commands = [
  {
    'title': 'echo a string',
    'file': 'echo',
    'arguments': [
      'this is echoed: __session:echoedString',
    ],
  },
  {
    title: 'more nothing',
    file: 'echo',
    arguments: [
      'second echoed function',
    ],
  },
]

const echoedString = 'foobar'
const session = { echoedString }

const targetDir = 'nonexistent'

(async () => {
  let listr = await bashFool(commands, targetDir, session)
  await listr.run() 
     // will echo: `this is echoed: foobar` 
     // and then: `second echoed function` 
})()

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    1
  • 1.1.0
    0
  • 1.0.0
    1

Package Sidebar

Install

npm i bash-fool

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

9.61 kB

Total Files

14

Last publish

Collaborators

  • yisroel