forked from postalsys/emailengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-generate.js
More file actions
96 lines (79 loc) · 3.13 KB
/
list-generate.js
File metadata and controls
96 lines (79 loc) · 3.13 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
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
'use strict';
const he = require('he');
const packageData = require('./package.json');
const satisfies = require('spdx-satisfies');
const ALLOWED_LICENSES = [
'ISC',
'MIT',
'Apache-1.0+',
'CC-BY-3.0',
'BSD-2-Clause',
'BSD-3-Clause',
'0BSD',
'CC0-1.0',
'MIT-0',
'MPL-2.0',
'Python-2.0',
'BlueOak-1.0.0'
];
let chunks = [];
process.stdin.on('readable', () => {
let chunk;
while ((chunk = process.stdin.read()) !== null) {
chunks.push(chunk);
}
});
process.stdin.on('end', () => {
let list = JSON.parse(Buffer.concat(chunks));
console.log(
'<!doctype html><html><head><meta charset="utf-8"><title>EmailEngine Licenses</title><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous"></head><body>'
);
console.log('<div class="container-fluid">');
console.log(`<h1>EmailEngine v${packageData.version}</h1><p>EmailEngine includes code from the following software packages:</p>`);
console.log('<table class="table table-sm">');
console.log(
'<tr><thead class="thead-dark"><th>Package</th><th>Version</th><th>License</th><th>Publisher</th><th>Publisher\'s Email</th><th>Package URL</th></tr>'
);
console.log('<tbody>');
for (let key of Object.keys(list)) {
let splitter = key.lastIndexOf('@');
let packageName = key.substr(0, splitter);
if (packageName === 'emailengine-app') {
continue;
}
let packageVersion = key.substr(splitter + 1);
let data = list[key];
console.log('<tr>');
console.log(`<td><a href="https://npmjs.com/package/${he.encode(packageName)}">${he.encode(packageName)}</a></td>`);
for (let license of [].concat(data.licenses || [])) {
license = license.replace(/MIT\*/, 'MIT');
license = license.replace(/BSD\*/, 'BSD-3-Clause');
let _satisfies;
try {
_satisfies = satisfies(license, ALLOWED_LICENSES);
} catch (err) {
console.error(err);
}
if (!_satisfies) {
console.error(`Failed to verify license for ${packageName}. Found: "${license}"`);
process.exit(1);
}
}
[packageVersion, [].concat(data.licenses || []).join(', '), data.publisher, data.email]
.map(entry => entry || '')
.forEach(entry => {
console.log('<td>' + he.encode(entry) + '</td>');
});
console.log('<td>');
if (data.repository || data.url) {
console.log(
`<a href="${he.encode(data.repository || data.url)}">${he.encode(
(data.repository || data.url || '').toString().replace(/^https?:\/\//i, '')
)}</a>`
);
}
console.log('</td');
console.log('</tr>');
}
console.log('</tbody></table></div></body></html>');
});