1 | 'use strict';
|
2 |
|
3 | const Plugin = require('broccoli-plugin');
|
4 | const MergeTrees = require('merge-trees');
|
5 |
|
6 | class BroccoliMergeTrees extends Plugin {
|
7 | constructor(inputNodes, options = {}) {
|
8 | let name = 'broccoli-merge-trees:' + (options.annotation || '');
|
9 | if (!Array.isArray(inputNodes)) {
|
10 | throw new TypeError(name + ': Expected array, got: [' + inputNodes +']');
|
11 | }
|
12 | super(inputNodes, {
|
13 | persistentOutput: true,
|
14 | needsCache: false,
|
15 | annotation: options.annotation
|
16 | });
|
17 |
|
18 | this.inputNodes = inputNodes;
|
19 | this.options = options;
|
20 | }
|
21 |
|
22 | build() {
|
23 | if (this.mergeTrees == null) {
|
24 |
|
25 |
|
26 | this.mergeTrees = new MergeTrees(this.inputPaths, this.outputPath, {
|
27 | overwrite: this.options.overwrite,
|
28 | annotation: this.options.annotation
|
29 | });
|
30 | }
|
31 |
|
32 | try {
|
33 | this.mergeTrees.merge();
|
34 | } catch(err) {
|
35 | if (err !== null && typeof err === 'object') {
|
36 | let nodesList = this.inputNodes.map((node, i) => ` ${i+1}. ${node.toString()}`).join('\n');
|
37 | let message = `${this.toString()} error while merging the following:\n${nodesList}`;
|
38 |
|
39 | err.message = `${message}\n${err.message}`;
|
40 | }
|
41 | throw err;
|
42 | }
|
43 | }
|
44 | }
|
45 |
|
46 | module.exports = function mergeTrees(...params) {
|
47 | return new BroccoliMergeTrees(...params);
|
48 | };
|
49 |
|
50 | module.exports.MergeTrees = BroccoliMergeTrees;
|