-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·31 lines (25 loc) · 1.04 KB
/
Copy pathbuild
File metadata and controls
executable file
·31 lines (25 loc) · 1.04 KB
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
#!/usr/bin/env node
import * as Handlebars from 'handlebars';
import { readFile, writeFile } from 'fs/promises';
async function render(templateFile, data, partials, output) {
const template = await readFile(templateFile, 'utf-8');
const compiled = Handlebars.default.compile(template);
const content = compiled(data);
await writeFile(output, content);
}
async function loadJson(file) {
const json = await readFile(file, 'utf-8');
return JSON.parse(json);
}
const partials = [ 'description', 'query', 'query-enum', 'query-media-type', 'query-range', 'unsupported' ];
for (const partial of partials) {
const content = await readFile(`${partial}.hbs`, 'utf-8');
Handlebars.default.registerPartial(partial, content);
}
const data = {
fudgel: await readFile('node_modules/fudgel/dist/fudgel.umd.min.js', 'utf-8'),
queries: await loadJson('queries.json'),
rangeFinder: await readFile('range-finder.js', 'utf-8'),
};
render('README.hbs', data, partials, 'README.md');
render('index.hbs', data, partials, 'index.html');