From 2d28391d454652987793adde0af5703e57e120b0 Mon Sep 17 00:00:00 2001 From: "luk.lu" Date: Wed, 30 Nov 2022 13:22:00 +0800 Subject: [PATCH] rename targetDir to targetFolder in deploy config --- deploy.js | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/deploy.js b/deploy.js index d283124..b62c6f3 100644 --- a/deploy.js +++ b/deploy.js @@ -36,8 +36,8 @@ const wo = (global.wo = { 'Destination path to deploy on the target.' ], [ - 'targetDir', - '-D, --targetDir ', + 'targetFolder', + '-D, --targetFolder ', 'Destination folder to deploy on the target.' ], @@ -68,7 +68,7 @@ const wo = (global.wo = { host: undefined, port: 22, targetPath: undefined, // 目标服务器上的目录。似乎该目录必须已经存在于服务器上 - targetDir: '_webroot', // 新系统将发布在这个文件夹里。建议为dist,和npm run build产生的目录一致,这样既可以远程自动部署,也可以直接登录服务器手动部署。 + targetFolder: '_webroot', // 新系统将发布在这个文件夹里。建议为dist,和npm run build产生的目录一致,这样既可以远程自动部署,也可以直接登录服务器手动部署。 user: undefined, password: undefined, privateKey: `${process.env.HOME}/.ssh/id_rsa` @@ -152,36 +152,38 @@ function deployToSsh (connection) { .connect(connection) .then(async () => { console.log( - `[ mv ${connection.targetDir} ${ - connection.targetDir + `[ mv ${connection.targetFolder} ${ + connection.targetFolder }-backup-${new Date().toISOString()} ... ]` ) await ssh.execCommand( - `mv ${connection.targetDir} ${ - connection.targetDir + `mv ${connection.targetFolder} ${ + connection.targetFolder }-backup-${new Date().toISOString()}`, { cwd: connection.targetPath } ) - console.log(`[ mkdir ${connection.targetDir} ... ]`) - await ssh.execCommand(`mkdir ${connection.targetDir}`, { + console.log(`[ mkdir ${connection.targetFolder} ... ]`) + await ssh.execCommand(`mkdir ${connection.targetFolder}`, { cwd: connection.targetPath }) const toCreate = necessaryPath(path.join('./', envarDeploy.fromPath)) for (const name of toCreate) { - console.log(`[ mkdir ${connection.targetDir}/${name.join('/')} ... ]`) + console.log( + `[ mkdir ${connection.targetFolder}/${name.join('/')} ... ]` + ) await ssh.execCommand( - `mkdir ${connection.targetDir}/${name.join('/')}`, + `mkdir ${connection.targetFolder}/${name.join('/')}`, { cwd: connection.targetPath } ) } let err console.log( - `[ Upload to ${connection.targetPath}/${connection.targetDir} ... ]` + `[ Upload to ${connection.targetPath}/${connection.targetFolder} ... ]` ) await ssh.putDirectory( path.join('./', envarDeploy.fromPath), - `${connection.targetPath}/${connection.targetDir}`, + `${connection.targetPath}/${connection.targetFolder}`, { concurrency: 10, recursive: true, @@ -191,8 +193,9 @@ function deployToSsh (connection) { }, tick: (fromPath, remotePath, error) => { console.log( - `Uploading "${fromPath}" ===> "${remotePath}" ${error || - 'succeeded!'}` + `Uploading "${fromPath}" ===> "${remotePath}" ${ + error || 'succeeded!' + }` ) err = error } @@ -201,12 +204,12 @@ function deployToSsh (connection) { ssh.dispose() if (err) { console.error( - `🤷‍♀️🤷‍♀️🤷‍♀️ Failed deploy ${envarDeploy.fromPath} to ${connection.targetPath}/${connection.targetDir} 🤷‍♀️🤷‍♀️🤷‍♀️` + `🤷‍♀️🤷‍♀️🤷‍♀️ Failed deploy ${envarDeploy.fromPath} to ${connection.targetPath}/${connection.targetFolder} 🤷‍♀️🤷‍♀️🤷‍♀️` ) process.exit(1) } else { console.info( - `😊😊😊 Successfully deployed [${envarDeploy.fromPath}] to [${connection.targetPath}/${connection.targetDir}] 😊😊😊` + `😊😊😊 Successfully deployed [${envarDeploy.fromPath}] to [${connection.targetPath}/${connection.targetFolder}] 😊😊😊` ) if (connection.url) { console.info(`😊😊😊 ${connection.url} 😊😊😊`) @@ -218,7 +221,7 @@ function deployToSsh (connection) { console.error(err) ssh.dispose() console.error( - `🤷‍♀️🤷‍♀️🤷‍♀️ Failed deploy [${envarDeploy.fromPath}] to [${connection.targetPath}/${connection.targetDir}] 🤷‍♀️🤷‍♀️🤷‍♀️` + `🤷‍♀️🤷‍♀️🤷‍♀️ Failed deploy [${envarDeploy.fromPath}] to [${connection.targetPath}/${connection.targetFolder}] 🤷‍♀️🤷‍♀️🤷‍♀️` ) process.exit(1) }) @@ -240,7 +243,8 @@ function deployToGit (connection) { } } - const rRepoURL = /^(?:(?:git|https?|git\+https|git\+ssh):\/\/)?(?:[^@]+@)?([^\/]+?)[\/:](.+?)\.git$/ // eslint-disable-line no-useless-escape + const rRepoURL = + /^(?:(?:git|https?|git\+https|git\+ssh):\/\/)?(?:[^@]+@)?([^\/]+?)[\/:](.+?)\.git$/ // eslint-disable-line no-useless-escape const rGithubPage = /\.github\.(io|com)$/ function parseRepo (repo) {