1 | #!/usr/bin/env node
|
2 |
|
3 | const fs = require("fs");
|
4 | const path = require("path");
|
5 |
|
6 | function 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 |
|
15 | const tests = getFiles("./test/programs");
|
16 | const ensureTrailingLineBrake = (contents) => (contents[contents.length - 1] === "\n" ? contents : contents + "\n");
|
17 |
|
18 | let source =
|
19 | "_Auto-generated file. Updated with NPM deploy. Update manually with 'yarn docs'._\n\n" +
|
20 | "# typescript-json-schema test examples\n\n";
|
21 | tests.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 |
|
27 | fs.writeFileSync("./api.md", source);
|