UNPKG

1.02 kBJavaScriptView Raw
1"use strict";
2
3const argx = require('argx'),
4 apemanfile = require('apemanfile'),
5 checkNeeds = require('./checking/check_needs'),
6 async = require('async');
7
8/** @lends apemanNeed */
9function apemanNeed(options, callback) {
10 let args = argx(arguments);
11 callback = args.pop('function') || argx.noop;
12 options = args.pop('object') || {};
13 let configuration = apemanfile(options.configuration || process.cwd());
14 async.waterfall([
15 (callback) => {
16 let needs = configuration.get('$needs');
17 let result = Object.assign({}, needs);
18 let $children = configuration.get('$children') || {};
19 Object.keys($children).forEach((key) => {
20 let $child = $children[key];
21 result = Object.assign(result, $child.get('$needs') || {});
22 });
23 callback(null, result);
24 },
25 (needs, callback) => {
26 checkNeeds(needs, callback);
27 }
28 ], callback);
29}
30
31module.exports = apemanNeed;