-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (54 loc) · 1.65 KB
/
Copy pathindex.js
File metadata and controls
60 lines (54 loc) · 1.65 KB
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
52
53
54
55
56
57
58
59
60
'use strict';
const { MergeTrees } = require('broccoli-merge-trees');
const Plugin = require('broccoli-plugin');
const fs = require('fs');
const path = require('path');
class ChunksWriter extends Plugin {
constructor(inputNodes, options = {}) {
super(inputNodes, {
annotation: options.annotation,
// see `options` in the below README to see a full list of constructor options
});
this.inserter = options.inserter;
}
build() {
const content = JSON.stringify(this.inserter.categorizeChunks(), null, 2);
fs.writeFileSync(
path.join(this.outputPath, 'chunks.json'),
content,
'utf8'
);
}
}
module.exports = {
name: require('./package').name,
isDevelopingAddon() {
return true;
},
postprocessTree(which, tree) {
if (which === 'all') {
if (tree._annotation === 'ember-auto-import-analyzer') {
// likely running in dev mode, don't need to generate chunks.json
return tree;
}
let inputNodes =
tree.inputNodes || (tree.inputTree && tree.inputTree.inputNodes);
if (!inputNodes) {
console.error(tree);
throw new Error(
'Unknown build tree configuration, this addon should follow exactly after ember-auto-import'
);
}
const inserter = inputNodes.find((node) => node._name === 'Inserter');
if (!inserter) {
console.error(tree);
throw new Error(
'Unable to find Inserter instance in emebr-auto-import build tree'
);
}
const chunkWriterInstance = new ChunksWriter(['app'], { inserter });
return new MergeTrees([tree, chunkWriterInstance]);
}
return tree;
},
};