Last active
July 31, 2022 10:02
-
-
Save alvaro-canepa/b1df9ab3a1c7566eb860947499b744c6 to your computer and use it in GitHub Desktop.
Deploy a versioned vue project throw ssh (using linux)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chalk = require("chalk"); | |
const { exec } = require("child_process"); | |
const { version } = require("../package.json"); | |
const sSourcePath = `./dist/${version}`; | |
const sDestPath = `./dist`; | |
const sFile = `${version}.zip`; | |
const sServer = "root@gestionweb.uy"; | |
const sServerDest = | |
"/var/www/devel.gestionweb.uy/plugins/planetadeleste/gw/assets/app/"; | |
const title = (sMessage) => { | |
console.log(chalk.blue(sMessage)); | |
console.log(chalk.blue("========================")); | |
}; | |
const log = (sMessage, stdout, error, stderr) => { | |
if (error) { | |
console.error(`error: ${error.message}`); | |
return; | |
} | |
if (stderr) { | |
console.error(`stderr: ${stderr}`); | |
return; | |
} | |
console.log(chalk.green(sMessage)); | |
console.log(chalk.grey(`Stdout: ${stdout}`)); | |
}; | |
const compress = () => { | |
title(`Compressing ${sSourcePath}`); | |
exec( | |
`cd ${sDestPath} && zip -r ${sFile} ${version}`, | |
(error, stdout, stderr) => { | |
log("Compression complete", stdout, error, stderr); | |
upload(); | |
} | |
); | |
}; | |
const upload = () => { | |
title(`Uploading ${sFile} to ${sServer}`); | |
exec( | |
`cd ${sDestPath} && scp -r ${sFile} ${sServer}:${sServerDest}`, | |
(error, stdout, stderr) => { | |
log("Upload complete", stdout, error, stderr); | |
extract(); | |
} | |
); | |
}; | |
const extract = () => { | |
const arCommands = [ | |
`cd ${sServerDest}`, | |
`unzip -o ${sFile}`, | |
`chown -R www-data:www-data ./${version}`, | |
]; | |
const sCommand = arCommands.join(" && "); | |
title(`Uncompressing ${sFile} on ${sServer}`); | |
exec(`ssh ${sServer} "${sCommand}"`, (error, stdout, stderr) => { | |
log("Uncompress complete", stdout, error, stderr); | |
removeCompress(); | |
}); | |
}; | |
const removeCompress = () => { | |
title(`Deleting file ${sFile}`); | |
exec(`rm -f ${sDestPath}/${sFile}`, (error, stdout, stderr) => { | |
log("File deleted", stdout, error, stderr); | |
}); | |
}; | |
const deploy = () => { | |
compress(); | |
}; | |
deploy(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used on https://medium.com/@bfpdevel/deploy-a-versioned-vue-project-throw-ssh-using-linux-38fb4f5c007b