Skip to content

Commit d69eb13

Browse files
skathuria29NicolasRitouet
authored andcommitted
Chore: Fix eslint issues (#33)
1 parent 77dd9c2 commit d69eb13

File tree

9 files changed

+125
-113
lines changed

9 files changed

+125
-113
lines changed

.eslintrc.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ module.exports = {
1111
"sourceType": "script"
1212
},
1313
"rules": {
14-
// TODO: change these rules to errors and fix codebase
15-
"prefer-const": 1, // 4 errors
16-
"no-unused-vars": 1, // 3 errors
17-
"no-use-before-define": 1, // 7 errors
18-
"one-var": 1, // 8 errors
19-
"consistent-return": 1, // 8 errors
20-
"no-param-reassign": 1, // 2 errors
21-
"global-require": 1, // 2 errors
22-
"import/no-dynamic-require": 1, // 1 error
14+
"prefer-const": "error",
15+
"no-unused-vars": "error",
16+
"no-use-before-define": "error",
17+
"one-var": "error",
18+
"consistent-return": "error",
19+
"no-param-reassign": "error",
20+
"global-require": "error",
21+
"import/no-dynamic-require": 1,
2322
"comma-dangle": ["error", "never"]
2423
}
2524
}

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ services: mongodb
66
node_js:
77
- "8"
88
- "7"
9-
- "6"
10-
- "5"
11-
- "4"
9+
- "6"

lib/cli/create.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const start = require('./start');
1616
/**
1717
* Create a new app with folder structure and files
1818
*/
19-
const create = function (name) {
20-
name = name || 'my-deployd-app';
19+
const create = function (_name) {
20+
const name = _name || 'my-deployd-app';
2121
if (test('-d', name)) {
2222
return console.info(`${name} already exists in this directory`);
2323
}
@@ -34,7 +34,7 @@ const create = function (name) {
3434
process.chdir(name);
3535

3636
console.log('dpd is installing the dependencies... please be patient (this may take a few minutes)');
37-
const child = exec('npm install',
37+
exec('npm install',
3838
(error, stdout, stderr) => {
3939
if (error !== null) {
4040
console.log(stderr);
@@ -47,6 +47,7 @@ const create = function (name) {
4747
console.info('\t$ dpd');
4848
}
4949
});
50+
return true;
5051
};
5152

5253
module.exports = create;

lib/cli/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ module.exports = {
2424
create,
2525
keygen,
2626
showkey,
27-
stop
27+
stop,
28+
createserver
2829
};

lib/cli/keygen.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
/**
44
* Generate a key
55
*/
6+
const Keys = require('../keys');
7+
68
const keygen = function () {
7-
const Keys = require('../keys'),
8-
keys = new Keys();
9+
const keys = new Keys();
910

1011
keys.create((err, key) => {
1112
if (err) return console.error(err);
1213
console.log('created key', `${key.substr(0, 16)}...`);
14+
return true;
1315
});
1416
};
1517

lib/cli/showkey.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
/**
44
* Show current key
55
*/
6+
7+
const Keys = require('../keys');
8+
69
const showkey = function () {
7-
const Keys = require('../keys'),
8-
keys = new Keys();
10+
const keys = new Keys();
911

1012
keys.getLocal((err, key) => {
1113
if (err) return console.error(err);
@@ -14,12 +16,13 @@ const showkey = function () {
1416
console.log();
1517
console.log('dpd keygen');
1618
console.log();
17-
return;
19+
return true;
1820
}
1921
console.log('Copy this key for use in remote dashboard');
2022
console.log();
2123
console.log(key);
2224
console.log();
25+
return true;
2326
});
2427
};
2528

lib/cli/start.js

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const program = require('commander');
88
const fs = require('fs');
99
const semver = require('semver');
1010
const Step = require('step');
11-
const shelljs = require('shelljs/global');
1211
const path = require('path');
1312

1413

@@ -23,18 +22,94 @@ const packageInfo = require('../../package');
2322
const latestversionFile = path.join(__dirname, '../../.latestversion');
2423
const createServer = require('./createserver');
2524

25+
function checkForUpdates() {
26+
http.get('http://registry.npmjs.org/deployd-cli', (err, res, body) => {
27+
if (!err) {
28+
let json;
29+
try {
30+
json = JSON.parse(body);
31+
} catch (ex) {
32+
console.log('Could not parse body', body);
33+
}
34+
35+
if (json && json['dist-tags'] && json['dist-tags'].latest) {
36+
const latest = json['dist-tags'].latest;
37+
fs.writeFile(latestversionFile, latest);
38+
}
39+
}
40+
});
41+
}
2642

2743
/**
2844
* Start the server
2945
*/
3046
const start = function (file) {
31-
let port = program.port,
32-
host = program.host || '127.0.0.1',
33-
dbname = program.dbname || '-deployd',
34-
mongoPort = program.mongoPort ? Number(program.mongoPort) : '27017',
35-
env = program.environment || process.env.DPD_ENV || 'development',
36-
retries = 0,
37-
credentials = {};
47+
let port = program.port;
48+
const host = program.host || '127.0.0.1';
49+
const dbname = program.dbname || '-deployd';
50+
const mongoPort = program.mongoPort ? Number(program.mongoPort) : '27017';
51+
const env = program.environment || process.env.DPD_ENV || 'development';
52+
let retries = 0;
53+
const credentials = {};
54+
55+
function startup(err) {
56+
if (err) {
57+
console.log("Failed to start MongoDB (Make sure 'mongod' are in your $PATH or use dpd --mongod option. Ref: http://docs.deployd.com/docs/basics/cli.html)");
58+
return stop(1);
59+
}
60+
61+
const options = { port, env: 'development', db: { host, port: mongoPort, name: dbname } };
62+
63+
options.env = program.environment || process.env.DPD_ENV || options.env;
64+
if (options.env !== 'development') console.log('starting in %s mode', options.env);
65+
66+
if (credentials && credentials.length > 0) options.db.credentials = credentials;
67+
68+
let dpd = createServer(options);
69+
70+
function onListening() {
71+
console.info('listening on port', options.port);
72+
const commands = repl(dpd);
73+
if (program.dashboard) {
74+
return commands.dashboard();
75+
} else if (program.open) {
76+
return commands.open();
77+
}
78+
79+
return true;
80+
}
81+
82+
function onError(err2) {
83+
if (err2.code === 'EADDRINUSE') {
84+
console.error();
85+
console.error(`ERROR: port ${options.port} is already in use`);
86+
if (retries > 0) {
87+
options.port += 1;
88+
console.log(`Trying again on port ${options.port}...`);
89+
console.log();
90+
retries -= 1;
91+
dpd = createServer(options);
92+
dpd.on('listening', onListening);
93+
dpd.on('error', onError);
94+
dpd.listen();
95+
} else {
96+
return process.exit();
97+
}
98+
} else {
99+
console.error(err2);
100+
return process.exit();
101+
}
102+
103+
return true;
104+
}
105+
106+
dpd.on('listening', onListening);
107+
dpd.on('error', onError);
108+
dpd.listen();
109+
dpd.deploydPath = program.deploydPath;
110+
111+
return true;
112+
}
38113

39114

40115
if (!port) {
@@ -94,9 +169,9 @@ const start = function (file) {
94169

95170
if (program.host) {
96171
if (program.auth) {
97-
const auth = program.auth.split(':'),
98-
username = auth[0],
99-
password = auth[1];
172+
const auth = program.auth.split(':');
173+
const username = auth[0];
174+
const password = auth[1];
100175
setCredentials(username, password);
101176
} else if (program.username || program.password) {
102177
setCredentials(program.username, program.password);
@@ -112,76 +187,6 @@ const start = function (file) {
112187
console.log('or use "dpd path/to/app.dpd" to start an app in another directory');
113188
stop(1);
114189
}
115-
116-
function startup(err) {
117-
if (err) {
118-
console.log("Failed to start MongoDB (Make sure 'mongod' are in your $PATH or use dpd --mongod option. Ref: http://docs.deployd.com/docs/basics/cli.html)");
119-
return stop(1);
120-
}
121-
122-
const options = { port, env: 'development', db: { host, port: mongoPort, name: dbname } };
123-
124-
options.env = program.environment || process.env.DPD_ENV || options.env;
125-
if (options.env !== 'development') console.log('starting in %s mode', options.env);
126-
127-
if (credentials && credentials.length > 0) options.db.credentials = credentials;
128-
129-
let dpd = createServer(options);
130-
dpd.on('listening', onListening);
131-
dpd.on('error', onError);
132-
dpd.listen();
133-
dpd.deploydPath = program.deploydPath;
134-
135-
function onListening() {
136-
console.info('listening on port', options.port);
137-
const commands = repl(dpd);
138-
if (program.dashboard) {
139-
commands.dashboard();
140-
} else if (program.open) {
141-
commands.open();
142-
}
143-
}
144-
145-
function onError(err2) {
146-
if (err2.code === 'EADDRINUSE') {
147-
console.error();
148-
console.error(`ERROR: port ${options.port} is already in use`);
149-
if (retries > 0) {
150-
options.port += 1;
151-
console.log(`Trying again on port ${options.port}...`);
152-
console.log();
153-
retries -= 1;
154-
dpd = createServer(options);
155-
dpd.on('listening', onListening);
156-
dpd.on('error', onError);
157-
dpd.listen();
158-
} else {
159-
process.exit();
160-
}
161-
} else {
162-
console.error(err2);
163-
process.exit();
164-
}
165-
}
166-
}
167190
};
168191

169-
function checkForUpdates() {
170-
http.get('http://registry.npmjs.org/deployd-cli', (err, res, body) => {
171-
if (!err) {
172-
let json;
173-
try {
174-
json = JSON.parse(body);
175-
} catch (ex) {
176-
console.log('Could not parse body', body);
177-
}
178-
179-
if (json && json['dist-tags'] && json['dist-tags'].latest) {
180-
const latest = json['dist-tags'].latest;
181-
fs.writeFile(latestversionFile, latest);
182-
}
183-
}
184-
});
185-
}
186-
187192
module.exports = start;

lib/keys.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ Keys.prototype.generate = function () {
3535
*/
3636

3737
Keys.prototype.create = function (fn) {
38-
const key = this.generate(),
39-
keys = this;
38+
const key = this.generate();
39+
const keys = this;
4040

4141
this.readFile((err, data) => {
4242
if (err) return fn(err);
4343

44-
data[key] = true;
45-
keys.writeFile(data, (errW) => {
46-
fn(errW, key);
44+
const fileData = data;
45+
46+
fileData[key] = true;
47+
return keys.writeFile(fileData, (errW) => {
48+
if (errW) return fn(errW);
49+
return fn(errW, key);
4750
});
4851
});
4952
};
@@ -54,8 +57,8 @@ Keys.prototype.create = function (fn) {
5457

5558
Keys.prototype.readFile = function (fn) {
5659
fs.readFile(this.path, 'utf-8', (err, data) => {
57-
let jsonData,
58-
error;
60+
let jsonData;
61+
let error;
5962

6063
try {
6164
jsonData = (data && JSON.parse(data)) || {};
@@ -82,6 +85,7 @@ Keys.prototype.writeFile = function (data, fn) {
8285
}
8386

8487
fs.writeFile(this.path, str, fn);
88+
return true;
8589
};
8690

8791
/*
@@ -93,9 +97,8 @@ Keys.prototype.getLocal = function (fn) {
9397
this.readFile((err, data) => {
9498
if (err) return fn(err);
9599
if (data && typeof data === 'object') {
96-
fn(null, Object.keys(data)[0]);
97-
} else {
98-
fn();
100+
return fn(null, Object.keys(data)[0]);
99101
}
102+
return fn();
100103
});
101104
};

tests/cli.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Integration tests for the Deployd Command Line Interface', () => {
3434

3535
it('should throw an error when running start in a directory which is not a deployd app', (done) => {
3636
execa(path.join(__dirname, '../bin/dpd.js'), ['cmdDontExist'])
37-
.then((result) => {
37+
.then(() => {
3838
done.fail();
3939
}).catch((err) => {
4040
expect(err.stdout).toContain('This directory does not contain a Deployd app!');

0 commit comments

Comments
 (0)