From da8cbca952a8d6d66ccc9d37012e720927863aec Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Tue, 5 Nov 2019 14:27:07 +0800 Subject: [PATCH] deploy parameter 'local' rename to 'from' --- deploy.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/deploy.js b/deploy.js index 82e1ee3..66a6b7a 100644 --- a/deploy.js +++ b/deploy.js @@ -28,8 +28,8 @@ try { commander .version('1.0', '-v, --version') // 默认是 -V。如果要 -v,就要加 '-v --version' + .option('-f, --from ', `from path to copy from. Default to ${Config.deploy.from}`) .option('-t, --type ', `Deploy to server type, web or git. Default to ${Config.deploy.type}`) - .option('-l, --local ', `Local path to copy from. Default to ${Config.deploy.local}`) .option('-H, --host ', `Host IP or domain name of the target server. Default to ${Config.deploy.host}`) .option('-P, --port ', `Ssh port number of the target server. Default to ${Config.deploy.port}`) .option('-D, --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 connection = { + from: commander.from || Config.deploy.from || './dist', type: commander.type || Config.deploy.type || 'web', host: commander.host || Config.deploy.host, port: commander.port || Config.deploy.port || 22, @@ -55,7 +56,6 @@ const connection = { branch: commander.branch || Config.deploy.branch || 'master', gitname: commander.gitname || Config.deploy.gitname, gitemail: commander.gitemail || Config.deploy.gitemail, - local: commander.local || Config.deploy.local || './dist', username: commander.user || Config.deploy.user, privateKey: fs.existsSync(privateKeyFile) ? privateKeyFile : undefined, 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 }) console.log(`[ mkdir ${connection.dist} ... ]`) 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) { console.log(`[ mkdir ${connection.dist}/${name.join('/')} ... ]`) await ssh.execCommand(`mkdir ${connection.dist}/${name.join('/')}`, { cwd: connection.dir }) @@ -112,15 +112,15 @@ function deployToWeb(){ let err 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, recursive: true, validate: itemPath => { const baseName = path.basename(itemPath) return !baseName.endsWith('.map') }, - tick: (localPath, remotePath, error) => { - console.log(`Uploading "${localPath}" ===> "${remotePath}" ${error || 'succeeded!'}`) + tick: (fromPath, remotePath, error) => { + console.log(`Uploading "${fromPath}" ===> "${remotePath}" ${error || 'succeeded!'}`) err = error }, }) @@ -158,7 +158,7 @@ function deployToGit(){ function exec() { const baseDir = '' const deployDir = pathFn.join(baseDir, '.deploy_git') - const publicDir = connection.local + const publicDir = connection.from let extendDirs = connection.extend_dirs const ignoreHidden = connection.ignore_hidden const ignorePattern = connection.ignore_pattern @@ -189,8 +189,8 @@ function deployToGit(){ } function setup() { - const userName = connection.name || connection.user || connection.userName || '' - const userEmail = connection.email || connection.userEmail || '' + const userName = Config.deploy.gitname || '' + const userEmail = Config.deploy.gitemail || '' // Create a placeholder for the first commit return fs.writeFile(pathFn.join(deployDir, 'placeholder'), '').then(() => {