forked from RevRocky/pack-it-in
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdependency-info.js
119 lines (107 loc) · 3.26 KB
/
dependency-info.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
'use strict';
const {TreeMap} = require('jstreemap');
class DependencyInfo {
constructor() {
this.name = '';
this.version = '';
this.description = '';
this.license = '';
this.hasApacheLicense = false;
this.hasCrypto = 'N';
this.url = '';
this.author = '';
this.bundled = new TreeMap();
this.visited = false;
this.dev = false;
this.prod = false;
this.optional = false;
this.mandatory = false;
this.timeProcessed = new Date();
}
static addInfo(map, info) {
let versions;
if (map.has(info.name)) {
versions = map.get(info.name);
}
else {
versions = new TreeMap();
map.set(info.name, versions);
}
if (!versions.has(info.version)) {
versions.set(info.version, info);
}
}
static mergeInfo(map, info) {
let versions;
if (map.has(info.name)) {
versions = map.get(info.name);
}
else {
versions = new TreeMap();
map.set(info.name, versions);
}
if (!versions.has(info.version)) {
versions.set(info.version, info);
}
else {
let oldInfo = versions.get(info.version);
oldInfo.dev = oldInfo.dev || info.dev;
oldInfo.prod = oldInfo.prod || info.prod;
oldInfo.optional = oldInfo.optional || info.optional;
oldInfo.mandatory = oldInfo.mandatory || info.mandatory;
}
}
visit(dev, optional) {
this.visited = true;
if (dev) {
this.dev = true;
}
else {
this.prod = true;
}
if (optional) {
this.optional = true;
}
else {
this.mandatory = true;
}
}
/**
* Seperates the licenses for a given project into two
* categories. The first is a license that can be found on
* the white list. The second is a list of all other licenses.
*
* @param {TreeMap} whiteList Our list of preferred licenses
*/
identifyPreferredLicense(whiteList) {
let lics = this.license.slice(); // Copy the array...
this.preferredLicense = '';
this.additionalLicenses = '';
for (let [index, lic] of lics.entries()) {
if (whiteList.has(lic)) {
this.preferredLicense = lic;
// Remove preferred licemce and join additional licenses.
lics.splice(index, 1);
this.additionalLicenses = lics.join(', ');
break; // No need to do anything else
}
}
this.additionalLicenses = lics.join(', ');
}
static *forEach(infos) {
for (let [name, versions] of infos) {
for (let [version, info] of versions) {
yield [name, version, info];
}
}
}
static *forEachRecursively(infos) {
for (let [name, version, info] of DependencyInfo.forEach(infos)) {
yield [name, version, info];
if (info.bundled.size > 0) {
yield *DependencyInfo.forEachRecursively(info.bundled);
}
}
}
}
module.exports = DependencyInfo;