UNPKG

829 BJavaScriptView Raw
1const map = require('lodash/map');
2const error = require('../error');
3
4const createApp = (app) => {
5 validateApp(app);
6 return app;
7};
8
9const validateApp = (app) => {
10 if (!app.appName) {
11 throw error('app name is required.');
12 }
13 if (!app.description) {
14 throw error('app description is required.');
15 }
16 if (!app.version) {
17 throw error('app version is required.');
18 }
19 // Validate options later
20 if (!app.commands) {
21 throw error('app commands map is required.');
22 }
23 map(app.commands, (modulePath, commandName) => {
24 if (!commandName || !commandName.match(/[a-z0-9][a-zA-Z0-9]*/)) {
25 throw error(`app command name '${commandName}' not valid.`);
26 }
27 if (!modulePath) {
28 throw error(`module path is required for command '${commandName}'.`);
29 }
30 });
31};
32
33module.exports = createApp;