Comparing version 0.0.1 to 0.0.2
require('colors'); | ||
exports.deploy = function(file, key) { | ||
var read = require('read'), | ||
async = require('async'), | ||
Server = require('./server'), | ||
debug = require('debug')('network'), | ||
path = require('path'), | ||
workflow = require('./workflow'); | ||
exports.deploy = function(file, project, key) { | ||
var setup = validateFile(file); | ||
var handler = function(passphrase) { | ||
var proj = findProject(setup, project); | ||
if(proj) { | ||
validateSetup(proj); | ||
var spree = constructDeploySpree(proj); | ||
connect(proj, key, passphrase, spree); | ||
} else { | ||
async.eachSeries(setup, function(item, cb) { | ||
validateSetup(item); | ||
var spree = constructDeploySpree(item, cb); | ||
connect(item, key, passphrase, spree, cb); | ||
}, function(err){ | ||
if(err) throw err; | ||
console.log('Deployment finished successfully!'.green); | ||
}); | ||
} | ||
}; | ||
readPassword(handler); | ||
}; | ||
exports.restart = function(file, project, key) { | ||
var setup = validateFile(file); | ||
var handler = function(passphrase) { | ||
var proj = findProject(setup, project); | ||
if(proj) { | ||
validateSetup(proj); | ||
var spree = constructRestartSpree(proj); | ||
connect(proj, key, passphrase, spree); | ||
} else { | ||
async.eachSeries(setup, function(item, cb) { | ||
validateSetup(item); | ||
var spree = constructRestartSpree(item, cb); | ||
connect(item, key, passphrase, spree, cb); | ||
}, function(err){ | ||
if(err) throw err; | ||
console.log('Restarted successfully!'.green); | ||
}); | ||
} | ||
}; | ||
readPassword(handler); | ||
}; | ||
exports.stop = function(file, project, key) { | ||
var setup = validateFile(file); | ||
var handler = function(passphrase) { | ||
var proj = findProject(setup, project); | ||
if(proj) { | ||
validateSetup(proj); | ||
var spree = constructStopSpree(proj); | ||
connect(proj, key, passphrase, spree); | ||
} else { | ||
async.eachSeries(setup, function(item, cb) { | ||
validateSetup(item); | ||
var spree = constructStopSpree(item, cb); | ||
connect(item, key, passphrase, spree, cb); | ||
}, function(err){ | ||
if(err) throw err; | ||
console.log('Stopped successfully!'.green); | ||
}); | ||
} | ||
}; | ||
readPassword(handler); | ||
}; | ||
var constructDeploySpree = function(proj, callback) { | ||
return function(s) { | ||
return [ | ||
function(callback){ | ||
if(proj.repo) { | ||
workflow.clone(s, proj, callback); | ||
} else { | ||
workflow.compress(s, proj, callback); | ||
} | ||
}, | ||
function(callback){ | ||
if(proj.repo) { | ||
workflow.checkout(s, proj, callback); | ||
} else { | ||
callback(); | ||
} | ||
}, | ||
function(callback){ | ||
workflow.install(s, proj, callback); | ||
}, | ||
function(callback){ | ||
if(proj.run !== 'false' && proj.run !== false) { | ||
workflow.execute(s, proj, callback); | ||
} else { | ||
console.log('[%s] Skipping run as specified.'.green, proj.name); | ||
callback(); | ||
} | ||
} | ||
]; | ||
}; | ||
}; | ||
var constructRestartSpree = function(proj, callback) { | ||
return function(s) { | ||
return [ | ||
function(callback){ | ||
workflow.restart(s, proj, callback); | ||
} | ||
]; | ||
}; | ||
}; | ||
var constructStopSpree = function(proj, callback) { | ||
return function(s) { | ||
return [ | ||
function(callback){ | ||
workflow.stop(s, proj, callback); | ||
} | ||
]; | ||
}; | ||
}; | ||
var readPassword = function(handler) { | ||
read({ prompt: 'passphrase: ', silent: true }, function(er, password) { | ||
handler(password); | ||
}); | ||
}; | ||
var validateFile = function(file) { | ||
try { | ||
var setup = require(file); | ||
file = path.resolve(process.cwd(), file); | ||
return require(file); | ||
} catch (err) { | ||
console.log('Setup/config file not found. (file: %s)'.red, file); | ||
throw new Error('Setup/config file not found. (file: ' + file + ')'); | ||
} | ||
}; | ||
var connect = function(setup, key, passphrase, spree, cb) { | ||
var s = new Server(setup.host, setup.port || 22, setup.user || 'root', key, passphrase); | ||
s.on('ready', function() { | ||
console.log(' ---------- '); | ||
console.log('[%s] Connected to %s'.green, setup.name, setup.host); | ||
async.waterfall(spree(s), function (err, result) { | ||
s.end(); | ||
cb(); | ||
}); | ||
}); | ||
}; | ||
var validateSetup = function(setup) { | ||
if(!setup.name) throw new Error('Name not specified.'); | ||
if(!setup.repo && !setup.folder) throw new Error('Repo or folder not specified in ' + setup.name); | ||
if(!setup.destination) throw new Error('Folder not specified in ' + setup.name); | ||
}; | ||
var findProject = function(setup, name) { | ||
for (var i = setup.length - 1; i >= 0; i--) { | ||
if(setup[i].name == name) { | ||
return setup[i]; | ||
} | ||
} | ||
return undefined; | ||
}; |
46
main.js
#!/usr/bin/env node | ||
require('colors'); | ||
var d = require('domain').create(); | ||
var instructions = require('./lib/instructions'); | ||
@@ -10,19 +12,33 @@ var argv = require('minimist')(process.argv.slice(2)); | ||
var key = argv.key || process.env['HOME'] + '/.ssh/id_rsa'; | ||
var project = argv.project; | ||
if(argv._.length == 2) { | ||
command = argv._[0]; | ||
file = argv._[1]; | ||
} else if(argv._.length == 1) { | ||
file = argv._[0]; | ||
} else { | ||
console.log('Humm... weird parameters.'.red); | ||
d.on('error', function(error) { | ||
console.log('%s'.red, error); | ||
process.exit(1); | ||
} | ||
}); | ||
switch(command) { | ||
case 'deploy': | ||
instructions.deploy(file, key); | ||
break; | ||
default: | ||
console.log('Unknown command.'); | ||
} | ||
d.run(function() { | ||
if(argv._.length == 2) { | ||
command = argv._[0]; | ||
file = argv._[1]; | ||
} else if(argv._.length == 1) { | ||
file = argv._[0]; | ||
} else { | ||
throw new Error('Humm... weird parameters.'); | ||
} | ||
switch(command) { | ||
case 'deploy': | ||
instructions.deploy(file, project, key); | ||
break; | ||
case 'restart': | ||
instructions.restart(file, project, key); | ||
break; | ||
case 'stop': | ||
instructions.stop(file, project, key); | ||
break; | ||
default: | ||
console.log('Unknown command.'); | ||
} | ||
}); |
{ | ||
"name" : "establish" | ||
, "version" : "0.0.1" | ||
, "version" : "0.0.2" | ||
, "homepage" : "http://abru.pt" | ||
@@ -14,4 +14,8 @@ , "description" : "Establish, a stupid simple git based deployment tool." | ||
"colors": "*", | ||
"ssh2": "*" | ||
"ssh2": "*", | ||
"read": "*", | ||
"async": "*", | ||
"debug": "*", | ||
"tar-pack": "*" | ||
} | ||
} |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 4 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
13459
8
401
7
8
5
1
+ Addedasync@*
+ Addeddebug@*
+ Addedread@*
+ Addedtar-pack@*
+ Addedasync@3.2.6(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedblock-stream@0.0.9(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@2.6.94.4.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfstream@1.0.12(transitive)
+ Addedfstream-ignore@1.0.5(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addedmute-stream@2.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedread@4.0.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtar@2.2.2(transitive)
+ Addedtar-pack@3.4.1(transitive)
+ Addeduid-number@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)