From 1363040f196b8e3b853d79781a45cffe123b0e62 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Tue, 26 Apr 2016 19:26:11 -0600 Subject: [PATCH] feat(bin): Resolve custom config with `process.cwd()` So we do not have to pass the full path to the config (which is still possible) --- bin/p-s.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/p-s.js b/bin/p-s.js index 2b34e08..34773f1 100755 --- a/bin/p-s.js +++ b/bin/p-s.js @@ -1,6 +1,7 @@ #!/usr/bin/env node /* eslint-disable */ // this file is not transpiled (maybe it should be?) so make sure it supports Node 0.10.0 +var resolve = require('path').resolve var findUp = require('find-up') var isEmpty = require('lodash.isempty') var merge = require('lodash.merge') @@ -8,6 +9,7 @@ var remove = require('lodash.remove') var contains = require('lodash.contains') var shellEscape = require('shell-escape') var program = require('commander') +var colors = require('colors/safe') var runPackageScript = require('../dist').default var binUtils = require('../dist/bin-utils') @@ -41,8 +43,13 @@ runPackageScript({ }) function getPSConfig() { - var psConfigFilename = program.config || findUp.sync('package-scripts.js') - return require(psConfigFilename) + var psConfigFilename = program.config ? resolve(process.cwd(), program.config) : findUp.sync('package-scripts.js') + try { + return require(psConfigFilename) + } catch(e) { + console.warn(colors.yellow('Unable to find config at ' + psConfigFilename)) + return {scripts: {}, options: {}} + } } function onHelp() {