ssh-deploy/dist/index.js

2 lines
8 KiB
JavaScript
Raw Normal View History

2019-10-02 23:52:52 +02:00
#!/usr/bin/env node
2023-01-02 02:01:47 +01:00
(()=>{var e={898:(e,r,s)=>{"use strict";var t=s(81).spawn;var o=s(837);var escapeSpaces=function(e){if(typeof e==="string"){return e.replace(/\b\s/g,"\\ ")}else{return e}};var escapeSpacesInOptions=function(e){["src","dest","include","exclude","excludeFirst"].forEach((function(r){var s=e[r];if(typeof s==="string"){e[r]=escapeSpaces(s)}else if(Array.isArray(s)===true){e[r]=s.map(escapeSpaces)}}));return e};e.exports=function(e,r){e=e||{};e=o._extend({},e);e=escapeSpacesInOptions(e);var s=e.platform||process.platform;var n=s==="win32";if(typeof e.src==="undefined"){throw new Error("'src' directory is missing from options")}if(typeof e.dest==="undefined"){throw new Error("'dest' directory is missing from options")}var i=e.dest;if(typeof e.host!=="undefined"){i=e.host+":"+e.dest}if(!Array.isArray(e.src)){e.src=[e.src]}var c=[].concat(e.src);c.push(i);var a=(e.args||[]).find((function(e){return e.match(/--chmod=/)}));if(n&&!a){c.push("--chmod=ugo=rwX")}if(typeof e.host!=="undefined"||e.ssh){c.push("--rsh");var l="ssh";if(typeof e.port!=="undefined"){l+=" -p "+e.port}if(typeof e.privateKey!=="undefined"){l+=" -i "+e.privateKey}if(typeof e.sshCmdArgs!=="undefined"){l+=" "+e.sshCmdArgs.join(" ")}c.push(l)}if(e.recursive===true){c.push("--recursive")}if(e.times===true){c.push("--times")}if(e.syncDest===true||e.deleteAll===true){c.push("--delete");c.push("--delete-excluded")}if(e.syncDestIgnoreExcl===true||e.delete===true){c.push("--delete")}if(e.dryRun===true){c.push("--dry-run");c.push("--verbose")}if(typeof e.excludeFirst!=="undefined"&&o.isArray(e.excludeFirst)){e.excludeFirst.forEach((function(e,r){c.push("--exclude="+e)}))}if(typeof e.include!=="undefined"&&o.isArray(e.include)){e.include.forEach((function(e,r){c.push("--include="+e)}))}if(typeof e.exclude!=="undefined"&&o.isArray(e.exclude)){e.exclude.forEach((function(e,r){c.push("--exclude="+e)}))}switch(e.compareMode){case"sizeOnly":c.push("--size-only");break;case"checksum":c.push("--checksum");break}if(typeof e.args!=="undefined"&&o.isArray(e.args)){c=[...new Set([...c,...e.args])]}c=[...new Set(c)];var noop=function(){};var d=e.onStdout||noop;var u=e.onStderr||noop;var f="rsync ";c.forEach((function(e){if(e.substr(0,4)==="ssh "){e='"'+e+'"'}f+=e+" "}));f=f.trim();if(e.noExec){r(null,null,null,f);return}try{var p="";var h="";var y;if(n){y=t("cmd.exe",["/s","/c",'"'+f+'"'],{windowsVerbatimArguments:true,stdio:[process.stdin,"pipe","pipe"]})}else{y=t("/bin/sh",["-c",f])}y.stdout.on("data",(function(e){d(e);p+=e}));y.stderr.on("data",(function(e){u(e);h+=e}));y.on("exit",(function(e){var s=null;if(e!==0){s=new Error("rsync exited with code "+e);s.code=e}r(s,p,h,f)}))}catch(e){r(e,null,null,f)}}},505:(e,r,s)=>{const{existsSync:t,mkdirSync:o,writeFileSync:n}=s(147);const{join:i}=s(17);const validateDir=e=>{if(!e){console.log("[DIR] dir is not defined");return}if(t(e)){console.log(`[DIR] ${e} dir exist`);return}console.log(`[DIR] Creating ${e} dir in workspace root`);o(e);console.log("✅ [DIR] dir created.")};const writeToFile=({dir:e,filename:r,content:s,isRequired:o})=>{validateDir(e);const c=i(e,r);if(t(c)){console.log(`[FILE] ${c} file exist`);if(o){throw new Error(`⚠️ [FILE] ${c} Required file exist, aborting ...`)}return}try{console.log(`[FILE] writing ${c} file ...`,s.length);n(c,s,{encoding:"utf8",mode:384})}catch(e){throw new Error(`⚠️[FILE] Writing to file error. filePath: ${c}, message: ${e.message}`)}};const validateRequiredInputs=e=>{const r=Object.keys(e);const s=r.filter((r=>{const s=e[r];if(!s){console.error(`⚠️ [INPUTS] ${r} is mandatory`)}return s}));if(s.length!==r.length){throw new Error("⚠️ [INPUTS] Inputs not valid, aborting ...")}};const snakeToCamel=e=>e.replace(/[^a-zA-Z0-9]+(.)/g,((e,r)=>r.toUpperCase()));e.exports={writeToFile:writeToFile,validateRequiredInputs:validateRequiredInputs,snakeToCamel:snakeToCamel}},229:(e,r,s)=>{const{snakeToCamel:t}=s(505);const o=["REMOTE_HOST","REMOTE_USER","REMOTE_PORT","SSH_PRIVATE_KEY","DEPLOY_KEY_NAME","SOURCE","TARGET","ARGS","SSH_CMD_ARGS","EXCLUDE","SCRIPT_BEFORE","SCRIPT_AFTER"];const n=pr