From b5f47fc23b23cb6b16a8fee9b926eb777484c430 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Mon, 24 Mar 2025 01:38:53 +0530 Subject: [PATCH] Add Todo button to homepage when examples are included Add project creation time display in success message --- .changeset/fresh-books-sink.md | 5 + apps/cli/package.json | 5 +- apps/cli/src/helpers/examples-setup.ts | 26 +++++ apps/cli/src/index.ts | 9 +- apps/cli/src/prompts/config-prompts.ts | 3 +- apps/cli/src/prompts/examples.ts | 5 +- .../base/packages/client/src/routes/index.tsx | 10 +- .../packages/client/src/routes/index.tsx | 97 ------------------- 8 files changed, 47 insertions(+), 113 deletions(-) create mode 100644 .changeset/fresh-books-sink.md delete mode 100644 apps/cli/template/with-auth/packages/client/src/routes/index.tsx diff --git a/.changeset/fresh-books-sink.md b/.changeset/fresh-books-sink.md new file mode 100644 index 0000000..2f8d7a3 --- /dev/null +++ b/.changeset/fresh-books-sink.md @@ -0,0 +1,5 @@ +--- +"create-better-t-stack": patch +--- + +Add Todo button to homepage when examples are included diff --git a/apps/cli/package.json b/apps/cli/package.json index 044f122..43fc78b 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -22,10 +22,7 @@ "test": "vitest run", "prepublishOnly": "npm run build" }, - "files": [ - "dist", - "template" - ], + "files": ["dist", "template"], "dependencies": { "@clack/prompts": "^0.10.0", "commander": "^13.1.0", diff --git a/apps/cli/src/helpers/examples-setup.ts b/apps/cli/src/helpers/examples-setup.ts index a44a4b3..3962fed 100644 --- a/apps/cli/src/helpers/examples-setup.ts +++ b/apps/cli/src/helpers/examples-setup.ts @@ -48,6 +48,7 @@ async function setupTodoExample( } await updateHeaderWithTodoLink(projectDir, auth); + await addTodoButtonToHomepage(projectDir); } } @@ -128,3 +129,28 @@ async function updateRouterIndex(projectDir: string): Promise { await fs.writeFile(routerFile, routerContent); } } + +async function addTodoButtonToHomepage(projectDir: string): Promise { + const indexPath = path.join( + projectDir, + "packages/client/src/routes/index.tsx", + ); + + if (await fs.pathExists(indexPath)) { + let indexContent = await fs.readFile(indexPath, "utf8"); + + indexContent = indexContent.replace( + /
<\/div>/, + `
+ +
`, + ); + + await fs.writeFile(indexPath, indexContent); + } +} diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts index d3266b0..ac96c91 100644 --- a/apps/cli/src/index.ts +++ b/apps/cli/src/index.ts @@ -19,6 +19,8 @@ process.on("SIGINT", () => { const program = new Command(); async function main() { + const startTime = Date.now(); + program .name("create-better-t-stack") .description("Create a new Better-T Stack project") @@ -169,7 +171,12 @@ async function main() { ), ); - outro(pc.magenta("Project created successfully!")); + const elapsedTimeInSeconds = ((Date.now() - startTime) / 1000).toFixed(2); + outro( + pc.magenta( + `Project created successfully in ${pc.bold(elapsedTimeInSeconds)} seconds!`, + ), + ); } catch (error) { s.stop(pc.red("Failed")); if (error instanceof Error) { diff --git a/apps/cli/src/prompts/config-prompts.ts b/apps/cli/src/prompts/config-prompts.ts index 2c8aa46..cb3712d 100644 --- a/apps/cli/src/prompts/config-prompts.ts +++ b/apps/cli/src/prompts/config-prompts.ts @@ -50,7 +50,8 @@ export async function gatherConfig( ? getTursoSetupChoice(flags.turso) : Promise.resolve(false), addons: () => getAddonsChoice(flags.addons), - examples: () => getExamplesChoice(flags.examples), + examples: ({ results }) => + getExamplesChoice(flags.examples, results.database), git: () => getGitChoice(flags.git), packageManager: () => getPackageManagerChoice(flags.packageManager), noInstall: () => getNoInstallChoice(flags.noInstall), diff --git a/apps/cli/src/prompts/examples.ts b/apps/cli/src/prompts/examples.ts index a274b9b..40629f5 100644 --- a/apps/cli/src/prompts/examples.ts +++ b/apps/cli/src/prompts/examples.ts @@ -1,13 +1,16 @@ import { cancel, isCancel, multiselect } from "@clack/prompts"; import pc from "picocolors"; import { DEFAULT_CONFIG } from "../constants"; -import type { ProjectExamples } from "../types"; +import type { ProjectDatabase, ProjectExamples } from "../types"; export async function getExamplesChoice( examples?: ProjectExamples[], + database?: ProjectDatabase, ): Promise { if (examples !== undefined) return examples; + if (database === "none") return []; + const response = await multiselect({ message: "Which examples would you like to include?", options: [ diff --git a/apps/cli/template/base/packages/client/src/routes/index.tsx b/apps/cli/template/base/packages/client/src/routes/index.tsx index e85e5d9..0b91e39 100644 --- a/apps/cli/template/base/packages/client/src/routes/index.tsx +++ b/apps/cli/template/base/packages/client/src/routes/index.tsx @@ -67,15 +67,7 @@ function HomeComponent() { /> - -
- -
+
); diff --git a/apps/cli/template/with-auth/packages/client/src/routes/index.tsx b/apps/cli/template/with-auth/packages/client/src/routes/index.tsx deleted file mode 100644 index 34358de..0000000 --- a/apps/cli/template/with-auth/packages/client/src/routes/index.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import { Button } from "@/components/ui/button"; -import { trpc } from "@/utils/trpc"; -import { Link, createFileRoute } from "@tanstack/react-router"; -import { ArrowRight } from "lucide-react"; - -export const Route = createFileRoute("/")({ - component: HomeComponent, -}); - -const TITLE_TEXT = ` - ██████╗ ███████╗████████╗████████╗███████╗██████╗ - ██╔══██╗██╔════╝╚══██╔══╝╚══██╔══╝██╔════╝██╔══██╗ - ██████╔╝█████╗ ██║ ██║ █████╗ ██████╔╝ - ██╔══██╗██╔══╝ ██║ ██║ ██╔══╝ ██╔══██╗ - ██████╔╝███████╗ ██║ ██║ ███████╗██║ ██║ - ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ - - ████████╗ ███████╗████████╗ █████╗ ██████╗██╗ ██╗ - ╚══██╔══╝ ██╔════╝╚══██╔══╝██╔══██╗██╔════╝██║ ██╔╝ - ██║ ███████╗ ██║ ███████║██║ █████╔╝ - ██║ ╚════██║ ██║ ██╔══██║██║ ██╔═██╗ - ██║ ███████║ ██║ ██║ ██║╚██████╗██║ ██╗ - ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ - `; - -function HomeComponent() { - const healthCheck = trpc.healthCheck.useQuery(); - - return ( -
-
{TITLE_TEXT}
-
-
-

API Status

-
-
- - {healthCheck.isLoading - ? "Checking..." - : healthCheck.data - ? "Connected" - : "Disconnected"} - -
-
- -
-

Core Features

-
    - - - - -
-
- -
- -
-
-
- ); -} - -function FeatureItem({ - title, - description, -}: { - title: string; - description: string; -}) { - return ( -
  • -

    {title}

    -

    {description}

    -
  • - ); -}