This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·156 lines (145 loc) · 4.3 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env node
var powerset = require('powerset')
var components = require('./components')
function combinations () {
var returned = powerset(
components.filter(function (component) {
return component.standard !== true
})
)
.filter(function (combo) {
return !combo.some(function (component) {
return (
(
component.requires &&
component.requires.some(function (requiredCode) {
return !combo.some(function (otherComponent) {
return otherComponent.code === requiredCode
})
})
) ||
(
component.conflicts &&
component.conflicts.some(function (conflictingCode) {
return combo.some(function (otherComponent) {
return otherComponent.code === conflictingCode
})
})
)
)
})
})
.map(function (combo) {
return combo
.map(function (component) {
return component.code
})
.sort()
.join('-')
})
returned[0] = 'BASE'
return returned
}
function generate (identifier, stream, done) {
identifier = identifier || 'BASE'
var meta = require('./components')
var codes = identifier === 'BASE'
? []
: identifier.toUpperCase().split('-')
var sorted = codes.every(function (code, index) {
return (
index === 0 ||
code.localeCompare(codes[index - 1]) === 1
)
})
if (!sorted) {
return done('Identifier codes are not in alpha order.')
}
var used = new Array(codes.length)
var fs = require('fs')
var path = require('path')
var VERSION = require('./version')
var license = [
'Berneout Kit License ' +
(identifier === 'BASE' ? 'BASE' : identifier.toUpperCase()),
// TODO: versioning
'Version ' + VERSION,
// TODO: canonical URIs
'https://berneout.org/kit/' + VERSION + '/' + identifier
]
meta.forEach(function (component) {
if (component.standard) {
printComponent(component)
} else {
var index = codes.indexOf(component.code.toUpperCase())
if (index !== -1) {
used[index] = true
printComponent(component)
}
}
})
var unused = []
for (var index = 0; index < used.length; index++) {
if (used[index] !== true) unused.push(codes[index])
}
if (unused.length !== 0) {
return done(
unused
.map(function (unused) {
stream.write('Invalid Code: ' + unused + '\n')
})
.join('\n')
)
}
stream.write(license.join('\n\n') + '\n')
done()
function printComponent (component) {
var file = path.join('components', component.code + '.md')
var stars = component.conspicuous ? '**' : ''
// Uniform Commercial Code 1-201(b)(10):
//
// "Conspicuous", with reference to a term, means so
// written, displayed, or presented that a reasonable
// person against which it is to operate ought to have
// noticed it. Whether a term is "conspicuous" or not is
// a decision for the court. Conspicuous terms include
// the following:
//
// (A) a heading in capitals equal to or greater in
// size than the surrounding text, or in
// contrasting type, font, or color to the
// surrounding text of the same or lesser size;
// and
//
// (B) language in the body of a record or display
// in larger type than the surrounding text, or
// in contrasting type, font, or color to the
// surrounding text of the same size, or set off
// from surrounding text of the same size by
// symbols or other marks that call attention to
// the language.
var label = component.standard ? '' : component.code.toUpperCase() + ': '
var defence = require('defence')
license.push(
label +
stars +
defence(fs.readFileSync(file, 'utf8'))
.replace(/[\n\r\s]+/g, ' ')
.trim() +
stars
)
}
}
var fs = require('fs')
var path = require('path')
combinations()
.forEach(function (identifier) {
var file = path.join(__dirname, 'licenses', identifier)
generate(
identifier,
fs.createWriteStream(file),
function (error) {
if (error) process.stderr.write(error + '\n')
}
)
})