From 58f9769baf0c309a250844f82eed2a7035eb0a9b Mon Sep 17 00:00:00 2001 From: ashish <68690233+asrvd@users.noreply.github.com> Date: Sat, 30 Jul 2022 21:26:42 +0530 Subject: [PATCH] refactor: add components/ in starter project (#353) This commit adds a `components/` folder to the starter project to indicate that one can also create components that are not themselves islands. --- README.md | 2 +- init.ts | 76 ++++++++++++++++++++++------------------------- tests/cli_test.ts | 15 +++++++++- 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 2d8eb410..8af10a13 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ You can scaffold a new project by running the Fresh init script. To scaffold a project in the `my-project` folder, run the following: ```sh -deno run -A -r https://fresh.deno.dev my-project +deno run -A -r https://fresh.deno.dev deno-fresh-demo ``` Then navigate to the newly created project folder: diff --git a/init.ts b/init.ts index 4401de70..7d6c737f 100644 --- a/init.ts +++ b/init.ts @@ -86,6 +86,7 @@ const useVSCode = flags.vscode === null await Deno.mkdir(join(resolvedDirectory, "routes", "api"), { recursive: true }); await Deno.mkdir(join(resolvedDirectory, "islands"), { recursive: true }); await Deno.mkdir(join(resolvedDirectory, "static"), { recursive: true }); +await Deno.mkdir(join(resolvedDirectory, "components"), { recursive: true }); if (useVSCode) { await Deno.mkdir(join(resolvedDirectory, ".vscode"), { recursive: true }); } @@ -140,57 +141,52 @@ await Deno.writeTextFile( ROUTES_INDEX_TSX, ); -let ISLANDS_COUNTER_TSX = `/** @jsx h */ +const COMPONENTS_BUTTON_TSX = `/** @jsx h */ import { h } from "preact"; -import { useState } from "preact/hooks"; import { IS_BROWSER } from "$fresh/runtime.ts"; ${useTwind ? 'import { tw } from "@twind";\n' : ""} +export function Button(props: h.JSX.HTMLAttributes) { + return ( + + + + ); +} `; -if (useTwind) { - ISLANDS_COUNTER_TSX += - ` const btn = tw\`px-2 py-1 border(gray-100 1) hover:bg-gray-200\`;\n`; - ISLANDS_COUNTER_TSX += ` return ( -
-

{count}

- - -
- ); -`; -} else { - ISLANDS_COUNTER_TSX += ` return ( -
-

{count}

- - -
- ); -`; -} -ISLANDS_COUNTER_TSX += `}\n`; await Deno.writeTextFile( join(resolvedDirectory, "islands", "Counter.tsx"), ISLANDS_COUNTER_TSX, diff --git a/tests/cli_test.ts b/tests/cli_test.ts index 4520b6f6..f021be8e 100644 --- a/tests/cli_test.ts +++ b/tests/cli_test.ts @@ -66,6 +66,13 @@ Deno.test({ { "type": "file", "name": "README.md" }, { "type": "file", "name": "import_map.json" }, { "type": "file", "name": "fresh.gen.ts" }, + { + "type": "directory", + "name": "components", + "contents": [ + { "type": "file", "name": "Button.tsx" }, + ], + }, { "type": "directory", "name": "islands", @@ -152,7 +159,6 @@ Deno.test({ await delay(100); counterValue = await counter?.evaluate((el) => el.textContent); - console.log(counterValue); assert(counterValue === "4"); await page.close(); await browser.close(); @@ -200,6 +206,13 @@ Deno.test({ { "type": "file", "name": "README.md" }, { "type": "file", "name": "import_map.json" }, { "type": "file", "name": "fresh.gen.ts" }, + { + "type": "directory", + "name": "components", + "contents": [ + { "type": "file", "name": "Button.tsx" }, + ], + }, { "type": "directory", "name": "islands",