UNPKG

1.03 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3const fs = require("fs");
4const path = require("path");
5
6function getFiles(base) {
7 const directory = fs.readdirSync(base, { withFileTypes: true });
8 const files = directory.map((dir) => {
9 const res = path.resolve(base, dir.name);
10 return dir.isDirectory() ? getFiles(res) : res;
11 });
12 return Array.prototype.concat(...files).filter((file) => file.indexOf(".ts") > 0);
13}
14
15const tests = getFiles("./test/programs");
16const ensureTrailingLineBrake = (contents) => (contents[contents.length - 1] === "\n" ? contents : contents + "\n");
17
18let source =
19 "_Auto-generated file. Updated with NPM deploy. Update manually with 'yarn docs'._\n\n" +
20 "# typescript-json-schema test examples\n\n";
21tests.forEach((file) => {
22 const contents = fs.readFileSync(file, "utf8");
23 const folder = file.split("/").slice(-2)[0];
24 source += `## [${folder}](./test/programs/${folder})\n\n\`\`\`ts\n${ensureTrailingLineBrake(contents)}\`\`\`\n\n\n`;
25});
26
27fs.writeFileSync("./api.md", source);