Skip to content

Commit 35819e1

Browse files
committed
feat: add an interactive playground to the documentation site
1 parent d982546 commit 35819e1

32 files changed

+2409
-65
lines changed

packages/documentation/next.config.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import nextra from "nextra"
2+
import NodePolyfillPlugin from "node-polyfill-webpack-plugin"
23

34
/** @type {import('next').NextConfig} */
45
const nextConfig = {
@@ -8,6 +9,20 @@ const nextConfig = {
89
images: {
910
unoptimized: true,
1011
},
12+
webpack: (config, {buildId, dev, isServer, defaultLoaders, webpack}) => {
13+
config.experiments = {...config.experiments, syncWebAssembly: true}
14+
config.plugins.push(new NodePolyfillPlugin())
15+
config.module.rules.push({
16+
test: /node:.+/i,
17+
use: "null-loader",
18+
})
19+
config.module.rules.push({
20+
test: /@biomejs\/wasm-nodejs/i,
21+
use: "null-loader",
22+
})
23+
24+
return config
25+
},
1126
async redirects() {
1227
return [{source: "/", destination: "/overview/about", permanent: false}]
1328
},

packages/documentation/package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,34 @@
1818
},
1919
"scripts": {
2020
"clean": "rm -rf ./.next ./dist",
21-
"dev": "next dev",
22-
"build": "next build",
23-
"lint": "next lint",
21+
"dev": "yarn copy-sample-data && next dev",
22+
"build": "yarn copy-sample-data && next build",
23+
"lint": "yarn run -T lint",
24+
"format": "yarn run -T format",
25+
"copy-sample-data": "tsx ./scripts/copy-sample-data.ts",
2426
"publish:gh-pages": "yarn gh-pages -d ./dist -b gh-pages --cname openapi-code-generator.nahkies.co.nz --nojekyll"
2527
},
2628
"dependencies": {
29+
"@hookform/resolvers": "^3.9.1",
30+
"@monaco-editor/react": "^4.6.0",
31+
"@nahkies/openapi-code-generator": "*",
32+
"monaco-editor": "^0.52.2",
33+
"monaco-editor-auto-typings": "^0.4.6",
2734
"next": "15.1.2",
2835
"nextra": "^3.3.0",
2936
"nextra-theme-docs": "^3.3.0",
37+
"node-polyfill-webpack-plugin": "^4.1.0",
3038
"react": "19.0.0",
31-
"react-dom": "19.0.0"
39+
"react-dom": "19.0.0",
40+
"react-hook-form": "^7.54.2"
3241
},
3342
"devDependencies": {
3443
"@types/node": "^22.10.2",
3544
"@types/react": "^19.0.2",
3645
"@types/react-dom": "^19.0.2",
3746
"gh-pages": "^6.2.0",
47+
"null-loader": "^4.0.1",
48+
"tsx": "^4.19.2",
3849
"typescript": "^5.7.2"
3950
}
4051
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {copyFile} from "node:fs/promises"
2+
import {dirname, resolve} from "node:path"
3+
import {fileURLToPath} from "node:url"
4+
import {sampleFilenames} from "../src/lib/playground/consts"
5+
6+
const __filename = fileURLToPath(import.meta.url)
7+
const __dirname = dirname(__filename)
8+
9+
for (const sample of sampleFilenames) {
10+
const sourcePath = resolve(
11+
__dirname,
12+
`../../../integration-tests-definitions/${sample}`,
13+
)
14+
const destinationPath = resolve(__dirname, `../public/samples/${sample}`)
15+
16+
try {
17+
await copyFile(sourcePath, destinationPath)
18+
console.log(`Copied ${sample} to ${destinationPath}`)
19+
} catch (error) {
20+
console.error(`Failed to copy ${sample}:`, error)
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.loader {
2+
width: 1rem;
3+
height: 1rem;
4+
border: 5px solid #363636;
5+
border-bottom-color: transparent;
6+
border-radius: 50%;
7+
display: inline-block;
8+
box-sizing: border-box;
9+
animation: rotation 1s linear infinite;
10+
}
11+
12+
@keyframes rotation {
13+
0% {
14+
transform: rotate(0deg);
15+
}
16+
100% {
17+
transform: rotate(360deg);
18+
}
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import styles from "./loading-spinner.module.css"
2+
3+
export const LoadingSpinner = () => {
4+
return <span className={styles.loader} />
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.editorContainer {
2+
display: grid;
3+
grid-template-columns: 1fr;
4+
grid-template-rows: auto;
5+
6+
/*
7+
TODO: rendering side-by-side results in weird stuff happening
8+
when breakpoints change, stick with the vertical stack for now.
9+
@media (min-width: 1536px) {
10+
grid-template-columns: 1fr 1fr;
11+
}
12+
*/
13+
}

0 commit comments

Comments
 (0)