npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sheller

v0.0.7

Published

sheller: Perform a series of local and remote commands

Downloads

23

Readme

sheller

Build Status 依赖模块状态 浏览数

sheller一个用于执行本地和远程服务器命令的nodejs模块。可执行本地命令,可连接远程服务器执行远程机的命令,也可以 通过配置顺序执行一系列的命令(本地和远程),像一个shell脚本一样,但这里只需要命令一条条配置出来就行,而且可以依赖前面执行的命令结果,帮你完成一系列任务的自动化处理。

grunt插件 grunt-shelltask


下载安装

npm install sheller

文档

  1. sheller.execLocal 执行本地命令的方法
    • 参数:
      • command [String] 命令字符串
      • cwd [String] 可选,当前路径
      • callback [Function] 可选,回调函数,第一个参数为错误信息,第二个参数为命令结果
  2. sheller.execSingleTask 执行单个命令任务
    • 参数:
      • cfg [Object] 任务配置对象
      • callback [Function] 回调函数,第一个参数为错误信息,第二个参数为命令任务结果数组
    • cfg格式:
    {
        options:{},//参数配置,可选
        task:[] //命令配置,具体参考下方例子
    }
  3. sheller.loadTasks 加载任务配置
    • 参数:config [Object/String] json对象或配置文件路径字符串 flag [Boolean] true/false 默认false merge/cover
    • 配置文件格式:
    module.exports = {
        "options": {
            //......
        },
        "task1": {
            "options": {
                //......
            },
            "task": [
                //......
            ]    
        },
        "task2": {
            //......
        } 
    };
  4. sheller.execTask 执行已加载的任务
    • 参数:
      • arr [Array] 需要执行的任务名数组,按指定数组顺序执行
      • callback [Function] 回调函数,第一个参数为错误信息,第二个参数为命令任务结果数组
  5. sheller.getssh 获得一个ssh远程的连接对象
    • 参数:
      • name [String] 远程连接的名称(自定义),可为空
      • cfg [Object] 远程机信息,包含地址、用户名及密码
    • cfg格式:
    {
        "host" : "",//ip地址
        "username" : "",//用户名
        "password" : "",//密码
        "workPath" : ""//执行路径,可选
    }
    • 连接对象有两个方法:
      • exec: 执行命令,参数command、callback
      • close: 关闭连接
  6. sheller.clear 清除当前已加载的任务和配置。

Usage Examples

var sheller = require('sheller');
//执行本地命令
sheller.execLocal("echo test", function (err, data){
        if(err){
            console.log(err);
        }else{
            console.log(data);//test
        }
    });
//执行单个命令任务
sheller.execSingleTask({
        options: {
            "testParam": "test"
        },
        task: [
            {
                command: "echo [%= testParam %]",
                after: function (data){
                    return data.replace(/(^\s+)|(\s+$)/, '');
                }
            }
        ]
    }, function (err, data){
        if(err){
            console.log(err);
        }else{
            console.log(data);//["test"]
        }
    });
//加载配置文件
sheller.loadTasks("./tasklist.js");
//执行任务
sheller.execTask(["task1"], function (err, data){
        if(err){
            console.log(err);
        }else{
            console.log(data);//result array
        }
    });

配置文件tasklist.js

module.exports = {
    "options": {
        //本地命令执行路径
        // "localWorkPath" : "E://workspace/",
        //远程机
        "rs110" : {
            "host" : "100.100.100.110",
            "username" : "test110",
            "password" : "123456",
            "workPath" : "/data1/nginx/htdocs/online"
        },
        "rs112" : {
            "host" : "100.100.100.112",
            "username" : "test112",
            "password" : "123456"
        },
        "testParam": "test sheller"
    },
    "task1": {
        "options": {
            // "localWorkPath" : "E://workspace/",
            name: "test options"
        },
        "task": [
            {
                "command": "echo test"
            },{
                "id": "test1",
                "command": "echo test1"
            },{
                "command": "echo test2",
                "after": function (data){
                    return {
                        data: data.replace(/(^\s+)|(\s+$)/, ''),
                        status: 1
                    };
                }
            },{
                "command": function (prev){
                    console.log(prev.ret.status == 1);//true
                    console.log(this.getResult("test1"));//test1
                    console.log(this.getResult());//test
                    console.log(this.getResult(2));//test2
                    console.log(this.options.name);//test options
                    console.log(this.task[0].command);//echo test                    
                    console.log(this.task[0].ret);//test
                    return "exit";
                }
            },{
                command: "echo test end",//不会执行,因为上个命令exit退出了
                remote: "rs110"
            }
        ]    
    },
    "task2": {
        "options": {
        
        },
        "task": [
            {
                "command": "cd"
            }
        ]
    } 
};

License

MIT license