1 | var fs = require('fs');
|
2 | var path = require('path');
|
3 |
|
4 | module.exports = function commandLoader(program) {
|
5 | 'use strict';
|
6 |
|
7 | var commands = {};
|
8 | var loadPath = path.dirname(__filename);
|
9 |
|
10 |
|
11 | fs.readdirSync(loadPath).filter(function (filename) {
|
12 | return (/\.js$/.test(filename) && filename !== 'index.js');
|
13 | }).forEach(function (filename) {
|
14 | var name = filename.substr(0, filename.lastIndexOf('.'));
|
15 |
|
16 |
|
17 | var command = require(path.join(loadPath, filename));
|
18 |
|
19 |
|
20 | commands[name] = command(program);
|
21 | });
|
22 |
|
23 | return commands;
|
24 | };
|