Fix cylon command issue if no node_modules directory is present

This commit is contained in:
Adrian Zankich 2014-01-21 00:57:56 -08:00
parent eced9ab6fe
commit f174386672
1 changed files with 20 additions and 16 deletions

View File

@ -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,8 +15,10 @@ program
argv = program.parse(process.argv);
var modules_path = process.cwd() + '/node_modules/';
if (fs.existsSync(modules_path)) {
// require all cylon-* modules
require('fs').readdirSync(process.cwd() + '/node_modules/').forEach(function(dir) {
fs.readdirSync(modules_path).forEach(function(dir) {
if (dir.match(/^cylon-.*/) !== null) {
if (typeof require(dir).registerCommands === 'function') {
var commands = require(dir).registerCommands();
@ -33,6 +36,7 @@ require('fs').readdirSync(process.cwd() + '/node_modules/').forEach(function(dir
}
}
});
}
// print help if no arguments were provided
if(!program.args.length) { program.help(); }