0.10.3 • Published 5 years ago

unshell v0.10.3

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

un shell

Set your shell free !

npm.io

Combine the flexibility of a programming language with the knowledge of shell command. As developer, sometimes, we need to run shell scripts. It will be cool to do so with the familiarity of a programming language. An an ops, sometimes, we need to run complex shell scripts. It will be cool to do so with the power of a programming language.

Features

  • Light: There are no dependencies
  • Easy: A small abstraction over child_process
  • Async: Work with async/await command
  • Testable: Unshell script are easily testable because they yield execution control

Setup

Execute script through Shell

npm install -g unshell

Embedded script inside apps

npm install unshell

Usage

Execute script through Shell

Execute script through unshell runtime

Usage:
  unshell COMMAND [SCRIPT_PATH] [ARGS...]

Commands:
  help      Print this help message
  run       run a script through unshell runtime

Given the script: pause.js to pause all docker containers

module.exports = function * pause () {
  const ids = yield * fetchContainerIds()

  for(const id of ids) {
    yield `docker pause ${id}`
  }
}

function * fetchContainerIds () {
  const ids = yield `docker ps -q --no-trunc`

  return ids.split('\n').filter(Boolean)
}

Run it through unshell

unshell run pause.js

Embedded script inside apps

Given the precedent script pause.js Run it with zeit/micro

module.exports = (req, res) => {
  const {resolve} = require('path')
  const {unshell} = require('unshell')

  try {
    const script = require(resolve('./scripts/pause.js'))
    unshell({env: process.env})(script)

    res.end('OK')
  } catch (err) {
    res.end('NOK')
  }
}

Examples

Here is some examples of what you can do with unshell

Contribute

Please check out the issues labeled help wanted or good-first-issue. Try npx good-first-issue unshell

License

The code is available under the MIT license.

0.10.3

5 years ago

0.10.2

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago