1 | var through = require("through2");
|
2 | var keys = require("lodash/keys");
|
3 | var isArray = require("lodash/isArray");
|
4 |
|
5 | module.exports = function() {
|
6 | return through.obj(function(data, enc, next) {
|
7 | try {
|
8 | next(null, addModuleIds(data));
|
9 | } catch (err) {
|
10 | next(err);
|
11 | }
|
12 | });
|
13 | };
|
14 |
|
15 | function addModuleIds(data) {
|
16 | var graph = data.graph;
|
17 | var options = data.options;
|
18 |
|
19 |
|
20 |
|
21 | if (isArray(graph)) {
|
22 | data.graph.forEach(function(node, index) {
|
23 | node.load.uniqueId = index;
|
24 | });
|
25 | } else {
|
26 | keys(graph).forEach(function(name, index) {
|
27 | graph[name].load.uniqueId = index;
|
28 | });
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 | options.normalize = function(name, load) {
|
34 | var node = load ? graph[load.name] : null;
|
35 | return node ? node.load.uniqueId : name;
|
36 | };
|
37 |
|
38 | return data;
|
39 | }
|