From b0f3b8bde75529163beaa10fd55fd660337dcbca Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sat, 29 Apr 2023 13:50:33 +0100 Subject: [PATCH 01/24] added import order sorting --- cli/.prettierrc.cjs | 5 ++- cli/package.json | 1 + cli/template/base/package.json | 1 + pnpm-lock.yaml | 60 +++++++++++++++++++++++++++++----- www/.prettierrc.cjs | 1 + www/package.json | 1 + 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/cli/.prettierrc.cjs b/cli/.prettierrc.cjs index a73eb7d623..78ee01d6ce 100644 --- a/cli/.prettierrc.cjs +++ b/cli/.prettierrc.cjs @@ -1,7 +1,10 @@ /** @type {import('prettier').Config} */ const config = { ...require("../.prettierrc.cjs"), - plugins: [require.resolve("prettier-plugin-tailwindcss")], + plugins: [ + require.resolve("prettier-plugin-tailwindcss"), + require.resolve("@ianvs/prettier-plugin-sort-imports"), + ], tailwindConfig: "./template/extras/config/tailwind.config.ts", }; diff --git a/cli/package.json b/cli/package.json index 4763bd5c9d..4c0d7d01be 100644 --- a/cli/package.json +++ b/cli/package.json @@ -51,6 +51,7 @@ "sort-package-json": "^2.4.1" }, "devDependencies": { + "@ianvs/prettier-plugin-sort-imports": "^3.7.2", "@prisma/client": "^4.11.0", "@tanstack/react-query": "^4.28.0", "@trpc/client": "^10.18.0", diff --git a/cli/template/base/package.json b/cli/template/base/package.json index 8b116a961c..aeb7368bdf 100644 --- a/cli/template/base/package.json +++ b/cli/template/base/package.json @@ -15,6 +15,7 @@ "zod": "^3.21.4" }, "devDependencies": { + "@ianvs/prettier-plugin-sort-imports": "^3.7.2", "@types/eslint": "^8.21.3", "@types/node": "^18.15.5", "@types/react": "^18.0.28", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11c4191d6e..f8cf01f4f0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,6 +92,9 @@ importers: specifier: ^2.4.1 version: 2.4.1 devDependencies: + '@ianvs/prettier-plugin-sort-imports': + specifier: ^3.7.2 + version: 3.7.2(prettier@2.8.6) '@prisma/client': specifier: ^4.11.0 version: 4.11.0(prisma@4.11.0) @@ -124,7 +127,7 @@ importers: version: 18.15.5 next: specifier: ^13.2.4 - version: 13.2.4(react-dom@18.2.0)(react@18.2.0) + version: 13.2.4(@babel/core@7.21.3)(react-dom@18.2.0)(react@18.2.0) next-auth: specifier: ^4.20.1 version: 4.20.1(next@13.2.4)(react-dom@18.2.0)(react@18.2.0) @@ -133,7 +136,7 @@ importers: version: 2.8.6 prettier-plugin-tailwindcss: specifier: ^0.2.6 - version: 0.2.6(prettier-plugin-astro@0.8.0)(prettier@2.8.6) + version: 0.2.6(@ianvs/prettier-plugin-sort-imports@3.7.2)(prettier-plugin-astro@0.8.0)(prettier@2.8.6) prisma: specifier: ^4.11.0 version: 4.11.0 @@ -216,6 +219,9 @@ importers: '@astrojs/tailwind': specifier: ^3.1.1 version: 3.1.1(astro@2.1.5)(tailwindcss@3.3.0) + '@ianvs/prettier-plugin-sort-imports': + specifier: ^3.7.2 + version: 3.7.2(prettier@2.8.6) '@types/node': specifier: ^18.15.5 version: 18.15.5 @@ -254,7 +260,7 @@ importers: version: 0.8.0 prettier-plugin-tailwindcss: specifier: ^0.2.6 - version: 0.2.6(prettier-plugin-astro@0.8.0)(prettier@2.8.6) + version: 0.2.6(@ianvs/prettier-plugin-sort-imports@3.7.2)(prettier-plugin-astro@0.8.0)(prettier@2.8.6) react: specifier: 18.2.0 version: 18.2.0 @@ -1269,6 +1275,28 @@ packages: /@humanwhocodes/object-schema@1.2.1: resolution: {integrity: sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==} + /@ianvs/prettier-plugin-sort-imports@3.7.2(prettier@2.8.6): + resolution: {integrity: sha512-bVckKToJM8XV2wTOG1VpeXrSmfAG49esVrikbxeFbY51RJdNke9AdMANJtGuACB59uo+pGlz0wBdWFrRzWyO1A==} + peerDependencies: + '@vue/compiler-sfc': '>=3.0.0' + prettier: 2.x + peerDependenciesMeta: + '@vue/compiler-sfc': + optional: true + dependencies: + '@babel/core': 7.21.3 + '@babel/generator': 7.21.3 + '@babel/parser': 7.21.3 + '@babel/traverse': 7.21.3 + '@babel/types': 7.21.3 + javascript-natural-sort: 0.7.1 + lodash.clone: 4.5.0 + lodash.isequal: 4.5.0 + prettier: 2.8.6 + transitivePeerDependencies: + - supports-color + dev: true + /@jridgewell/gen-mapping@0.1.1: resolution: {integrity: sha512-sQXCasFk+U8lWYEe66WxRDOE9PjVz4vSM51fTu3Hw+ClTpUSQb718772vH3pyS5pShp6lvQM7SxgIDXXXmOX7w==} engines: {node: '>=6.0.0'} @@ -1676,7 +1704,7 @@ packages: '@trpc/client': 10.18.0(@trpc/server@10.18.0) '@trpc/react-query': 10.18.0(@tanstack/react-query@4.28.0)(@trpc/client@10.18.0)(@trpc/server@10.18.0)(react-dom@18.2.0)(react@18.2.0) '@trpc/server': 10.18.0 - next: 13.2.4(react-dom@18.2.0)(react@18.2.0) + next: 13.2.4(@babel/core@7.21.3)(react-dom@18.2.0)(react@18.2.0) react: 18.2.0 react-dom: 18.2.0(react@18.2.0) react-ssr-prepass: 1.5.0(react@18.2.0) @@ -4405,6 +4433,10 @@ packages: /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + /javascript-natural-sort@0.7.1: + resolution: {integrity: sha512-nO6jcEfZWQXDhOiBtG2KvKyEptz7RVbpGP4vTD2hLBdmNQSsCiicO2Ioinv6UI4y9ukqnBpy+XZ9H6uLNgJTlw==} + dev: true + /jiti@1.18.2: resolution: {integrity: sha512-QAdOptna2NYiSSpv0O/BwoHBSmz4YhpzJHyi+fnMRTXFjp7B8i/YG5Z8IfusxB1ufjcD2Sre1F3R+nX3fvy7gg==} hasBin: true @@ -4567,6 +4599,14 @@ packages: dependencies: p-locate: 5.0.0 + /lodash.clone@4.5.0: + resolution: {integrity: sha512-GhrVeweiTD6uTmmn5hV/lzgCQhccwReIVRLHp7LT4SopOjqEZ5BbX8b5WWEtAKasjmy8hR7ZPwsYlxRCku5odg==} + dev: true + + /lodash.isequal@4.5.0: + resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} + dev: true + /lodash.merge@4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} @@ -5280,7 +5320,7 @@ packages: '@panva/hkdf': 1.0.4 cookie: 0.5.0 jose: 4.13.1 - next: 13.2.4(react-dom@18.2.0)(react@18.2.0) + next: 13.2.4(@babel/core@7.21.3)(react-dom@18.2.0)(react@18.2.0) oauth: 0.9.15 openid-client: 5.4.0 preact: 10.13.1 @@ -5290,7 +5330,7 @@ packages: uuid: 8.3.2 dev: true - /next@13.2.4(react-dom@18.2.0)(react@18.2.0): + /next@13.2.4(@babel/core@7.21.3)(react-dom@18.2.0)(react@18.2.0): resolution: {integrity: sha512-g1I30317cThkEpvzfXujf0O4wtaQHtDCLhlivwlTJ885Ld+eOgcz7r3TGQzeU+cSRoNHtD8tsJgzxVdYojFssw==} engines: {node: '>=14.6.0'} hasBin: true @@ -5317,7 +5357,7 @@ packages: postcss: 8.4.14 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) - styled-jsx: 5.1.1(react@18.2.0) + styled-jsx: 5.1.1(@babel/core@7.21.3)(react@18.2.0) optionalDependencies: '@next/swc-android-arm-eabi': 13.2.4 '@next/swc-android-arm64': 13.2.4 @@ -5886,7 +5926,7 @@ packages: synckit: 0.8.5 dev: true - /prettier-plugin-tailwindcss@0.2.6(prettier-plugin-astro@0.8.0)(prettier@2.8.6): + /prettier-plugin-tailwindcss@0.2.6(@ianvs/prettier-plugin-sort-imports@3.7.2)(prettier-plugin-astro@0.8.0)(prettier@2.8.6): resolution: {integrity: sha512-F+7XCl9RLF/LPrGdUMHWpsT6TM31JraonAUyE6eBmpqymFvDwyl0ETHsKFHP1NG+sEfv8bmKqnTxEbWQbHPlBA==} engines: {node: '>=12.17.0'} peerDependencies: @@ -5938,6 +5978,7 @@ packages: prettier-plugin-twig-melody: optional: true dependencies: + '@ianvs/prettier-plugin-sort-imports': 3.7.2(prettier@2.8.6) prettier: 2.8.6 prettier-plugin-astro: 0.8.0 dev: true @@ -6756,7 +6797,7 @@ packages: inline-style-parser: 0.1.1 dev: false - /styled-jsx@5.1.1(react@18.2.0): + /styled-jsx@5.1.1(@babel/core@7.21.3)(react@18.2.0): resolution: {integrity: sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==} engines: {node: '>= 12.0.0'} peerDependencies: @@ -6769,6 +6810,7 @@ packages: babel-plugin-macros: optional: true dependencies: + '@babel/core': 7.21.3 client-only: 0.0.1 react: 18.2.0 dev: true diff --git a/www/.prettierrc.cjs b/www/.prettierrc.cjs index adb2140a0d..d4dc1900df 100644 --- a/www/.prettierrc.cjs +++ b/www/.prettierrc.cjs @@ -3,6 +3,7 @@ const config = { ...require("../.prettierrc.cjs"), plugins: [ require.resolve("prettier-plugin-astro"), + require.resolve("@ianvs/prettier-plugin-sort-imports"), require.resolve("prettier-plugin-tailwindcss"), // MUST come last ], pluginSearchDirs: false, diff --git a/www/package.json b/www/package.json index af973d2dd4..d3187441b3 100644 --- a/www/package.json +++ b/www/package.json @@ -37,6 +37,7 @@ "devDependencies": { "@astrojs/react": "^2.1.0", "@astrojs/tailwind": "^3.1.1", + "@ianvs/prettier-plugin-sort-imports": "^3.7.2", "@types/node": "^18.15.5", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", From d8169926eb5e78720cfdb2e250fb4c2da5e75bd4 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sat, 29 Apr 2023 13:50:46 +0100 Subject: [PATCH 02/24] cli format --- cli/src/index.ts | 19 +++++++++---------- cli/template/base/src/pages/_app.tsx | 1 - .../extras/config/prettier.config.cjs | 5 ++++- .../extras/src/pages/_app/with-auth-trpc.tsx | 4 +--- .../extras/src/pages/_app/with-auth.tsx | 3 +-- .../extras/src/pages/_app/with-trpc.tsx | 2 -- .../src/pages/index/with-auth-trpc-tw.tsx | 3 +-- .../extras/src/pages/index/with-auth-trpc.tsx | 3 +-- .../extras/src/pages/index/with-trpc-tw.tsx | 1 - .../extras/src/pages/index/with-trpc.tsx | 1 - 10 files changed, 17 insertions(+), 25 deletions(-) diff --git a/cli/src/index.ts b/cli/src/index.ts index 4bd2e7b228..66bca71a87 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -1,23 +1,22 @@ #!/usr/bin/env node - -import { type PackageJson } from "type-fest"; -import path from "path"; +import { installDependencies } from "./helpers/installDependencies.js"; +import { getVersion } from "./utils/getT3Version.js"; +import { + getNpmVersion, + renderVersionWarning, +} from "./utils/renderVersionWarning.js"; import fs from "fs-extra"; +import path from "path"; +import { type PackageJson } from "type-fest"; import { runCli } from "~/cli/index.js"; import { createProject } from "~/helpers/createProject.js"; import { initializeGit } from "~/helpers/git.js"; -import { setImportAlias } from "~/helpers/setImportAlias.js"; import { logNextSteps } from "~/helpers/logNextSteps.js"; +import { setImportAlias } from "~/helpers/setImportAlias.js"; import { buildPkgInstallerMap } from "~/installers/index.js"; import { logger } from "~/utils/logger.js"; import { parseNameAndPath } from "~/utils/parseNameAndPath.js"; import { renderTitle } from "~/utils/renderTitle.js"; -import { - getNpmVersion, - renderVersionWarning, -} from "./utils/renderVersionWarning.js"; -import { installDependencies } from "./helpers/installDependencies.js"; -import { getVersion } from "./utils/getT3Version.js"; type CT3APackageJSON = PackageJson & { ct3aMetadata?: { diff --git a/cli/template/base/src/pages/_app.tsx b/cli/template/base/src/pages/_app.tsx index d280cbd380..5d4858ed44 100644 --- a/cli/template/base/src/pages/_app.tsx +++ b/cli/template/base/src/pages/_app.tsx @@ -1,5 +1,4 @@ import { type AppType } from "next/dist/shared/lib/utils"; - import "~/styles/globals.css"; const MyApp: AppType = ({ Component, pageProps }) => { diff --git a/cli/template/extras/config/prettier.config.cjs b/cli/template/extras/config/prettier.config.cjs index ca28ed9e46..e62bb60bf1 100644 --- a/cli/template/extras/config/prettier.config.cjs +++ b/cli/template/extras/config/prettier.config.cjs @@ -1,6 +1,9 @@ /** @type {import("prettier").Config} */ const config = { - plugins: [require.resolve("prettier-plugin-tailwindcss")], + plugins: [ + require.resolve("prettier-plugin-tailwindcss"), + require.resolve("@ianvs/prettier-plugin-sort-imports"), + ], }; module.exports = config; diff --git a/cli/template/extras/src/pages/_app/with-auth-trpc.tsx b/cli/template/extras/src/pages/_app/with-auth-trpc.tsx index 81e8bcc340..e319df459f 100644 --- a/cli/template/extras/src/pages/_app/with-auth-trpc.tsx +++ b/cli/template/extras/src/pages/_app/with-auth-trpc.tsx @@ -1,9 +1,7 @@ -import { type AppType } from "next/app"; import { type Session } from "next-auth"; import { SessionProvider } from "next-auth/react"; - +import { type AppType } from "next/app"; import { api } from "~/utils/api"; - import "~/styles/globals.css"; const MyApp: AppType<{ session: Session | null }> = ({ diff --git a/cli/template/extras/src/pages/_app/with-auth.tsx b/cli/template/extras/src/pages/_app/with-auth.tsx index 76a32df788..fad7ab27dc 100644 --- a/cli/template/extras/src/pages/_app/with-auth.tsx +++ b/cli/template/extras/src/pages/_app/with-auth.tsx @@ -1,7 +1,6 @@ -import { type AppType } from "next/app"; import { type Session } from "next-auth"; import { SessionProvider } from "next-auth/react"; - +import { type AppType } from "next/app"; import "~/styles/globals.css"; const MyApp: AppType<{ session: Session | null }> = ({ diff --git a/cli/template/extras/src/pages/_app/with-trpc.tsx b/cli/template/extras/src/pages/_app/with-trpc.tsx index 18319174ef..279d2188e8 100644 --- a/cli/template/extras/src/pages/_app/with-trpc.tsx +++ b/cli/template/extras/src/pages/_app/with-trpc.tsx @@ -1,7 +1,5 @@ import { type AppType } from "next/app"; - import { api } from "~/utils/api"; - import "~/styles/globals.css"; const MyApp: AppType = ({ Component, pageProps }) => { diff --git a/cli/template/extras/src/pages/index/with-auth-trpc-tw.tsx b/cli/template/extras/src/pages/index/with-auth-trpc-tw.tsx index 97ec863fa1..c173f6f985 100644 --- a/cli/template/extras/src/pages/index/with-auth-trpc-tw.tsx +++ b/cli/template/extras/src/pages/index/with-auth-trpc-tw.tsx @@ -1,8 +1,7 @@ import { type NextPage } from "next"; +import { signIn, signOut, useSession } from "next-auth/react"; import Head from "next/head"; import Link from "next/link"; -import { signIn, signOut, useSession } from "next-auth/react"; - import { api } from "~/utils/api"; const Home: NextPage = () => { diff --git a/cli/template/extras/src/pages/index/with-auth-trpc.tsx b/cli/template/extras/src/pages/index/with-auth-trpc.tsx index c85095e83a..1e3484fc02 100644 --- a/cli/template/extras/src/pages/index/with-auth-trpc.tsx +++ b/cli/template/extras/src/pages/index/with-auth-trpc.tsx @@ -1,9 +1,8 @@ import styles from "./index.module.css"; import { type NextPage } from "next"; +import { signIn, signOut, useSession } from "next-auth/react"; import Head from "next/head"; import Link from "next/link"; -import { signIn, signOut, useSession } from "next-auth/react"; - import { api } from "~/utils/api"; const Home: NextPage = () => { diff --git a/cli/template/extras/src/pages/index/with-trpc-tw.tsx b/cli/template/extras/src/pages/index/with-trpc-tw.tsx index bf665c8399..52cccbe62d 100644 --- a/cli/template/extras/src/pages/index/with-trpc-tw.tsx +++ b/cli/template/extras/src/pages/index/with-trpc-tw.tsx @@ -1,7 +1,6 @@ import { type NextPage } from "next"; import Head from "next/head"; import Link from "next/link"; - import { api } from "~/utils/api"; const Home: NextPage = () => { diff --git a/cli/template/extras/src/pages/index/with-trpc.tsx b/cli/template/extras/src/pages/index/with-trpc.tsx index 2e97a27a0a..3768eb3583 100644 --- a/cli/template/extras/src/pages/index/with-trpc.tsx +++ b/cli/template/extras/src/pages/index/with-trpc.tsx @@ -2,7 +2,6 @@ import styles from "./index.module.css"; import { type NextPage } from "next"; import Head from "next/head"; import Link from "next/link"; - import { api } from "~/utils/api"; const Home: NextPage = () => { From 1149c085032f13d8942fa02ec5a4fb2458d33e52 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sat, 29 Apr 2023 13:51:47 +0100 Subject: [PATCH 03/24] format www --- www/src/components/docs/breadCrumbs.tsx | 2 +- www/src/components/docs/pageContent.astro | 8 ++++---- www/src/components/footer/footer.astro | 1 + www/src/components/landingPage/tweets/tweetSlider.astro | 2 +- www/src/components/landingPage/tweets/tweets.astro | 2 +- www/src/components/navigation/LanguageSelect.tsx | 2 +- www/src/components/navigation/OnThisPageLinks.tsx | 4 ++-- www/src/components/navigation/Search.tsx | 6 +++--- www/src/components/navigation/githubIcon.astro | 2 +- www/src/components/navigation/leftSidebar.astro | 2 +- www/src/components/navigation/navbar.astro | 4 ++-- www/src/components/navigation/rightSidebar.astro | 2 +- www/src/components/navigation/tableOfContents.astro | 2 +- www/src/languages.ts | 1 + www/src/layouts/docs.astro | 4 ++-- www/src/layouts/landingPage.astro | 3 +-- www/src/pages/404.astro | 2 +- www/src/pages/ar/usage/trpc.md | 4 ++-- www/src/pages/en/deployment/index.astro | 2 +- www/src/pages/en/usage/index.astro | 2 +- www/src/pages/en/usage/trpc.md | 4 ++-- www/src/pages/es/deployment/index.astro | 2 +- www/src/pages/es/usage/index.astro | 2 +- www/src/pages/es/usage/trpc.md | 4 ++-- www/src/pages/fr/deployment/index.astro | 2 +- www/src/pages/fr/usage/index.astro | 2 +- www/src/pages/fr/usage/trpc.md | 4 ++-- www/src/pages/index.astro | 6 +++--- www/src/pages/no/usage/trpc.md | 4 ++-- www/src/pages/pl/deployment/index.astro | 2 +- www/src/pages/pl/usage/index.astro | 2 +- www/src/pages/pl/usage/trpc.md | 4 ++-- www/src/pages/pt/deployment/index.astro | 2 +- www/src/pages/pt/usage/index.astro | 2 +- www/src/pages/pt/usage/trpc.md | 4 ++-- www/src/pages/ru/deployment/index.astro | 2 +- www/src/pages/ru/usage/index.astro | 2 +- www/src/pages/ru/usage/trpc.md | 4 ++-- www/src/pages/zh-hans/deployment/index.astro | 2 +- www/src/pages/zh-hans/usage/index.astro | 2 +- www/src/pages/zh-hans/usage/trpc.md | 4 ++-- 41 files changed, 60 insertions(+), 59 deletions(-) diff --git a/www/src/components/docs/breadCrumbs.tsx b/www/src/components/docs/breadCrumbs.tsx index 5020dd9959..39a3565e1a 100644 --- a/www/src/components/docs/breadCrumbs.tsx +++ b/www/src/components/docs/breadCrumbs.tsx @@ -1,6 +1,6 @@ -import clsx from "clsx"; import { SIDEBAR, SIDEBAR_HEADER_MAP, type OuterHeaders } from "../../config"; import { getIsRtlFromLangCode, getLanguageFromURL } from "../../languages"; +import clsx from "clsx"; type SlugType = "" | "usage" | "deployment"; type Entry = { text: string; link: string }; diff --git a/www/src/components/docs/pageContent.astro b/www/src/components/docs/pageContent.astro index ec47352aed..ab64745711 100644 --- a/www/src/components/docs/pageContent.astro +++ b/www/src/components/docs/pageContent.astro @@ -1,11 +1,11 @@ --- -import { type MarkdownHeading } from "astro"; import { type Frontmatter, type KnownLanguageCode } from "../../config"; -import OutdatedDocsBanner from "./outdatedDocsBanner.astro"; +import { getIsRtlFromLangCode } from "../../languages"; +import OnThisPageLinks from "../navigation/OnThisPageLinks"; import BreadCrumbs from "./breadCrumbs"; +import OutdatedDocsBanner from "./outdatedDocsBanner.astro"; import Pagination from "./pagination.astro"; -import OnThisPageLinks from "../navigation/OnThisPageLinks"; -import { getIsRtlFromLangCode } from "../../languages"; +import { type MarkdownHeading } from "astro"; export interface Props { frontmatter: Frontmatter; diff --git a/www/src/components/footer/footer.astro b/www/src/components/footer/footer.astro index 0f015338cb..bb2a26e4f9 100644 --- a/www/src/components/footer/footer.astro +++ b/www/src/components/footer/footer.astro @@ -1,5 +1,6 @@ --- import AvatarList from "../docs/avatarList.astro"; + export interface Props { path: string; isBlog: boolean; diff --git a/www/src/components/landingPage/tweets/tweetSlider.astro b/www/src/components/landingPage/tweets/tweetSlider.astro index a9feb98d40..0422895e0d 100644 --- a/www/src/components/landingPage/tweets/tweetSlider.astro +++ b/www/src/components/landingPage/tweets/tweetSlider.astro @@ -1,6 +1,6 @@ --- -import TweetCard from "./tweetCard.astro"; import { type Tweet } from "./featuredTweets"; +import TweetCard from "./tweetCard.astro"; export interface Props { tweets: Tweet[]; diff --git a/www/src/components/landingPage/tweets/tweets.astro b/www/src/components/landingPage/tweets/tweets.astro index c25e9d03af..fe9155ff4f 100644 --- a/www/src/components/landingPage/tweets/tweets.astro +++ b/www/src/components/landingPage/tweets/tweets.astro @@ -1,7 +1,7 @@ --- import PageSection from "../pageSection.astro"; -import TweetSlider from "./tweetSlider.astro"; import { featuredTweets } from "./featuredTweets"; +import TweetSlider from "./tweetSlider.astro"; --- diff --git a/www/src/pages/ar/usage/trpc.md b/www/src/pages/ar/usage/trpc.md index a266db63e5..d55539cd89 100644 --- a/www/src/pages/ar/usage/trpc.md +++ b/www/src/pages/ar/usage/trpc.md @@ -296,9 +296,9 @@ const MyComponent = () => { ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createContextInner } from "~/server/router/context"; -import { appRouter, type AppRouter } from "~/server/router/_app"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/router/_app"; +import { createContextInner } from "~/server/router/context"; test("example router", async () => { const ctx = await createContextInner({ session: null }); diff --git a/www/src/pages/en/deployment/index.astro b/www/src/pages/en/deployment/index.astro index 01cda9ff0a..55641abc94 100644 --- a/www/src/pages/en/deployment/index.astro +++ b/www/src/pages/en/deployment/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Deployment", diff --git a/www/src/pages/en/usage/index.astro b/www/src/pages/en/usage/index.astro index b93505fac4..f84d5aed15 100644 --- a/www/src/pages/en/usage/index.astro +++ b/www/src/pages/en/usage/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Usage", diff --git a/www/src/pages/en/usage/trpc.md b/www/src/pages/en/usage/trpc.md index f5a9cc6b93..11d6582154 100644 --- a/www/src/pages/en/usage/trpc.md +++ b/www/src/pages/en/usage/trpc.md @@ -337,9 +337,9 @@ Here is a sample integration test that uses [Vitest](https://vitest.dev) to chec ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createInnerTRPCContext } from "~/server/api/trpc"; -import { appRouter, type AppRouter } from "~/server/api/root"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/api/root"; +import { createInnerTRPCContext } from "~/server/api/trpc"; test("example router", async () => { const ctx = await createInnerTRPCContext({ session: null }); diff --git a/www/src/pages/es/deployment/index.astro b/www/src/pages/es/deployment/index.astro index e7a98b5ee5..0412a84f11 100644 --- a/www/src/pages/es/deployment/index.astro +++ b/www/src/pages/es/deployment/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Despliegue", diff --git a/www/src/pages/es/usage/index.astro b/www/src/pages/es/usage/index.astro index 67b3a96897..57fb63d9e9 100644 --- a/www/src/pages/es/usage/index.astro +++ b/www/src/pages/es/usage/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Uso", diff --git a/www/src/pages/es/usage/trpc.md b/www/src/pages/es/usage/trpc.md index 0acca55620..68ad1774ec 100644 --- a/www/src/pages/es/usage/trpc.md +++ b/www/src/pages/es/usage/trpc.md @@ -296,9 +296,9 @@ Aquí hay una prueba de integración de muestra que utiliza [Vitest](https://vit ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createContextInner } from "~/server/router/context"; -import { appRouter, type AppRouter } from "~/server/router/_app"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/router/_app"; +import { createContextInner } from "~/server/router/context"; test("example router", async () => { const ctx = await createContextInner({ session: null }); diff --git a/www/src/pages/fr/deployment/index.astro b/www/src/pages/fr/deployment/index.astro index 59f64a7522..62849b2831 100644 --- a/www/src/pages/fr/deployment/index.astro +++ b/www/src/pages/fr/deployment/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Déploiement", diff --git a/www/src/pages/fr/usage/index.astro b/www/src/pages/fr/usage/index.astro index 3b2aef4e99..40f62b568d 100644 --- a/www/src/pages/fr/usage/index.astro +++ b/www/src/pages/fr/usage/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Utilisation", diff --git a/www/src/pages/fr/usage/trpc.md b/www/src/pages/fr/usage/trpc.md index 799e538743..525a521d72 100644 --- a/www/src/pages/fr/usage/trpc.md +++ b/www/src/pages/fr/usage/trpc.md @@ -307,9 +307,9 @@ Voici un exemple de test d'intégration qui utilise [Vitest](https://vitest.dev) ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createInnerTRPCContext } from "~/server/api/trpc"; -import { appRouter, type AppRouter } from "~/server/api/root"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/api/root"; +import { createInnerTRPCContext } from "~/server/api/trpc"; test("example router", async () => { const ctx = await createInnerTRPCContext({ session: null }); diff --git a/www/src/pages/index.astro b/www/src/pages/index.astro index 25c3ffca9c..6cbfc5e87b 100644 --- a/www/src/pages/index.astro +++ b/www/src/pages/index.astro @@ -1,9 +1,9 @@ --- -import LandingPage from "../layouts/landingPage.astro"; -import Banner from "../components/landingPage/banner.astro"; import About from "../components/landingPage/about.astro"; -import Features from "../components/landingPage/stack/stack.astro"; +import Banner from "../components/landingPage/banner.astro"; import Community from "../components/landingPage/community/community.astro"; +import Features from "../components/landingPage/stack/stack.astro"; +import LandingPage from "../layouts/landingPage.astro"; --- diff --git a/www/src/pages/no/usage/trpc.md b/www/src/pages/no/usage/trpc.md index 2b43eb0ed1..398166991c 100644 --- a/www/src/pages/no/usage/trpc.md +++ b/www/src/pages/no/usage/trpc.md @@ -300,9 +300,9 @@ Her er et eksempel på en integrasjonstest som bruker [Vitest](https://vitest.de ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createInnerTRPCContext } from "~/server/api/trpc"; -import { appRouter, type AppRouter } from "~/server/api/root"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/api/root"; +import { createInnerTRPCContext } from "~/server/api/trpc"; test("example router", async () => { const ctx = await createInnerTRPCContext({ session: null }); diff --git a/www/src/pages/pl/deployment/index.astro b/www/src/pages/pl/deployment/index.astro index 7c5b3fb74c..b21b4de255 100644 --- a/www/src/pages/pl/deployment/index.astro +++ b/www/src/pages/pl/deployment/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Deployment", diff --git a/www/src/pages/pl/usage/index.astro b/www/src/pages/pl/usage/index.astro index adbea6aa2d..65c6fe3583 100644 --- a/www/src/pages/pl/usage/index.astro +++ b/www/src/pages/pl/usage/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Korzystanie z technologii", diff --git a/www/src/pages/pl/usage/trpc.md b/www/src/pages/pl/usage/trpc.md index 3af1fcdcca..834dbfd0cc 100644 --- a/www/src/pages/pl/usage/trpc.md +++ b/www/src/pages/pl/usage/trpc.md @@ -303,9 +303,9 @@ Tu znajdziesz przykładowy test integracji korzystający z paczki [Vitest](https ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createInnerTRPCContext } from "~/server/api/trpc"; -import { appRouter, type AppRouter } from "~/server/api/root"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/api/root"; +import { createInnerTRPCContext } from "~/server/api/trpc"; test("example router", async () => { const ctx = await createInnerTRPCContext({ session: null }); diff --git a/www/src/pages/pt/deployment/index.astro b/www/src/pages/pt/deployment/index.astro index 55feb3c639..fc1e8dbdc9 100644 --- a/www/src/pages/pt/deployment/index.astro +++ b/www/src/pages/pt/deployment/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Deployment", diff --git a/www/src/pages/pt/usage/index.astro b/www/src/pages/pt/usage/index.astro index 3e4c0797e3..4ebe4311b3 100644 --- a/www/src/pages/pt/usage/index.astro +++ b/www/src/pages/pt/usage/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Uso", diff --git a/www/src/pages/pt/usage/trpc.md b/www/src/pages/pt/usage/trpc.md index d5e13c807b..ea6d231c64 100644 --- a/www/src/pages/pt/usage/trpc.md +++ b/www/src/pages/pt/usage/trpc.md @@ -307,9 +307,9 @@ Aqui está um exemplo de teste de integração que usa [Vitest](https://vitest.d ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createContextInner } from "~/server/router/context"; -import { appRouter, type AppRouter } from "~/server/router/_app"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/router/_app"; +import { createContextInner } from "~/server/router/context"; test("example router", async () => { const ctx = await createContextInner({ session: null }); diff --git a/www/src/pages/ru/deployment/index.astro b/www/src/pages/ru/deployment/index.astro index 6c196d0774..a3284ab95c 100644 --- a/www/src/pages/ru/deployment/index.astro +++ b/www/src/pages/ru/deployment/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Развертывание", diff --git a/www/src/pages/ru/usage/index.astro b/www/src/pages/ru/usage/index.astro index 851fcaebd1..43976ef1ce 100644 --- a/www/src/pages/ru/usage/index.astro +++ b/www/src/pages/ru/usage/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Использование", diff --git a/www/src/pages/ru/usage/trpc.md b/www/src/pages/ru/usage/trpc.md index ba5de1bb76..9e91c99835 100644 --- a/www/src/pages/ru/usage/trpc.md +++ b/www/src/pages/ru/usage/trpc.md @@ -301,9 +301,9 @@ const MyComponent = () => { ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createInnerTRPCContext } from "~/server/api/trpc"; -import { appRouter, type AppRouter } from "~/server/api/root"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/api/root"; +import { createInnerTRPCContext } from "~/server/api/trpc"; test("example router", async () => { const ctx = await createInnerTRPCContext({ session: null }); diff --git a/www/src/pages/zh-hans/deployment/index.astro b/www/src/pages/zh-hans/deployment/index.astro index 01cda9ff0a..55641abc94 100644 --- a/www/src/pages/zh-hans/deployment/index.astro +++ b/www/src/pages/zh-hans/deployment/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Deployment", diff --git a/www/src/pages/zh-hans/usage/index.astro b/www/src/pages/zh-hans/usage/index.astro index b93505fac4..f84d5aed15 100644 --- a/www/src/pages/zh-hans/usage/index.astro +++ b/www/src/pages/zh-hans/usage/index.astro @@ -1,8 +1,8 @@ --- -import Layout from "../../../layouts/docs.astro"; import IndexPage from "../../../components/docs/indexPage.astro"; import { type Frontmatter, SIDEBAR } from "../../../config"; import { getLanguageFromURL } from "../../../languages"; +import Layout from "../../../layouts/docs.astro"; const frontmatter: Frontmatter = { title: "Usage", diff --git a/www/src/pages/zh-hans/usage/trpc.md b/www/src/pages/zh-hans/usage/trpc.md index 604285fa36..28218a82d5 100644 --- a/www/src/pages/zh-hans/usage/trpc.md +++ b/www/src/pages/zh-hans/usage/trpc.md @@ -338,9 +338,9 @@ const MyComponent = () => { ```ts import { type inferProcedureInput } from "@trpc/server"; -import { createInnerTRPCContext } from "~/server/api/trpc"; -import { appRouter, type AppRouter } from "~/server/api/root"; import { expect, test } from "vitest"; +import { appRouter, type AppRouter } from "~/server/api/root"; +import { createInnerTRPCContext } from "~/server/api/trpc"; test("example router", async () => { const ctx = await createInnerTRPCContext({ session: null }); From 882177e262cdcd13d118dd3e9f4b4793777b943e Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Fri, 5 May 2023 14:20:27 +0100 Subject: [PATCH 04/24] . --- cli/src/cli/index.ts | 15 +++- cli/src/installers/index.ts | 8 +- cli/src/installers/strictEslintAndPrettier.ts | 74 +++++++++++++++++++ .../extras/config/_strict-eslint.config.cjs | 35 +++++++++ 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 cli/src/installers/strictEslintAndPrettier.ts create mode 100644 cli/template/extras/config/_strict-eslint.config.cjs diff --git a/cli/src/cli/index.ts b/cli/src/cli/index.ts index 7d995594ec..f406f44e7b 100644 --- a/cli/src/cli/index.ts +++ b/cli/src/cli/index.ts @@ -1,9 +1,11 @@ -import { type AvailablePackages } from "~/installers/index.js"; -import { availablePackages } from "~/installers/index.js"; import chalk from "chalk"; import { Command } from "commander"; import inquirer from "inquirer"; import { CREATE_T3_APP, DEFAULT_APP_NAME } from "~/consts.js"; +import { + availablePackages, + type AvailablePackages, +} from "~/installers/index.js"; import { getVersion } from "~/utils/getT3Version.js"; import { getUserPkgManager } from "~/utils/getUserPkgManager.js"; import { logger } from "~/utils/logger.js"; @@ -15,6 +17,7 @@ interface CliFlags { noInstall: boolean; default: boolean; importAlias: string; + strictEslintAndPrettier: boolean; /** @internal Used in CI. */ CI: boolean; @@ -47,6 +50,7 @@ const defaultOptions: CliResults = { prisma: false, nextAuth: false, importAlias: "~/", + strictEslintAndPrettier: false, }, }; @@ -114,6 +118,11 @@ export const runCli = async () => { "Explicitly tell the CLI to use a custom import alias", defaultOptions.flags.importAlias, ) + .option( + "-ep -eslint-pretteier", + "enable prettier and a strict eslint config", + defaultOptions.flags.strictEslintAndPrettier, + ) /** END CI-FLAGS */ .version(getVersion(), "-v, --version", "Display the version number") .addHelpText( @@ -153,6 +162,8 @@ export const runCli = async () => { if (cliResults.flags.tailwind) cliResults.packages.push("tailwind"); if (cliResults.flags.prisma) cliResults.packages.push("prisma"); if (cliResults.flags.nextAuth) cliResults.packages.push("nextAuth"); + if (cliResults.flags.strictEslintAndPrettier) + cliResults.packages.push("strictEslintAndPrettier"); } // Explained below why this is in a try/catch block diff --git a/cli/src/installers/index.ts b/cli/src/installers/index.ts index b8ef062926..d09db8ba84 100644 --- a/cli/src/installers/index.ts +++ b/cli/src/installers/index.ts @@ -1,9 +1,10 @@ -import { type PackageManager } from "~/utils/getUserPkgManager.js"; import { envVariablesInstaller } from "~/installers/envVars.js"; import { nextAuthInstaller } from "~/installers/nextAuth.js"; import { prismaInstaller } from "~/installers/prisma.js"; +import { strictEsLintAndPrettier } from "~/installers/strictEslintAndPrettier.js"; import { tailwindInstaller } from "~/installers/tailwind.js"; import { trpcInstaller } from "~/installers/trpc.js"; +import { type PackageManager } from "~/utils/getUserPkgManager.js"; // Turning this into a const allows the list to be iterated over for programatically creating prompt options // Should increase extensability in the future @@ -13,6 +14,7 @@ export const availablePackages = [ "tailwind", "trpc", "envVariables", + "strictEslintAndPrettier", ] as const; export type AvailablePackages = (typeof availablePackages)[number]; @@ -56,4 +58,8 @@ export const buildPkgInstallerMap = ( inUse: true, installer: envVariablesInstaller, }, + strictEslintAndPrettier: { + inUse: true, + installer: strictEsLintAndPrettier, + }, }); diff --git a/cli/src/installers/strictEslintAndPrettier.ts b/cli/src/installers/strictEslintAndPrettier.ts new file mode 100644 index 0000000000..d1651fd7c6 --- /dev/null +++ b/cli/src/installers/strictEslintAndPrettier.ts @@ -0,0 +1,74 @@ +import fs from "fs-extra"; +import path from "path"; +import { PKG_ROOT } from "~/consts"; +import { type Installer } from "~/installers/index"; + +// import defaultESlintConfig from "~/tesmplate/base/_eslintrc.cjs"; +// import { addPackageDependency } from "~/utils/addPackageDependency.js"; + +export const strictEsLintAndPrettier: Installer = ({ + projectDir, + packages, +}) => { + const usingTailwind = packages?.prisma.inUse; + console.log(defaultESlintConfig); + addPackageDependency({ + projectDir, + dependencies: ["prettier", "@types/prettier"], + devMode: true, + }); + + const eslintExtra = path.join(PKG_ROOT, "template/extras/src/.eslintrc.js"); + fs.copySync(eslintExtra, projectDir); +}; + +// const getEnvContent = (usingAuth: boolean, usingPrisma: boolean) => { +// let content = ` +// # When adding additional environment variables, the schema in "/src/env.mjs" +// # should be updated accordingly. +// ` +// .trim() +// .concat("\n"); +// +// if (usingPrisma) +// content += ` +// # Prisma +// # https://www.prisma.io/docs/reference/database-reference/connection-urls#env +// DATABASE_URL="file:./db.sqlite" +// `; +// +// if (usingAuth) +// content += ` +// # Next Auth +// # You can generate a new secret on the command line with: +// # openssl rand -base64 32 +// # https://next-auth.js.org/configuration/options#secret +// # NEXTAUTH_SECRET="" +// NEXTAUTH_URL="http://localhost:3000" +// +// # Next Auth Discord Provider +// DISCORD_CLIENT_ID="" +// DISCORD_CLIENT_SECRET="" +// `; +// +// if (!usingAuth && !usingPrisma) +// content += ` +// # Example: +// # SERVERVAR="foo" +// # NEXT_PUBLIC_CLIENTVAR="bar" +// `; +// +// return content; +// }; +// +// const exampleEnvContent = ` +// # Since the ".env" file is gitignored, you can use the ".env.example" file to +// # build a new ".env" file when you clone the repo. Keep this file up-to-date +// # when you add new variables to \`.env\`. +// +// # This file will be committed to version control, so make sure not to have any +// # secrets in it. If you are cloning this repo, create a copy of this file named +// # ".env" and populate it with your secrets. +// ` +// .trim() +// diff --git a/cli/template/extras/config/_strict-eslint.config.cjs b/cli/template/extras/config/_strict-eslint.config.cjs new file mode 100644 index 0000000000..8b7a0e8f9c --- /dev/null +++ b/cli/template/extras/config/_strict-eslint.config.cjs @@ -0,0 +1,35 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const path = require("path"); + +/** @type {import("eslint").Linter.Config} */ +const config = { + overrides: [ + { + extends: [ + "plugin:@typescript-eslint/recommended-requiring-type-checking", + ], + files: ["*.ts", "*.tsx"], + parserOptions: { + project: path.join(__dirname, "tsconfig.json"), + }, + }, + ], + parser: "@typescript-eslint/parser", + parserOptions: { + project: path.join(__dirname, "tsconfig.json"), + }, + plugins: ["@typescript-eslint"], + extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended"], + rules: { + "@typescript-eslint/consistent-type-imports": [ + "warn", + { + prefer: "type-imports", + fixStyle: "inline-type-imports", + }, + ], + "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], + }, +}; + +module.exports = config; From 760614aa85d368dfb8c257ecfd597a708be05b47 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Fri, 5 May 2023 17:40:21 +0100 Subject: [PATCH 05/24] done? --- cli/src/index.ts | 22 ++--- cli/src/installers/dependencyVersionMap.ts | 3 + cli/src/installers/index.ts | 2 +- cli/src/installers/nextAuth.ts | 6 +- cli/src/installers/strictEslintAndPrettier.ts | 89 ++++++------------- cli/src/installers/tailwind.ts | 13 ++- ...eslint.config.cjs => _strict-eslintrc.cjs} | 8 ++ .../config/prettier-with-tailwind.config.cjs | 6 ++ .../extras/config/prettier.config.cjs | 5 +- .../strict-prettier-with-tailwind.config.cjs | 9 ++ 10 files changed, 81 insertions(+), 82 deletions(-) rename cli/template/extras/config/{_strict-eslint.config.cjs => _strict-eslintrc.cjs} (86%) create mode 100644 cli/template/extras/config/prettier-with-tailwind.config.cjs create mode 100644 cli/template/extras/config/strict-prettier-with-tailwind.config.cjs diff --git a/cli/src/index.ts b/cli/src/index.ts index 66bca71a87..5aaf57fb50 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -1,10 +1,4 @@ #!/usr/bin/env node -import { installDependencies } from "./helpers/installDependencies.js"; -import { getVersion } from "./utils/getT3Version.js"; -import { - getNpmVersion, - renderVersionWarning, -} from "./utils/renderVersionWarning.js"; import fs from "fs-extra"; import path from "path"; import { type PackageJson } from "type-fest"; @@ -17,6 +11,12 @@ import { buildPkgInstallerMap } from "~/installers/index.js"; import { logger } from "~/utils/logger.js"; import { parseNameAndPath } from "~/utils/parseNameAndPath.js"; import { renderTitle } from "~/utils/renderTitle.js"; +import { installDependencies } from "./helpers/installDependencies.js"; +import { getVersion } from "./utils/getT3Version.js"; +import { + getNpmVersion, + renderVersionWarning, +} from "./utils/renderVersionWarning.js"; type CT3APackageJSON = PackageJson & { ct3aMetadata?: { @@ -67,10 +67,12 @@ const main = async () => { } // Rename _eslintrc.json to .eslintrc.json - we use _eslintrc.json to avoid conflicts with the monorepos linter - fs.renameSync( - path.join(projectDir, "_eslintrc.cjs"), - path.join(projectDir, ".eslintrc.cjs"), - ); + if (fs.existsSync(path.join(projectDir, "_eslintrc.cjs"))) { + fs.renameSync( + path.join(projectDir, "_eslintrc.cjs"), + path.join(projectDir, ".eslintrc.cjs"), + ); + } if (!noGit) { await initializeGit(projectDir); diff --git a/cli/src/installers/dependencyVersionMap.ts b/cli/src/installers/dependencyVersionMap.ts index 368c944063..8040678e13 100644 --- a/cli/src/installers/dependencyVersionMap.ts +++ b/cli/src/installers/dependencyVersionMap.ts @@ -26,5 +26,8 @@ export const dependencyVersionMap = { "@trpc/next": "^10.18.0", "@tanstack/react-query": "^4.28.0", superjson: "1.12.2", + + // strictEslintAndPrettier + "@ianvs/prettier-plugin-sort-imports": "^3.7.2", } as const; export type AvailableDependencies = keyof typeof dependencyVersionMap; diff --git a/cli/src/installers/index.ts b/cli/src/installers/index.ts index d09db8ba84..403881189e 100644 --- a/cli/src/installers/index.ts +++ b/cli/src/installers/index.ts @@ -59,7 +59,7 @@ export const buildPkgInstallerMap = ( installer: envVariablesInstaller, }, strictEslintAndPrettier: { - inUse: true, + inUse: packages.includes("strictEslintAndPrettier"), installer: strictEsLintAndPrettier, }, }); diff --git a/cli/src/installers/nextAuth.ts b/cli/src/installers/nextAuth.ts index 4265480222..628bbf272a 100644 --- a/cli/src/installers/nextAuth.ts +++ b/cli/src/installers/nextAuth.ts @@ -1,8 +1,8 @@ -import { type Installer } from "~/installers/index.js"; -import { type AvailableDependencies } from "~/installers/dependencyVersionMap.js"; -import path from "path"; import fs from "fs-extra"; +import path from "path"; import { PKG_ROOT } from "~/consts.js"; +import { type AvailableDependencies } from "~/installers/dependencyVersionMap.js"; +import { type Installer } from "~/installers/index.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; export const nextAuthInstaller: Installer = ({ projectDir, packages }) => { diff --git a/cli/src/installers/strictEslintAndPrettier.ts b/cli/src/installers/strictEslintAndPrettier.ts index d1651fd7c6..17ab281848 100644 --- a/cli/src/installers/strictEslintAndPrettier.ts +++ b/cli/src/installers/strictEslintAndPrettier.ts @@ -1,74 +1,41 @@ +import { type Installer } from "../installers/index.js"; import fs from "fs-extra"; import path from "path"; -import { PKG_ROOT } from "~/consts"; -import { type Installer } from "~/installers/index"; - -// import defaultESlintConfig from "~/tesmplate/base/_eslintrc.cjs"; -// import { addPackageDependency } from "~/utils/addPackageDependency.js"; +import { PKG_ROOT } from "~/consts.js"; +import { addPackageDependency } from "~/utils/addPackageDependency.js"; export const strictEsLintAndPrettier: Installer = ({ projectDir, packages, }) => { - const usingTailwind = packages?.prisma.inUse; - console.log(defaultESlintConfig); addPackageDependency({ projectDir, - dependencies: ["prettier", "@types/prettier"], + dependencies: [ + "prettier", + "@types/prettier", + "@ianvs/prettier-plugin-sort-imports", + ], devMode: true, }); - const eslintExtra = path.join(PKG_ROOT, "template/extras/src/.eslintrc.js"); - fs.copySync(eslintExtra, projectDir); -}; + const configDir = path.join(PKG_ROOT, "template/extras/config"); -// const getEnvContent = (usingAuth: boolean, usingPrisma: boolean) => { -// let content = ` -// # When adding additional environment variables, the schema in "/src/env.mjs" -// # should be updated accordingly. -// ` -// .trim() -// .concat("\n"); -// -// if (usingPrisma) -// content += ` -// # Prisma -// # https://www.prisma.io/docs/reference/database-reference/connection-urls#env -// DATABASE_URL="file:./db.sqlite" -// `; -// -// if (usingAuth) -// content += ` -// # Next Auth -// # You can generate a new secret on the command line with: -// # openssl rand -base64 32 -// # https://next-auth.js.org/configuration/options#secret -// # NEXTAUTH_SECRET="" -// NEXTAUTH_URL="http://localhost:3000" -// -// # Next Auth Discord Provider -// DISCORD_CLIENT_ID="" -// DISCORD_CLIENT_SECRET="" -// `; -// -// if (!usingAuth && !usingPrisma) -// content += ` -// # Example: -// # SERVERVAR="foo" -// # NEXT_PUBLIC_CLIENTVAR="bar" -// `; -// -// return content; -// }; -// -// const exampleEnvContent = ` -// # Since the ".env" file is gitignored, you can use the ".env.example" file to -// # build a new ".env" file when you clone the repo. Keep this file up-to-date -// # when you add new variables to \`.env\`. -// -// # This file will be committed to version control, so make sure not to have any -// # secrets in it. If you are cloning this repo, create a copy of this file named -// # ".env" and populate it with your secrets. -// ` -// .trim() -// + fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); + fs.copySync( + path.join(configDir, "_strict-eslintrc.cjs"), + path.join(projectDir, "_eslintrc.cjs"), + ); + + if (packages?.tailwind.inUse) { + // Include the congig with tailwind class ordering + fs.copySync( + path.join(configDir, "strict-prettier-with-tailwind.config.cjs"), + path.join(projectDir, "prettier.config.cjs"), + ); + } else { + fs.copySync( + path.join(configDir, "prettier.config.cjs"), + path.join(projectDir, "prettier.config.cjs"), + ); + } +}; diff --git a/cli/src/installers/tailwind.ts b/cli/src/installers/tailwind.ts index 10fd860a3c..6de095ea33 100644 --- a/cli/src/installers/tailwind.ts +++ b/cli/src/installers/tailwind.ts @@ -4,7 +4,7 @@ import { PKG_ROOT } from "~/consts.js"; import { type Installer } from "~/installers/index.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; -export const tailwindInstaller: Installer = ({ projectDir }) => { +export const tailwindInstaller: Installer = ({ projectDir, packages }) => { addPackageDependency({ projectDir, dependencies: [ @@ -26,7 +26,10 @@ export const tailwindInstaller: Installer = ({ projectDir }) => { const postcssCfgSrc = path.join(extrasDir, "config/postcss.config.cjs"); const postcssCfgDest = path.join(projectDir, "postcss.config.cjs"); - const prettierSrc = path.join(extrasDir, "config/prettier.config.cjs"); + const prettierSrc = path.join( + extrasDir, + "config/prettier-with-tailwind.config.cjs", + ); const prettierDest = path.join(projectDir, "prettier.config.cjs"); const cssSrc = path.join(extrasDir, "src/styles/globals.css"); @@ -35,7 +38,11 @@ export const tailwindInstaller: Installer = ({ projectDir }) => { fs.copySync(twCfgSrc, twCfgDest); fs.copySync(postcssCfgSrc, postcssCfgDest); fs.copySync(cssSrc, cssDest); - fs.copySync(prettierSrc, prettierDest); + + // Let strictEslintAndPrettier install the prettier config + if (!packages?.strictEslintAndPrettier.inUse) { + fs.copySync(prettierSrc, prettierDest); + } // Remove vanilla css file const indexModuleCss = path.join(projectDir, "src/pages/index.module.css"); diff --git a/cli/template/extras/config/_strict-eslint.config.cjs b/cli/template/extras/config/_strict-eslintrc.cjs similarity index 86% rename from cli/template/extras/config/_strict-eslint.config.cjs rename to cli/template/extras/config/_strict-eslintrc.cjs index 8b7a0e8f9c..758c95a7b3 100644 --- a/cli/template/extras/config/_strict-eslint.config.cjs +++ b/cli/template/extras/config/_strict-eslintrc.cjs @@ -29,6 +29,14 @@ const config = { }, ], "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], + "@typescript-eslint/no-misused-promises": [ + 2, + { + checksVoidReturn: { + attributes: false, + }, + }, + ], }, }; diff --git a/cli/template/extras/config/prettier-with-tailwind.config.cjs b/cli/template/extras/config/prettier-with-tailwind.config.cjs new file mode 100644 index 0000000000..ca28ed9e46 --- /dev/null +++ b/cli/template/extras/config/prettier-with-tailwind.config.cjs @@ -0,0 +1,6 @@ +/** @type {import("prettier").Config} */ +const config = { + plugins: [require.resolve("prettier-plugin-tailwindcss")], +}; + +module.exports = config; diff --git a/cli/template/extras/config/prettier.config.cjs b/cli/template/extras/config/prettier.config.cjs index e62bb60bf1..146db6f1e6 100644 --- a/cli/template/extras/config/prettier.config.cjs +++ b/cli/template/extras/config/prettier.config.cjs @@ -1,9 +1,6 @@ /** @type {import("prettier").Config} */ const config = { - plugins: [ - require.resolve("prettier-plugin-tailwindcss"), - require.resolve("@ianvs/prettier-plugin-sort-imports"), - ], + plugins: [require.resolve("@ianvs/prettier-plugin-sort-import")], }; module.exports = config; diff --git a/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs b/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs new file mode 100644 index 0000000000..b9852b2b1a --- /dev/null +++ b/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs @@ -0,0 +1,9 @@ +/** @type {import("prettier").Config} */ +const config = { + plugins: [ + require.resolve("prettier-plugin-tailwindcss"), + require.resolve("@ianvs/prettier-plugin-sort-import"), + ], +}; + +module.exports = config; From d955bc2b92f9de9118103b5862104cf889089180 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Fri, 5 May 2023 17:48:22 +0100 Subject: [PATCH 06/24] lint --- cli/src/helpers/createProject.ts | 2 +- cli/src/helpers/installPackages.ts | 4 ++-- cli/src/helpers/logNextSteps.ts | 2 +- cli/src/helpers/scaffoldProject.ts | 2 +- cli/src/helpers/selectBoilerplate.ts | 4 ++-- cli/src/index.ts | 12 +++++----- cli/src/installers/envVars.ts | 4 ++-- cli/src/installers/prisma.ts | 6 ++--- cli/src/installers/strictEslintAndPrettier.ts | 2 +- cli/src/installers/trpc.ts | 2 +- cli/src/utils/addPackageDependency.ts | 4 ++-- cli/src/utils/getT3Version.ts | 4 ++-- cli/src/utils/renderVersionWarning.ts | 19 ++++++++------- ...ettier.config.cjs => _prettier.config.cjs} | 0 .../extras/src/pages/api/trpc/[trpc].ts | 3 +-- cli/template/extras/src/server/api/root.ts | 2 +- .../src/server/api/routers/example/base.ts | 1 - .../api/routers/example/with-auth-prisma.ts | 1 - .../server/api/routers/example/with-auth.ts | 1 - .../server/api/routers/example/with-prisma.ts | 1 - .../extras/src/server/api/trpc/base.ts | 22 +++++++++--------- .../src/server/api/trpc/with-auth-prisma.ts | 23 +++++++++---------- .../extras/src/server/api/trpc/with-auth.ts | 23 +++++++++---------- .../extras/src/server/api/trpc/with-prisma.ts | 23 +++++++++---------- .../extras/src/server/auth/with-prisma.ts | 2 +- cli/template/extras/src/server/db.ts | 1 - cli/template/extras/src/utils/api.ts | 1 - 27 files changed, 80 insertions(+), 91 deletions(-) rename cli/template/extras/config/{prettier.config.cjs => _prettier.config.cjs} (100%) diff --git a/cli/src/helpers/createProject.ts b/cli/src/helpers/createProject.ts index 6d3963466b..ea1e3942f4 100644 --- a/cli/src/helpers/createProject.ts +++ b/cli/src/helpers/createProject.ts @@ -1,8 +1,8 @@ -import { type PkgInstallerMap } from "~/installers/index.js"; import path from "path"; import { installPackages } from "~/helpers/installPackages.js"; import { scaffoldProject } from "~/helpers/scaffoldProject.js"; import { selectAppFile, selectIndexFile } from "~/helpers/selectBoilerplate.js"; +import { type PkgInstallerMap } from "~/installers/index.js"; import { getUserPkgManager } from "~/utils/getUserPkgManager.js"; interface CreateProjectOptions { diff --git a/cli/src/helpers/installPackages.ts b/cli/src/helpers/installPackages.ts index 4bef6a1f0c..d65eb20d7a 100644 --- a/cli/src/helpers/installPackages.ts +++ b/cli/src/helpers/installPackages.ts @@ -1,9 +1,9 @@ +import chalk from "chalk"; +import ora from "ora"; import { type InstallerOptions, type PkgInstallerMap, } from "~/installers/index.js"; -import chalk from "chalk"; -import ora from "ora"; import { logger } from "~/utils/logger.js"; type InstallPackagesOptions = { diff --git a/cli/src/helpers/logNextSteps.ts b/cli/src/helpers/logNextSteps.ts index b03078e978..d1bdcef44c 100644 --- a/cli/src/helpers/logNextSteps.ts +++ b/cli/src/helpers/logNextSteps.ts @@ -1,5 +1,5 @@ -import { type InstallerOptions } from "~/installers/index.js"; import { DEFAULT_APP_NAME } from "~/consts.js"; +import { type InstallerOptions } from "~/installers/index.js"; import { getUserPkgManager } from "~/utils/getUserPkgManager.js"; import { logger } from "~/utils/logger.js"; diff --git a/cli/src/helpers/scaffoldProject.ts b/cli/src/helpers/scaffoldProject.ts index 593f1abe4e..2c46b2fa36 100644 --- a/cli/src/helpers/scaffoldProject.ts +++ b/cli/src/helpers/scaffoldProject.ts @@ -1,8 +1,8 @@ -import path from "path"; import chalk from "chalk"; import fs from "fs-extra"; import inquirer from "inquirer"; import ora from "ora"; +import path from "path"; import { PKG_ROOT } from "~/consts.js"; import { type InstallerOptions } from "~/installers/index.js"; import { logger } from "~/utils/logger.js"; diff --git a/cli/src/helpers/selectBoilerplate.ts b/cli/src/helpers/selectBoilerplate.ts index 32e7ef1f20..6589ec8b7c 100644 --- a/cli/src/helpers/selectBoilerplate.ts +++ b/cli/src/helpers/selectBoilerplate.ts @@ -1,7 +1,7 @@ -import { type InstallerOptions } from "~/installers/index.js"; -import path from "path"; import fs from "fs-extra"; +import path from "path"; import { PKG_ROOT } from "~/consts.js"; +import { type InstallerOptions } from "~/installers/index.js"; type SelectBoilerplateProps = Required< Pick diff --git a/cli/src/index.ts b/cli/src/index.ts index 5aaf57fb50..09e451ded5 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -1,4 +1,10 @@ #!/usr/bin/env node +import { installDependencies } from "./helpers/installDependencies.js"; +import { getVersion } from "./utils/getT3Version.js"; +import { + getNpmVersion, + renderVersionWarning, +} from "./utils/renderVersionWarning.js"; import fs from "fs-extra"; import path from "path"; import { type PackageJson } from "type-fest"; @@ -11,12 +17,6 @@ import { buildPkgInstallerMap } from "~/installers/index.js"; import { logger } from "~/utils/logger.js"; import { parseNameAndPath } from "~/utils/parseNameAndPath.js"; import { renderTitle } from "~/utils/renderTitle.js"; -import { installDependencies } from "./helpers/installDependencies.js"; -import { getVersion } from "./utils/getT3Version.js"; -import { - getNpmVersion, - renderVersionWarning, -} from "./utils/renderVersionWarning.js"; type CT3APackageJSON = PackageJson & { ct3aMetadata?: { diff --git a/cli/src/installers/envVars.ts b/cli/src/installers/envVars.ts index 950ee2fdc3..6696470b77 100644 --- a/cli/src/installers/envVars.ts +++ b/cli/src/installers/envVars.ts @@ -1,7 +1,7 @@ -import { type Installer } from "~/installers/index.js"; -import path from "path"; import fs from "fs-extra"; +import path from "path"; import { PKG_ROOT } from "~/consts.js"; +import { type Installer } from "~/installers/index.js"; export const envVariablesInstaller: Installer = ({ projectDir, packages }) => { const usingAuth = packages?.nextAuth.inUse; diff --git a/cli/src/installers/prisma.ts b/cli/src/installers/prisma.ts index 9180a8417b..fba0451aea 100644 --- a/cli/src/installers/prisma.ts +++ b/cli/src/installers/prisma.ts @@ -1,8 +1,8 @@ -import { type PackageJson } from "type-fest"; -import { type Installer } from "~/installers/index.js"; -import path from "path"; import fs from "fs-extra"; +import path from "path"; +import { type PackageJson } from "type-fest"; import { PKG_ROOT } from "~/consts.js"; +import { type Installer } from "~/installers/index.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; export const prismaInstaller: Installer = ({ projectDir, packages }) => { diff --git a/cli/src/installers/strictEslintAndPrettier.ts b/cli/src/installers/strictEslintAndPrettier.ts index 17ab281848..c162ad304a 100644 --- a/cli/src/installers/strictEslintAndPrettier.ts +++ b/cli/src/installers/strictEslintAndPrettier.ts @@ -34,7 +34,7 @@ export const strictEsLintAndPrettier: Installer = ({ ); } else { fs.copySync( - path.join(configDir, "prettier.config.cjs"), + path.join(configDir, "_prettier.config.cjs"), path.join(projectDir, "prettier.config.cjs"), ); } diff --git a/cli/src/installers/trpc.ts b/cli/src/installers/trpc.ts index d2bdd438cc..9901cdb8d9 100644 --- a/cli/src/installers/trpc.ts +++ b/cli/src/installers/trpc.ts @@ -1,8 +1,8 @@ import fs from "fs-extra"; import path from "path"; import { PKG_ROOT } from "~/consts.js"; -import { addPackageDependency } from "~/utils/addPackageDependency.js"; import { type Installer } from "~/installers/index.js"; +import { addPackageDependency } from "~/utils/addPackageDependency.js"; export const trpcInstaller: Installer = ({ projectDir, packages }) => { addPackageDependency({ diff --git a/cli/src/utils/addPackageDependency.ts b/cli/src/utils/addPackageDependency.ts index 967ea8a033..df77d129d1 100644 --- a/cli/src/utils/addPackageDependency.ts +++ b/cli/src/utils/addPackageDependency.ts @@ -1,11 +1,11 @@ -import path from "path"; import fs from "fs-extra"; +import path from "path"; +import sortPackageJson from "sort-package-json"; import { type PackageJson } from "type-fest"; import { dependencyVersionMap, type AvailableDependencies, } from "~/installers/dependencyVersionMap.js"; -import sortPackageJson from "sort-package-json"; export const addPackageDependency = (opts: { dependencies: AvailableDependencies[]; diff --git a/cli/src/utils/getT3Version.ts b/cli/src/utils/getT3Version.ts index 0852291974..aae451eb39 100644 --- a/cli/src/utils/getT3Version.ts +++ b/cli/src/utils/getT3Version.ts @@ -1,6 +1,6 @@ -import { type PackageJson } from "type-fest"; -import path from "path"; import fs from "fs-extra"; +import path from "path"; +import { type PackageJson } from "type-fest"; import { PKG_ROOT } from "~/consts.js"; export const getVersion = () => { diff --git a/cli/src/utils/renderVersionWarning.ts b/cli/src/utils/renderVersionWarning.ts index bc96a2c83c..e73ea2c74b 100644 --- a/cli/src/utils/renderVersionWarning.ts +++ b/cli/src/utils/renderVersionWarning.ts @@ -1,6 +1,14 @@ -import { execSync } from "child_process"; import { getVersion } from "./getT3Version.js"; import { logger } from "./logger.js"; +import { execSync } from "child_process"; +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + * https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/LICENSE + */ +import https from "https"; export const renderVersionWarning = (npmVersion: string) => { const currentVersion = getVersion(); @@ -29,15 +37,6 @@ export const renderVersionWarning = (npmVersion: string) => { console.log(""); }; -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the LICENSE file in the root - * directory of this source tree. - * https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/LICENSE - */ -import https from "https"; - type DistTagsBody = { latest: string; }; diff --git a/cli/template/extras/config/prettier.config.cjs b/cli/template/extras/config/_prettier.config.cjs similarity index 100% rename from cli/template/extras/config/prettier.config.cjs rename to cli/template/extras/config/_prettier.config.cjs diff --git a/cli/template/extras/src/pages/api/trpc/[trpc].ts b/cli/template/extras/src/pages/api/trpc/[trpc].ts index 3c744a024c..dc36ccf780 100644 --- a/cli/template/extras/src/pages/api/trpc/[trpc].ts +++ b/cli/template/extras/src/pages/api/trpc/[trpc].ts @@ -1,8 +1,7 @@ import { createNextApiHandler } from "@trpc/server/adapters/next"; - import { env } from "~/env.mjs"; -import { createTRPCContext } from "~/server/api/trpc"; import { appRouter } from "~/server/api/root"; +import { createTRPCContext } from "~/server/api/trpc"; // export API handler export default createNextApiHandler({ diff --git a/cli/template/extras/src/server/api/root.ts b/cli/template/extras/src/server/api/root.ts index 93fba9246b..7caea0fed0 100644 --- a/cli/template/extras/src/server/api/root.ts +++ b/cli/template/extras/src/server/api/root.ts @@ -1,5 +1,5 @@ -import { createTRPCRouter } from "~/server/api/trpc"; import { exampleRouter } from "~/server/api/routers/example"; +import { createTRPCRouter } from "~/server/api/trpc"; /** * This is the primary router for your server. diff --git a/cli/template/extras/src/server/api/routers/example/base.ts b/cli/template/extras/src/server/api/routers/example/base.ts index 1c70bb2840..df732786c6 100644 --- a/cli/template/extras/src/server/api/routers/example/base.ts +++ b/cli/template/extras/src/server/api/routers/example/base.ts @@ -1,5 +1,4 @@ import { z } from "zod"; - import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; export const exampleRouter = createTRPCRouter({ diff --git a/cli/template/extras/src/server/api/routers/example/with-auth-prisma.ts b/cli/template/extras/src/server/api/routers/example/with-auth-prisma.ts index 73de162882..fbb066a5e8 100644 --- a/cli/template/extras/src/server/api/routers/example/with-auth-prisma.ts +++ b/cli/template/extras/src/server/api/routers/example/with-auth-prisma.ts @@ -1,5 +1,4 @@ import { z } from "zod"; - import { createTRPCRouter, publicProcedure, diff --git a/cli/template/extras/src/server/api/routers/example/with-auth.ts b/cli/template/extras/src/server/api/routers/example/with-auth.ts index 147aa6829f..cc244715b6 100644 --- a/cli/template/extras/src/server/api/routers/example/with-auth.ts +++ b/cli/template/extras/src/server/api/routers/example/with-auth.ts @@ -1,5 +1,4 @@ import { z } from "zod"; - import { createTRPCRouter, publicProcedure, diff --git a/cli/template/extras/src/server/api/routers/example/with-prisma.ts b/cli/template/extras/src/server/api/routers/example/with-prisma.ts index be8d0e1f95..50c47c671e 100644 --- a/cli/template/extras/src/server/api/routers/example/with-prisma.ts +++ b/cli/template/extras/src/server/api/routers/example/with-prisma.ts @@ -1,5 +1,4 @@ import { z } from "zod"; - import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; export const exampleRouter = createTRPCRouter({ diff --git a/cli/template/extras/src/server/api/trpc/base.ts b/cli/template/extras/src/server/api/trpc/base.ts index 5d1335a323..a51fee7bc0 100644 --- a/cli/template/extras/src/server/api/trpc/base.ts +++ b/cli/template/extras/src/server/api/trpc/base.ts @@ -14,7 +14,18 @@ * * These allow you to access things when processing a request, like the database, the session, etc. */ + +/** + * 2. INITIALIZATION + * + * This is where the tRPC API is initialized, connecting the context and transformer. We also parse + * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation + * errors on the backend. + */ +import { initTRPC } from "@trpc/server"; import { type CreateNextContextOptions } from "@trpc/server/adapters/next"; +import superjson from "superjson"; +import { ZodError } from "zod"; /** Replace this with an object if you want to pass things to `createContextInner`. */ type CreateContextOptions = Record; @@ -43,17 +54,6 @@ export const createTRPCContext = (_opts: CreateNextContextOptions) => { return createInnerTRPCContext({}); }; -/** - * 2. INITIALIZATION - * - * This is where the tRPC API is initialized, connecting the context and transformer. We also parse - * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation - * errors on the backend. - */ -import { initTRPC } from "@trpc/server"; -import superjson from "superjson"; -import { ZodError } from "zod"; - const t = initTRPC.context().create({ transformer: superjson, errorFormatter({ shape, error }) { diff --git a/cli/template/extras/src/server/api/trpc/with-auth-prisma.ts b/cli/template/extras/src/server/api/trpc/with-auth-prisma.ts index 7c3bad05da..c847794470 100644 --- a/cli/template/extras/src/server/api/trpc/with-auth-prisma.ts +++ b/cli/template/extras/src/server/api/trpc/with-auth-prisma.ts @@ -14,9 +14,19 @@ * * These allow you to access things when processing a request, like the database, the session, etc. */ + +/** + * 2. INITIALIZATION + * + * This is where the tRPC API is initialized, connecting the context and transformer. We also parse + * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation + * errors on the backend. + */ +import { initTRPC, TRPCError } from "@trpc/server"; import { type CreateNextContextOptions } from "@trpc/server/adapters/next"; import { type Session } from "next-auth"; - +import superjson from "superjson"; +import { ZodError } from "zod"; import { getServerAuthSession } from "~/server/auth"; import { prisma } from "~/server/db"; @@ -58,17 +68,6 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => { }); }; -/** - * 2. INITIALIZATION - * - * This is where the tRPC API is initialized, connecting the context and transformer. We also parse - * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation - * errors on the backend. - */ -import { initTRPC, TRPCError } from "@trpc/server"; -import superjson from "superjson"; -import { ZodError } from "zod"; - const t = initTRPC.context().create({ transformer: superjson, errorFormatter({ shape, error }) { diff --git a/cli/template/extras/src/server/api/trpc/with-auth.ts b/cli/template/extras/src/server/api/trpc/with-auth.ts index 1705d0f386..c241cc0b6f 100644 --- a/cli/template/extras/src/server/api/trpc/with-auth.ts +++ b/cli/template/extras/src/server/api/trpc/with-auth.ts @@ -14,9 +14,19 @@ * * These allow you to access things when processing a request, like the database, the session, etc. */ + +/** + * 2. INITIALIZATION + * + * This is where the tRPC API is initialized, connecting the context and transformer. We also parse + * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation + * errors on the backend. + */ +import { initTRPC, TRPCError } from "@trpc/server"; import { type CreateNextContextOptions } from "@trpc/server/adapters/next"; import { type Session } from "next-auth"; - +import superjson from "superjson"; +import { ZodError } from "zod"; import { getServerAuthSession } from "~/server/auth"; type CreateContextOptions = { @@ -56,17 +66,6 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => { }); }; -/** - * 2. INITIALIZATION - * - * This is where the tRPC API is initialized, connecting the context and transformer. We also parse - * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation - * errors on the backend. - */ -import { initTRPC, TRPCError } from "@trpc/server"; -import superjson from "superjson"; -import { ZodError } from "zod"; - const t = initTRPC.context().create({ transformer: superjson, errorFormatter({ shape, error }) { diff --git a/cli/template/extras/src/server/api/trpc/with-prisma.ts b/cli/template/extras/src/server/api/trpc/with-prisma.ts index 08305da4e7..7569a32930 100644 --- a/cli/template/extras/src/server/api/trpc/with-prisma.ts +++ b/cli/template/extras/src/server/api/trpc/with-prisma.ts @@ -14,8 +14,18 @@ * * These allow you to access things when processing a request, like the database, the session, etc. */ -import { type CreateNextContextOptions } from "@trpc/server/adapters/next"; +/** + * 2. INITIALIZATION + * + * This is where the tRPC API is initialized, connecting the context and transformer. We also parse + * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation + * errors on the backend. + */ +import { initTRPC } from "@trpc/server"; +import { type CreateNextContextOptions } from "@trpc/server/adapters/next"; +import superjson from "superjson"; +import { ZodError } from "zod"; import { prisma } from "~/server/db"; type CreateContextOptions = Record; @@ -46,17 +56,6 @@ export const createTRPCContext = (_opts: CreateNextContextOptions) => { return createInnerTRPCContext({}); }; -/** - * 2. INITIALIZATION - * - * This is where the tRPC API is initialized, connecting the context and transformer. We also parse - * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation - * errors on the backend. - */ -import { initTRPC } from "@trpc/server"; -import superjson from "superjson"; -import { ZodError } from "zod"; - const t = initTRPC.context().create({ transformer: superjson, errorFormatter({ shape, error }) { diff --git a/cli/template/extras/src/server/auth/with-prisma.ts b/cli/template/extras/src/server/auth/with-prisma.ts index 7e6d826a47..321be1fa18 100644 --- a/cli/template/extras/src/server/auth/with-prisma.ts +++ b/cli/template/extras/src/server/auth/with-prisma.ts @@ -1,3 +1,4 @@ +import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { type GetServerSidePropsContext } from "next"; import { getServerSession, @@ -5,7 +6,6 @@ import { type DefaultSession, } from "next-auth"; import DiscordProvider from "next-auth/providers/discord"; -import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { env } from "~/env.mjs"; import { prisma } from "~/server/db"; diff --git a/cli/template/extras/src/server/db.ts b/cli/template/extras/src/server/db.ts index f3d7be3850..b54b62322a 100644 --- a/cli/template/extras/src/server/db.ts +++ b/cli/template/extras/src/server/db.ts @@ -1,5 +1,4 @@ import { PrismaClient } from "@prisma/client"; - import { env } from "~/env.mjs"; const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }; diff --git a/cli/template/extras/src/utils/api.ts b/cli/template/extras/src/utils/api.ts index f4f4ad5ca4..b2d5afd023 100644 --- a/cli/template/extras/src/utils/api.ts +++ b/cli/template/extras/src/utils/api.ts @@ -8,7 +8,6 @@ import { httpBatchLink, loggerLink } from "@trpc/client"; import { createTRPCNext } from "@trpc/next"; import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server"; import superjson from "superjson"; - import { type AppRouter } from "~/server/api/root"; const getBaseUrl = () => { From 28ced029780064493996ede16c709ed37670d352 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sun, 7 May 2023 10:40:14 +0100 Subject: [PATCH 07/24] we do a little reverse --- cli/.prettierrc.cjs | 2 +- .../extras/config/strict-prettier-with-tailwind.config.cjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/.prettierrc.cjs b/cli/.prettierrc.cjs index 78ee01d6ce..90384bada5 100644 --- a/cli/.prettierrc.cjs +++ b/cli/.prettierrc.cjs @@ -2,8 +2,8 @@ const config = { ...require("../.prettierrc.cjs"), plugins: [ - require.resolve("prettier-plugin-tailwindcss"), require.resolve("@ianvs/prettier-plugin-sort-imports"), + require.resolve("prettier-plugin-tailwindcss"), ], tailwindConfig: "./template/extras/config/tailwind.config.ts", }; diff --git a/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs b/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs index b9852b2b1a..adafc8e8da 100644 --- a/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs +++ b/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs @@ -1,8 +1,8 @@ /** @type {import("prettier").Config} */ const config = { plugins: [ - require.resolve("prettier-plugin-tailwindcss"), require.resolve("@ianvs/prettier-plugin-sort-import"), + require.resolve("prettier-plugin-tailwindcss"), ], }; From ff5643f888820905694176f71cc8a1423da80bc3 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sun, 7 May 2023 10:47:45 +0100 Subject: [PATCH 08/24] fixed format:check writing --- cli/package.json | 4 ++-- cli/template/base/package.json | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/package.json b/cli/package.json index 4c0d7d01be..fc627a8cb0 100644 --- a/cli/package.json +++ b/cli/package.json @@ -33,8 +33,8 @@ "start": "node dist/index.js", "lint": "eslint . --report-unused-disable-directives", "lint:fix": "pnpm lint --fix", - "format": "prettier --write --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern", - "format:check": "pnpm format --check", + "format": "pnpm format:check --write", + "format:check": "pnpm prettier --check --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern", "release": "changeset version", "pub:beta": "pnpm build && npm publish --tag beta", "pub:next": "pnpm build && npm publish --tag next", diff --git a/cli/template/base/package.json b/cli/template/base/package.json index aeb7368bdf..53de2c6198 100644 --- a/cli/template/base/package.json +++ b/cli/template/base/package.json @@ -6,7 +6,9 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "format": "pnpm format:check --write", + "format:check": "pnpm prettier --check --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern" }, "dependencies": { "next": "^13.2.4", From 75f09f9c952c454e639fa7098cda2f1dc13ac258 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Mon, 8 May 2023 11:30:11 +0100 Subject: [PATCH 09/24] smoll changes --- cli/template/base/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/template/base/package.json b/cli/template/base/package.json index 53de2c6198..de4bec0154 100644 --- a/cli/template/base/package.json +++ b/cli/template/base/package.json @@ -17,7 +17,6 @@ "zod": "^3.21.4" }, "devDependencies": { - "@ianvs/prettier-plugin-sort-imports": "^3.7.2", "@types/eslint": "^8.21.3", "@types/node": "^18.15.5", "@types/react": "^18.0.28", From 68bd14152abbad30353882d3aae2307fc24b09f3 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 9 May 2023 18:41:10 +0100 Subject: [PATCH 10/24] split out installers --- cli/src/installers/eslint.ts | 15 +++++++ cli/src/installers/index.ts | 16 +++++--- cli/src/installers/prettier.ts | 39 ++++++++++++++++++ cli/src/installers/strictEslintAndPrettier.ts | 41 ------------------- cli/src/installers/tailwind.ts | 20 +-------- cli/template/base/_eslintrc.cjs | 35 ---------------- .../strict-prettier-with-tailwind.config.cjs | 9 ---- 7 files changed, 66 insertions(+), 109 deletions(-) create mode 100644 cli/src/installers/eslint.ts create mode 100644 cli/src/installers/prettier.ts delete mode 100644 cli/src/installers/strictEslintAndPrettier.ts delete mode 100644 cli/template/base/_eslintrc.cjs delete mode 100644 cli/template/extras/config/strict-prettier-with-tailwind.config.cjs diff --git a/cli/src/installers/eslint.ts b/cli/src/installers/eslint.ts new file mode 100644 index 0000000000..4dca4ac1bc --- /dev/null +++ b/cli/src/installers/eslint.ts @@ -0,0 +1,15 @@ +import fs from "fs-extra"; +import path from "path"; +import { PKG_ROOT } from "~/consts.js"; +import { type Installer } from "./index.js"; + +export const eslint: Installer = ({ projectDir, packages }) => { + const configDir = path.join(PKG_ROOT, "template/extras/config"); + + fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); + + fs.copySync( + path.join(configDir, "_prettier.config.cjs"), + path.join(projectDir, "prettier.config.cjs"), + ); +}; diff --git a/cli/src/installers/index.ts b/cli/src/installers/index.ts index 403881189e..f1abb1f7a7 100644 --- a/cli/src/installers/index.ts +++ b/cli/src/installers/index.ts @@ -1,10 +1,11 @@ import { envVariablesInstaller } from "~/installers/envVars.js"; import { nextAuthInstaller } from "~/installers/nextAuth.js"; import { prismaInstaller } from "~/installers/prisma.js"; -import { strictEsLintAndPrettier } from "~/installers/strictEslintAndPrettier.js"; import { tailwindInstaller } from "~/installers/tailwind.js"; import { trpcInstaller } from "~/installers/trpc.js"; import { type PackageManager } from "~/utils/getUserPkgManager.js"; +import { eslint } from "./eslint.js"; +import { prettier } from "./prettier.js"; // Turning this into a const allows the list to be iterated over for programatically creating prompt options // Should increase extensability in the future @@ -14,7 +15,8 @@ export const availablePackages = [ "tailwind", "trpc", "envVariables", - "strictEslintAndPrettier", + "eslint", + "prettier", ] as const; export type AvailablePackages = (typeof availablePackages)[number]; @@ -58,8 +60,12 @@ export const buildPkgInstallerMap = ( inUse: true, installer: envVariablesInstaller, }, - strictEslintAndPrettier: { - inUse: packages.includes("strictEslintAndPrettier"), - installer: strictEsLintAndPrettier, + prettier: { + inUse: packages.includes("prettier"), + installer: prettier, + }, + eslint: { + inUse: packages.includes("eslint"), + installer: eslint, }, }); diff --git a/cli/src/installers/prettier.ts b/cli/src/installers/prettier.ts new file mode 100644 index 0000000000..0b7411f055 --- /dev/null +++ b/cli/src/installers/prettier.ts @@ -0,0 +1,39 @@ +import fs from "fs-extra"; +import path from "path"; +import { PKG_ROOT } from "~/consts.js"; +import { addPackageDependency } from "~/utils/addPackageDependency.js"; +import { type Installer } from "../installers/index.js"; +import { type AvailableDependencies } from "./dependencyVersionMap.js"; + +export const prettier: Installer = ({ projectDir, packages }) => { + const packeagesToInstall: AvailableDependencies[] = [ + "prettier", + "@types/prettier", + "@ianvs/prettier-plugin-sort-imports", + ]; + + if (packages?.tailwind.inUse) { + packeagesToInstall.push("prettier-plugin-tailwindcss"); + } + + addPackageDependency({ + projectDir, + dependencies: packeagesToInstall, + devMode: true, + }); + + if (packages?.tailwind.inUse) { + fs.copySync( + path.join( + PKG_ROOT, + "template/extras/config/prettier-with-tailwind.config.cjs", + ), + path.join(projectDir, "prettier.config.cjs"), + ); + } else { + fs.copySync( + path.join(PKG_ROOT, "template/extras/config/prettier.config.cjs"), + path.join(projectDir, "prettier.config.cjs"), + ); + } +}; diff --git a/cli/src/installers/strictEslintAndPrettier.ts b/cli/src/installers/strictEslintAndPrettier.ts deleted file mode 100644 index c162ad304a..0000000000 --- a/cli/src/installers/strictEslintAndPrettier.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { type Installer } from "../installers/index.js"; -import fs from "fs-extra"; -import path from "path"; -import { PKG_ROOT } from "~/consts.js"; -import { addPackageDependency } from "~/utils/addPackageDependency.js"; - -export const strictEsLintAndPrettier: Installer = ({ - projectDir, - packages, -}) => { - addPackageDependency({ - projectDir, - dependencies: [ - "prettier", - "@types/prettier", - "@ianvs/prettier-plugin-sort-imports", - ], - devMode: true, - }); - - const configDir = path.join(PKG_ROOT, "template/extras/config"); - - fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); - fs.copySync( - path.join(configDir, "_strict-eslintrc.cjs"), - path.join(projectDir, "_eslintrc.cjs"), - ); - - if (packages?.tailwind.inUse) { - // Include the congig with tailwind class ordering - fs.copySync( - path.join(configDir, "strict-prettier-with-tailwind.config.cjs"), - path.join(projectDir, "prettier.config.cjs"), - ); - } else { - fs.copySync( - path.join(configDir, "_prettier.config.cjs"), - path.join(projectDir, "prettier.config.cjs"), - ); - } -}; diff --git a/cli/src/installers/tailwind.ts b/cli/src/installers/tailwind.ts index 6de095ea33..42417b7da1 100644 --- a/cli/src/installers/tailwind.ts +++ b/cli/src/installers/tailwind.ts @@ -7,14 +7,7 @@ import { addPackageDependency } from "~/utils/addPackageDependency.js"; export const tailwindInstaller: Installer = ({ projectDir, packages }) => { addPackageDependency({ projectDir, - dependencies: [ - "tailwindcss", - "postcss", - "autoprefixer", - "prettier", - "prettier-plugin-tailwindcss", - "@types/prettier", - ], + dependencies: ["tailwindcss", "postcss", "autoprefixer"], devMode: true, }); @@ -26,12 +19,6 @@ export const tailwindInstaller: Installer = ({ projectDir, packages }) => { const postcssCfgSrc = path.join(extrasDir, "config/postcss.config.cjs"); const postcssCfgDest = path.join(projectDir, "postcss.config.cjs"); - const prettierSrc = path.join( - extrasDir, - "config/prettier-with-tailwind.config.cjs", - ); - const prettierDest = path.join(projectDir, "prettier.config.cjs"); - const cssSrc = path.join(extrasDir, "src/styles/globals.css"); const cssDest = path.join(projectDir, "src/styles/globals.css"); @@ -39,11 +26,6 @@ export const tailwindInstaller: Installer = ({ projectDir, packages }) => { fs.copySync(postcssCfgSrc, postcssCfgDest); fs.copySync(cssSrc, cssDest); - // Let strictEslintAndPrettier install the prettier config - if (!packages?.strictEslintAndPrettier.inUse) { - fs.copySync(prettierSrc, prettierDest); - } - // Remove vanilla css file const indexModuleCss = path.join(projectDir, "src/pages/index.module.css"); fs.unlinkSync(indexModuleCss); diff --git a/cli/template/base/_eslintrc.cjs b/cli/template/base/_eslintrc.cjs deleted file mode 100644 index 8b7a0e8f9c..0000000000 --- a/cli/template/base/_eslintrc.cjs +++ /dev/null @@ -1,35 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-var-requires -const path = require("path"); - -/** @type {import("eslint").Linter.Config} */ -const config = { - overrides: [ - { - extends: [ - "plugin:@typescript-eslint/recommended-requiring-type-checking", - ], - files: ["*.ts", "*.tsx"], - parserOptions: { - project: path.join(__dirname, "tsconfig.json"), - }, - }, - ], - parser: "@typescript-eslint/parser", - parserOptions: { - project: path.join(__dirname, "tsconfig.json"), - }, - plugins: ["@typescript-eslint"], - extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended"], - rules: { - "@typescript-eslint/consistent-type-imports": [ - "warn", - { - prefer: "type-imports", - fixStyle: "inline-type-imports", - }, - ], - "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], - }, -}; - -module.exports = config; diff --git a/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs b/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs deleted file mode 100644 index adafc8e8da..0000000000 --- a/cli/template/extras/config/strict-prettier-with-tailwind.config.cjs +++ /dev/null @@ -1,9 +0,0 @@ -/** @type {import("prettier").Config} */ -const config = { - plugins: [ - require.resolve("@ianvs/prettier-plugin-sort-import"), - require.resolve("prettier-plugin-tailwindcss"), - ], -}; - -module.exports = config; From 4ee772f18d55e0cd777e3f965295c0aee3090d11 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 9 May 2023 18:55:03 +0100 Subject: [PATCH 11/24] removed eslint from base project --- cli/src/installers/dependencyVersionMap.ts | 12 ++++++++---- cli/src/installers/eslint.ts | 13 +++++++++---- .../config/{_strict-eslintrc.cjs => _eslintrc.cjs} | 0 3 files changed, 17 insertions(+), 8 deletions(-) rename cli/template/extras/config/{_strict-eslintrc.cjs => _eslintrc.cjs} (100%) diff --git a/cli/src/installers/dependencyVersionMap.ts b/cli/src/installers/dependencyVersionMap.ts index bfdebd3333..538ffb37d7 100644 --- a/cli/src/installers/dependencyVersionMap.ts +++ b/cli/src/installers/dependencyVersionMap.ts @@ -15,9 +15,6 @@ export const dependencyVersionMap = { tailwindcss: "^3.3.0", autoprefixer: "^10.4.14", postcss: "^8.4.21", - prettier: "^2.8.6", - "prettier-plugin-tailwindcss": "^0.2.6", - "@types/prettier": "^2.7.2", // tRPC "@trpc/client": "^10.18.0", @@ -27,7 +24,14 @@ export const dependencyVersionMap = { "@tanstack/react-query": "^4.28.0", superjson: "1.12.2", - // strictEslintAndPrettier + // Prettier + prettier: "^2.8.6", + "prettier-plugin-tailwindcss": "^0.2.6", + "@types/prettier": "^2.7.2", "@ianvs/prettier-plugin-sort-imports": "^3.7.2", + + // Eslint + eslint: "^8.36.0", + "eslint-config-next": "^13.4.1", } as const; export type AvailableDependencies = keyof typeof dependencyVersionMap; diff --git a/cli/src/installers/eslint.ts b/cli/src/installers/eslint.ts index 4dca4ac1bc..852438bd7b 100644 --- a/cli/src/installers/eslint.ts +++ b/cli/src/installers/eslint.ts @@ -1,15 +1,20 @@ import fs from "fs-extra"; import path from "path"; import { PKG_ROOT } from "~/consts.js"; +import { addPackageDependency } from "~/utils/addPackageDependency.js"; import { type Installer } from "./index.js"; -export const eslint: Installer = ({ projectDir, packages }) => { +export const eslint: Installer = ({ projectDir }) => { const configDir = path.join(PKG_ROOT, "template/extras/config"); - fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); + addPackageDependency({ + dependencies: ["eslint", "eslint-config-next"], + devMode: true, + projectDir, + }); fs.copySync( - path.join(configDir, "_prettier.config.cjs"), - path.join(projectDir, "prettier.config.cjs"), + path.join(configDir, "_eslintrc.cjs"), + path.join(projectDir, "eslintrc.cjs"), ); }; diff --git a/cli/template/extras/config/_strict-eslintrc.cjs b/cli/template/extras/config/_eslintrc.cjs similarity index 100% rename from cli/template/extras/config/_strict-eslintrc.cjs rename to cli/template/extras/config/_eslintrc.cjs From 01de8cd792f5b1dcc14f44a3e5a54d065b4c7a27 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 9 May 2023 19:23:39 +0100 Subject: [PATCH 12/24] added eslint back --- cli/src/installers/dependencyVersionMap.ts | 1 - cli/src/installers/eslint.ts | 11 +++++++---- cli/src/installers/prettier.ts | 2 +- cli/template/base/_eslintrc.cjs | 4 ++++ cli/template/base/package.json | 1 - 5 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 cli/template/base/_eslintrc.cjs diff --git a/cli/src/installers/dependencyVersionMap.ts b/cli/src/installers/dependencyVersionMap.ts index 538ffb37d7..5fde931227 100644 --- a/cli/src/installers/dependencyVersionMap.ts +++ b/cli/src/installers/dependencyVersionMap.ts @@ -31,7 +31,6 @@ export const dependencyVersionMap = { "@ianvs/prettier-plugin-sort-imports": "^3.7.2", // Eslint - eslint: "^8.36.0", "eslint-config-next": "^13.4.1", } as const; export type AvailableDependencies = keyof typeof dependencyVersionMap; diff --git a/cli/src/installers/eslint.ts b/cli/src/installers/eslint.ts index 852438bd7b..51fd6bb586 100644 --- a/cli/src/installers/eslint.ts +++ b/cli/src/installers/eslint.ts @@ -5,16 +5,19 @@ import { addPackageDependency } from "~/utils/addPackageDependency.js"; import { type Installer } from "./index.js"; export const eslint: Installer = ({ projectDir }) => { - const configDir = path.join(PKG_ROOT, "template/extras/config"); - addPackageDependency({ - dependencies: ["eslint", "eslint-config-next"], + dependencies: ["eslint-config-next"], devMode: true, projectDir, }); + const configDir = path.join(PKG_ROOT, "template/extras/config"); + + // Remove the default config + fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); + fs.copySync( path.join(configDir, "_eslintrc.cjs"), - path.join(projectDir, "eslintrc.cjs"), + path.join(projectDir, ".eslintrc.cjs"), ); }; diff --git a/cli/src/installers/prettier.ts b/cli/src/installers/prettier.ts index 0b7411f055..e5909c095c 100644 --- a/cli/src/installers/prettier.ts +++ b/cli/src/installers/prettier.ts @@ -32,7 +32,7 @@ export const prettier: Installer = ({ projectDir, packages }) => { ); } else { fs.copySync( - path.join(PKG_ROOT, "template/extras/config/prettier.config.cjs"), + path.join(PKG_ROOT, "template/extras/config/_prettier.config.cjs"), path.join(projectDir, "prettier.config.cjs"), ); } diff --git a/cli/template/base/_eslintrc.cjs b/cli/template/base/_eslintrc.cjs new file mode 100644 index 0000000000..61e6a8af68 --- /dev/null +++ b/cli/template/base/_eslintrc.cjs @@ -0,0 +1,4 @@ +/** @type {import("eslint").Linter.Config} */ +const config = {}; + +module.exports = config; diff --git a/cli/template/base/package.json b/cli/template/base/package.json index 3150d5437e..f75441c2b8 100644 --- a/cli/template/base/package.json +++ b/cli/template/base/package.json @@ -25,7 +25,6 @@ "@typescript-eslint/eslint-plugin": "^5.56.0", "@typescript-eslint/parser": "^5.56.0", "eslint": "^8.36.0", - "eslint-config-next": "^13.4.1", "typescript": "^5.0.2" } } From aa796987c4e44449816e86a18521e1f252ca34aa Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 9 May 2023 19:36:13 +0100 Subject: [PATCH 13/24] formatting --- cli/src/installers/eslint.ts | 2 +- cli/src/installers/index.ts | 4 ++-- cli/src/installers/prettier.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/src/installers/eslint.ts b/cli/src/installers/eslint.ts index 51fd6bb586..c9d97096ca 100644 --- a/cli/src/installers/eslint.ts +++ b/cli/src/installers/eslint.ts @@ -1,8 +1,8 @@ +import { type Installer } from "./index.js"; import fs from "fs-extra"; import path from "path"; import { PKG_ROOT } from "~/consts.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; -import { type Installer } from "./index.js"; export const eslint: Installer = ({ projectDir }) => { addPackageDependency({ diff --git a/cli/src/installers/index.ts b/cli/src/installers/index.ts index f1abb1f7a7..27d69b4d09 100644 --- a/cli/src/installers/index.ts +++ b/cli/src/installers/index.ts @@ -1,11 +1,11 @@ +import { eslint } from "./eslint.js"; +import { prettier } from "./prettier.js"; import { envVariablesInstaller } from "~/installers/envVars.js"; import { nextAuthInstaller } from "~/installers/nextAuth.js"; import { prismaInstaller } from "~/installers/prisma.js"; import { tailwindInstaller } from "~/installers/tailwind.js"; import { trpcInstaller } from "~/installers/trpc.js"; import { type PackageManager } from "~/utils/getUserPkgManager.js"; -import { eslint } from "./eslint.js"; -import { prettier } from "./prettier.js"; // Turning this into a const allows the list to be iterated over for programatically creating prompt options // Should increase extensability in the future diff --git a/cli/src/installers/prettier.ts b/cli/src/installers/prettier.ts index e5909c095c..ca2cf90a00 100644 --- a/cli/src/installers/prettier.ts +++ b/cli/src/installers/prettier.ts @@ -1,9 +1,9 @@ +import { type Installer } from "../installers/index.js"; +import { type AvailableDependencies } from "./dependencyVersionMap.js"; import fs from "fs-extra"; import path from "path"; import { PKG_ROOT } from "~/consts.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; -import { type Installer } from "../installers/index.js"; -import { type AvailableDependencies } from "./dependencyVersionMap.js"; export const prettier: Installer = ({ projectDir, packages }) => { const packeagesToInstall: AvailableDependencies[] = [ From c14ca2a084fe164bbc8e7e2cdfcc9aade4d43302 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 9 May 2023 19:37:37 +0100 Subject: [PATCH 14/24] fixed linting --- cli/src/installers/tailwind.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/installers/tailwind.ts b/cli/src/installers/tailwind.ts index 42417b7da1..681841b989 100644 --- a/cli/src/installers/tailwind.ts +++ b/cli/src/installers/tailwind.ts @@ -4,7 +4,7 @@ import { PKG_ROOT } from "~/consts.js"; import { type Installer } from "~/installers/index.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; -export const tailwindInstaller: Installer = ({ projectDir, packages }) => { +export const tailwindInstaller: Installer = ({ projectDir }) => { addPackageDependency({ projectDir, dependencies: ["tailwindcss", "postcss", "autoprefixer"], From 86d07ed024b8a63c555f750005cf1f726bcd0b2f Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 9 May 2023 19:44:19 +0100 Subject: [PATCH 15/24] fixed base project --- cli/template/base/_eslintrc.cjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cli/template/base/_eslintrc.cjs b/cli/template/base/_eslintrc.cjs index 61e6a8af68..3733acb0cf 100644 --- a/cli/template/base/_eslintrc.cjs +++ b/cli/template/base/_eslintrc.cjs @@ -1,4 +1,13 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const path = require("path"); + /** @type {import("eslint").Linter.Config} */ -const config = {}; +const config = { + parser: "@typescript-eslint/parser", + parserOptions: { + project: path.join(__dirname, "tsconfig.json"), + }, + plugins: ["@typescript-eslint"], +}; module.exports = config; From d37d8134cffd8d9fa3d91a38098c4794454b5589 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 9 May 2023 20:00:27 +0100 Subject: [PATCH 16/24] rip ci time --- .github/workflows/e2e.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index ad5e089cba..eb64047223 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -27,6 +27,8 @@ jobs: tailwind: ["true", "false"] nextAuth: ["true", "false"] prisma: ["true", "false"] + eslint: ["true", "false"] + prettier: ["true", "false"] name: "Build and Start T3 App ${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}" steps: From f0b4089e4bd1a0e119b44ad4836088997257df49 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 13 May 2023 22:09:17 +0200 Subject: [PATCH 17/24] Update cli/template/extras/config/_prettier.config.cjs --- cli/template/extras/config/_prettier.config.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/template/extras/config/_prettier.config.cjs b/cli/template/extras/config/_prettier.config.cjs index 146db6f1e6..6058b6de93 100644 --- a/cli/template/extras/config/_prettier.config.cjs +++ b/cli/template/extras/config/_prettier.config.cjs @@ -1,6 +1,6 @@ /** @type {import("prettier").Config} */ const config = { - plugins: [require.resolve("@ianvs/prettier-plugin-sort-import")], + plugins: ["@ianvs/prettier-plugin-sort-imports"], }; module.exports = config; From a665f393f9ce8687cad97dd471536cc964f20fb2 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sat, 13 May 2023 21:21:19 +0100 Subject: [PATCH 18/24] need to test this but. --- cli/src/installers/prettier.ts | 16 ++++++++++++++++ cli/src/utils/addPackageScript.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 cli/src/utils/addPackageScript.ts diff --git a/cli/src/installers/prettier.ts b/cli/src/installers/prettier.ts index ca2cf90a00..817aef62ed 100644 --- a/cli/src/installers/prettier.ts +++ b/cli/src/installers/prettier.ts @@ -4,6 +4,7 @@ import fs from "fs-extra"; import path from "path"; import { PKG_ROOT } from "~/consts.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; +import { addPackageScript } from "~/utils/addPackageScript.js"; export const prettier: Installer = ({ projectDir, packages }) => { const packeagesToInstall: AvailableDependencies[] = [ @@ -22,6 +23,21 @@ export const prettier: Installer = ({ projectDir, packages }) => { devMode: true, }); + addPackageScript({ + projectDir, + scripts: [ + { + name: "format", + value: "pnpm format:check --write", + }, + { + name: "format:check", + value: + "pnpm prettier --check --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern", + }, + ], + }); + if (packages?.tailwind.inUse) { fs.copySync( path.join( diff --git a/cli/src/utils/addPackageScript.ts b/cli/src/utils/addPackageScript.ts new file mode 100644 index 0000000000..6ad54b3e44 --- /dev/null +++ b/cli/src/utils/addPackageScript.ts @@ -0,0 +1,26 @@ +import fs from "fs-extra"; +import path from "path"; +import sortPackageJson from "sort-package-json"; +import { type PackageJson } from "type-fest"; + +export const addPackageScript = (opts: { + scripts: { name: string; value: string }[]; + projectDir: string; +}) => { + const pkgJson = fs.readJSONSync( + path.join(opts.projectDir, "package.json"), + ) as PackageJson; + + if (!pkgJson.scripts) { + pkgJson.scripts = {}; + } + + for (const script of opts.scripts) { + pkgJson.scripts[script.name] = script.value; + } + const sortedPkgJson = sortPackageJson(pkgJson); + + fs.writeJSONSync(path.join(opts.projectDir, "package.json"), sortedPkgJson, { + spaces: 2, + }); +}; From db03947acff059caca9fc96133d17600baec6f8e Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sat, 13 May 2023 21:45:32 +0100 Subject: [PATCH 19/24] removed uneeded resolve --- cli/template/base/package.json | 4 +--- cli/template/extras/config/prettier-with-tailwind.config.cjs | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/template/base/package.json b/cli/template/base/package.json index f75441c2b8..104332ac5c 100644 --- a/cli/template/base/package.json +++ b/cli/template/base/package.json @@ -6,9 +6,7 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint", - "format": "pnpm format:check --write", - "format:check": "pnpm prettier --check --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern" + "lint": "next lint" }, "dependencies": { "@t3-oss/env-nextjs": "^0.2.1", diff --git a/cli/template/extras/config/prettier-with-tailwind.config.cjs b/cli/template/extras/config/prettier-with-tailwind.config.cjs index ca28ed9e46..f817bf3608 100644 --- a/cli/template/extras/config/prettier-with-tailwind.config.cjs +++ b/cli/template/extras/config/prettier-with-tailwind.config.cjs @@ -1,6 +1,9 @@ /** @type {import("prettier").Config} */ const config = { - plugins: [require.resolve("prettier-plugin-tailwindcss")], + plugins: [ + "@ianvs/prettier-plugin-sort-imports", + "prettier-plugin-tailwindcss", + ], }; module.exports = config; From 63fad9249b5b33cffb46750045ac62f5d7126404 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Sun, 14 May 2023 10:43:04 +0100 Subject: [PATCH 20/24] docs update --- www/src/pages/en/usage/tailwind.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/src/pages/en/usage/tailwind.md b/www/src/pages/en/usage/tailwind.md index bdb355a4b0..12e11a3521 100644 --- a/www/src/pages/en/usage/tailwind.md +++ b/www/src/pages/en/usage/tailwind.md @@ -74,7 +74,7 @@ Make sure you have editor plugins for Tailwind installed to improve your experie ### Formatting -Tailwind CSS classes can easily get a bit messy, so a formatter for the classes is a must have. [Tailwind CSS Prettier Plugin](https://github.com/tailwindlabs/prettier-plugin-tailwindcss) sorts the classes in the [recommended order](https://tailwindcss.com/blog/automatic-class-sorting-with-prettier#how-classes-are-sorted) so that the classes match the outputted css bundle. When selecting Tailwind in the CLI, we will install and configure this for you. +Tailwind CSS classes can easily get a bit messy, so a formatter for the classes is a must have. [Tailwind CSS Prettier Plugin](https://github.com/tailwindlabs/prettier-plugin-tailwindcss) sorts the classes in the [recommended order](https://tailwindcss.com/blog/automatic-class-sorting-with-prettier#how-classes-are-sorted) so that the classes match the outputted css bundle. When selecting Tailwind in the CLI, we will install and configure this for you when the prettier option is selected. ### Conditionally Applying Classes From 02b64ded995d7f433f0e48df57acd3170a4272fd Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 16 May 2023 18:22:03 +0100 Subject: [PATCH 21/24] Moved over to a seperate prompt --- cli/src/cli/index.ts | 33 ++++++++++++++++++++++++++++++-- cli/src/helpers/createProject.ts | 14 ++++++++++++++ cli/src/index.ts | 3 ++- cli/src/installers/eslint.ts | 2 +- cli/src/installers/index.ts | 12 ------------ cli/src/installers/prettier.ts | 2 +- 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/cli/src/cli/index.ts b/cli/src/cli/index.ts index 73c8833879..bc7e3b8e71 100644 --- a/cli/src/cli/index.ts +++ b/cli/src/cli/index.ts @@ -2,8 +2,10 @@ import chalk from "chalk"; import { Command } from "commander"; import inquirer from "inquirer"; import { CREATE_T3_APP, DEFAULT_APP_NAME } from "~/consts.js"; -import { type AvailablePackages } from "~/installers/index.js"; -import { availablePackages } from "~/installers/index.js"; +import { + availablePackages, + type AvailablePackages, +} from "~/installers/index.js"; import { getVersion } from "~/utils/getT3Version.js"; import { getUserPkgManager } from "~/utils/getUserPkgManager.js"; import { logger } from "~/utils/logger.js"; @@ -15,6 +17,7 @@ interface CliFlags { noInstall: boolean; default: boolean; importAlias: string; + prettierAndExtendedEslint: boolean; /** @internal Used in CI. */ CI: boolean; @@ -47,6 +50,7 @@ const defaultOptions: CliResults = { prisma: false, nextAuth: false, importAlias: "~/", + prettierAndExtendedEslint: false, }, }; @@ -114,6 +118,12 @@ export const runCli = async () => { "Explicitly tell the CLI to use a custom import alias", defaultOptions.flags.importAlias, ) + /** @experimental - Used for CI E2E tests. Used in conjunction with `--CI` to skip prompting. */ + .option( + "-p, --prettier-and-extended-eslint", + "Explicitly tell the CLI to use a custom import alias", + defaultOptions.flags.prettierAndExtendedEslint, + ) /** END CI-FLAGS */ .version(getVersion(), "-v, --version", "Display the version number") .addHelpText( @@ -153,6 +163,9 @@ export const runCli = async () => { if (cliResults.flags.tailwind) cliResults.packages.push("tailwind"); if (cliResults.flags.prisma) cliResults.packages.push("prisma"); if (cliResults.flags.nextAuth) cliResults.packages.push("nextAuth"); + if (cliResults.flags.prettierAndExtendedEslint) { + cliResults.flags.prettierAndExtendedEslint = true; + } } // Explained below why this is in a try/catch block @@ -186,6 +199,9 @@ export const runCli = async () => { } cliResults.flags.importAlias = await promptImportAlias(); + + cliResults.flags.prettierAndExtendedEslint = + await promtPrettierAndExtendedEslint(); } } catch (err) { // If the user is not calling create-t3-app from an interactive terminal, inquirer will throw an error with isTTYError = true @@ -329,3 +345,16 @@ const promptImportAlias = async (): Promise => { return importAlias; }; + +const promtPrettierAndExtendedEslint = async (): Promise => { + const { prettierAndExtendedEslint } = await inquirer.prompt< + Pick + >({ + name: "prettierAndExtendedEslint", + type: "confirm", + message: "Would you like to use prettier and extended eslint conifg?", + default: defaultOptions.flags.prettierAndExtendedEslint, + }); + + return prettierAndExtendedEslint; +}; diff --git a/cli/src/helpers/createProject.ts b/cli/src/helpers/createProject.ts index ea1e3942f4..fe2ca1560c 100644 --- a/cli/src/helpers/createProject.ts +++ b/cli/src/helpers/createProject.ts @@ -2,7 +2,9 @@ import path from "path"; import { installPackages } from "~/helpers/installPackages.js"; import { scaffoldProject } from "~/helpers/scaffoldProject.js"; import { selectAppFile, selectIndexFile } from "~/helpers/selectBoilerplate.js"; +import { installExtendedEslint } from "~/installers/eslint.js"; import { type PkgInstallerMap } from "~/installers/index.js"; +import { installPrettier } from "~/installers/prettier.js"; import { getUserPkgManager } from "~/utils/getUserPkgManager.js"; interface CreateProjectOptions { @@ -10,12 +12,14 @@ interface CreateProjectOptions { packages: PkgInstallerMap; noInstall: boolean; importAlias: string; + prettierAndExtendedEslint: boolean; } export const createProject = async ({ projectName, packages, noInstall, + prettierAndExtendedEslint, }: CreateProjectOptions) => { const pkgManager = getUserPkgManager(); const projectDir = path.resolve(process.cwd(), projectName); @@ -36,6 +40,16 @@ export const createProject = async ({ noInstall, }); + if (prettierAndExtendedEslint) { + const installArgs = { + projectDir, + pkgManager, + noInstall, + }; + installPrettier(installArgs); + installExtendedEslint(installArgs); + } + // TODO: Look into using handlebars or other templating engine to scaffold without needing to maintain multiple copies of the same file selectAppFile({ projectDir, packages }); selectIndexFile({ projectDir, packages }); diff --git a/cli/src/index.ts b/cli/src/index.ts index 09e451ded5..3e867b6e88 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -32,7 +32,7 @@ const main = async () => { const { appName, packages, - flags: { noGit, noInstall, importAlias }, + flags: { noGit, noInstall, importAlias, prettierAndExtendedEslint }, } = await runCli(); const usePackages = buildPkgInstallerMap(packages); @@ -45,6 +45,7 @@ const main = async () => { packages: usePackages, importAlias: importAlias, noInstall, + prettierAndExtendedEslint, }); // Write name to package.json diff --git a/cli/src/installers/eslint.ts b/cli/src/installers/eslint.ts index c9d97096ca..7c5536132b 100644 --- a/cli/src/installers/eslint.ts +++ b/cli/src/installers/eslint.ts @@ -4,7 +4,7 @@ import path from "path"; import { PKG_ROOT } from "~/consts.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; -export const eslint: Installer = ({ projectDir }) => { +export const installExtendedEslint: Installer = ({ projectDir }) => { addPackageDependency({ dependencies: ["eslint-config-next"], devMode: true, diff --git a/cli/src/installers/index.ts b/cli/src/installers/index.ts index 27d69b4d09..5f47d24b20 100644 --- a/cli/src/installers/index.ts +++ b/cli/src/installers/index.ts @@ -1,5 +1,3 @@ -import { eslint } from "./eslint.js"; -import { prettier } from "./prettier.js"; import { envVariablesInstaller } from "~/installers/envVars.js"; import { nextAuthInstaller } from "~/installers/nextAuth.js"; import { prismaInstaller } from "~/installers/prisma.js"; @@ -15,8 +13,6 @@ export const availablePackages = [ "tailwind", "trpc", "envVariables", - "eslint", - "prettier", ] as const; export type AvailablePackages = (typeof availablePackages)[number]; @@ -60,12 +56,4 @@ export const buildPkgInstallerMap = ( inUse: true, installer: envVariablesInstaller, }, - prettier: { - inUse: packages.includes("prettier"), - installer: prettier, - }, - eslint: { - inUse: packages.includes("eslint"), - installer: eslint, - }, }); diff --git a/cli/src/installers/prettier.ts b/cli/src/installers/prettier.ts index 817aef62ed..8b33d3b9d0 100644 --- a/cli/src/installers/prettier.ts +++ b/cli/src/installers/prettier.ts @@ -6,7 +6,7 @@ import { PKG_ROOT } from "~/consts.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; import { addPackageScript } from "~/utils/addPackageScript.js"; -export const prettier: Installer = ({ projectDir, packages }) => { +export const installPrettier: Installer = ({ projectDir, packages }) => { const packeagesToInstall: AvailableDependencies[] = [ "prettier", "@types/prettier", From 7e77640dffdccafb9eb4d10473c49be2b59c9911 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 16 May 2023 18:55:40 +0100 Subject: [PATCH 22/24] yuh --- .github/workflows/e2e.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index eb64047223..c81709d0b2 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -27,10 +27,9 @@ jobs: tailwind: ["true", "false"] nextAuth: ["true", "false"] prisma: ["true", "false"] - eslint: ["true", "false"] - prettier: ["true", "false"] + prettierAndExtenedEslint: ["true", "false"] - name: "Build and Start T3 App ${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}" + name: "Build and Start T3 App ${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.prettierAndExtenedEslint }}" steps: - uses: actions/checkout@v3 with: @@ -67,7 +66,7 @@ jobs: # has to be scaffolded outside the CLI project so that no lint/tsconfig are leaking # through. this way it ensures that it is the app's configs that are being used # FIXME: this is a bit hacky, would rather have --packages=trpc,tailwind,... but not sure how to setup the matrix for that - - run: cd cli && pnpm start ../../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} --noGit --CI --trpc=${{ matrix.trpc }} --tailwind=${{ matrix.tailwind }} --nextAuth=${{ matrix.nextAuth }} --prisma=${{ matrix.prisma }} + - run: cd cli && pnpm start ../../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} --noGit --CI --trpc=${{ matrix.trpc }} --tailwind=${{ matrix.tailwind }} --nextAuth=${{ matrix.nextAuth }} --prisma=${{ matrix.prisma }} --prettier-and-extended-eslint=${{ matrix.prettierAndExtenedEslint }} - run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} && pnpm build env: NEXTAUTH_SECRET: foo From f16ce4473e91e9e3ef5707852f45cc5399c03ea5 Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 16 May 2023 19:02:07 +0100 Subject: [PATCH 23/24] spelling --- .github/workflows/e2e.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index c81709d0b2..936c8dd380 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -27,9 +27,9 @@ jobs: tailwind: ["true", "false"] nextAuth: ["true", "false"] prisma: ["true", "false"] - prettierAndExtenedEslint: ["true", "false"] + prettierAndExtendedEslint: ["true", "false"] - name: "Build and Start T3 App ${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.prettierAndExtenedEslint }}" + name: "Build and Start T3 App ${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.prettierAndExtendedEslint }}" steps: - uses: actions/checkout@v3 with: @@ -66,7 +66,7 @@ jobs: # has to be scaffolded outside the CLI project so that no lint/tsconfig are leaking # through. this way it ensures that it is the app's configs that are being used # FIXME: this is a bit hacky, would rather have --packages=trpc,tailwind,... but not sure how to setup the matrix for that - - run: cd cli && pnpm start ../../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} --noGit --CI --trpc=${{ matrix.trpc }} --tailwind=${{ matrix.tailwind }} --nextAuth=${{ matrix.nextAuth }} --prisma=${{ matrix.prisma }} --prettier-and-extended-eslint=${{ matrix.prettierAndExtenedEslint }} + - run: cd cli && pnpm start ../../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} --noGit --CI --trpc=${{ matrix.trpc }} --tailwind=${{ matrix.tailwind }} --nextAuth=${{ matrix.nextAuth }} --prisma=${{ matrix.prisma }} --prettier-and-extended-eslint=${{ matrix.prettierAndExtendedEslint }} - run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} && pnpm build env: NEXTAUTH_SECRET: foo From ab01b4d2c2f70645f9906ebae7983ebb42060bdf Mon Sep 17 00:00:00 2001 From: Finn <34718806+FinnDore@users.noreply.github.com> Date: Tue, 16 May 2023 19:11:25 +0100 Subject: [PATCH 24/24] this? --- .github/workflows/e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 936c8dd380..fbc4663aa4 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -66,7 +66,7 @@ jobs: # has to be scaffolded outside the CLI project so that no lint/tsconfig are leaking # through. this way it ensures that it is the app's configs that are being used # FIXME: this is a bit hacky, would rather have --packages=trpc,tailwind,... but not sure how to setup the matrix for that - - run: cd cli && pnpm start ../../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} --noGit --CI --trpc=${{ matrix.trpc }} --tailwind=${{ matrix.tailwind }} --nextAuth=${{ matrix.nextAuth }} --prisma=${{ matrix.prisma }} --prettier-and-extended-eslint=${{ matrix.prettierAndExtendedEslint }} - - run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }} && pnpm build + - run: cd cli && pnpm start ../../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.prettierAndExtendedEslint }} --noGit --CI --trpc=${{ matrix.trpc }} --tailwind=${{ matrix.tailwind }} --nextAuth=${{ matrix.nextAuth }} --prisma=${{ matrix.prisma }} --prettier-and-extended-eslint=${{ matrix.prettierAndExtendedEslint }} + - run: cd ../ci-${{ matrix.trpc }}-${{ matrix.tailwind }}-${{ matrix.nextAuth }}-${{ matrix.prisma }}-${{ matrix.prettierAndExtendedEslint }} && pnpm build env: NEXTAUTH_SECRET: foo