1 | "use strict";
|
2 |
|
3 | const { join } = require("path");
|
4 | const { Map } = require("immutable");
|
5 | const promisified = require("@njudah/cursor/promisified");
|
6 |
|
7 | module.exports = function (aBuild) {
|
8 | return promisified(toCurriedFunction(aBuild), function (aState) {
|
9 | const item = aState.tree.children[2].binding;
|
10 | const destination = item.attributes["destination"].value;
|
11 | const metadata = flatten("", item.attributes["metadata"].value);
|
12 |
|
13 | return { destination, metadata };
|
14 | });
|
15 | };
|
16 |
|
17 | function flatten(parent, metadata) {
|
18 | return metadata.reduce(function (flattened, value, key) {
|
19 | if (!Map.isMap(value)) return flattened.set(join(parent, key), value);
|
20 |
|
21 | return flattened.merge(flatten(join(parent, key), value));
|
22 | }, Map());
|
23 | }
|
24 |
|
25 | function toCurriedFunction(anArray) {
|
26 | if (typeof anArray === "function") return anArray;
|
27 |
|
28 | const [aFunction, attributes, ...children] = anArray;
|
29 |
|
30 | return require("generic-jsx").curry(aFunction, attributes, ...children.map(toCurriedFunction));
|
31 | } |
\ | No newline at end of file |