-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollupModuleData.js
79 lines (79 loc) · 2.8 KB
/
rollupModuleData.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
var logger = require('./logger');
var readFile = require('./singleFileProcessor').readFile;
var writeFile = require('./singleFileProcessor').writeFile;
var rollupModuleData = function (projectPath) {
console.log('rollupModuleData: ', projectPath);
var map = {};
var data = JSON.parse(readFile('./modules.json'));
for (var m in data) {
if (data.hasOwnProperty(m)) {
var sourceModule = data[m].requires;
//console.log(m, sourceModule);
for (var dm in sourceModule) {
if (sourceModule.hasOwnProperty(dm)) {
var dependency = sourceModule[dm];
var hash = map[dm];
if (hash) {
var count = hash + 1;
map[dm] = count;
} else {
map[dm] = 1;
}
//console.log(dm, map[dm]);
}
}
}
}
var output = [];
for (var m in map) {
if (map.hasOwnProperty(m)) {
//console.log(m);
var kind = '?';
if (m.indexOf('-path/') !== -1) {
kind = 'LOCAL';
} else if (m.indexOf('/') === -1 || m.indexOf('plugins/') !== -1 || m.indexOf('uiBasePath') !== -1) {
kind = 'COMMON';
} else if (m.indexOf('galileo-lib') !== -1) {
kind = 'ENGINE';
}
// else if (m.indexOf('css!') !== -1) {
// kind = 'LOCAL-CSS';
// } else if (m.indexOf('text!') !== -1) {
// kind = 'LOCAL-TEMPLATE';
// } else if (m.indexOf('i18n!') !== -1) {
// kind = 'LOCAL-I18N';
// }
output.push({
name: m,
count: map[m],
kind: kind
});
}
}
output = output.sort(function compare(a, b) {
if (a.kind < b.kind) {
return 1;
} else if (a.kind > b.kind) {
return -1;
} else {
if (a.count < b.count) {
return 1;
} else if (a.count > b.count) {
return -1;
}
}
return 0;
});
console.log('rollupModuleData: ', rollupModuleData);
writeFile(projectPath + '/module-stats.json', JSON.stringify(output, null, 2));
var buffer = [];
buffer.push("NAME" + ',' + "REFERENCES" + ',' + "LOCATION");
for (var index = 0; index < output.length; index++) {
var record = output[index]
buffer.push(record.name + ',' + record.count + ',' + record.kind);
}
writeFile(projectPath + '/module-stats' + '.csv', buffer.join('\n'));
};
module.exports = {
'rollupModuleData': rollupModuleData
};