async function handleConfig2Sidebar()

in scripts/sync-docs.js [281:300]


async function handleConfig2Sidebar(source, target, version, versionedTarget) {
  log(`load ${source} latest docs config.json`);
  const config = JSON.parse(await fs.readFile(`${source}/config.json`));

  const sidebar = JSON.stringify({ docs: config.sidebar || [] }, null, 2);

  const writeVersionedSidebar = async () => {
    if (typeof version === 'undefined') return Promise.resolve();

    const versionedSidebar = JSON.stringify(normalizeSidebar(config.sidebar, version), null, 2);
    await fs.mkdir(versionedTarget, { recursive: true });
    return fs.writeFile(`${versionedTarget}/version-${version}-sidebars.json`, versionedSidebar);
  };

  await Promise.allSettled([
    fs.unlink(`${source}/config.json`),
    fs.writeFile(`${target}/sidebars.json`, sidebar),
    writeVersionedSidebar(),
  ]);
}