mirror of
https://github.com/tauri-apps/rustdocusaurus.git
synced 2026-02-04 10:41:19 +01:00
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
const core = require("@actions/core");
|
|
const { transformDocs } = require("../main");
|
|
const generateSidebar = require("../generateSidebar");
|
|
const fs = require("fs").promises;
|
|
|
|
(async () => {
|
|
try {
|
|
// Where your docs live, should be the folder containing the crates docs
|
|
const originPath = core.getInput("originPath"); // e.g. "/path/to/project/target/doc/";
|
|
|
|
// Where you'll save your MD files
|
|
const targetPath = core.getInput("targetPath"); // e.g. "/path/to/docusaurus/website/docs/api/rust/";
|
|
|
|
/*
|
|
Where lives your sidebars config file
|
|
Doesn't have to be JSON but it's easier to change programmatically,
|
|
you may create your own saving method
|
|
*/
|
|
const sidebarPath = core.getInput("sidebarPath"); // e.g. "/path/to/docusaurus/website/sidebars.json";
|
|
|
|
// rustdoc uses relative links for crate types relations
|
|
const linksRoot = core.getInput("linksRoot"); // e.g. "/docs/api/rust/";
|
|
|
|
const cratesToProcess = core.getInput("cratesToProcess").split(",");
|
|
|
|
await Promise.all(
|
|
cratesToProcess.map((crateName) =>
|
|
fs.rmdir(targetPath + crateName, { recursive: true })
|
|
)
|
|
);
|
|
|
|
const sidebarItems = (
|
|
await Promise.all(
|
|
cratesToProcess.map(async (crateName) => ({
|
|
crateName,
|
|
docs: await transformDocs(
|
|
originPath + crateName,
|
|
originPath,
|
|
targetPath
|
|
),
|
|
}))
|
|
)
|
|
).map((item) => generateSidebar(item.docs, item.crateName, originPath));
|
|
|
|
fs.writeFile(sidebarPath, JSON.stringify(sidebarItems, null, 2));
|
|
|
|
console.log("Tasks completed!");
|
|
} catch (error) {
|
|
core.debug(error.stack);
|
|
core.setFailed(error.message);
|
|
}
|
|
})();
|