From 166348e3296e1f594c2d3a819ad2ba286b5330a4 Mon Sep 17 00:00:00 2001 From: mzabriskie Date: Tue, 14 Jul 2015 22:10:37 -0600 Subject: [PATCH] Suppress errors when operating on a non-project directory --- lib/get_component_file.js | 7 ++++++- lib/get_component_name.js | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/get_component_file.js b/lib/get_component_file.js index 58eaa9f..de946d1 100755 --- a/lib/get_component_file.js +++ b/lib/get_component_file.js @@ -1,4 +1,9 @@ #!/usr/bin/env node var path = require('path'); -console.log(require(path.join(process.cwd(), 'package.json')).name); +var fs = require('fs'); +var file = path.join(process.cwd(), 'package.json'); + +if (fs.existsSync(file)) { + console.log(require(file).name); +} diff --git a/lib/get_component_name.js b/lib/get_component_name.js index 05462cc..d17d981 100755 --- a/lib/get_component_name.js +++ b/lib/get_component_name.js @@ -1,6 +1,8 @@ #!/usr/bin/env node var path = require('path'); +var fs = require('fs'); +var file = path.join(process.cwd(), 'package.json'); function PascalCase(str) { var parts = str.split('-'); @@ -10,4 +12,6 @@ function PascalCase(str) { return parts.join(''); } -console.log(PascalCase(require(path.join(process.cwd(), 'package.json')).name)); +if (fs.existsSync(file)) { + console.log(PascalCase(require(file).name)); +}