-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.js
51 lines (43 loc) · 1.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const Plugin = require('broccoli-plugin');
const MergeTrees = require('merge-trees');
class BroccoliMergeTrees extends Plugin {
constructor(inputNodes, options = {}) {
let name = 'broccoli-merge-trees:' + (options.annotation || '');
if (!Array.isArray(inputNodes)) {
throw new TypeError(name + ': Expected array, got: [' + inputNodes +']');
}
super(inputNodes, {
persistentOutput: true,
needsCache: false,
annotation: options.annotation
});
this.inputNodes = inputNodes;
this.options = options;
}
build() {
if (this.mergeTrees == null) {
// Defer instantiation until the first build because we only
// have this.inputPaths and this.outputPath once we build.
let outputPath = `${this.outputPath}${this.options.destDir ? '/' + this.options.destDir : ''}`;
this.mergeTrees = new MergeTrees(this.inputPaths, outputPath, {
overwrite: this.options.overwrite,
annotation: this.options.annotation
});
}
try {
this.mergeTrees.merge();
} catch(err) {
if (err !== null && typeof err === 'object') {
let nodesList = this.inputNodes.map((node, i) => ` ${i+1}. ${node.toString()}`).join('\n');
let message = `${this.toString()} error while merging the following:\n${nodesList}`;
err.message = `${message}\n${err.message}`;
}
throw err;
}
}
}
module.exports = function mergeTrees(...params) {
return new BroccoliMergeTrees(...params);
};
module.exports.MergeTrees = BroccoliMergeTrees;