#!/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();