io-run v2.3.6
๐ IO-RUN
import 'io-run'
await $`echo Hello World!`
let branch = await $ `git rev-parse --abbrev-ref HEAD`
$ `git checkout ${branch}`
Simple to run command line for nodejs with typescript ๐ฅ
๐น Install
$ yarn add io-run
$ npm install io-run
๐จ How to use it?
import { $ } from 'io-run'
//or
import 'io-run'
The $
function executes the given command line using the spawn
function of the child process
module.
let user = await $ `whoami`
console.log(user)
If the program returns a non-zero exit code, ProcessOutput
will be thrown.
ProcessOutput {
stdout:
stderr: 'HOLY' is not recognized as an internal or external command, operable program or batch file.
code: 1
}
๐ฟ Configuration
๐ฅ๏ธ $.shell
Specifies the shell to use. Default is /bin/sh
on Unix, process.env.ComSpec
on Windows. or use cli argument: --shell
$.shell = which('powershell') //C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
which
function is implemented to find the path.
๐ $.prefix
Specifies the prefix for all commands run. or use a cli argument: --prefix
๐งพ $.verbose
Specifies verbosity. Default is false
. prints all executed commands output using process.stdout
.
๐ $.stdio
Specifies the stdio of the subprocess. The default is pipe
.
$.stdio = ['inherit', 'pipe', 'pipe'] // [stdin, stdout, stderr]
More information about
stdio
can be found here.
๐งท ELSE?
๐ cd function
: changes the current working directory.
cd('src')
await $ `node test.js`
๐ isWindow
: returns true if os is windows
.
$ `${ isWindow ? 'explorer.exe' : 'open' } https://www.google.com`
๐ License
Distributed under the MIT License. See LICENSE
for more information.
ยฉ 2022 IXFX, All rights reserved.