From aa35f4319144724f372139ef47956d4109bbde95 Mon Sep 17 00:00:00 2001 From: pegasust Date: Fri, 2 Dec 2022 22:42:02 +0000 Subject: [PATCH] add some scaffolding to name-generator --- .gitignore | 3 + .npmrc | 12 ++ .prettierrc.cjs | 12 ++ apps/name-generator/.eslintrc.cjs | 4 + apps/name-generator/README.md | 131 ++++++++++++++++++ apps/name-generator/next-env.d.ts | 5 + apps/name-generator/next.config.mjs | 22 +++ apps/name-generator/package.json | 40 ++++++ apps/name-generator/postcss.config.cjs | 1 + apps/name-generator/public/favicon.ico | Bin 0 -> 15406 bytes apps/name-generator/src/env/client.mjs | 33 +++++ apps/name-generator/src/env/schema.mjs | 29 ++++ apps/name-generator/src/env/server.mjs | 27 ++++ apps/name-generator/src/pages/_app.tsx | 20 +++ .../src/pages/api/auth/[...nextauth].ts | 5 + .../src/pages/api/trpc/[trpc].ts | 22 +++ apps/name-generator/src/pages/index.tsx | 81 +++++++++++ apps/name-generator/src/styles/globals.css | 3 + apps/name-generator/src/utils/trpc.ts | 44 ++++++ apps/name-generator/tailwind.config.cjs | 4 + apps/name-generator/tsconfig.json | 12 ++ flake.nix | 1 + package.json | 23 ++- packages/config/tailwind/index.js | 8 ++ packages/config/tailwind/package.json | 15 ++ packages/config/tailwind/postcss.js | 6 + turbo.json | 42 +++++- 27 files changed, 596 insertions(+), 9 deletions(-) create mode 100644 .npmrc create mode 100644 .prettierrc.cjs create mode 100644 apps/name-generator/.eslintrc.cjs create mode 100644 apps/name-generator/README.md create mode 100644 apps/name-generator/next-env.d.ts create mode 100644 apps/name-generator/next.config.mjs create mode 100644 apps/name-generator/package.json create mode 100644 apps/name-generator/postcss.config.cjs create mode 100644 apps/name-generator/public/favicon.ico create mode 100644 apps/name-generator/src/env/client.mjs create mode 100644 apps/name-generator/src/env/schema.mjs create mode 100644 apps/name-generator/src/env/server.mjs create mode 100644 apps/name-generator/src/pages/_app.tsx create mode 100644 apps/name-generator/src/pages/api/auth/[...nextauth].ts create mode 100644 apps/name-generator/src/pages/api/trpc/[trpc].ts create mode 100644 apps/name-generator/src/pages/index.tsx create mode 100644 apps/name-generator/src/styles/globals.css create mode 100644 apps/name-generator/src/utils/trpc.ts create mode 100644 apps/name-generator/tailwind.config.cjs create mode 100644 apps/name-generator/tsconfig.json create mode 100644 packages/config/tailwind/index.js create mode 100644 packages/config/tailwind/package.json create mode 100644 packages/config/tailwind/postcss.js diff --git a/.gitignore b/.gitignore index d24d26f..c49e69b 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ yarn-error.log* # turbo .turbo .direnv + +# I just clone create-t3-turbo and copy the apps and packages, so pls ignore it +create-t3-turbo diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..e165d81 --- /dev/null +++ b/.npmrc @@ -0,0 +1,12 @@ +# Expo doesn't play nice with pnpm by default. +# The symbolic links of pnpm break the rules of Expo monorepos. +# @link https://docs.expo.dev/guides/monorepos/#common-issues +node-linker=hoisted + +# In order to cache Prisma correctly +public-hoist-pattern[]=*prisma* + +# FIXME: @prisma/client is required by the @acme/auth, +# but we don't want it installed there since it's already +# installed in the @acme/db package +strict-peer-dependencies=false diff --git a/.prettierrc.cjs b/.prettierrc.cjs new file mode 100644 index 0000000..b704e6a --- /dev/null +++ b/.prettierrc.cjs @@ -0,0 +1,12 @@ +/** @type {import("prettier").Config} */ +module.exports = { + arrowParens: "always", + printWidth: 80, + singleQuote: false, + jsxSingleQuote: false, + semi: true, + trailingComma: "all", + tabWidth: 2, + plugins: [require.resolve("prettier-plugin-tailwindcss")], + tailwindConfig: "./packages/config/tailwind", +}; diff --git a/apps/name-generator/.eslintrc.cjs b/apps/name-generator/.eslintrc.cjs new file mode 100644 index 0000000..8fbae96 --- /dev/null +++ b/apps/name-generator/.eslintrc.cjs @@ -0,0 +1,4 @@ +/** @type {import("eslint").Linter.Config} */ +module.exports = { + extends: ["../../.eslintrc.cjs", "next"], +}; diff --git a/apps/name-generator/README.md b/apps/name-generator/README.md new file mode 100644 index 0000000..658d71e --- /dev/null +++ b/apps/name-generator/README.md @@ -0,0 +1,131 @@ +# Create T3 App + +This is an app bootstrapped according to the [init.tips](https://init.tips) stack, also known as the T3-Stack. + +## Why are there `.js` files in here? + +As per [T3-Axiom #3](https://github.com/t3-oss/create-t3-app/tree/next#3-typesafety-isnt-optional), we believe take typesafety as a first class citizen. Unfortunately, not all frameworks and plugins support TypeScript which means some of the configuration files have to be `.js` files. + +We try to emphasize that these files are javascript for a reason, by explicitly declaring its type (`cjs` or `mjs`) depending on what's supported by the library it is used by. Also, all the `js` files in this project are still typechecked using a `@ts-check` comment at the top. + +## What's next? How do I make an app with this? + +We try to keep this project as simple as possible, so you can start with the most basic configuration and then move on to more advanced configuration. + +If you are not familiar with the different technologies used in this project, please refer to the respective docs. If you still are in the wind, please join our [Discord](https://t3.gg/discord) and ask for help. + +- [Next-Auth.js](https://next-auth.js.org) +- [Prisma](https://prisma.io) +- [TailwindCSS](https://tailwindcss.com) +- [tRPC](https://trpc.io) (using @next version? [see v10 docs here](https://alpha.trpc.io)) + +## How do I deploy this? + +### Vercel + +We recommend deploying to [Vercel](https://vercel.com/?utm_source=t3-oss&utm_campaign=oss). It makes it super easy to deploy NextJs apps. + +- Push your code to a GitHub repository. +- Go to [Vercel](https://vercel.com/?utm_source=t3-oss&utm_campaign=oss) and sign up with GitHub. +- Create a Project and import the repository you pushed your code to. +- Add your environment variables. +- Click **Deploy** +- Now whenever you push a change to your repository, Vercel will automatically redeploy your website! + +### Docker + +You can also dockerize this stack and deploy a container. + +1. In your [next.config.mjs](./next.config.mjs), add the `output: "standalone"` option to your config. +2. Create a `.dockerignore` file with the following contents: +
+ .dockerignore + + ``` + Dockerfile + .dockerignore + node_modules + npm-debug.log + README.md + .next + .git + ``` + +
+ +3. Create a `Dockerfile` with the following contents: +
+ Dockerfile + + ```Dockerfile + # Install dependencies only when needed + FROM node:16-alpine AS deps + # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. + RUN apk add --no-cache libc6-compat + WORKDIR /app + + # Install dependencies based on the preferred package manager + COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ + RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + elif [ -f package-lock.json ]; then npm ci; \ + elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i; \ + else echo "Lockfile not found." && exit 1; \ + fi + + + # Rebuild the source code only when needed + FROM node:16-alpine AS builder + WORKDIR /app + COPY --from=deps /app/node_modules ./node_modules + COPY . . + + # Next.js collects completely anonymous telemetry data about general usage. + # Learn more here: https://nextjs.org/telemetry + # Uncomment the following line in case you want to disable telemetry during the build. + # ENV NEXT_TELEMETRY_DISABLED 1 + + RUN yarn build + + # If using npm comment out above and use below instead + # RUN npm run build + + # Production image, copy all the files and run next + FROM node:16-alpine AS runner + WORKDIR /app + + ENV NODE_ENV production + # Uncomment the following line in case you want to disable telemetry during runtime. + # ENV NEXT_TELEMETRY_DISABLED 1 + + RUN addgroup --system --gid 1001 nodejs + RUN adduser --system --uid 1001 nextjs + + # You only need to copy next.config.js if you are NOT using the default configuration + # COPY --from=builder /app/next.config.js ./ + COPY --from=builder /app/public ./public + COPY --from=builder /app/package.json ./package.json + + # Automatically leverage output traces to reduce image size + # https://nextjs.org/docs/advanced-features/output-file-tracing + COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ + COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + + USER nextjs + + EXPOSE 3000 + + ENV PORT 3000 + + CMD ["node", "server.js"] + ``` + +
+ +4. You can now build an image to deploy yourself, or use a PaaS such as [Railway's](https://railway.app) automated [Dockerfile deployments](https://docs.railway.app/deploy/dockerfiles) to deploy your app. + +## Useful resources + +Here are some resources that we commonly refer to: + +- [Protecting routes with Next-Auth.js](https://next-auth.js.org/configuration/nextjs#unstable_getserversession) diff --git a/apps/name-generator/next-env.d.ts b/apps/name-generator/next-env.d.ts new file mode 100644 index 0000000..4f11a03 --- /dev/null +++ b/apps/name-generator/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/apps/name-generator/next.config.mjs b/apps/name-generator/next.config.mjs new file mode 100644 index 0000000..e19a29d --- /dev/null +++ b/apps/name-generator/next.config.mjs @@ -0,0 +1,22 @@ +// @ts-check +/** + * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. + * This is especially useful for Docker builds. + */ +!process.env.SKIP_ENV_VALIDATION && (await import("./src/env/server.mjs")); + +/** @type {import("next").NextConfig} */ +const config = { + reactStrictMode: true, + swcMinify: true, + experimental: { + // Enables hot-reload and easy integration for local packages + transpilePackages: ["@acme/api", "@acme/auth", "@acme/db"], + }, + // We already do linting on GH actions + eslint: { + ignoreDuringBuilds: !!process.env.CI, + }, +}; + +export default config; diff --git a/apps/name-generator/package.json b/apps/name-generator/package.json new file mode 100644 index 0000000..27e9ea5 --- /dev/null +++ b/apps/name-generator/package.json @@ -0,0 +1,40 @@ +{ + "name": "@acme/name-generator", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "next dev", + "build": "next build", + "clean": "rm -rf .next .turbo node_modules", + "start": "next start", + "lint": "next lint", + "type-check": "tsc --noEmit" + }, + "dependencies": { + "@acme/api": "*", + "@acme/auth": "*", + "@acme/db": "*", + "@acme/tailwind-config": "*", + "@tanstack/react-query": "^4.16.1", + "@trpc/client": "^10.1.0", + "@trpc/next": "^10.1.0", + "@trpc/react-query": "^10.1.0", + "@trpc/server": "^10.1.0", + "next": "^13.0.5", + "next-auth": "^4.17.0", + "react": "18.2.0", + "react-dom": "18.2.0", + "zod": "^3.18.0" + }, + "devDependencies": { + "@types/node": "^18.0.0", + "@types/react": "^18.0.25", + "@types/react-dom": "^18.0.9", + "autoprefixer": "^10.4.13", + "eslint": "^8.28.0", + "eslint-config-next": "13.0.4", + "postcss": "^8.4.19", + "tailwindcss": "^3.2.4", + "typescript": "^4.9.3" + } +} diff --git a/apps/name-generator/postcss.config.cjs b/apps/name-generator/postcss.config.cjs new file mode 100644 index 0000000..5559738 --- /dev/null +++ b/apps/name-generator/postcss.config.cjs @@ -0,0 +1 @@ +module.exports = require("@acme/tailwind-config/postcss"); diff --git a/apps/name-generator/public/favicon.ico b/apps/name-generator/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..efd76f16a3593544115c9a60576374dc3660b9f1 GIT binary patch literal 15406 zcmeI2No*BI5QZm86t3iuyH62ECx@JK#R3TwFxMayCm2~AIIu{Z0U>rH7K4Gl1e>G&-CBbRn^ti?RnpL-+Dub zdRpdqe}CtBzj~gRlk@3**bkmps?TzB9-Z zP{cRNh01NAKJ--{NV~qz126aO+b5GJPnPlH$IGNilVtn$?Sb|CzU=Pqmizbb%e8CQ zBo>Rw$B!TTRtdasZEcmSSFg&A8#kn`u1;>=yct;E|B|-Ad-Uj0xpL)-T)uo+9z1y9 zuM&9u^5sjZudkQKj~`1-O^uv7btB9zA+w z*pUPH!_bQtFQl@vQg-j&EqCtRk>=*+FrQmp#_q$14>o@MFD!L+by+`zkM3gfC_`~3jc%O#1GDxF{2l+S+hpYoH--ZiHewe z^7Hd$`0(LLdF05EQc+P6Rr7+3J32aS4&JtHoA|l5wpQN0eQR|h1K`MykwY?$8s4i{ zuVnAuy)t|DY&m)Iq?|r|S~hRqESolMGG4oOtz5cvDKZ!7$lG1iRl)2B~O?`WH~1GdLCj30dS z=1mmM+y7ZNFa}SaJQ4IA1`~b84@B8Mooa7ym$PTj+WbcO@Zm$*vSo{~9$`MjCd019 z1|lqUZ0gjh!a8#9+`0A(Fhr^Qew-ICUNn90?Ci90p=2EJ1F0Z%A79HHoLEQUlbCl? zMXcM-ojWHdPMom5qZ?VuObMv(O6&SV+pkNP zzk_lDU&}l4B$}f2{!s2mo@9vX%g@SXD#KRglmr z=H=zdgb5R*u&_|bb&+Rqfsp5{S+iu+s8IsO|H}g>o{tzYLZ(ljZu^cd;3tQ{nwkAO z_D+{BU25xj*7SZRw~owNYqHjL(H4*=xPsUPnP)M$CjrhckUwD`AA7*3awdUX9?$*E zGjhBx5Wbuo*t~i3Wbxv~vT)%-S-*b0Y}~lfa&qM7{Cw!pAv-TX-pU0cXT4;}63bmK zSg=4AEm~wUCx@3{a;@}{{5p9}_O)E0va&LhcX@fatX#R$a?s>o6WGD}`t@te$&#OD zpOQSG3q;NuJe;zf5^dOw_wF~k$D3DyLazC zj|KU0SFkhweer{hcmiF=-;hU6?5UC8rLQhgGW_g+u=lfU*)l6R!Rve)NPrTx8DKFk)2vDc3I0^XJcH*REZ%eED+o@qYZVSj=RPts;BkJ9LV5 z0sTlfVV~$V`_l9QpALS;1Nk36eq7iy$A^NQXZRuN^KH6`J#X|Q5g)L(4}OR_b@l4i zvSY^%+j|3hqEF1bQJzETuUv@Tj~qE-Ye25?FW?6!u|#!swa`b1XPhZyOkBYaCVV}( z(GUDPexH~Jokz#ndu(WEF#AQv&^K4`BUkj8`4+sKQNTXgvtz#&AH#f$%!xCx55|jU z^w$+acaS@Na@w?M))(|>+_-TvWy%zTi5_t-mp643uT=9{_ z&e#KX0b{S|J@bPL^VXMS#~jNU4(2WxyCD8yp34*hD`Nn&=5keMGDV(QoLLD3NWh(7 zBmiWxSLzp_jNU)heyvN^w+wm4S%_R612-1bA%v!wIm^MBlkb)P)O$A)!Tsn%9BYAA k^`Ak>)%$gfg|c%&7MPUK6V7XZ)v$AhCQDff3{(RD0`^Hap8x;= literal 0 HcmV?d00001 diff --git a/apps/name-generator/src/env/client.mjs b/apps/name-generator/src/env/client.mjs new file mode 100644 index 0000000..c2b3601 --- /dev/null +++ b/apps/name-generator/src/env/client.mjs @@ -0,0 +1,33 @@ +// @ts-check +import { clientEnv, clientSchema } from "./schema.mjs"; + +const _clientEnv = clientSchema.safeParse(clientEnv); + +export const formatErrors = ( + /** @type {import('zod').ZodFormattedError,string>} */ + errors, +) => + Object.entries(errors) + .map(([name, value]) => { + if (value && "_errors" in value) + return `${name}: ${value._errors.join(", ")}\n`; + }) + .filter(Boolean); + +if (!_clientEnv.success) { + console.error( + "❌ Invalid environment variables:\n", + ...formatErrors(_clientEnv.error.format()), + ); + throw new Error("Invalid environment variables"); +} + +for (let key of Object.keys(_clientEnv.data)) { + if (!key.startsWith("NEXT_PUBLIC_")) { + console.warn("❌ Invalid public environment variable name:", key); + + throw new Error("Invalid public environment variable name"); + } +} + +export const env = _clientEnv.data; diff --git a/apps/name-generator/src/env/schema.mjs b/apps/name-generator/src/env/schema.mjs new file mode 100644 index 0000000..24b283d --- /dev/null +++ b/apps/name-generator/src/env/schema.mjs @@ -0,0 +1,29 @@ +// @ts-check +import { z } from "zod"; + +/** + * Specify your server-side environment variables schema here. + * This way you can ensure the app isn't built with invalid env vars. + */ +export const serverSchema = z.object({ + NODE_ENV: z.enum(["development", "test", "production"]), +}); + +/** + * Specify your client-side environment variables schema here. + * This way you can ensure the app isn't built with invalid env vars. + * To expose them to the client, prefix them with `NEXT_PUBLIC_`. + */ +export const clientSchema = z.object({ + // NEXT_PUBLIC_BAR: z.string(), +}); + +/** + * You can't destruct `process.env` as a regular object, so you have to do + * it manually here. This is because Next.js evaluates this at build time, + * and only used environment variables are included in the build. + * @type {{ [k in keyof z.infer]: z.infer[k] | undefined }} + */ +export const clientEnv = { + // NEXT_PUBLIC_BAR: process.env.NEXT_PUBLIC_BAR, +}; diff --git a/apps/name-generator/src/env/server.mjs b/apps/name-generator/src/env/server.mjs new file mode 100644 index 0000000..736e3a6 --- /dev/null +++ b/apps/name-generator/src/env/server.mjs @@ -0,0 +1,27 @@ +// @ts-check +/** + * This file is included in `/next.config.mjs` which ensures the app isn't built with invalid env vars. + * It has to be a `.mjs`-file to be imported there. + */ +import { serverSchema } from "./schema.mjs"; +import { env as clientEnv, formatErrors } from "./client.mjs"; + +const _serverEnv = serverSchema.safeParse(process.env); + +if (!_serverEnv.success) { + console.error( + "❌ Invalid environment variables:\n", + ...formatErrors(_serverEnv.error.format()), + ); + throw new Error("Invalid environment variables"); +} + +for (let key of Object.keys(_serverEnv.data)) { + if (key.startsWith("NEXT_PUBLIC_")) { + console.warn("❌ You are exposing a server-side env-variable:", key); + + throw new Error("You are exposing a server-side env-variable"); + } +} + +export const env = { ..._serverEnv.data, ...clientEnv }; diff --git a/apps/name-generator/src/pages/_app.tsx b/apps/name-generator/src/pages/_app.tsx new file mode 100644 index 0000000..e03281f --- /dev/null +++ b/apps/name-generator/src/pages/_app.tsx @@ -0,0 +1,20 @@ +// src/pages/_app.tsx +import "../styles/globals.css"; +import { SessionProvider } from "next-auth/react"; +import type { Session } from "next-auth"; +import type { AppType } from "next/app"; + +import { trpc } from "../utils/trpc"; + +const MyApp: AppType<{ session: Session | null }> = ({ + Component, + pageProps: { session, ...pageProps }, +}) => { + return ( + + + + ); +}; + +export default trpc.withTRPC(MyApp); diff --git a/apps/name-generator/src/pages/api/auth/[...nextauth].ts b/apps/name-generator/src/pages/api/auth/[...nextauth].ts new file mode 100644 index 0000000..02cc69f --- /dev/null +++ b/apps/name-generator/src/pages/api/auth/[...nextauth].ts @@ -0,0 +1,5 @@ +import NextAuth from "next-auth"; + +import { authOptions } from "@acme/auth"; + +export default NextAuth(authOptions); diff --git a/apps/name-generator/src/pages/api/trpc/[trpc].ts b/apps/name-generator/src/pages/api/trpc/[trpc].ts new file mode 100644 index 0000000..bf357b7 --- /dev/null +++ b/apps/name-generator/src/pages/api/trpc/[trpc].ts @@ -0,0 +1,22 @@ +import { appRouter, createContext } from "@acme/api"; +import { createNextApiHandler } from "@trpc/server/adapters/next"; + +// export API handler +export default createNextApiHandler({ + router: appRouter, + createContext, +}); + +// If you need to enable cors, you can do so like this: +// const handler = async (req: NextApiRequest, res: NextApiResponse) => { +// // Enable cors +// await cors(req, res); + +// // Let the tRPC handler do its magic +// return createNextApiHandler({ +// router: appRouter, +// createContext, +// })(req, res); +// }; + +// export default handler; diff --git a/apps/name-generator/src/pages/index.tsx b/apps/name-generator/src/pages/index.tsx new file mode 100644 index 0000000..0afbbe5 --- /dev/null +++ b/apps/name-generator/src/pages/index.tsx @@ -0,0 +1,81 @@ +import type { NextPage } from "next"; +import Head from "next/head"; +import { signIn, signOut } from "next-auth/react"; +import { trpc } from "../utils/trpc"; +import type { inferProcedureOutput } from "@trpc/server"; +import type { AppRouter } from "@acme/api"; + +const PostCard: React.FC<{ + post: inferProcedureOutput[number]; +}> = ({ post }) => { + return ( +
+

+ {post.title} +

+

{post.content}

+
+ ); +}; + +const Home: NextPage = () => { + const postQuery = trpc.post.all.useQuery(); + + return ( + <> + + Create T3 App + + + +
+
+

+ Create T3 Turbo +

+ + +
+ {postQuery.data ? ( +
+ {postQuery.data?.map((p) => { + return ; + })} +
+ ) : ( +

Loading..

+ )} +
+
+
+ + ); +}; + +export default Home; + +const AuthShowcase: React.FC = () => { + const { data: session } = trpc.auth.getSession.useQuery(); + + const { data: secretMessage } = trpc.auth.getSecretMessage.useQuery( + undefined, // no input + { enabled: !!session?.user }, + ); + + return ( +
+ {session?.user && ( +

+ {session && Logged in as {session?.user?.name}} + {secretMessage && - {secretMessage}} +

+ )} + +
+ ); +}; diff --git a/apps/name-generator/src/styles/globals.css b/apps/name-generator/src/styles/globals.css new file mode 100644 index 0000000..b5c61c9 --- /dev/null +++ b/apps/name-generator/src/styles/globals.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/apps/name-generator/src/utils/trpc.ts b/apps/name-generator/src/utils/trpc.ts new file mode 100644 index 0000000..af38900 --- /dev/null +++ b/apps/name-generator/src/utils/trpc.ts @@ -0,0 +1,44 @@ +// src/utils/trpc.ts +import { createTRPCNext } from "@trpc/next"; +import { httpBatchLink, loggerLink } from "@trpc/client"; +import { inferRouterInputs, inferRouterOutputs } from "@trpc/server"; +import type { AppRouter } from "@acme/api"; +import { transformer } from "@acme/api/transformer"; + +const getBaseUrl = () => { + if (typeof window !== "undefined") return ""; // browser should use relative url + if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url + + return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost +}; + +export const trpc = createTRPCNext({ + config() { + return { + transformer, + links: [ + loggerLink({ + enabled: (opts) => + process.env.NODE_ENV === "development" || + (opts.direction === "down" && opts.result instanceof Error), + }), + httpBatchLink({ + url: `${getBaseUrl()}/api/trpc`, + }), + ], + }; + }, + ssr: false, +}); + +/** + * Inference helpers for input types + * @example type HelloInput = RouterInputs['example']['hello'] + **/ +export type RouterInputs = inferRouterInputs; + +/** + * Inference helpers for output types + * @example type HelloOutput = RouterOutputs['example']['hello'] + **/ +export type RouterOutputs = inferRouterOutputs; diff --git a/apps/name-generator/tailwind.config.cjs b/apps/name-generator/tailwind.config.cjs new file mode 100644 index 0000000..e0a8bb5 --- /dev/null +++ b/apps/name-generator/tailwind.config.cjs @@ -0,0 +1,4 @@ +/** @type {import("tailwindcss").Config} */ +module.exports = { + presets: [require("@acme/tailwind-config")], +}; diff --git a/apps/name-generator/tsconfig.json b/apps/name-generator/tsconfig.json new file mode 100644 index 0000000..a97687e --- /dev/null +++ b/apps/name-generator/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.json", + "exclude": [], + "include": [ + "next-env.d.ts", + "node_modules/@acme/auth/next-auth.d.ts", + "**/*.ts", + "**/*.tsx", + "**/*.cjs", + "**/*.mjs" + ] +} diff --git a/flake.nix b/flake.nix index facec69..5924ec7 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,7 @@ nativeBuildInputs = [ pkgs.bashInteractive ]; buildInputs = [ pkgs.nodejs-18_x + # pkgs.prettierd # not available? pkgs.nodePackages.pnpm pkgs.nodePackages.prisma pkgs.prisma-engines diff --git a/package.json b/package.json index 6494c36..96066bf 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,15 @@ "packages/*" ], "scripts": { - "build": "turbo run build", - "dev": "turbo run dev --parallel", - "lint": "turbo run lint", - "format": "prettier --write \"**/*.{ts,tsx,md}\"" + "build": "turbo build", + "clean": "rm -rf node_modules", + "clean:workspaces": "turbo clean", + "db-generate": "turbo db-generate", + "db-push": "turbo db-push", + "dev": "turbo dev --parallel", + "format": "prettier --write \"**/*.{ts,tsx,md}\"", + "lint": "turbo lint && manypkg check", + "type-check": "turbo type-check" }, "devDependencies": { "eslint-config-custom": "workspace:*", @@ -20,6 +25,14 @@ "engines": { "node": ">=14.0.0" }, - "dependencies": {}, + "dependencies": { + "@manypkg/cli": "^0.19.2", + "@typescript-eslint/eslint-plugin": "^5.43.0", + "@typescript-eslint/parser": "^5.43.0", + "eslint": "^8.28.0", + "prettier": "^2.7.1", + "prettier-plugin-tailwindcss": "^0.1.13", + "typescript": "^4.9.3" + }, "packageManager": "pnpm@7.14.0" } diff --git a/packages/config/tailwind/index.js b/packages/config/tailwind/index.js new file mode 100644 index 0000000..b1a3410 --- /dev/null +++ b/packages/config/tailwind/index.js @@ -0,0 +1,8 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: ["./src/**/*.{ts,tsx}", "./src/_app.tsx"], + theme: { + extend: {}, + }, + plugins: [], +}; diff --git a/packages/config/tailwind/package.json b/packages/config/tailwind/package.json new file mode 100644 index 0000000..7265f00 --- /dev/null +++ b/packages/config/tailwind/package.json @@ -0,0 +1,15 @@ +{ + "name": "@acme/tailwind-config", + "version": "0.1.0", + "main": "index.js", + "license": "MIT", + "files": [ + "index.js", + "postcss.js" + ], + "devDependencies": { + "autoprefixer": "^10.4.13", + "postcss": "^8.4.19", + "tailwindcss": "^3.2.4" + } +} diff --git a/packages/config/tailwind/postcss.js b/packages/config/tailwind/postcss.js new file mode 100644 index 0000000..12a703d --- /dev/null +++ b/packages/config/tailwind/postcss.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; diff --git a/turbo.json b/turbo.json index 52eb5ed..ba12bc9 100644 --- a/turbo.json +++ b/turbo.json @@ -2,25 +2,56 @@ "$schema": "https://turbo.build/schema.json", "pipeline": { "build": { - "dependsOn": ["^build"], - "outputs": ["dist/**", ".next/**"] + "dependsOn": [ + "^build", + "^db-generate" + ], + "outputs": [ + "dist/**", + ".next/**", + ".expo/**" + ] }, "lint": { "outputs": [] }, "dev": { + "dependsOn": [ + "^db-generate" + ], "cache": false }, "dev:local_infra": { "cache": false }, - "db:migrate": { + "db-generate": { + "inputs": [ + "prisma/schema.prisma" + ], + "cache": false + }, + "db-push": { + "inputs": [ + "prisma/schema.prisma" + ], "cache": false }, "test": { "outputs": [], "cache": false }, + "type-check": { + "dependsOn": [ + "^db-generate" + ], + "cache": false + }, + "clean": { + "cache": false + }, + "//#clean": { + "cache": false + }, "about-me#build": { "dependsOn": [ "^build" @@ -32,7 +63,10 @@ "NODE_ENV", "DATABASE_URL" ], - "outputs": ["dist/**", ".next/**"] + "outputs": [ + "dist/**", + ".next/**" + ] } } }