This commit is contained in:
陆柯 2019-09-10 15:00:23 +08:00
parent 1085afe7ca
commit 4e17830a03
2 changed files with 23 additions and 15 deletions

14
README.md Normal file
View File

@ -0,0 +1,14 @@
## 参数
* -t, --type: web(默认) 或 git
* 如果是 git
* -r, --repo: 'https://github.com/ORG/ORG.github.io'
* -b, --branch
* 如果是 web
* -H, --host: 远程主机
* -P, --port: 端口
* -D, --dir: 例如 /home/USER/FOLDER
* -d, --dist: 默认为 dist。例如 www
* -l, --local: 本地文件夹,例如 ../../project/public。默认为 dist
* -p, --password: 密码
* -k, --key: 密钥文件

View File

@ -5,12 +5,6 @@ const path = require('path')
const commander = require('commander')
const deepmerge = require('deepmerge')
/**
* repo: 'git@github.com:fivapp/fivapp.github.io.git',
name: 'Limo Saplf',
email: 'limosaplf@gmail.com',
*/
var Config = { deploy: {} }
// 读取配置文件
@ -36,10 +30,12 @@ commander
.version('1.0', '-v, --version') // 默认是 -V。如果要 -v就要加 '-v --version'
.option('-t, --type <type>', `Deploy to server type, web or git. Default to ${Config.deploy.type}`)
.option('-H, --host <host>', `Host IP or domain name of the target server. Default to ${Config.deploy.host}`)
.option('-P, --port <port>', `Ssh port number of the target server. Default to ${Config.deploy.port}`)
.option('-D, --dir <dir>', `Directory to deploy on the target server. Default to ${Config.deploy.dir}`)
.option('-d, --dist <dist>', `Folder to deploy on the target server. Default to ${Config.deploy.dist}`)
.option('-r, --repo <repo>', `git repo address. Default to ${Config.deploy.repo}`)
.option('-b, --branch <branch', `git repo branch. Default to ${Config.deploy.branch}`)
.option('-l, --local <local>', `Local folder to copy from. Default to ${Config.deploy.local}`)
.option('-P, --port <port>', `Ssh port number of the target server. Default to ${Config.deploy.port}`)
.option('-u, --user <user>', `User id to login the target server. Default to ${Config.deploy.user}`)
.option('-k, --key <key>', `User private key file to login the target server. Default to ${Config.deploy.key}`)
.option('-p, --password <password>', `User password to login the target server. You may have to enclose it in "". Default to "${Config.deploy.password}"`)
@ -53,6 +49,8 @@ const connection = {
port: commander.port || Config.deploy.port || 22,
dir: commander.dir || Config.deploy.dir, // 目标服务器上的目录。似乎该目录必须已经存在于服务器上
dist: commander.dist || Config.deploy.dist || 'dist', // 新系统将发布在这个文件夹里。建议为dist和npm run build产生的目录一致这样既可以远程自动部署也可以直接登录服务器手动部署。
repo: commander.repo || Config.deploy.repo,
branch: commander.branch || Config.deploy.branch || 'master',
local: commander.local || Config.deploy.local || 'dist',
username: commander.user || Config.deploy.user,
privateKey: fs.existsSync(privateKeyFile) ? privateKeyFile : undefined,
@ -156,7 +154,7 @@ function deployToGit(){
function exec() {
const baseDir = ''
const deployDir = pathFn.join(baseDir, '.deploy_git')
const publicDir = connection.dist
const publicDir = connection.local
let extendDirs = connection.extend_dirs
const ignoreHidden = connection.ignore_hidden
const ignorePattern = connection.ignore_pattern
@ -172,13 +170,7 @@ function deployToGit(){
help += 'You have to configure the deployment settings in config files or command line first!\n\n'
help += 'Example:\n'
help += ' deploy:\n'
help += ' type: git\n'
help += ' repo: <repository url>\n'
help += ' branch: [branch]\n'
help += ' message: [message]\n\n'
help += ' extend_dirs: [extend directory]\n\n'
help += 'For more help, you can check the docs: ' + chalk.underline('http://hexo.io/docs/deployment.html')
help += ' node deploy.js -t git -r https://github.com/log-home/log-home.github.io -b master -l ../../project/public'
console.log(help)
return
@ -281,6 +273,8 @@ function deployToGit(){
}).then(() => {
return parseConfig(connection)
}).each(function(repo) {
console.log('##########################')
console.log(repo)
return push(repo)
})
}