From 933c4acabdbce84758f082a6201fbd87c455d267 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Fri, 18 Apr 2025 08:43:24 +0530 Subject: [PATCH] refactor: Implement @/* path aliases and move dotenv imports --- .changeset/khaki-garlics-trade.md | 5 ++++ .../templates/backend/elysia/src/index.ts.hbs | 4 +-- .../templates/backend/hono/src/index.ts.hbs | 8 ++--- .../backend/server-base/tsconfig.json | 18 ------------ .../backend/server-base/tsconfig.json.hbs | 29 +++++++++++++++++++ 5 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 .changeset/khaki-garlics-trade.md delete mode 100644 apps/cli/templates/backend/server-base/tsconfig.json create mode 100644 apps/cli/templates/backend/server-base/tsconfig.json.hbs diff --git a/.changeset/khaki-garlics-trade.md b/.changeset/khaki-garlics-trade.md new file mode 100644 index 0000000..77d1c23 --- /dev/null +++ b/.changeset/khaki-garlics-trade.md @@ -0,0 +1,5 @@ +--- +"create-better-t-stack": patch +--- + +Implement @/\* path aliases and move dotenv imports diff --git a/apps/cli/templates/backend/elysia/src/index.ts.hbs b/apps/cli/templates/backend/elysia/src/index.ts.hbs index 498653a..3e87b32 100644 --- a/apps/cli/templates/backend/elysia/src/index.ts.hbs +++ b/apps/cli/templates/backend/elysia/src/index.ts.hbs @@ -1,7 +1,7 @@ +import "dotenv/config"; {{#if (eq runtime "node")}} import { node } from "@elysiajs/node"; {{/if}} -import "dotenv/config"; import { Elysia } from "elysia"; import { cors } from "@elysiajs/cors"; {{#if (eq api "trpc")}} @@ -69,4 +69,4 @@ const app = new Elysia() .get("/", () => "OK") .listen(3000, () => { console.log(`Server is running on http://localhost:3000`); - }); \ No newline at end of file + }); diff --git a/apps/cli/templates/backend/hono/src/index.ts.hbs b/apps/cli/templates/backend/hono/src/index.ts.hbs index 8519782..7241eaf 100644 --- a/apps/cli/templates/backend/hono/src/index.ts.hbs +++ b/apps/cli/templates/backend/hono/src/index.ts.hbs @@ -1,3 +1,4 @@ +import "dotenv/config"; {{#if (eq api "orpc")}} import { RPCHandler } from "@orpc/server/fetch"; import { createContext } from "./lib/context"; @@ -9,7 +10,6 @@ import { auth } from "./lib/auth"; {{#if (eq api "trpc")}} import { trpcServer } from "@hono/trpc-server"; {{/if}} -import "dotenv/config"; import { Hono } from "hono"; import { cors } from "hono/cors"; import { logger } from "hono/logger"; @@ -74,7 +74,7 @@ app.use("/trpc/*", trpcServer({ app.post("/ai", async (c) => { const body = await c.req.json(); const messages = body.messages || []; - + const result = streamText({ model: google("gemini-1.5-flash"), messages, @@ -82,7 +82,7 @@ app.post("/ai", async (c) => { c.header("X-Vercel-AI-Data-Stream", "v1"); c.header("Content-Type", "text/plain; charset=utf-8"); - + return stream(c, (stream) => stream.pipe(result.toDataStream())); }); {{/if}} @@ -102,4 +102,4 @@ serve({ }); {{else}} export default app; -{{/if}} \ No newline at end of file +{{/if}} diff --git a/apps/cli/templates/backend/server-base/tsconfig.json b/apps/cli/templates/backend/server-base/tsconfig.json deleted file mode 100644 index c09fccd..0000000 --- a/apps/cli/templates/backend/server-base/tsconfig.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "compilerOptions": { - "target": "ESNext", - "module": "ESNext", - "moduleResolution": "bundler", - "verbatimModuleSyntax": true, - "strict": true, - "skipLibCheck": true, - "baseUrl": "./", - "outDir": "./dist", - "types": ["node", "bun"], - "jsx": "react-jsx", - "jsxImportSource": "hono/jsx" - }, - "tsc-alias": { - "resolveFullPaths": true - } -} diff --git a/apps/cli/templates/backend/server-base/tsconfig.json.hbs b/apps/cli/templates/backend/server-base/tsconfig.json.hbs new file mode 100644 index 0000000..91a6d10 --- /dev/null +++ b/apps/cli/templates/backend/server-base/tsconfig.json.hbs @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "bundler", + "verbatimModuleSyntax": true, + "strict": true, + "skipLibCheck": true, + "baseUrl": "./", + "paths": { + "@/*": ["./src/*"] + }, + "outDir": "./dist", + "types": [ + {{#if (eq runtime 'node')}} + "node" + {{else if (eq runtime 'bun')}} + "bun" + {{else}} + "node", "bun" + {{/if}} + ], + "jsx": "react-jsx"{{#if (eq backend 'hono')}}, + "jsxImportSource": "hono/jsx"{{/if}} + }, + "tsc-alias": { + "resolveFullPaths": true + } +}