0.23.0 • Published 3 months ago

@rondymesquita/nutshell v0.23.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Nutshell

Write better shell scripts using NodeJS

Create a example.js

#!/usr/bin/env nutshell

;(async () => {
  run`echo "Hello"`

  run`
    echo "Multiline commands"
    echo "using template literals"
  `
  await withContext(() => {
    run`
      echo "I am running"
      echo "in a separated process"
    `
  })
})()

Run:

./example.js

Require

const {
  ls,
  run,
  withContext,
} = require('@rondymesquita/nutshell')

;(async () => {
  run`echo "Hello"`

  await withContext(() => {
    ls()
  })
})()

Run:

node example.js

Using Typescript

For usage with Typescript, change intepreter to any typescript interpreter like tsx or ts-node.

https://github.com/esbuild-kit/tsx https://www.npmjs.com/package/ts-node

#!/usr/bin/env tsx

// import to enable type checking
import '@rondymesquita/nutshell/src/globals'

;(async () => {
  run`echo "Hello"`

  run`
    echo "Multiline commands"
    echo "using template literals"
  `
  await withContext(() => {
    run`
      echo "I am running"
      echo "in a separated process"
    `
  })
})()
./example.ts

Import

import { ls, run, withContext } from '@rondymesquita/nutshell'

;(async () => {
  run`echo "Hello"`

  await withContext(() => {
    ls()
  })
})()

Run:

tsx example.ts

Using with tasks

@rondymesquita/tasks

const unit = async() => {
  run`echo "Hello"`

  run`
    echo "Multiline commands"
    echo "using template literals"
  `
  await withContext(async() => {
    run`
      echo "I am running"
      echo "in a separated process"
    `
  })

  ls()
}

tasks({ unit, })
$ node file.js unit

Configuration

Set custom configuration with setConfig

TBD

Configuration options

TBD

API

TBD

Motivation

Sometimes, writing shell scripts can be challenging, specially when we need to do conditionals, loops, reading files like JSON or YAML. Nutshell helps in these cases leveraging the knowledge in Javascript without being too far of Shell Scripts.

Logo By icons8

Inspired by Google zx, but using libraries I personaly prefer.

0.23.0

3 months ago

0.21.0

8 months ago

0.20.0

8 months ago

0.19.0

8 months ago

0.18.0

8 months ago

0.22.0

8 months ago

0.10.0

11 months ago

0.11.0

11 months ago

0.9.0

11 months ago

0.12.0

11 months ago

0.8.0

11 months ago

0.13.0

11 months ago

0.14.0

11 months ago

0.15.0

11 months ago

0.16.0

11 months ago

0.17.0

11 months ago

0.7.0

12 months ago

0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.1

2 years ago