1 | 'use strict';
|
2 |
|
3 | const { asyncParamCallback } = require('../../utils');
|
4 |
|
5 | module.exports = ({ commandName, command }, { Command, PreLoadCondition, PreCondition }) => {
|
6 | const commandSettings = {
|
7 | name: commandName,
|
8 | };
|
9 |
|
10 | if (!Array.isArray(command))
|
11 | command = [command];
|
12 |
|
13 | return command.reduce((result, item, priority) => {
|
14 |
|
15 | if (typeof item === 'function') {
|
16 | result.command = new Command(commandSettings, item);
|
17 | return result;
|
18 | }
|
19 |
|
20 |
|
21 | if (item.settings) {
|
22 | Object.assign(commandSettings, item.settings);
|
23 | return result;
|
24 | }
|
25 |
|
26 | if (item.preLoadCondition) {
|
27 | result.preLoadConditions.push(new PreLoadCondition({ name: [commandName], priority }, asyncParamCallback(item.preLoadCondition, 'cmd')));
|
28 | return result;
|
29 | }
|
30 |
|
31 | if (item.preCondition) {
|
32 | result.preConditions.push(new PreCondition({ name: [commandName], priority }, asyncParamCallback(item.preCondition, 'cmd', 'agg')));
|
33 | return result;
|
34 | }
|
35 |
|
36 | return result;
|
37 | }, {
|
38 | preLoadConditions: [],
|
39 | preConditions: [],
|
40 | command: null,
|
41 | });
|
42 | };
|