mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2025-04-29 03:10:43 -04:00
27 lines
872 B
JavaScript
27 lines
872 B
JavaScript
const { join } = require('path');
|
|
const { exec } = require('child_process');
|
|
|
|
const { sshServer, githubWorkspace } = require('./inputs');
|
|
const { writeToFile } = require('./helpers');
|
|
|
|
const remoteCmd = (cmd, label) => {
|
|
const localScriptPath = join(githubWorkspace, `local_ssh_script-${label}.sh`);
|
|
try {
|
|
writeToFile(localScriptPath, cmd);
|
|
|
|
exec(`ssh ${sshServer} 'bash -s' < ${localScriptPath}`, (err, data, stderr) => {
|
|
if (err) {
|
|
console.log('⚠️ [CMD] Remote script failed. ', err.message);
|
|
} else {
|
|
console.log('✅ [CMD] Remote script executed. \n', data, stderr);
|
|
}
|
|
});
|
|
} catch (err) {
|
|
console.log('⚠️ [CMD] Starting Remote script execution failed. ', err.message);
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
remoteCmdBefore: (cmd) => remoteCmd(cmd, 'before'),
|
|
remoteCmdAfter: (cmd) => remoteCmd(cmd, 'after')
|
|
};
|