-
Notifications
You must be signed in to change notification settings - Fork 4
/
build
executable file
·56 lines (53 loc) · 1.41 KB
/
build
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
#!/usr/bin/env node
var fs = require('fs')
var semver = require('semver')
var validateNpmPackageName = require('validate-npm-package-name')
var spdxExpressionValidate = require('spdx-expression-validate')
var haveError = false
var csv = fs.readFileSync('index.csv', 'utf8')
var data = csv
.split('\n')
.filter(Boolean)
.map(function (line) {
var split = line
.split(',')
.map(function (element) {
return element.trim()
})
var object = {
name: split[0],
license: split[1],
versions: split.slice(2)
}
if (!validateNpmPackageName(object.name).validForOldPackages) {
haveError = true
console.error(object.name + ' is not a valid package name.')
}
object.versions.forEach(function (version) {
if (!semver.valid(version)) {
haveError = true
console.error(version + ' is not a valid version.')
}
})
if (!spdxExpressionValidate(object.license)) {
haveError = true
console.error(object.license + ' is not a valid SPDX expression.')
}
return object
})
if (haveError) process.exit(1)
var json = JSON.stringify(
data.reduce(function (data, object) {
return data.concat(
object.versions.map(function (version) {
return {
name: object.name,
version,
license: object.license
}
})
)
}, []),
null, 2
)
fs.writeFileSync('index.json', json + '\n')