1
0
Fork 0
mirror of https://github.com/kou029w/zenn.dev.git synced 2025-01-18 16:07:59 +00:00
zenn.dev/bin/bookgen

34 lines
760 B
Text
Raw Normal View History

2020-09-17 23:28:18 +09:00
#!/usr/bin/env node
const path = require("path");
const fs = require("fs/promises");
const sidebars = require("../csb-jp.github.io/sidebars.js");
const docsPath = "csb-jp.github.io/docs";
const bookPath = "books/codesandbox-guidebook";
function flatten(object) {
const values = (value) =>
typeof value === "object" ? flatten(value) : [value];
return Object.values(object).flatMap(values);
}
async function main() {
2022-06-13 23:36:23 +09:00
let chapter = 1;
2020-09-17 23:28:18 +09:00
for (const id of flatten(sidebars)) {
const file = path.resolve(docsPath, `${id}.md`);
try {
await fs.stat(file);
} catch {
continue;
}
2022-06-13 23:36:23 +09:00
await fs.copyFile(
file,
path.resolve(bookPath, `${chapter}.${id.replaceAll("/", "-")}.md`)
);
chapter += 1;
2020-09-17 23:28:18 +09:00
}
}
main();