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
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander'),
|
var program = require('commander'),
|
||||||
pkg = require('../package.json');
|
pkg = require('../package.json'),
|
||||||
|
fs = require('fs');
|
||||||
|
|
||||||
program
|
program
|
||||||
.version(pkg.version)
|
.version(pkg.version)
|
||||||
|
@ -14,25 +15,28 @@ program
|
||||||
|
|
||||||
argv = program.parse(process.argv);
|
argv = program.parse(process.argv);
|
||||||
|
|
||||||
// require all cylon-* modules
|
var modules_path = process.cwd() + '/node_modules/';
|
||||||
require('fs').readdirSync(process.cwd() + '/node_modules/').forEach(function(dir) {
|
if (fs.existsSync(modules_path)) {
|
||||||
if (dir.match(/^cylon-.*/) !== null) {
|
// require all cylon-* modules
|
||||||
if (typeof require(dir).registerCommands === 'function') {
|
fs.readdirSync(modules_path).forEach(function(dir) {
|
||||||
var commands = require(dir).registerCommands();
|
if (dir.match(/^cylon-.*/) !== null) {
|
||||||
for (name in commands) {
|
if (typeof require(dir).registerCommands === 'function') {
|
||||||
var command = commands[name];
|
var commands = require(dir).registerCommands();
|
||||||
|
for (name in commands) {
|
||||||
|
var command = commands[name];
|
||||||
|
|
||||||
// get subcommand arguments
|
// get subcommand arguments
|
||||||
args = argv.args.slice(1)
|
args = argv.args.slice(1)
|
||||||
|
|
||||||
program
|
program
|
||||||
.command(name)
|
.command(name)
|
||||||
.description(command.description)
|
.description(command.description)
|
||||||
.action(command.command(args));
|
.action(command.command(args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
// print help if no arguments were provided
|
// print help if no arguments were provided
|
||||||
if(!program.args.length) { program.help(); }
|
if(!program.args.length) { program.help(); }
|
||||||
|
|
Loading…
Reference in New Issue