-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
77 lines (60 loc) · 1.88 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
70
71
72
73
74
75
76
77
const fs = require('extra-fs');
const build = require('extra-build');
const owner = 'ifct2017';
const repo = build.readMetadata('.').name.replace(/@.+\//g, '');
function readAssets() {
var a = new Map();
for (var f of fs.readdirSync('assets'))
a.set(f.replace('.txt', ''), fs.readFileTextSync(`assets/${f}`));
return a;
}
function readIndex() {
var a = new Map(), txt = fs.readFileTextSync('index.txt');
var re = /\[\[([\w:]+)\]\]\n([\w\W]*?)\n\n\n/g, m;
while ((m = re.exec(txt)) != null) {
var k = m[1], v = m[2].trim();
if (!k.endsWith(':')) a.set(k, [v]);
else a.set(k.replace(/:.*/, ''), v.split('\n'));
}
return a;
}
function writeCorpus(map) {
var a = `const CORPUS = new Map([\n`;
for (var [k, v] of map)
a += ` ["${k}", ${JSON.stringify(v)}],\n`;
a += `]);\n`;
a += `module.exports = CORPUS;\n`;
fs.writeFileTextSync('corpus.js', a);
}
// 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);
}
// Pushish root, sub packages to NPM, GitHub.
function publishPackages() {
var m = build.readMetadata('.');
var ver = build.nextUnpublishedVersion(m.name, m.version);
if (fs.existsSync('index.txt')) writeCorpus(readIndex());
else writeCorpus(readAssets());
publishRootPackage(ver);
}
// Publish docs.
function publishDocs() {
var m = build.readMetadata('.');
build.updateGithubRepoDetails({owner, repo, topics: m.keywords});
}
// Finally.
function main(a) {
if (a[2]==='publish-docs') publishDocs();
else if (a[2]==='publish-packages') publishPackages();
else if (/index/i.test(a[2])) writeCorpus(readIndex());
else writeCorpus(readAssets());
}
main(process.argv);