Skip to content

Commit

Permalink
fix(northbrook): only display northbrook config warning in debug mode
Browse files Browse the repository at this point in the history
AFFECTS: northbrook
  • Loading branch information
TylorS committed Jan 21, 2017
1 parent a4770de commit 2b0620b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions bin/northbrook.js
Expand Up @@ -15,6 +15,8 @@ var defaultPlugins = require('../plugins');

var index = argv.indexOf('--config');

var debug = argv.indexOf('--debug') > -1 || argv.indexOf('-d') > -1;

try {
require('ts-node/register');
} catch (e) {}
Expand All @@ -35,7 +37,7 @@ var defaultPlugins = require('../plugins');

config = { path: process.cwd(), config: require(configPath) };
} else {
config = northbrook.findNorthbrookConfig();
config = northbrook.findNorthbrookConfig(debug);
}

var path = config.path;
Expand All @@ -51,7 +53,6 @@ var defaultPlugins = require('../plugins');
? findAdditionalPlugins(path)
: [];

var debug = argv.indexOf('--debug') > -1 || argv.indexOf('-d') > -1;

var start = northbrook.northbrook(nbConfig, additionalPlugins, path, {}, debug).start;

Expand Down
Expand Up @@ -9,7 +9,7 @@ describe('findNorthbrookConfig', () => {
const cwd = join(__dirname, '__test__');

const { path, config } =
findNorthbrookConfig(stdio(), { cwd, case: false });
findNorthbrookConfig(false, stdio(), { cwd, case: false });

assert.strictEqual(typeof path, 'string');
assert.strictEqual(typeof config, 'object');
Expand All @@ -18,7 +18,9 @@ describe('findNorthbrookConfig', () => {
});

it('returns null if it can not find a northbrook config', () => {
const { path, config } = findNorthbrookConfig(stdio(), { cwd: dirname(process.env.HOME) });
const { path, config } =
findNorthbrookConfig(false, stdio(), { cwd: dirname(process.env.HOME) });

assert.strictEqual(path, null);
assert.strictEqual(config, null);
});
Expand Down
10 changes: 6 additions & 4 deletions src/northbrook/findNorthbrookConfig/findNorthbrookConfig.ts
Expand Up @@ -20,17 +20,19 @@ export type PathConfig =
* @returns {({ path: string, config: NorthbrookConfig } | null)}
*/
export function findNorthbrookConfig(
debug = false,
stdio: STDIO = {}, options?: { cwd?: string, case?: boolean }): PathConfig
{
const { stdout = process.stdout } = stdio;

const northbrookFilePath: string = findup(NORTHBROOK_CONFIG, options);

if (!northbrookFilePath) {
stdout.write(yellow(bold(`WARNING`)) + `: `
+ bold(`Failed to find a Northbrook configuration file`)
+ EOL,
);
if (debug)
stdout.write(yellow(bold(`WARNING`)) + `: `
+ bold(`Failed to find a Northbrook configuration file`)
+ EOL,
);

return { path: null, config: null };
}
Expand Down

0 comments on commit 2b0620b

Please sign in to comment.