@liuyinlin/upload-server
v1.0.12
Published
上传本地文件夹到 Linux 服务器
Downloads
5
Readme
上传本地文件到 Linux 服务器
使用场景:将打包的产物上传到部署服务器
安装
npm i @liuyinlin/upload-server -g
安装完成后,会提供 upload [command] [options]
命令
配置文件
生成配置文件
在当前目录下生成 upload-server.config.mjs
文件
upload init
支持以下配置文件的文件名
upload-server.config.json
upload-server.config.js
upload-server.config.ts
upload-server.config.mjs
upload-server.config.cjs
配置文件选项
export declare type Config = {
/**
* 服务器 ip
*/
host: string;
/**
* 端口
* @default 22
*/
port?: number;
/**
* 用户名
* @default 'root'
*/
username?: string;
/**
* 密码
*/
password: string;
/**
* 上传到服务器的路径
*/
serverPath: string;
/**
* 本地目录
* @default 'dist'
*/
localDir?: string;
/**
* 上传成功后是否删除本地文件
* @default true
*/
deleteLocalFile?: boolean;
/**
* 在删除服务器文件前,是否需要确认文件路径,如果为 `false` 则不会提示
* @default true
*/
confirmServerFilePath?: boolean;
};
上传文件
在上传文件之前,会先删除服务器的文件,命令行会提示你是否要删除,选择 y
即可,若发现文件路径不正确,选择 n
即可取消删除,也会取消上传
upload [-m, --mode mode]
-m, --mode:指定
.env
的 mode例如:
upload -m dev
将会读取.env.dev
和.env
文件,前者会覆盖后者同名属性
配置文件使用环境变量
执行 upload
会默认读取 .env
文件(如果存在)
# .env
SERVER_USERNAME=root
SERVER_PASSWORD=123456
使用环境变量替换,语法 %ENV_NAME%
/**
* @type {import('@liuyinlin/upload-server').Config}
*/
export default {
host: '127.0.0.1',
port: 22,
username: '%SERVER_USERNAME%',
password: '%SERVER_PASSWORD%',
serverPath: '/usr/local/nginx/html/dist',
localDir: 'dist',
deleteLocalFile: true
};
如果你的配置文件是 js
,也可以直接使用 process.env
来读取环境变量
/**
* @type {import('@liuyinlin/upload-server').Config}
*/
export default {
host: '127.0.0.1',
port: 22,
username: process.env.SERVER_USERNAME,
password: process.env.SERVER_PASSWORD',
serverPath: '/usr/local/nginx/html/dist',
localDir: 'dist',
deleteLocalFile: true
}