Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

establish

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

establish - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

examples/test.json

184

lib/instructions.js
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": "*"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc