UNPKG

591 BJavaScriptView Raw
1var fs = require('fs');
2var path = require('path');
3
4module.exports = function commandLoader(program) {
5 'use strict';
6
7 var commands = {};
8 var loadPath = path.dirname(__filename);
9
10 // Loop though command files
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 // Require command
17 var command = require(path.join(loadPath, filename));
18
19 // Initialize command
20 commands[name] = command(program);
21 });
22
23 return commands;
24};