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 🙏

© 2025 – Pkg Stats / Ryan Hefner

build-deploy-cli

v1.1.1

Published

自动化部署工具 - 支持构建和上传到远程服务器

Readme

deploy-cli

自动化部署工具 - 支持构建和上传项目到远程服务器

功能特性

  • 🚀 快速部署:默认只执行构建和上传(最常用场景)
  • 🔄 完整流程:支持拉取代码、安装依赖、构建、上传的完整流程
  • 📦 多项目支持:通过 Git 地址自动匹配项目配置
  • 🔧 灵活配置:支持自定义构建命令和部署路径
  • 🔐 安全可靠:配置文件本地管理,不包含在 npm 包中

安装

npm install -g build-deploy-cli

⚡ 快速开始

重要:首次使用前,必须先初始化配置文件!

第一步:交互式配置(推荐)

在项目目录下运行:

deploy init

这会启动交互式配置向导,引导你填写所有配置信息:

  • 📝 项目名称和类型
  • 📦 构建目录和命令
  • 🖥️ 服务器信息
  • 🔐 安全的认证方式(密码/SSH密钥/环境变量)

💡 提示:如果直接运行 deploy 命令,会提示你运行 deploy init 初始化配置。

第二步:开始部署

# 快速部署(默认:只构建+上传)
deploy

# 完整流程(拉取+安装+构建+上传)
deploy --full

# 只拉取代码+构建+上传
deploy --pull

# 只安装依赖+构建+上传
deploy --install

命令行选项

  • -c, --config <path>: 指定配置文件路径(默认: deploy.config.json
  • --pull: 拉取最新代码
  • --install: 安装依赖
  • --skip-build: 跳过构建
  • --skip-upload: 跳过上传
  • --full: 完整流程(拉取+安装+构建+上传)

配置说明

配置文件字段

  • name: 项目名称(可选)
  • type: 项目类型(web/wgt/resource
  • buildDir: 构建产物目录(默认: dist
  • buildCommand: 构建命令(可选,会根据 type 自动推断)
  • deployPath: 服务器部署路径
  • server: 服务器配置
    • host: 服务器地址(IP 或域名,不需要 http:// 前缀)
    • username: SSH 用户名
    • port: SSH 端口(默认: 22)
    • authMethod: 认证方式(必填,三选一)
      • password: 密码认证(部署时交互式输入,密码不会保存在配置文件中,更安全)
      • key: SSH 密钥认证(推荐,需要配置 privateKey 字段)
      • env: 环境变量认证(需要配置 passwordEnv 字段)
    • privateKey: SSH 私钥路径(当 authMethodkey 时必填,如:~/.ssh/id_rsa
    • passwordEnv: 环境变量名(当 authMethodenv 时必填,如:DEPLOY_PASSWORD

项目类型

  • web: Web 项目,默认执行 npm run build
  • wgt: UniApp 项目,默认执行 npm run build:app-plusnpm run build:wgt
  • resource: 资源项目,不执行构建,直接上传

多项目配置

可以在配置文件中配置多个项目,工具会根据当前 Git 仓库地址自动匹配:

{
  "https://gitee.com/user/project1": {
    "name": "项目1",
    "type": "web",
    "buildDir": "dist",
    "buildCommand": "npm run build",
    "deployPath": "/var/www/html/project1",
    "server": {
      "host": "server1.com",
      "username": "root",
      "port": 22,
      "authMethod": "password"
    }
  },
  "https://gitee.com/user/project2": {
    "name": "项目2",
    "type": "web",
    "buildDir": "dist",
    "buildCommand": "npm run build",
    "deployPath": "/var/www/html/project2",
    "server": {
      "host": "server2.com",
      "username": "root",
      "port": 22,
      "authMethod": "key",
      "privateKey": "~/.ssh/id_rsa"
    }
  }
}

注意authMethod 支持三种值:

  • password: 密码认证(部署时交互式输入,密码不会保存在配置文件中)
  • key: SSH 密钥认证(需要配置 privateKey 字段)
  • env: 环境变量认证(需要配置 passwordEnv 字段)

使用示例

基本使用

# 在项目目录下
deploy

完整流程

# 拉取代码、安装依赖、构建、上传
deploy --full

只构建不上传

deploy --skip-upload

使用自定义配置文件

deploy --config my-config.json

🔐 安全建议

认证方式推荐(按安全性排序)

  1. SSH 密钥认证(最推荐) ⭐⭐⭐

    {
      "server": {
        "host": "your-server.com",
        "username": "root",
        "port": 22,
        "authMethod": "key",
        "privateKey": "~/.ssh/id_rsa"
      }
    }
    • 最安全,无需存储密码
    • 支持密钥加密(passphrase)
  2. 环境变量认证 ⭐⭐

    {
      "server": {
        "host": "your-server.com",
        "username": "root",
        "port": 22,
        "authMethod": "env",
        "passwordEnv": "DEPLOY_PASSWORD"
      }
    }
    export DEPLOY_PASSWORD="your-password"
    deploy
    • 密码不存储在配置文件中
    • 适合 CI/CD 环境
  3. 交互式密码输入

    {
      "server": {
        "host": "your-server.com",
        "username": "root",
        "port": 22,
        "authMethod": "password"
      }
    }
    • 部署时会提示交互式输入密码
    • 密码不会保存到配置文件,每次部署时输入
    • 适合偶尔部署的场景
  4. 配置文件密码(已废弃,不推荐) ⚠️

    • 旧版本支持在配置文件中直接存储密码
    • 新版本已移除此功能,改为使用 authMethod: "password" 交互式输入
    • 如果配置文件中仍有 password 字段,工具会提示不安全并继续使用(兼容旧配置)

注意事项

  1. 配置文件安全

    • 如果使用密码认证,deploy.config.json 包含敏感信息,不要提交到 Git
    • 建议添加到 .gitignore
    • 强烈推荐使用 SSH 密钥或环境变量
  2. Git 仓库

    • 工具会在当前目录检测 Git 仓库
    • 确保在项目根目录运行
  3. 服务器连接

    • 确保服务器 SSH 连接正常
    • 可以使用私钥替代密码(需要修改代码)
  4. 构建命令

    • 确保项目的 package.json 中有对应的构建脚本
    • 例如:"build": "vite build""build:app-plus": "uni build"

常见问题

1. 找不到配置文件

问题未找到配置文件: deploy.config.json

解决

  • 运行 deploy init 初始化配置
  • 或使用 --config 参数指定配置文件路径

2. Git 仓库检测失败

问题当前目录不是 Git 仓库

解决

  • 确保在 Git 仓库根目录运行
  • 检查是否有 .git 目录

3. 构建失败

问题:构建命令执行失败

解决

  • 检查 package.json 中是否有对应的构建脚本
  • 手动运行构建命令测试
  • 检查 Node.js 和 npm 版本

4. 上传失败

问题:SSH 连接失败

解决

  • 检查服务器地址、用户名、密码
  • 测试 SSH 连接:ssh username@host
  • 检查防火墙设置

开发

# 克隆项目
git clone <repository-url>
cd deploy-cli

# 安装依赖
npm install

# 本地测试
npm link

# 在项目目录下测试
deploy

License

ISC