forked from noonat/intersect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
64 lines (59 loc) · 1.7 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
const {execFile} = require('child_process');
const {readFile, rename, writeFile} = require('fs');
const md = require('markdown-it')();
execFile('docco', [
'--css', 'template/docco.css',
'--template', 'template/docco.jst',
'src/intersect.ts.md',
], (err, stdout, stderr) => {
if (err) {
console.log('ERROR: docco failed');
console.log('docco stdout:', stdout);
console.log('docco stderr:', stderr);
throw err;
}
rename('docs/src/intersect.ts.html', 'index.html', (err) => {
if (err) {
throw err;
}
})
});
readFile('src/intersect.ts.md', (err, data) => {
if (err) {
throw err;
}
let blocks = ['"use strict";\n\n'];
md.renderer.rules = {
code_block(tokens, index) {
// We can't express empty lines for readability in Markdown, since most
// of the code is in separate code blocks. Try to make the result more
// readable by adding a blank line after blocks ending in a closing brace.
if (blocks.length > 0 && blocks[blocks.length - 1].match(/}\s+$/)) {
blocks.push('\n');
}
blocks.push(tokens[index].content);
}
};
md.render(data.toString('UTF-8'));
writeFile('src/intersect.ts', blocks.join(''), (err) => {
if (err) {
throw err;
}
execFile('tsc', (err, stdout, stderr) => {
if (err) {
console.log('ERROR: tsc failed');
console.log('tsc stdout:', stdout);
console.log('tsc stderr:', stderr);
throw err;
}
});
execFile('webpack', (err, stdout, stderr) => {
if (err) {
console.log('ERROR: webpack failed');
console.log('webpack stdout', stdout);
console.log('webpack stderr', stderr);
throw err;
}
});
});
});