Skip to content

Commit 3ffa6ab

Browse files
committed
docs: recover main site with documentation generation
1 parent 292d170 commit 3ffa6ab

File tree

6 files changed

+94
-63
lines changed

6 files changed

+94
-63
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ build --repo_env=CC=clang
3333

3434
# linux
3535
build:linux --cxxopt=-stdlib=libc++
36+
# TODO: we need to comment this while building the documentation
37+
# we need a way to make it conditional
3638

3739
# windows
3840
# MSVC

docs/site/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ _DEPS = [
7171
"//:node_modules/@mdx-js/react",
7272
"//:node_modules/@monaco-editor/react",
7373
"//:node_modules/@rtbot-dev/rtbot",
74+
"//:node_modules/@radix-ui/colors",
7475
"//:node_modules/@rtbot-dev/wasm",
7576
"//:node_modules/autoprefixer",
7677
"//:node_modules/clsx",
@@ -89,6 +90,8 @@ _DEPS = [
8990
"//:node_modules/vega",
9091
"//:node_modules/vega-lite",
9192
"//:node_modules/usehooks-ts",
93+
"//:node_modules/remark-math",
94+
"//:node_modules/rehype-katex",
9295
]
9396

9497
docusaurus_bin.docusaurus_binary(

libs/core/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ filegroup(
88
name = "md",
99
srcs = glob([
1010
"include/**/*.md",
11-
]),
11+
], exclude = ["**/README.md", "**/Operator.md"]),
1212
)
1313

1414
filegroup(

libs/std/include/rtbot/std/ArithmeticScalar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ jsonschemas:
213213
required: ["id"]
214214
---
215215

216-
# ArithmeticScalar
216+
# Arithmetic Scalar Operators
217217

218218
The ArithmeticScalar class serves as a base for operators that perform mathematical operations on a single numeric input stream. Each derived class implements a specific mathematical function that is applied to each input value.
219219

libs/std/include/rtbot/std/BooleanSync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ operators:
2020
LogicalNand:
2121
latex:
2222
template: |
23-
\uparrow
23+
2424
LogicalNor:
2525
latex:
2626
template: |

tools/generator/src/index.ts

Lines changed: 86 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ program
2121
.description("RtBot code generator")
2222
.option(
2323
"-s, --sources [sources...]",
24-
"A list of markdown files where the documentation and schema of the operators are stored"
24+
"A list of markdown files where the documentation and schema of the operators are stored",
2525
)
2626
.option("-o, --output <string>", "Output directory")
2727
.addOption(
@@ -31,7 +31,7 @@ program
3131
"cpp",
3232
"python",
3333
"markdown",
34-
])
34+
]),
3535
)
3636
.action(async ({ output, sources, target }) => {
3737
if (sources.length === 1) sources = sources[0].split(" ");
@@ -61,16 +61,16 @@ program
6161
} catch (e) {
6262
console.log(chalk.red(`Error: ${e.message}, file ${f}`));
6363
}
64-
})
64+
}),
6565
);
6666
schemas = schemas
6767
.filter((s) => s)
6868
// flatten the array of schemas
6969
.reduce((acc, s) => acc.concat(s), []);
7070
console.log(
7171
`${chalk.cyan("[schemas] found operators:\n - ")}${chalk.yellow(
72-
schemas.map((s) => s.properties.type.enum[0]).reduce((acc, s) => `${acc}\n - ${s}`)
73-
)}`
72+
schemas.map((s) => s.properties.type.enum[0]).reduce((acc, s) => `${acc}\n - ${s}`),
73+
)}`,
7474
);
7575

7676
const programJsonschema = JSON.parse(jsonschemaTemplate({ schemas: schemas.map((s) => JSON.stringify(s)) }));
@@ -85,62 +85,88 @@ program
8585
if (fileContent.indexOf("---") > -1) {
8686
const frontMatterStr = fileContent.split("---")[1];
8787
const frontMatter = parse(frontMatterStr);
88-
const schema = frontMatter.jsonschema;
89-
// cook up an example parameter object
90-
const getExampleParameter = (k: string) => {
91-
if (k === "id") return '"id"';
92-
if (schema.properties[k].examples) {
93-
if (schema.properties[k].type === "array") return `[${schema.properties[k].examples[0]}]`;
94-
return schema.properties[k].examples[0];
95-
}
96-
if (schema.properties[k].type === "integer") return 2;
97-
if (schema.properties[k].type === "numeric") return 2.0;
98-
if (schema.properties[k].type === "string") return "some";
99-
if (schema.properties[k].type === "boolean") return true;
100-
};
101-
const exampleParameters = Object.keys(schema.properties).reduce(
102-
(acc, k) => ({ ...acc, [`${k}`]: getExampleParameter(k) }),
103-
{}
104-
);
105-
const opParams = Object.keys(exampleParameters).join(", ");
106-
const opParamsDef = Object.keys(exampleParameters).reduce(
107-
(acc, k) => `${acc}const ${k} = ${exampleParameters[k]};\n`,
108-
""
109-
);
110-
const opParamsDefPy = Object.keys(exampleParameters).reduce(
111-
(acc, k) => `${acc}${k} = ${exampleParameters[k]};\n`,
112-
""
113-
);
114-
const opParamsDefCpp = Object.keys(exampleParameters)
115-
.reduce((acc, k) => `${acc}auto ${k} = ${exampleParameters[k]};\n`, "")
116-
.replaceAll("[", "{")
117-
.replaceAll("]", "}");
118-
const opParamsYaml = Object.keys(exampleParameters).reduce(
119-
(acc, k) => `${acc} ${k}: ${exampleParameters[k]}\n`,
120-
""
121-
);
122-
const opParamsJson = Object.keys(exampleParameters)
123-
.reduce((acc, k) => [...acc, `"${k}": ${exampleParameters[k]}`], [])
124-
.join(", ");
88+
const schemas = frontMatter.jsonschemas || [frontMatter.jsonschema];
89+
90+
// Determine if this file has multiple schemas
91+
const hasMultipleSchemas = Array.isArray(schemas) && schemas.length > 1;
92+
93+
let newFileContent = fileContent;
94+
95+
schemas.forEach((schema: any) => {
96+
if (!schema) return;
97+
98+
// Use the filename as the operator type if `type` is not specified
99+
const op = schema.properties?.type?.enum?.[0] || path.basename(f).replace(".md", "");
100+
101+
// Generate the parameters section
102+
const parameters = {
103+
parameters: Object.entries(schema.properties).map(([k, v]: [string, any]) => ({ name: k, ...v })),
104+
};
105+
const parametersSection = parametersMdTemplate(parameters);
125106

126-
const op = path.basename(f).replace(".md", "");
127-
const usageSection = usageMdTemplate({
128-
op,
129-
opParams,
130-
opParamsDef,
131-
opParamsDefPy,
132-
opParamsDefCpp,
133-
opParamsYaml,
134-
opParamsJson,
107+
// Append the parameters section to the file content
108+
// deprecated
109+
// newFileContent += "\n\n" + parametersSection;
110+
111+
// For single schema files, inject the usage section
112+
if (!hasMultipleSchemas) {
113+
// cook up an example parameter object
114+
const getExampleParameter = (k: string) => {
115+
if (k === "id") return '"id"';
116+
if (schema.properties[k].examples) {
117+
if (schema.properties[k].type === "array") return `[${schema.properties[k].examples[0]}]`;
118+
return schema.properties[k].examples[0];
119+
}
120+
if (schema.properties[k].type === "integer") return 2;
121+
if (schema.properties[k].type === "numeric") return 2.0;
122+
if (schema.properties[k].type === "string") return "some";
123+
if (schema.properties[k].type === "boolean") return true;
124+
};
125+
126+
const exampleParameters = Object.keys(schema.properties).reduce(
127+
(acc, k) => ({ ...acc, [`${k}`]: getExampleParameter(k) }),
128+
{},
129+
);
130+
131+
const opParams = Object.keys(exampleParameters).join(", ");
132+
const opParamsDef = Object.keys(exampleParameters).reduce(
133+
(acc, k) => `${acc}const ${k} = ${exampleParameters[k]};\n`,
134+
"",
135+
);
136+
const opParamsDefPy = Object.keys(exampleParameters).reduce(
137+
(acc, k) => `${acc}${k} = ${exampleParameters[k]};\n`,
138+
"",
139+
);
140+
const opParamsDefCpp = Object.keys(exampleParameters)
141+
.reduce((acc, k) => `${acc}auto ${k} = ${exampleParameters[k]};\n`, "")
142+
.replaceAll("[", "{")
143+
.replaceAll("]", "}");
144+
const opParamsYaml = Object.keys(exampleParameters).reduce(
145+
(acc, k) => `${acc} ${k}: ${exampleParameters[k]}\n`,
146+
"",
147+
);
148+
const opParamsJson = Object.keys(exampleParameters)
149+
.reduce((acc, k) => [...acc, `"${k}": ${exampleParameters[k]}`], [])
150+
.join(", ");
151+
152+
const usageSection = usageMdTemplate({
153+
op,
154+
opParams,
155+
opParamsDef,
156+
opParamsDefPy,
157+
opParamsDefCpp,
158+
opParamsYaml,
159+
opParamsJson,
160+
});
161+
162+
// deprecated
163+
//newFileContent += "\n\n" + usageSection;
164+
}
135165
});
136-
const parameters = {
137-
parameters: Object.entries(schema.properties).map(([k, v]: [string, any]) => ({ name: k, ...v })),
138-
};
139-
const parametersSection = parametersMdTemplate(parameters);
140-
fileContent += "\n\n" + parametersSection;
141-
fileContent += "\n\n" + usageSection;
142166

143-
fs.writeFileSync(`${output}/${path.basename(f)}x`, fileContent);
167+
// Write the file with the same name as the original
168+
const outputFileName = `${output}/${path.basename(f)}x`;
169+
fs.writeFileSync(outputFileName, newFileContent);
144170
}
145171
} catch (e) {
146172
console.log(chalk.red(`Error: ${e.message}, file ${f}`), e.stack);
@@ -164,7 +190,7 @@ program
164190
.map((l) => '"' + l.replaceAll('"', '\\"') + '"')
165191
.join("\n")}
166192
""_json;
167-
#endif`.replace(/ +/g, "")
193+
#endif`.replace(/ +/g, ""),
168194
);
169195
}
170196

@@ -230,7 +256,7 @@ program
230256
};
231257

232258
const nonPrototypeSchemas = programJsonschema.properties.operators.items.oneOf.filter(
233-
(schema: any) => !schema.properties?.prototype
259+
(schema: any) => !schema.properties?.prototype,
234260
);
235261

236262
const typescriptContent = typescriptTemplate({

0 commit comments

Comments
 (0)