deploy parameter 'local' rename to 'from'
This commit is contained in:
parent
0840eb01c3
commit
da8cbca952
18
deploy.js
18
deploy.js
@ -28,8 +28,8 @@ try {
|
|||||||
|
|
||||||
commander
|
commander
|
||||||
.version('1.0', '-v, --version') // 默认是 -V。如果要 -v,就要加 '-v --version'
|
.version('1.0', '-v, --version') // 默认是 -V。如果要 -v,就要加 '-v --version'
|
||||||
|
.option('-f, --from <from>', `from path to copy from. Default to ${Config.deploy.from}`)
|
||||||
.option('-t, --type <type>', `Deploy to server type, web or git. Default to ${Config.deploy.type}`)
|
.option('-t, --type <type>', `Deploy to server type, web or git. Default to ${Config.deploy.type}`)
|
||||||
.option('-l, --local <local>', `Local path to copy from. Default to ${Config.deploy.local}`)
|
|
||||||
.option('-H, --host <host>', `Host IP or domain name of the target server. Default to ${Config.deploy.host}`)
|
.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('-P, --port <port>', `Ssh port number of the target server. Default to ${Config.deploy.port}`)
|
||||||
.option('-D, --dir <dir>', `Destination path to deploy on the target server. Default to ${Config.deploy.dir}`)
|
.option('-D, --dir <dir>', `Destination path to deploy on the target server. Default to ${Config.deploy.dir}`)
|
||||||
@ -46,6 +46,7 @@ commander
|
|||||||
const privateKeyFile = commander.key || Config.deploy.key || `${process.env.HOME}/.ssh/id_rsa`
|
const privateKeyFile = commander.key || Config.deploy.key || `${process.env.HOME}/.ssh/id_rsa`
|
||||||
|
|
||||||
const connection = {
|
const connection = {
|
||||||
|
from: commander.from || Config.deploy.from || './dist',
|
||||||
type: commander.type || Config.deploy.type || 'web',
|
type: commander.type || Config.deploy.type || 'web',
|
||||||
host: commander.host || Config.deploy.host,
|
host: commander.host || Config.deploy.host,
|
||||||
port: commander.port || Config.deploy.port || 22,
|
port: commander.port || Config.deploy.port || 22,
|
||||||
@ -55,7 +56,6 @@ const connection = {
|
|||||||
branch: commander.branch || Config.deploy.branch || 'master',
|
branch: commander.branch || Config.deploy.branch || 'master',
|
||||||
gitname: commander.gitname || Config.deploy.gitname,
|
gitname: commander.gitname || Config.deploy.gitname,
|
||||||
gitemail: commander.gitemail || Config.deploy.gitemail,
|
gitemail: commander.gitemail || Config.deploy.gitemail,
|
||||||
local: commander.local || Config.deploy.local || './dist',
|
|
||||||
username: commander.user || Config.deploy.user,
|
username: commander.user || Config.deploy.user,
|
||||||
privateKey: fs.existsSync(privateKeyFile) ? privateKeyFile : undefined,
|
privateKey: fs.existsSync(privateKeyFile) ? privateKeyFile : undefined,
|
||||||
password: commander.password || Config.deploy.password,
|
password: commander.password || Config.deploy.password,
|
||||||
@ -104,7 +104,7 @@ function deployToWeb(){
|
|||||||
await ssh.execCommand(`mv ${connection.dist} ${connection.dist}-backup-${new Date().toISOString()}`, { cwd: connection.dir })
|
await ssh.execCommand(`mv ${connection.dist} ${connection.dist}-backup-${new Date().toISOString()}`, { cwd: connection.dir })
|
||||||
console.log(`[ mkdir ${connection.dist} ... ]`)
|
console.log(`[ mkdir ${connection.dist} ... ]`)
|
||||||
await ssh.execCommand(`mkdir ${connection.dist}`, { cwd: connection.dir })
|
await ssh.execCommand(`mkdir ${connection.dist}`, { cwd: connection.dir })
|
||||||
const toCreate = necessaryPath(path.join('./', connection.local))
|
const toCreate = necessaryPath(path.join('./', connection.from))
|
||||||
for (const name of toCreate) {
|
for (const name of toCreate) {
|
||||||
console.log(`[ mkdir ${connection.dist}/${name.join('/')} ... ]`)
|
console.log(`[ mkdir ${connection.dist}/${name.join('/')} ... ]`)
|
||||||
await ssh.execCommand(`mkdir ${connection.dist}/${name.join('/')}`, { cwd: connection.dir })
|
await ssh.execCommand(`mkdir ${connection.dist}/${name.join('/')}`, { cwd: connection.dir })
|
||||||
@ -112,15 +112,15 @@ function deployToWeb(){
|
|||||||
|
|
||||||
let err
|
let err
|
||||||
console.log(`[ Upload to ${connection.dir}/${connection.dist} ... ]`)
|
console.log(`[ Upload to ${connection.dir}/${connection.dist} ... ]`)
|
||||||
await ssh.putDirectory(path.join('./', connection.local), `${connection.dir}/${connection.dist}`, {
|
await ssh.putDirectory(path.join('./', connection.from), `${connection.dir}/${connection.dist}`, {
|
||||||
concurrency: 10,
|
concurrency: 10,
|
||||||
recursive: true,
|
recursive: true,
|
||||||
validate: itemPath => {
|
validate: itemPath => {
|
||||||
const baseName = path.basename(itemPath)
|
const baseName = path.basename(itemPath)
|
||||||
return !baseName.endsWith('.map')
|
return !baseName.endsWith('.map')
|
||||||
},
|
},
|
||||||
tick: (localPath, remotePath, error) => {
|
tick: (fromPath, remotePath, error) => {
|
||||||
console.log(`Uploading "${localPath}" ===> "${remotePath}" ${error || 'succeeded!'}`)
|
console.log(`Uploading "${fromPath}" ===> "${remotePath}" ${error || 'succeeded!'}`)
|
||||||
err = error
|
err = error
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -158,7 +158,7 @@ function deployToGit(){
|
|||||||
function exec() {
|
function exec() {
|
||||||
const baseDir = ''
|
const baseDir = ''
|
||||||
const deployDir = pathFn.join(baseDir, '.deploy_git')
|
const deployDir = pathFn.join(baseDir, '.deploy_git')
|
||||||
const publicDir = connection.local
|
const publicDir = connection.from
|
||||||
let extendDirs = connection.extend_dirs
|
let extendDirs = connection.extend_dirs
|
||||||
const ignoreHidden = connection.ignore_hidden
|
const ignoreHidden = connection.ignore_hidden
|
||||||
const ignorePattern = connection.ignore_pattern
|
const ignorePattern = connection.ignore_pattern
|
||||||
@ -189,8 +189,8 @@ function deployToGit(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
const userName = connection.name || connection.user || connection.userName || ''
|
const userName = Config.deploy.gitname || ''
|
||||||
const userEmail = connection.email || connection.userEmail || ''
|
const userEmail = Config.deploy.gitemail || ''
|
||||||
|
|
||||||
// Create a placeholder for the first commit
|
// Create a placeholder for the first commit
|
||||||
return fs.writeFile(pathFn.join(deployDir, 'placeholder'), '').then(() => {
|
return fs.writeFile(pathFn.join(deployDir, 'placeholder'), '').then(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user