forked from MinaProtocol/docs2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-sidebars-snarkyjs-api.js
64 lines (53 loc) · 2.16 KB
/
update-sidebars-snarkyjs-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Usage: node update-sidebars-snarkyjs-api.js
* This script will update the sidebars.js file with the latest SnarkyJS API. It will only modify the `SnarkyJS API Reference` category.
*/
const fs = require("fs");
const sidebars = require("./sidebars.js");
function getAllSnarkyJSAPIPathnames(directory) {
return fs
.readdirSync(`./docs/zkapps/snarkyjs-reference/${directory}`)
.map((file) => {
const fileName = file.replace(".md", "");
return {
type: "doc",
id: `zkapps/snarkyjs-reference/${directory}/${fileName}`,
label: `${fileName}`,
};
});
}
function updateSidebars(sidebars, category, snarkyJSItems) {
let { ...newSidebars } = sidebars;
// Find the index of the `zkApp Developers` category in the sidebars
const zkAppCategory = newSidebars.docs.findIndex(
(item) => item.label === "zkApp Developers"
);
// Find the index of the `SnarkyJS API Reference` category in the sidebars
const snarkyJSAPICategory = newSidebars.docs[zkAppCategory].items.findIndex(
(item) => item.label === "SnarkyJS Reference"
);
// Find the index of the category we want to update in the sidebars
const categoryToFind = newSidebars.docs[zkAppCategory].items[
snarkyJSAPICategory
].items.findIndex((item) => {
return item.label === category;
});
// Update the category with the new items
newSidebars.docs[zkAppCategory].items[snarkyJSAPICategory].items[
categoryToFind
].items = snarkyJSItems;
return newSidebars;
}
// Import all the "classes" from the SnarkyJS API Reference
const snarkyjsClasses = getAllSnarkyJSAPIPathnames("classes");
// Import all the "interfaces" from the SnarkyJS API Reference
const snarkyjsInterfaces = getAllSnarkyJSAPIPathnames("interfaces");
// Import all the "modules" from the SnarkyJS API Reference
const snarkyjsModules = getAllSnarkyJSAPIPathnames("modules");
let newSidebars = updateSidebars(sidebars, "Classes", snarkyjsClasses);
newSidebars = updateSidebars(sidebars, "Interfaces", snarkyjsInterfaces);
newSidebars = updateSidebars(sidebars, "Modules", snarkyjsModules);
fs.writeFileSync(
"./sidebars.js",
`module.exports = ${JSON.stringify(newSidebars, null, 2)}`
);