UNPKG

629 BJavaScriptView Raw
1const error = require('../error');
2
3/**
4 * Load a command for an app.
5 *
6 * @param {Application} app - The scaffold app.
7 * @param {String} commandName - The name of the command to be executed.
8 * @return {Command} This function returns the loaded command.
9 */
10const loadCommand = (app, commandName) => {
11 if (!app.commands[commandName]) {
12 throw error(`command '${commandName}' not exist.`);
13 }
14 let command;
15 try {
16 command = require(app.commands[commandName]);
17 } catch(e) {
18 console.log(e);
19 throw error(`command '${commandName}' can't be required.`);
20 }
21 return command;
22};
23
24module.exports = loadCommand;