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

au_deploy

v1.0.1

Published

Automatically deploy the package to the server

Downloads

827

Readme

au_deploy

au_deploy 是一个基于 SFTP 的自动化部署命令行工具,用于把本地打包产物上传到服务器指定目录。

它会根据当前执行命令所在目录,自动推导本地打包产物路径和服务器发布目录。上传时会先把新版本传到 .uploading 临时路径,上传成功后再备份旧版本并切换到正式路径,尽量避免上传中断导致线上目录缺失或内容不完整。

特性

  • 自动识别当前项目名,并上传对应的打包产物。
  • 支持目录和单文件上传。
  • 上传前自动清理上一次残留的 .uploading 临时路径。
  • 已存在同名远端文件或目录时,会先重命名为备份。
  • 备份名格式为 原文件名.bakYYYYMMDD.HHMMSS,例如 au_deploy.bak20260707.125959
  • 自动清理 48 小时前的历史备份,近 48 小时内的备份会保留。
  • 目录上传显示文件数量进度,单文件上传显示字节进度。
  • 支持通过 AU_DEPLOY_PASSWORD 环境变量传入服务器密码,减少密码出现在命令历史中的风险。

安装

全局安装:

npm install -g au_deploy

也可以在项目中安装:

npm install -D au_deploy

如果发布 npm 时改成了 scoped package,例如 @your-scope/au_deploy,安装命令中的包名替换成实际包名即可。

使用方式

推荐使用环境变量传入服务器密码:

AU_DEPLOY_PASSWORD=<password> au_deploy --host <host> --port <port> --root <username>

示例:

AU_DEPLOY_PASSWORD=****** au_deploy --host 120.25.233.113 --port 22 --root h5_dev

如果是项目内安装,也可以通过 npx 执行:

AU_DEPLOY_PASSWORD=<password> npx au_deploy --host <host> --port <port> --root <username>

兼容旧用法,也可以通过 --password 传入密码:

au_deploy --host <host> --port <port> --root <username> --password <password>

不推荐长期使用 --password,因为命令参数可能出现在 shell history 或进程列表中。

参数说明

| 参数 | 必填 | 说明 | | --- | --- | --- | | --host | 是 | 服务器地址 | | --port | 是 | SSH/SFTP 端口,通常为 22 | | --root | 是 | 服务器登录用户名 | | --password | 否 | 服务器登录密码;建议改用 AU_DEPLOY_PASSWORD |

环境变量

| 环境变量 | 说明 | | --- | --- | | AU_DEPLOY_PASSWORD | 服务器登录密码 |

macOS / Linux 可以临时这样使用:

AU_DEPLOY_PASSWORD=****** au_deploy --host <host> --port 22 --root <username>

也可以写入当前 shell 配置中,例如 ~/.zshrc

export AU_DEPLOY_PASSWORD="你的服务器密码"

然后重新加载配置:

source ~/.zshrc

CI/CD 中建议把 AU_DEPLOY_PASSWORD 配置到平台提供的 Secret / Environment Variables 中,不要提交到代码仓库。

目录约定

脚本会以“执行命令时所在目录”为当前项目目录:

currentDirName = 当前目录名
parentName     = 当前目录的父级目录名

本地打包产物路径会根据父级目录名推导:

| 父级目录名 | 本地打包产物根目录 | | --- | --- | | skills | act_test | | act_dev | act_test | | page_dev | page_test |

例如当前执行目录是:

/project/act_dev/au_deploy

则脚本会尝试上传:

/project/act_test/au_deploy

服务器目标目录也会根据父级目录名推导:

| 父级目录名 | 服务器目标目录 | | --- | --- | | skills | remote/h5/act | | act_dev | remote/h5/act | | page_dev | remote/h5 |

如果父级目录名不在上述配置中,脚本会直接报错,避免误上传到错误目录。

部署流程

假设当前项目名为 au_deploy,服务器正式路径为:

remote/h5/act/au_deploy

部署时流程如下:

  1. 校验本地打包产物是否存在。
  2. 连接服务器。
  3. 确保服务器目标目录存在。
  4. 清理残留的临时上传路径,例如 remote/h5/act/au_deploy.uploading
  5. 上传新版本到 .uploading 临时路径。
  6. 上传成功后,清理 48 小时前的历史备份。
  7. 如果服务器存在同名正式路径,则重命名为备份,例如 au_deploy.bak20260707.125959
  8. .uploading 临时路径重命名为正式路径。
  9. 如果正式路径切换失败,脚本会尝试把刚才生成的备份恢复回正式路径。

备份和清理规则

当服务器已存在同名文件或目录时,不会直接覆盖,而是先重命名为备份:

au_deploy -> au_deploy.bak20260707.125959

备份清理规则:

  • 只清理与当前上传目标同名的备份。
  • 只清理超过 48 小时的备份。
  • 近 48 小时内的备份会保留,方便回滚。

例如当前上传目标是 au_deploy,脚本只会处理类似下面的备份:

au_deploy.bak20260707.010135
au_deploy.bak20260707.010234

不会处理其他项目的备份文件。

上传进度

目录上传时,进度按已上传文件数量统计:

上传进度:3/20 (15%) 目标文件 -> remote/h5/act/au_deploy/index.html

单文件上传时,进度按字节大小统计:

上传进度:256.0KB/1.2MB (21%)

注意事项

  • 请在源码项目目录中执行命令,不要在打包产物目录中执行。
  • 执行目录的父级目录名必须是 skillsact_devpage_dev
  • 服务器需要允许当前账号通过 SFTP 创建目录、上传文件、重命名和删除文件。
  • AU_DEPLOY_PASSWORD 只存在于运行环境中,不应该写入 README 示例之外的真实密码,也不要提交到 Git。
  • 如果部署中断,下次部署会先清理残留的 .uploading 临时路径。

常见问题

为什么推荐使用 AU_DEPLOY_PASSWORD

因为 --password 属于命令行参数,可能被 shell history 记录,也可能在命令运行期间通过进程列表看到。环境变量也不是绝对安全,但比把密码直接写在命令参数里更适合作为 npm CLI 的默认方案。

服务器没有同名文件时会发生什么?

脚本会输出新文件/目录提示,不会生成备份,上传完成后直接把 .uploading 临时路径切换为正式路径。

上传失败会影响线上目录吗?

如果失败发生在临时上传阶段,正式路径不会被移动。如果失败发生在最终切换阶段,脚本会尝试把刚刚重命名出来的备份恢复为正式路径。

作者:龍