-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrender.ts
41 lines (38 loc) · 1.17 KB
/
render.ts
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
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-floating-promises */
import * as fs from 'fs';
import * as child from 'child_process';
import * as assert from 'assert';
import * as util from 'util';
const md: string = fs.readFileSync('README.template.md', 'utf8');
const examples: string[] = [];
fs.writeFileSync(
'README.md',
md.replace(/^>>(.*)/gm, (match, file) => {
const m = file.trim();
const example: any = fs.readFileSync('./' + m, 'utf8');
const runner = example.split('\n')[0].match(/\/\/(.*)/)[1];
assert(runner, 'missing runner command');
examples.push(runner.trim());
return example;
})
);
Promise.all(
examples.map(async example => {
console.log('testing ' + example);
try {
await util.promisify(child.exec)(example);
return example + ': ok';
} catch (e: any) {
return example + ': error ' + e.message;
}
})
).then(results => {
const errors = results.filter(result => /: error/.test(result));
if (errors.length > 0) {
console.error('errors in rendering');
errors.map(error => console.error(error));
process.exit(1);
}
results.map(result => console.log(result));
});