@rondymesquita/nutshell
v0.23.0
Published
Write better shell scripts using NodeJS
Downloads
33
Readme
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
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.