1 |
|
2 | const nomnoml = require('nomnoml');
|
3 | const fs = require('fs');
|
4 | const path = require('path');
|
5 |
|
6 | const basePath = path.resolve(__dirname, '..');
|
7 | const docImageDir = path.join(basePath, 'docs/images');
|
8 | const nomnomlSourceDir = path.join(basePath, 'docs/images/sources');
|
9 |
|
10 | const buildImages = {
|
11 | build() {
|
12 | const files = fs.readdirSync(nomnomlSourceDir);
|
13 |
|
14 | while (files.length > 0) {
|
15 | const file = path.resolve(nomnomlSourceDir, files.shift());
|
16 | const basename = path.basename(file, 'txt');
|
17 |
|
18 | if (/.nomnoml/.test(basename)) {
|
19 | const fileContents = fs.readFileSync(file, 'utf-8');
|
20 | const generated = nomnoml.renderSvg(fileContents);
|
21 | const newFilePath = path.join(docImageDir, basename) + 'svg';
|
22 | const outFile = fs.createWriteStream(newFilePath);
|
23 |
|
24 | console.log(`wrote file ${newFilePath}`);
|
25 | outFile.write(generated);
|
26 | }
|
27 | }
|
28 | }
|
29 | };
|
30 |
|
31 | buildImages.build();
|