Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#16 global require #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ module.exports = {
"prefer-const": 1, // 4 errors
"no-unused-vars": 1, // 3 errors
"no-use-before-define": 1, // 7 errors
"one-var": 1, // 8 errors
"consistent-return": 1, // 8 errors
"no-param-reassign": 1, // 2 errors
"global-require": 1, // 2 errors
"import/no-dynamic-require": 1, // 1 error
"comma-dangle": ["error", "never"]
}
Expand Down
5 changes: 3 additions & 2 deletions lib/cli/keygen.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const Keys = require('../keys');

/**
* Generate a key
*/
const keygen = function () {
const Keys = require('../keys'),
keys = new Keys();
const keys = new Keys();

keys.create((err, key) => {
if (err) return console.error(err);
Expand Down
5 changes: 3 additions & 2 deletions lib/cli/showkey.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const Keys = require('../keys');

/**
* Show current key
*/
const showkey = function () {
const Keys = require('../keys'),
keys = new Keys();
const keys = new Keys();

keys.getLocal((err, key) => {
if (err) return console.error(err);
Expand Down
32 changes: 10 additions & 22 deletions lib/cli/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,20 @@ const createServer = require('./createserver');
* Start the server
*/
const start = function (file) {
let port = program.port,
host = program.host || '127.0.0.1',
dbname = program.dbname || '-deployd',
mongoPort = generatePort(),
env = program.environment || process.env.DPD_ENV || 'development',
retries = 0,
credentials = {};
let port = program.port;
const host = program.host || '127.0.0.1';
const dbname = program.dbname || '-deployd';
const mongoPort = program.mongoPort ? Number(program.mongoPort) : '27017';
const env = program.environment || process.env.DPD_ENV || 'development';
let retries = 0;
const credentials = {};


if (!port) {
port = 2403;
retries = env === 'development' && 5;
}

if (program.mongoPort) {
mongoPort = Number(program.mongoPort);
}

if (file) {
process.chdir(path.dirname(file));
}
Expand Down Expand Up @@ -98,9 +94,9 @@ const start = function (file) {

if (program.host) {
if (program.auth) {
const auth = program.auth.split(':'),
username = auth[0],
password = auth[1];
const auth = program.auth.split(':');
const username = auth[0];
const password = auth[1];
setCredentials(username, password);
} else if (program.username || program.password) {
setCredentials(program.username, program.password);
Expand Down Expand Up @@ -170,14 +166,6 @@ const start = function (file) {
}
};

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

function checkForUpdates() {
http.get('http://registry.npmjs.org/deployd-cli', (err, res, body) => {
if (!err) {
Expand Down
8 changes: 4 additions & 4 deletions lib/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Keys.prototype.generate = function () {
*/

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

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

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

try {
jsonData = (data && JSON.parse(data)) || {};
Expand Down