extract_sidebar.mjs
1 // Imports a Docusaurus sidebar JS file, renders it as a JSON and writes it to a file. 2 // Usage: node extract_sidebar.mjs <path-to-sidebars.js> <output-path> 3 4 import { pathToFileURL } from "url"; 5 import { resolve } from "path"; 6 import { writeFileSync } from "fs"; 7 8 const [, , sidebarPath, outputPath] = process.argv; 9 10 if (!sidebarPath || !outputPath) { 11 process.stderr.write("Usage: node extract_sidebar.mjs <path-to-sidebars.js> <output-path>\n"); 12 process.exit(1); 13 } 14 15 const mod = await import(pathToFileURL(resolve(sidebarPath)).href); 16 writeFileSync(resolve(outputPath), JSON.stringify(mod.default, null, 2));