@saiweng/fast-publish
v1.2.1
Published
SFTP 部署 CLI 工具,支持多环境配置与交互式发布
Downloads
492
Readme
@saiweng/fast-publish
基于 SFTP 的前端部署 CLI 工具,支持多环境配置与交互式发布。
安装
# 全局安装(推荐,任意目录可用)
npm install -g @saiweng/fast-publish
# 或作为项目 devDependency
npm install --save-dev @saiweng/fast-publish快速开始
1. 在项目根目录创建 fastpublish.config.ts
import { defineConfig } from '@saiweng/fast-publish'
export default defineConfig({
environments: {
test: {
host: '192.168.1.100',
port: 22,
user: 'root',
password: 'your-password',
remotePath: '/var/www/html/test',
localDir: 'dist', // 可选,默认 'dist'
},
pro: {
host: 'prod.example.com',
port: 22,
user: 'deploy',
password: 'your-password',
remotePath: '/var/www/html',
localDir: 'dist',
},
},
})2. 构建项目
npm run build3. 执行发布
fast-publish交互界面效果:
◆ fast-publish v1.0.0
│
◆ 请选择发布环境(空格选择,回车确认)
│ ◻ test 192.168.1.100:/var/www/html/test
│ ◻ pro prod.example.com:/var/www/html
└
⠸ [test] 正在上传 dist → /var/www/html/test
◆ [test] 上传成功 共 42 个文件
⠸ [pro] 正在上传 dist → /var/www/html
◆ [pro] 上传成功 共 42 个文件
◆ 所有环境部署完成 ✓在 package.json 中配置脚本
{
"scripts": {
"deploy": "fast-publish",
"build:deploy": "npm run build && fast-publish"
}
}配置项说明
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|------|------|------|--------|------|
| host | string | ✅ | — | SFTP 服务器地址 |
| port | number | — | 22 | SFTP 端口 |
| user | string | ✅ | — | SSH 用户名 |
| password | string | ✅ | — | SSH 密码 |
| remotePath | string | ✅ | — | 服务器目标目录 |
| localDir | string | — | 'dist' | 本地上传目录(相对项目根目录) |
多环境示例
import { defineConfig } from '@saiweng/fast-publish'
export default defineConfig({
environments: {
dev: {
host: '10.0.0.1',
user: 'root',
password: 'dev-pass',
remotePath: '/var/www/dev',
},
test: {
host: '10.0.0.2',
user: 'root',
password: 'test-pass',
remotePath: '/var/www/test',
},
pro: {
host: 'prod.example.com',
user: 'deploy',
password: 'prod-pass',
remotePath: '/var/www/html',
},
},
})运行 fast-publish 后,通过空格多选目标环境,回车确认,所有选中的环境将依次上传并展示各自结果。
注意事项
fastpublish.config.ts包含服务器密码,请将其加入.gitignore,避免泄露到代码仓库- 上传前请确保
localDir目录已存在(即先执行构建) - 需要 Node.js >= 18
