UNPKG

951 BJavaScriptView Raw
1/* eslint-disable no-console */
2const nomnoml = require('nomnoml');
3const fs = require('fs');
4const path = require('path');
5
6const basePath = path.resolve(__dirname, '..');
7const docImageDir = path.join(basePath, 'docs/images');
8const nomnomlSourceDir = path.join(basePath, 'docs/images/sources');
9
10const 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
31buildImages.build();