1.0.0 • Published 8 years ago

local-shell v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Local Shell

Local shell is a util to manage shell commands in asynchronous way like it's executed remotely. It has the same interface as Ssh-Shell to simplify usage.

Installation

Install via npm

npm i local-shell

Example

Example of variable usage:

const LocalShell = require('local-shell');
const fs = require('fs');

const shell = new LocalShell({
    cwd: process.cwd(),
});

shell.set('NAME', 'World');
shell.exec('echo Hello $NAME')
.then(result => {
    var {code, io} = result;
    if (code) {
        throw new Error('Exit code is ' + code);
    }

    console.log(io.toString()); // -> Hello World
});

API

exec(cmd:String) -> Promise<{code,io},Error>

Execute command and return promised Result object.

open()

Added for compatibility with SshShell

Start session. Emit open event.

close()

Added for compatibility with SshShell

Stop session. Emit close event.

uploadFile(source:String, dest:String) -> Promise(<null,Error>)

Upload file from source to destination. Destination is resolving from cwd value. If destination not set than it replaces with source's filename.

uploadBuffer(source:Buffer, dest:string) -> Promise(<null,Error>)

Upload data from buffer to the server.

downloadFile(source:String, dest:String)

Download file from source into destination. If destination not set than it replaces with source's filename.