Fix cylon command issue if no node_modules directory is present
This commit is contained in:
parent
eced9ab6fe
commit
f174386672
36
bin/cylon
36
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(); }
|
||||
|
|
Loading…
Reference in New Issue