forked from ivanvanderbyl/ember-d3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
122 lines (101 loc) · 3.12 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* eslint "no-var":off, "ember-suave/prefer-destructuring":off */
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var path = require('path');
var rename = require('broccoli-stew').rename;
var RecastFilter = require('./lib/recast-filter');
var rewriteAMDFunction = require('./lib/rewrite-amd-definition');
var replaceVersionString = require('./lib/replace-version-string');
var d3DepsForPackage = require('./lib/d3-deps-for-package');
var d3Version = require('./lib/d3-version');
var inclusionFilter = require('./lib/inclusion-filter');
var exclusionFilter = require('./lib/exclusion-filter');
module.exports = {
isDevelopingAddon() {
return false;
},
name: 'ember-d3',
/**
* Array of d3 packages to load
*
* @private
* @type {Array<String>}
*/
d3Modules: [],
/**
* `import()` taken from ember-cli 2.7
* @private
*/
import(asset, options) {
var app = this.app;
while (app.app) {
app = app.app;
}
app.import(asset, options);
},
included(app) {
this._super.included && this._super.included.apply(this, arguments);
this.app = app;
/*
Find all dependencies of `d3`
*/
var config = app.project.config(app.env) || {};
var addonConfig = config[this.name] || {};
this.d3Modules = this.getD3Modules(addonConfig);
/*
This essentially means we'll skip importing this package twice, if it's
a dependency of another package.
*/
if (!this.import) {
if (this.isDevelopingAddon()) {
this.ui.writeWarnLine('[ember-d3] skipping included hook for', this.name);
}
return;
}
/*
Actually import the vendor tree packages to our app.
*/
var _this = this;
this.d3Modules.forEach(function(pkg) {
_this.import(path.join('vendor', pkg.name, `${ pkg.name }.js`));
});
app.import(path.join('vendor', 'ember-d3', 'register-d3-version.js'));
},
getD3Modules(config) {
var allModules = this._getAllD3Modules();
var onlyModules = config.only || [];
var exceptModules = config.except || [];
return allModules
.filter(inclusionFilter(onlyModules))
.filter(exclusionFilter(exceptModules));
},
_getAllD3Modules() {
return d3DepsForPackage('d3', this.parent.nodeModulesPath, this.ui);
},
treeForVendor(tree) {
var trees = [];
if (tree) {
let versionTree = new RecastFilter(tree, null, replaceVersionString, {
version: d3Version('d3', this.parent.nodeModulesPath)
});
trees.push(rename(versionTree, function() {
return path.join('ember-d3', 'register-d3-version.js');
}));
}
this.d3Modules.forEach(function(pkg) {
if (!(pkg && pkg.path)) {
return;
}
var tree = new Funnel(pkg.path, {
include: [pkg.buildPath],
destDir: `/${ pkg.name}`,
annotation: `Funnel: D3 Source [${ pkg.name }]`
});
var srcTree = new RecastFilter(tree, pkg.name, rewriteAMDFunction);
trees.push(rename(srcTree, function() {
return `/${ pkg.name }/${ pkg.name }.js`;
}));
});
return mergeTrees(trees);
}
};