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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pgy-deploy

v1.2.0

Published

使用ssh2实现代码发布

Readme

pgy-deploy

使用 SSH2 与 SCP2 实现的自动化代码部署工具。

设计理念

  • 简化打包后提交到服务器的繁琐操作
  • 前置与后置命令用于解决项目文件发布后需要执行部分命令的需求
  • 安全确认机制,防止误操作

环境

Node.js >= 12

安装

# npm
npm i pgy-deploy -g

# yarn
yarn global add pgy-deploy

快速开始

# 1. 初始化配置文件
pgy-deploy init

# 2. 编辑 deploy.json 配置

# 3. 执行部署
pgy-deploy -i test

配置文件

默认配置文件:deploy.json(UTF-8)

配置文件默认在执行命令的当前目录下,支持自定义路径和名称。

{
    "test": {
        "serverName": "测试服务器",
        "loginWay": 0,
        "host": "192.168.1.100",
        "port": 22,
        "username": "root",
        "password": "your_password",
        "privateKeyPath": "",
        "localPath": "./dist",
        "serverPath": "/var/www/html",
        "connectTimeout": 30000,
        "cmdTimeout": 60000,
        "preCmd": "cd /var/www && mkdir -p backup",
        "rearCmd": [
            "cd /var/www/html",
            "npm install --production",
            "pm2 restart app"
        ]
    },
    "prod": {
        "serverName": "生产服务器",
        "loginWay": 1,
        "host": "10.0.0.100",
        "port": 22,
        "username": "deploy",
        "password": "",
        "privateKeyPath": "~/.ssh/id_rsa",
        "localPath": "./dist",
        "serverPath": "/var/www/html",
        "connectTimeout": 30000,
        "cmdTimeout": 120000,
        "preCmd": "cd /var/www && mkdir -p backup",
        "rearCmd": [
            "cd /var/www/html",
            "npm install --production",
            "pm2 restart app"
        ]
    }
}

配置项说明

| 字段 | 必填 | 说明 | |------|------|------| | serverName | 否 | 服务器简称,方便管理 | | loginWay | 是 | 登录方式:0-密码,1-证书 | | host | 是 | 服务器 IP 地址 | | port | 是 | 端口号 | | username | 是 | 登录用户名 | | password | 条件 | 登录密码(loginWay=0 时必填) | | privateKeyPath | 条件 | 证书路径(loginWay=1 时必填),支持 ~ 展开 | | localPath | 是 | 本地文件路径 | | serverPath | 是 | 服务器文件路径 | | connectTimeout | 否 | SSH 连接超时(毫秒),默认 30000 | | cmdTimeout | 否 | 命令执行超时(毫秒),默认 60000 | | preCmd | 否 | 前置命令,支持字符串或数组 | | rearCmd | 否 | 后置命令,支持字符串或数组 |

命令

执行部署

pgy-deploy -i <key>

示例:

# 部署到测试环境
pgy-deploy -i test

# 部署到生产环境
pgy-deploy -i prod

# Dry Run 模式(预览操作,不实际执行)
pgy-deploy -i prod --dry-run

查看配置

# 查看当前配置文件信息
pgy-deploy -config

# 查看指定配置项
pgy-deploy -config prod

修改配置文件路径

# 设置自定义配置文件
pgy-deploy -d myconfig.json

# 设置相对路径
pgy-deploy -d ../config/deploy.json

# 设置绝对路径
pgy-deploy -d C:/Users/my/Desktop/deploy.json

# 重置为默认配置文件
pgy-deploy -d

初始化配置

# 在当前目录创建 deploy.json(基于模板)
pgy-deploy init

查看版本

pgy-deploy -v

显示帮助

pgy-deploy ?

安全特性

  • 部署前确认:显示部署信息,需要用户输入 y 确认
  • Dry Run 模式:使用 --dry-run 预览将执行的操作
  • 敏感信息保护.gitignore 已配置忽略配置文件

错误处理

  • SSH 连接超时:默认 30 秒,可配置
  • 命令执行超时:默认 60 秒,可配置
  • 优雅退出:错误时自动清理资源

License

ISC