Skip to content

Commit 0f3bfcd

Browse files
author
Dom Harrington
committed
Switch to using config module
1 parent 5da2fa4 commit 0f3bfcd

File tree

13 files changed

+48
-59
lines changed

13 files changed

+48
-59
lines changed

cli.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
require('colors');
22

33
const path = require('path');
4+
const config = require('config');
45

5-
const utils = require('./utils');
6-
7-
function load(config, command = 'help') {
6+
function load(command = 'help') {
87
const file = path.join(__dirname, 'lib', `${command}.js`);
98
try {
109
// eslint-disable-next-line global-require, import/no-dynamic-require
@@ -15,14 +14,12 @@ function load(config, command = 'help') {
1514
process.exitCode = 1;
1615
return undefined;
1716
}
18-
};
17+
}
1918

2019
module.exports = function(args, opts = {}) {
21-
const config = utils.config(opts.env);
22-
23-
const command = load(config, args[0]);
20+
const command = load(args[0]);
2421

2522
if (!command) return;
2623

27-
command.run(config, { args, opts });
24+
command.run({ args, opts });
2825
};

config/config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/default.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
// eslint-disable-next-line global-require
3+
cli: require('../package.json').name,
4+
host: 'https://dash.readme.io',
5+
};

config/development.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"host": "http://dash.readme.local:3000"
3+
}

config/test.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/testing.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

lib/swagger.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const request = require('request');
22
const fs = require('fs');
33
const path = require('path');
4+
const config = require('config');
45

56
exports.desc = 'Upload your swagger file to ReadMe';
67
exports.category = 'services';
@@ -14,7 +15,7 @@ function defaultCallback(err) {
1415
return process.exit();
1516
}
1617

17-
exports.run = function(config, info, cb = defaultCallback) {
18+
exports.run = function(info, cb = defaultCallback) {
1819
const [apiKey, id] = info.opts.token.split('-');
1920

2021
function callback(err, response, data) {
@@ -39,8 +40,8 @@ exports.run = function(config, info, cb = defaultCallback) {
3940
};
4041

4142
if (!id) {
42-
request.post(`${config.host.url}/api/v1/swagger`, options, callback);
43+
request.post(`${config.host}/api/v1/swagger`, options, callback);
4344
} else {
44-
request.put(`${config.host.url}/api/v1/swagger/${id}`, options, callback);
45+
request.put(`${config.host}/api/v1/swagger/${id}`, options, callback);
4546
}
4647
};

package-lock.json

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"main": "index.js",
2929
"dependencies": {
3030
"colors": "^1.1.2",
31+
"config": "^1.30.0",
3132
"minimist": "^1.2.0",
3233
"request": "^2.81.0"
3334
},
@@ -47,12 +48,15 @@
4748
"test": "jest --coverage"
4849
},
4950
"jest": {
51+
"setupFiles": [
52+
"./test/set-node-env"
53+
],
5054
"coverageThreshold": {
5155
"global": {
52-
"branches": 15,
53-
"functions": 20,
54-
"lines": 40,
55-
"statements": 40
56+
"branches": 40,
57+
"functions": 80,
58+
"lines": 80,
59+
"statements": 75
5660
}
5761
}
5862
}

test/set-node-env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.env.NODE_ENV = 'testing';

0 commit comments

Comments
 (0)