forked from npm/npm-expansions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
32 lines (29 loc) · 897 Bytes
/
build.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
var fs = require("fs")
var infile = __dirname + '/expansions.txt'
var outfile_pre = __dirname + '/expansions'
var outfile_json = outfile_pre + '.json'
var outfile_txt = outfile_pre + '.txt'
var list = fs
.readFileSync(infile, 'utf8')
.split("\n")
.map(function(e) { return e.trim() })
.filter(function(e) { return (e.length > 0) })
.filter(function(e) { return e.charAt(0) !== '#' })
.sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
})
fs.writeFileSync(outfile_json, JSON.stringify(list, null, 2))
fs.writeFileSync(outfile_txt, list.reduce(
function(p, c){
return p + c + '\n'
}, list.shift() + '\n')
)
// reappend the instructions
fs.appendFileSync(
outfile_txt,
"#\n" +
"# please don't add your expansions down here!\n" +
"# insert them in alphabetical order to help reduce merge conflicts.\n" +
"#\n" +
"# <3\n"
)