From 2195c79c185aabfff70716628b1d24536cb30e10 Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:04:48 -0700 Subject: [PATCH 1/9] wip --- .github/workflows/check.tsx | 2 + .github/workflows/shared.tsx | 2 + .gitignore | 11 ++ .vscode/extensions.json | 5 + .vscode/settings.json | 15 +- README.md | 4 - components/Button.tsx | 12 ++ deno.jsonc | 47 ++++-- deno.lock | 87 ---------- dev.ts | 8 + docs.ts | 110 ------------- fresh.config.ts | 3 + fresh.gen.ts | 27 ++++ .../playground_island.tsx | 55 ++----- lib/docs/docs.ts | 69 ++++++++ lib/docs/mod.ts | 1 + lib/kv/kv.ts | 1 + lib/kv/mod.ts | 1 + lib/playground/build.ts | 29 ++++ lib/playground/deps.ts | 7 + lib/playground/editor.ts | 23 +++ lib/playground/elements.ts | 119 ++++++++++++++ lib/playground/mod.ts | 1 + lib/playground/output.ts | 38 +++++ lib/playground/playground.ts | 150 ++++++++++++++++++ main.ts | 31 ++-- routes/_404.tsx | 27 ++++ routes/_app.tsx | 17 ++ routes/index.tsx | 42 +++++ routes/meta.ts | 9 ++ routes/playgrounds/[id].ts | 15 ++ static/lib/playground/build.js | 21 --- static/lib/playground/editor.js | 16 -- static/lib/playground/index.js | 1 - static/lib/playground/output.js | 32 ---- static/lib/playground/playground.js | 100 ------------ static/logo.svg | 6 + static/play.js | 37 ----- static/{lib/playground => }/playground.css | 0 static/styles.css | 129 +++++++++++++++ 40 files changed, 825 insertions(+), 485 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 components/Button.tsx delete mode 100644 deno.lock create mode 100644 dev.ts delete mode 100644 docs.ts create mode 100644 fresh.config.ts create mode 100644 fresh.gen.ts rename static/index.html => islands/playground_island.tsx (55%) create mode 100644 lib/docs/docs.ts create mode 100644 lib/docs/mod.ts create mode 100644 lib/kv/kv.ts create mode 100644 lib/kv/mod.ts create mode 100644 lib/playground/build.ts create mode 100644 lib/playground/deps.ts create mode 100644 lib/playground/editor.ts create mode 100644 lib/playground/elements.ts create mode 100644 lib/playground/mod.ts create mode 100644 lib/playground/output.ts create mode 100644 lib/playground/playground.ts create mode 100644 routes/_404.tsx create mode 100644 routes/_app.tsx create mode 100644 routes/index.tsx create mode 100644 routes/meta.ts create mode 100644 routes/playgrounds/[id].ts delete mode 100644 static/lib/playground/build.js delete mode 100644 static/lib/playground/editor.js delete mode 100644 static/lib/playground/index.js delete mode 100644 static/lib/playground/output.js delete mode 100644 static/lib/playground/playground.js create mode 100644 static/logo.svg delete mode 100644 static/play.js rename static/{lib/playground => }/playground.css (100%) create mode 100644 static/styles.css diff --git a/.github/workflows/check.tsx b/.github/workflows/check.tsx index 7646b56..b443178 100644 --- a/.github/workflows/check.tsx +++ b/.github/workflows/check.tsx @@ -1,3 +1,5 @@ +/** @jsxImportSource @fartlabs/jsonx */ + import { stringify } from "@std/yaml"; import { CheckoutStep, SetupDenoStep } from "./shared.tsx"; diff --git a/.github/workflows/shared.tsx b/.github/workflows/shared.tsx index f238fda..28dd5bd 100644 --- a/.github/workflows/shared.tsx +++ b/.github/workflows/shared.tsx @@ -1,3 +1,5 @@ +/** @jsxImportSource @fartlabs/jsonx */ + /** * CheckoutStep is a step that checks out the repository. */ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b4bdef --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# Fresh build directory +_fresh/ +# npm dependencies +node_modules/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..09cf720 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "denoland.vscode-deno" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 0d99cbf..563216d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,19 +1,18 @@ { "deno.enable": true, "deno.unstable": true, - "editor.formatOnSave": true, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "[markdown]": { - "editor.defaultFormatter": "denoland.vscode-deno" - }, - "[jsonc]": { + "deno.lint": true, + "editor.defaultFormatter": "denoland.vscode-deno", + "[typescriptreact]": { "editor.defaultFormatter": "denoland.vscode-deno" }, "[typescript]": { "editor.defaultFormatter": "denoland.vscode-deno" }, - "[typescriptreact]": { + "[javascriptreact]": { "editor.defaultFormatter": "denoland.vscode-deno" }, - "files.eol": "\n" + "[javascript]": { + "editor.defaultFormatter": "denoland.vscode-deno" + } } diff --git a/README.md b/README.md index 294edc0..1f66a39 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,6 @@ Run `deno task generate` to generate code. Run `deno task start` to locally serve the jsonx documentation site. -### Testing - -Run `deno task test` to run the unit tests. - --- Developed with ❤️ [**@FartLabs**](https://github.com/FartLabs) diff --git a/components/Button.tsx b/components/Button.tsx new file mode 100644 index 0000000..f1b80a0 --- /dev/null +++ b/components/Button.tsx @@ -0,0 +1,12 @@ +import { JSX } from "preact"; +import { IS_BROWSER } from "$fresh/runtime.ts"; + +export function Button(props: JSX.HTMLAttributes) { + return ( + diff --git a/islands/playground/playground_script.tsx b/islands/playground/playground_script.tsx new file mode 100644 index 0000000..17f8fcd --- /dev/null +++ b/islands/playground/playground_script.tsx @@ -0,0 +1,25 @@ +export interface PlaygroundScriptProps { + code: string; + autoplay?: boolean; +} + +export default function PlaygroundScript(props: PlaygroundScriptProps) { + return ( +
`, + }} + > +
+ ); +} + +function initializeConstants(props: PlaygroundScriptProps) { + return Object.keys(props).map((key) => { + return `const INITIAL_${key.toUpperCase()} = ${ + JSON.stringify(props[key as keyof PlaygroundScriptProps]) + };`; + }).join(); +} diff --git a/routes/examples/[id].ts b/routes/examples/[id].ts new file mode 100644 index 0000000..19dfb2c --- /dev/null +++ b/routes/examples/[id].ts @@ -0,0 +1,9 @@ +import type { Handlers } from "$fresh/server.ts"; +import { getExampleByName } from "#/server/examples/mod.ts"; + +export const handler: Handlers = { + async GET(_request, ctx) { + const example = await getExampleByName(ctx.params.id); + return new Response(example); + }, +}; diff --git a/routes/index.tsx b/routes/index.tsx index f3357c9..285eb06 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -1,19 +1,41 @@ import { Head } from "$fresh/runtime.ts"; import PlaygroundIsland from "#/islands/playground/playground_island.tsx"; import Nav from "#/client/nav.tsx"; +import { kv } from "#/server/kv.ts"; +import { getExampleByName } from "#/server/examples/mod.ts"; +import { getPlayground } from "#/server/playgrounds.ts"; +import { getMeta } from "#/client/meta.ts"; + +export default async function Home(request: Request) { + const url = new URL(request.url); + const id = url.searchParams.get("id"); + let code = ""; + let version: string | undefined = undefined; + if (id) { + const playground = await getPlayground(kv, id); + if (!playground) { + throw new Error("Playground not found!"); + } + + code = playground.code; + version = playground.version; + } else { + code = await getExampleByName("01_animals.tsx"); + } + + const meta = await getMeta(); -export default function Home() { return ( <> jsonx | Documentation - +