-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
69 lines (54 loc) · 1.69 KB
/
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
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
const fs = require('extra-fs');
const build = require('extra-build');
const csv = require('csv-parse');
const owner = 'ifct2017';
const repo = build.readMetadata('.').name.replace(/@.+\//g, '');
function writeCorpus() {
return new Promise(resolve => {
var map = new Map();
var stream = fs.createReadStream('index.csv').pipe(csv.parse({columns: true, comment: '#'}));
stream.on('data', r => {
r.entries = parseInt(r.entries, 10);
map.set(r.code, r);
});
stream.on('end', () => {
var a = `const CORPUS = new Map([\n`;
for (var [k, v] of map)
a += ` ["${k}", ${JSON.stringify(v).replace(/\"(\w+)\":/g, '$1:')}],\n`;
a += `]);\n`;
a += `module.exports = CORPUS;\n`;
fs.writeFileTextSync('corpus.js', a);
resolve();
});
});
}
// Publish a root package to NPM, GitHub.
function publishRootPackage(ver) {
var _package = build.readDocument('package.json');
var m = build.readMetadata('.');
m.version = ver;
build.writeMetadata('.', m);
build.publish('.');
try { build.publishGithub('.', owner); }
catch {}
build.writeDocument(_package);
}
// Publish root, sub packages to NPM, GitHub.
async function publishPackages() {
var m = build.readMetadata('.');
var ver = build.nextUnpublishedVersion(m.name, m.version);
await writeCorpus();
publishRootPackage(ver);
}
// Publish docs.
function publishDocs() {
var m = build.readMetadata('.');
build.updateGithubRepoDetails({owner, repo, topics: m.keywords});
}
// Finally.
async function main(a) {
if (a[2]==='publish-docs') publishDocs();
else if (a[2]==='publish-packages') await publishPackages();
else await writeCorpus();
}
main(process.argv);