From f174386672b4462c512cc1846f4b0d4a0f226e0f Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Tue, 21 Jan 2014 00:57:56 -0800 Subject: [PATCH] Fix cylon command issue if no node_modules directory is present --- bin/cylon | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/bin/cylon b/bin/cylon index d50a4c3..15a5553 100755 --- a/bin/cylon +++ b/bin/cylon @@ -1,7 +1,8 @@ #!/usr/bin/env node var program = require('commander'), - pkg = require('../package.json'); + pkg = require('../package.json'), + fs = require('fs'); program .version(pkg.version) @@ -14,25 +15,28 @@ program argv = program.parse(process.argv); -// require all cylon-* modules -require('fs').readdirSync(process.cwd() + '/node_modules/').forEach(function(dir) { - if (dir.match(/^cylon-.*/) !== null) { - if (typeof require(dir).registerCommands === 'function') { - var commands = require(dir).registerCommands(); - for (name in commands) { - var command = commands[name]; +var modules_path = process.cwd() + '/node_modules/'; +if (fs.existsSync(modules_path)) { + // require all cylon-* modules + fs.readdirSync(modules_path).forEach(function(dir) { + if (dir.match(/^cylon-.*/) !== null) { + if (typeof require(dir).registerCommands === 'function') { + var commands = require(dir).registerCommands(); + for (name in commands) { + var command = commands[name]; - // get subcommand arguments - args = argv.args.slice(1) + // get subcommand arguments + args = argv.args.slice(1) - program - .command(name) - .description(command.description) - .action(command.command(args)); + program + .command(name) + .description(command.description) + .action(command.command(args)); + } } } - } -}); + }); +} // print help if no arguments were provided if(!program.args.length) { program.help(); }