1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-29 16:47:56 +00:00

Some web tooling changes

- Switch to tsx from ts-node, fixing issues on Node 20
 - Update rehype
This commit is contained in:
Jonathan Coates
2023-09-18 17:15:03 +01:00
parent b1248e4901
commit 6c8b391dab
5 changed files with 863 additions and 1777 deletions

View File

@@ -67,7 +67,7 @@ val jsxDocs by tasks.registering(cc.tweaked.gradle.NpxExecToDir::class) {
// Output directory. Also defined in src/transform.tsx
output.set(buildDir.resolve("jsxDocs"))
args = listOf("ts-node", "-T", "--esm", "src/transform.tsx")
args = listOf("tsx", "src/transform.tsx")
}
val docWebsite by tasks.registering(Copy::class) {

View File

@@ -4,7 +4,7 @@
import type { FunctionComponent } from "react";
import { createElement as h } from "react";
import useExport from "./WithExport.js";
import useExport from "./WithExport";
const Item: FunctionComponent<{ item: string }> = ({ item }) => {
const data = useExport();

View File

@@ -13,38 +13,38 @@
import * as fs from "fs/promises";
import { glob } from "glob";
import * as path from "path";
import { createElement, createElement as h, Fragment } from 'react';
import { createElement as h } from 'react';
import runtime from 'react/jsx-runtime';
import { renderToStaticMarkup } from "react-dom/server";
import rehypeHighlight from "rehype-highlight";
import rehypeParse from 'rehype-parse';
import rehypeReact from 'rehype-react';
import rehypeReact, { type Options as ReactOptions } from 'rehype-react';
import { unified } from 'unified';
// Our components
import Recipe from "./components/Recipe.js";
import { noChildren } from "./components/support.js";
import { type DataExport, WithExport } from "./components/WithExport.js";
import Recipe from "./components/Recipe";
import { noChildren } from "./components/support";
import { type DataExport, WithExport } from "./components/WithExport";
(async () => {
const base = "build/illuaminate";
const reactOptions: ReactOptions = {
...(runtime as ReactOptions),
components: {
['mc-recipe']: noChildren(Recipe),
['mcrecipe']: noChildren(Recipe),
// Wrap example snippets in a <div class="lua-example">...</div>, so we can inject a
// Run button into them.
['pre']: (args: JSX.IntrinsicElements["pre"] & { "data-lua-kind"?: undefined }) => {
const element = <pre {...args} />;
return args["data-lua-kind"] ? <div className="lua-example">{element}</div> : element
}
} as any
};
const processor = unified()
.use(rehypeParse, { emitParseErrors: true })
.use(rehypeHighlight, { prefix: "" })
.use(rehypeReact, {
createElement,
Fragment,
passNode: false,
components: {
['mc-recipe']: noChildren(Recipe),
['mcrecipe']: noChildren(Recipe),
// Wrap example snippets in a <div class="lua-example">...</div>, so we can inject a
// Run button into them.
['pre']: (args: JSX.IntrinsicElements["pre"] & { "data-lua-kind"?: undefined }) => {
const element = <pre {...args} />;
return args["data-lua-kind"] ? <div className="lua-example">{element}</div> : element
}
} as any
});
.use(rehypeReact, reactOptions);
const dataExport = JSON.parse(await fs.readFile("src/export/index.json", "utf-8")) as DataExport;