mirror of
https://github.com/kou029w/zenn.dev.git
synced 2025-01-18 16:07:59 +00:00
33 lines
760 B
JavaScript
Executable file
33 lines
760 B
JavaScript
Executable file
#!/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() {
|
|
let chapter = 1;
|
|
|
|
for (const id of flatten(sidebars)) {
|
|
const file = path.resolve(docsPath, `${id}.md`);
|
|
try {
|
|
await fs.stat(file);
|
|
} catch {
|
|
continue;
|
|
}
|
|
await fs.copyFile(
|
|
file,
|
|
path.resolve(bookPath, `${chapter}.${id.replaceAll("/", "-")}.md`)
|
|
);
|
|
chapter += 1;
|
|
}
|
|
}
|
|
|
|
main();
|