Skip to content

Commit

Permalink
Chore: Refactoring, comments and removal of request dep
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRitouet committed Nov 6, 2016
1 parent 7ce059f commit 0d70ba1
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 45 deletions.
3 changes: 1 addition & 2 deletions lib/cli/createserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ var upgrade = require('doh').upgrade,
program = require('commander'),
resolve = require('resolve').sync;


/**
* Start server
*/
function createServer(config) {
var createServer = function(config) {
var deploydpath;
try {
deploydpath = program.deploydPath || resolve('deployd', {basedir: process.cwd()});
Expand Down
6 changes: 6 additions & 0 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/**
* External dependencies
*/
var program = require('commander');

/**
* Local modules
*/
var create = require('./create'),
createserver = require('./createserver'),
keygen = require('./keygen'),
Expand Down
3 changes: 3 additions & 0 deletions lib/cli/keygen.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Generate a key
*/
var keygen = function() {
var Keys = require('../keys')
, keys = new Keys();
Expand Down
33 changes: 18 additions & 15 deletions lib/cli/showkey.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
/**
* Show current key
*/
var showkey = function() {
var Keys = require('../keys')
, keys = new Keys();
var Keys = require('../keys'),
keys = new Keys();

keys.getLocal(function(err, key) {
if(err) return console.error(err);
if(!key) {
console.log('No key file found. Run the following to create one:');
console.log();
console.log('dpd keygen');
console.log();
return;
}
console.log("Copy this key for use in remote dashboard");
keys.getLocal(function(err, key) {
if(err) return console.error(err);
if(!key) {
console.log('No key file found. Run the following to create one:');
console.log();
console.log(key);
console.log('dpd keygen');
console.log();
});
}
return;
}
console.log("Copy this key for use in remote dashboard");
console.log();
console.log(key);
console.log();
});
}

module.exports = showkey;
23 changes: 16 additions & 7 deletions lib/cli/start.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
var program = require('commander'),
/**
* External dependencies
*/
var http = require('http'),
program = require('commander'),
fs = require('fs'),
semver = require('semver'),
Step = require('step'),
request = require('request'),
shelljs = require('shelljs/global'),
path = require('path');



/**
* Local modules
*/
var stop = require('./stop'),
mongod = require('../util/mongod'),
repl = require('../client/repl'),
packageInfo = require('../../package'),
latestversionFile = path.join(__dirname, '../../.latestversion'),
createServer = require('./createserver');

function start(file) {
/**
* Start the server
*/
var start = function(file) {
var port = program.port,
host = program.host || '127.0.0.1',
dbname = program.dbname || '-deployd',
Expand Down Expand Up @@ -156,19 +164,20 @@ function start(file) {
/**
* Port generation
*/

function generatePort() {
var portRange = [ 3000, 9000 ];
return Math.floor(Math.random() * (portRange[1] - portRange[0])) + portRange[0];
}

function checkForUpdates() {
request('http://registry.npmjs.org/deployd-cli', function(err, res, body) {
http.get('http://registry.npmjs.org/deployd-cli', function(err, res, body) {
if (!err) {
var json;
try {
json = JSON.parse(body);
} catch (ex) {}
} catch (ex) {
console.log('Could not parse body', body);
}

if (json && json['dist-tags'] && json['dist-tags'].latest) {
var latest = json['dist-tags'].latest;
Expand Down
6 changes: 4 additions & 2 deletions lib/cli/stop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

function stop(code) {
/**
* Start the server
*/
var stop = function(code) {
var fn = function() {
exit(code);
};
Expand Down
13 changes: 4 additions & 9 deletions lib/client/repl.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
var os = require('os')
, resolve = require('resolve').sync
, exec = require('child_process').exec
, sh = require('shelljs')
, _open = require('opener')
, Keys = require('../keys')
, keys = new Keys();
var resolve = require('resolve').sync,
_open = require('opener'),
repl = require('repl');

var server;

module.exports = function (dpd) {
console.log('type help for a list of commands');
var repl = require("repl")
, context = repl.start("dpd > ", null, replEval, true, true).context;
var context = repl.start("dpd > ", null, replEval, true, true).context;
server = dpd;

context.dpd = buildReplClient(dpd);
Expand Down
12 changes: 6 additions & 6 deletions lib/keys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fs = require('fs')
, crypto = require('crypto');
var fs = require('fs'),
crypto = require('crypto');

/*!
* A collection of keys backed by a file.
Expand Down Expand Up @@ -33,8 +33,8 @@ Keys.prototype.generate = function() {
*/

Keys.prototype.create = function(fn) {
var key = this.generate()
, keys = this;
var key = this.generate(),
keys = this;

this.readFile(function(err, data) {
if(err) return fn(err);
Expand All @@ -52,8 +52,8 @@ Keys.prototype.create = function(fn) {

Keys.prototype.readFile = function(fn) {
fs.readFile(this.path, 'utf-8', function(err, data) {
var jsonData
, error;
var jsonData,
error;

try {
jsonData = (data && JSON.parse(data)) || {};
Expand Down
6 changes: 3 additions & 3 deletions lib/util/mongod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs')
, spawn = require('child_process').spawn
, debug = require('debug')('mongod');
var fs = require('fs'),
spawn = require('child_process').spawn,
debug = require('debug')('mongod');

/*!
* Utility for restarting the current apps mongod instance.
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"resolve": "^1.1.0",
"opener": "^1.4.0",
"debug": "^2.1.0",
"request": "2.51.0",
"doh": "^0.0.4"
},
"preferGlobal": true,
Expand Down

0 comments on commit 0d70ba1

Please sign in to comment.