Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
begin fresh refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Dec 24, 2022
1 parent e066c9c commit 5ad6758
Show file tree
Hide file tree
Showing 23 changed files with 179 additions and 12 deletions.
8 changes: 3 additions & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
"**/.git/subtree-cache/**": true,
"target/**": true
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"deno.codeLens.testArgs": ["--no-check=remote", "-A", "-L=info"],
"deno.config": "./deno.jsonc",
"deno.codeLens.testArgs": ["-A", "-L=info"],
"deno.config": "./deno.json",
"deno.enable": true,
"deno.lint": true,
"editor.defaultFormatter": "dprint.dprint",
Expand All @@ -34,6 +31,7 @@
"dprint.dprint",
"esbenp.prettier-vscode",
"ms-azuretools.vscode-docker",
"sastan.twind-intellisense",
"streetsidesoftware.code-spell-checker",
"vadimcn.vscode-lldb"
],
Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dprint.dprint",
"esbenp.prettier-vscode",
"ms-azuretools.vscode-docker",
"sastan.twind-intellisense",
"streetsidesoftware.code-spell-checker",
"vadimcn.vscode-lldb"
]
Expand Down
7 changes: 2 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"deno.codeLens.testArgs": ["--no-check=remote", "-A", "-L=info"],
"deno.config": "./deno.jsonc",
"deno.codeLens.testArgs": ["-A", "-L=info"],
"deno.config": "./deno.json",
"deno.importMap": "./import_map.json",
"deno.suggest.imports.hosts": {
"https://deno.land": true,
Expand Down
12 changes: 12 additions & 0 deletions components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { JSX } from "preact";
import { IS_BROWSER } from "$fresh/runtime.ts";

export function Button(props: JSX.HTMLAttributes<HTMLButtonElement>) {
return (
<button
{...props}
disabled={!IS_BROWSER || props.disabled}
class="px-2 py-1 border(gray-100 2) hover:bg-gray-200"
/>
);
}
11 changes: 11 additions & 0 deletions components/Meta.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Head } from "$fresh/runtime.ts"

export function Meta({ pageTitle }: { pageTitle: string }) {
const title = `Capi Console –– ${pageTitle}`
return (
<Head>
<title>{title}</title>
<meta name="description" content={title} />
</Head>
)
}
5 changes: 4 additions & 1 deletion deno.jsonc → deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"compilerOptions": {
"checkJs": false,
"jsx": "react-jsx",
"jsxImportSource": "preact",
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
Expand Down Expand Up @@ -38,6 +40,7 @@
"test": "deno task run test_util/ctx.ts -- deno test -A -L=info --ignore=target --parallel",
"test:update": "deno task test -- -- --update",
"bench": "deno bench -A",
"moderate": "deno task run https://deno.land/x/[email protected]/mod.ts && dprint fmt"
"moderate": "deno task run https://deno.land/x/[email protected]/mod.ts && dprint fmt",
"start": "deno task run --watch=docs/,routes/,static/ dev.ts"
}
}
3 changes: 3 additions & 0 deletions dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import dev from "$fresh/dev.ts"

await dev(import.meta.url, "./main.ts")
2 changes: 1 addition & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"semiColons": "asi"
},
"includes": ["**.{dockerfile,json,md,toml,ts,tsx}"],
"excludes": ["frame_metadata/raw_erc20_metadata.json", "target"],
"excludes": ["target"],
"plugins": [
"https://plugins.dprint.dev/dockerfile-0.3.0.wasm",
"https://plugins.dprint.dev/json-0.17.0.wasm",
Expand Down
30 changes: 30 additions & 0 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// DO NOT EDIT. This file is generated by fresh.
// This file SHOULD be checked into source version control.
// This file is automatically updated during development when running `dev.ts`.

import config from "./deno.json" assert { type: "json" };
import * as $0 from "./routes/[...path].tsx";
import * as $1 from "./routes/_404.tsx";
import * as $2 from "./routes/_500.tsx";
import * as $3 from "./routes/_app.tsx";
import * as $4 from "./routes/docs/[...path].tsx";
import * as $5 from "./routes/index.tsx";
import * as $$0 from "./islands/Counter.tsx";

const manifest = {
routes: {
"./routes/[...path].tsx": $0,
"./routes/_404.tsx": $1,
"./routes/_500.tsx": $2,
"./routes/_app.tsx": $3,
"./routes/docs/[...path].tsx": $4,
"./routes/index.tsx": $5,
},
islands: {
"./islands/Counter.tsx": $$0,
},
baseUrl: import.meta.url,
config,
};

export default manifest;
10 changes: 10 additions & 0 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"imports": {
"$fresh/": "https://deno.land/x/[email protected]/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
"preact-render-to-string": "https://esm.sh/*[email protected]",
"@preact/signals": "https://esm.sh/*@preact/[email protected]",
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
"twind": "https://esm.sh/[email protected]",
"twind/": "https://esm.sh/[email protected]/"
},
"scopes": {
"examples/": {
"http://localhost:5646/@local/": "./",
Expand Down
17 changes: 17 additions & 0 deletions islands/Counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useState } from "preact/hooks";
import { Button } from "../components/Button.tsx";

interface CounterProps {
start: number;
}

export default function Counter(props: CounterProps) {
const [count, setCount] = useState(props.start);
return (
<div class="flex gap-2 w-full">
<p class="flex-grow-1 font-bold text-xl">{count}</p>
<Button onClick={() => setCount(count - 1)}>-1</Button>
<Button onClick={() => setCount(count + 1)}>+1</Button>
</div>
);
}
19 changes: 19 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />

import twindPlugin from "$fresh/plugins/twind.ts"
import { start } from "$fresh/server.ts"
import manifest from "./fresh.gen.ts"
import twindConfig from "./twind.config.ts"

const abortController = new AbortController()

await start(manifest, {
signal: abortController.signal,
plugins: [
twindPlugin(twindConfig),
],
})
12 changes: 12 additions & 0 deletions routes/[...path].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Handlers } from "$fresh/server.ts"

export const handler: Handlers = {
GET(_req, ctx) {
const path = ctx.params.path!
try {
return new Response(Deno.readFileSync(path))
} catch (_e) {
return ctx.renderNotFound()
}
},
}
5 changes: 5 additions & 0 deletions routes/_404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { UnknownPageProps } from "$fresh/server.ts"

export default function NotFoundPage({ url }: UnknownPageProps) {
return <p>404 not found: {url.pathname}</p>
}
11 changes: 11 additions & 0 deletions routes/_500.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ErrorPageProps } from "$fresh/server.ts"

export default function ErrorPage({ error }: ErrorPageProps) {
return (
<p>
500 internal error: {error instanceof Error
? error.message
: `the following data was thrown: ${JSON.stringify(error)}`}
</p>
)
}
9 changes: 9 additions & 0 deletions routes/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AppProps } from "$fresh/server.ts"

export default function App({ Component }: AppProps) {
return (
<body>
<Component />
</body>
)
}
6 changes: 6 additions & 0 deletions routes/docs/[...path].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PageProps } from "$fresh/server.ts"

export default function DocsPage({ params }: PageProps) {
const path = params.path!
return <p>Docs –– {path}</p>
}
12 changes: 12 additions & 0 deletions routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Meta } from "../components/Meta.tsx"

export default function LandingPage() {
return (
<>
<Meta pageTitle="Landing" />,
<div class="p-4 mx-auto max-w-screen-md">
Welcome to the Capi Console
</div>,
</>
)
}
1 change: 1 addition & 0 deletions serve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LocalCapiCodegenServer } from "./server/local.ts"

console.log("Listening on http://localhost:5646/")

new LocalCapiCodegenServer().listen(5646)
Binary file added static/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions static/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions twind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Options } from "$fresh/plugins/twind.ts"

export default ((): Options => ({
selfURL: import.meta.url,
}))()
4 changes: 4 additions & 0 deletions words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,7 @@ paritypr
lparachain
unioned
rustc
twind
preact
asynciterable
sastan

0 comments on commit 5ad6758

Please sign in to comment.