1 | "use strict";
|
2 |
|
3 | const argx = require('argx'),
|
4 | async = require('async'),
|
5 | arrayreduce = require('arrayreduce'),
|
6 | arrayfilter = require('arrayfilter'),
|
7 | apemanfile = require('apemanfile'),
|
8 | apemancwd = require('apemancwd'),
|
9 | listInfrs = require('./infring/list_infrs'),
|
10 | buildInfrs = require('./infring/build_infrs'),
|
11 | removeInfrs = require('./infring/remove_infrs');
|
12 |
|
13 | let concatArray = arrayreduce.arrayConcat(),
|
14 | rejectEmpty = arrayfilter.emptyReject();
|
15 |
|
16 |
|
17 | function apemanInfr(names, options, callback) {
|
18 | let args = argx(arguments);
|
19 | callback = args.pop('function') || argx.noop;
|
20 | options = args.pop('object') || {};
|
21 | names = args.remain().filter(rejectEmpty).reduce(concatArray, []);
|
22 |
|
23 | let cwd = apemancwd.create({prefix: 'apeman-infr'});
|
24 |
|
25 | async.waterfall([
|
26 | (callback) => {
|
27 | apemanfile.load(options.configuration, callback);
|
28 | },
|
29 | (apemanfile, callback) => {
|
30 | cwd.chdir(apemanfile.$cwd);
|
31 | if (options.list) {
|
32 | listInfrs(apemanfile, names, {}, callback);
|
33 | return;
|
34 | }
|
35 | if (options.delete) {
|
36 | removeInfrs(apemanfile, names, {
|
37 | force: options.force
|
38 | }, callback);
|
39 | return;
|
40 | }
|
41 | buildInfrs(apemanfile, names, {
|
42 | force: options.force
|
43 | }, callback);
|
44 | }
|
45 | ], (err) => {
|
46 | cwd.restoreAll();
|
47 | callback(err);
|
48 | });
|
49 | }
|
50 |
|
51 |
|
52 | module.exports = apemanInfr;
|