Skip to content

Commit

Permalink
chore: update prettier and migrate to an esm config (t3-oss#1500)
Browse files Browse the repository at this point in the history
* updated prettier and config

* cjs -> ts

* remove require resolve?

* Revert "remove require resolve?"

This reverts commit 86a6853.

* upgraded monorepo

* half working now

* the state of this plugin

* template

* version map

* trust issues

* astro update

* format changes

* whoops

* .

* revert ian vs

* cli formats it anyways

* this fixed it?

* .

* yes

* moved these back to then move them back

* moved back

* behond confusion

* v?

* surely this cant hurt

* fixed??

* .

* 🤡

* move back

* cli: rename prettier config

* imports

* small tweaks

* bump eslint-config-prettier version

* oh lawd

* re-write format functions as --check ---write breaks ivanas eslint stuff

* we do a little quote

* last formatting

* bumped prettier-plugin-tailwindcss 0.4.1 -> 0.5.1

* formatting

* we do a little tweak

* more tweaking

* reverse tweaking

* added import thing

* begone

* :pog:

* adjust regexp

* formatted the rest of the repo

* move config to sub configs

---------

Co-authored-by: juliusmarminge <[email protected]>
  • Loading branch information
FinnDore and juliusmarminge committed Aug 10, 2023
1 parent 5559a42 commit ea2a8c6
Show file tree
Hide file tree
Showing 113 changed files with 1,078 additions and 764 deletions.
11 changes: 0 additions & 11 deletions cli/.prettierrc.cjs

This file was deleted.

10 changes: 5 additions & 5 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"start": "node dist/index.js",
"lint": "eslint . --report-unused-disable-directives",
"lint:fix": "pnpm lint --fix",
"format": "pnpm format:check --write",
"format:check": "pnpm prettier --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --check",
"format": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --write",
"format:check": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --check",
"release": "changeset version",
"pub:beta": "pnpm build && npm publish --tag beta",
"pub:next": "pnpm build && npm publish --tag next",
"pub:release": "pnpm build && npm publish"
},
"dependencies": {
"@ianvs/prettier-plugin-sort-imports": "^3.7.2",
"@ianvs/prettier-plugin-sort-imports": "^4.1.0",
"chalk": "5.2.0",
"commander": "^10.0.0",
"execa": "^7.1.1",
Expand All @@ -65,8 +65,8 @@
"@types/node": "^18.16.0",
"next": "^13.4.1",
"next-auth": "^4.22.1",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.2.8",
"prettier": "^3.0.0",
"prettier-plugin-tailwindcss": "^0.5.1",
"prisma": "^4.14.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
21 changes: 21 additions & 0 deletions cli/prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import baseConfig from "../prettier.config.mjs";

/**
* @type {import('prettier').Config & import('prettier-plugin-tailwindcss').options &
* import("@ianvs/prettier-plugin-sort-imports").PluginConfig}
*/
const config = {
...baseConfig,
arrowParens: "always",
plugins: [
"@ianvs/prettier-plugin-sort-imports",
"prettier-plugin-tailwindcss",
],
tailwindConfig: "./template/extras/config/tailwind.config.ts",
trailingComma: "es5",
importOrder: ["<THIRD_PARTY_MODULES>", "", "^~/", "^[../]", "^[./]"],
importOrderParserPlugins: ["typescript", "jsx", "decorators-legacy"],
importOrderTypeScriptVersion: "4.4.0",
};

export default config;
7 changes: 5 additions & 2 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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 { IsTTYError } from "~/utils/isTTYError.js";
Expand Down
1 change: 1 addition & 0 deletions cli/src/helpers/createProject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";

import { installPackages } from "~/helpers/installPackages.js";
import { scaffoldProject } from "~/helpers/scaffoldProject.js";
import { selectAppFile, selectIndexFile } from "~/helpers/selectBoilerplate.js";
Expand Down
5 changes: 3 additions & 2 deletions cli/src/helpers/git.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import chalk from "chalk";
import { execSync } from "child_process";
import path from "path";
import chalk from "chalk";
import { execa } from "execa";
import fs from "fs-extra";
import inquirer from "inquirer";
import ora from "ora";
import path from "path";

import { logger } from "~/utils/logger.js";

const isGitInstalled = (dir: string): boolean => {
Expand Down
1 change: 1 addition & 0 deletions cli/src/helpers/installDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from "chalk";
import { execa } from "execa";
import ora, { type Ora } from "ora";

import {
getUserPkgManager,
type PackageManager,
Expand Down
1 change: 1 addition & 0 deletions cli/src/helpers/installPackages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from "chalk";
import ora from "ora";

import {
type InstallerOptions,
type PkgInstallerMap,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/helpers/logNextSteps.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isInsideGitRepo, isRootGitRepo } from "./git.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";
import { isInsideGitRepo, isRootGitRepo } from "./git.js";

// This logs the next steps that the user should take in order to advance the project
export const logNextSteps = async ({
Expand Down
3 changes: 2 additions & 1 deletion cli/src/helpers/scaffoldProject.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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";
Expand Down
3 changes: 2 additions & 1 deletion cli/src/helpers/selectBoilerplate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";

import { PKG_ROOT } from "~/consts.js";
import { type InstallerOptions } from "~/installers/index.js";

Expand Down
15 changes: 8 additions & 7 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/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 fs from "fs-extra";
import { type PackageJson } from "type-fest";

import { runCli } from "~/cli/index.js";
import { createProject } from "~/helpers/createProject.js";
import { initializeGit } from "~/helpers/git.js";
Expand All @@ -17,6 +12,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?: {
Expand Down
5 changes: 2 additions & 3 deletions cli/src/installers/dependencyVersionMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export const dependencyVersionMap = {
tailwindcss: "^3.3.3",
autoprefixer: "^10.4.14",
postcss: "^8.4.27",
prettier: "^2.8.8",
"prettier-plugin-tailwindcss": "^0.2.8",
"@types/prettier": "^2.7.2",
prettier: "^3.0.0",
"prettier-plugin-tailwindcss": "^0.5.1",

// tRPC
"@trpc/client": "^10.34.0",
Expand Down
3 changes: 2 additions & 1 deletion cli/src/installers/envVars.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";

import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";

Expand Down
3 changes: 2 additions & 1 deletion cli/src/installers/nextAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";

import { PKG_ROOT } from "~/consts.js";
import { type AvailableDependencies } from "~/installers/dependencyVersionMap.js";
import { type Installer } from "~/installers/index.js";
Expand Down
3 changes: 2 additions & 1 deletion cli/src/installers/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";
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";
Expand Down
8 changes: 4 additions & 4 deletions cli/src/installers/tailwind.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";

import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";
Expand All @@ -13,7 +14,6 @@ export const tailwindInstaller: Installer = ({ projectDir }) => {
"autoprefixer",
"prettier",
"prettier-plugin-tailwindcss",
"@types/prettier",
],
devMode: true,
});
Expand All @@ -26,8 +26,8 @@ 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 prettierDest = path.join(projectDir, "prettier.config.cjs");
const prettierSrc = path.join(extrasDir, "config/_prettier.config.mjs");
const prettierDest = path.join(projectDir, "prettier.config.mjs");

const cssSrc = path.join(extrasDir, "src/styles/globals.css");
const cssDest = path.join(projectDir, "src/styles/globals.css");
Expand Down
3 changes: 2 additions & 1 deletion cli/src/installers/trpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";

import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";
Expand Down
3 changes: 2 additions & 1 deletion cli/src/utils/addPackageDependency.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";
import sortPackageJson from "sort-package-json";
import { type PackageJson } from "type-fest";

import {
dependencyVersionMap,
type AvailableDependencies,
Expand Down
3 changes: 2 additions & 1 deletion cli/src/utils/getT3Version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs-extra";
import path from "path";
import fs from "fs-extra";
import { type PackageJson } from "type-fest";

import { PKG_ROOT } from "~/consts.js";

export const getVersion = () => {
Expand Down
3 changes: 2 additions & 1 deletion cli/src/utils/parseNameAndPath.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { removeTrailingSlash } from "./removeTrailingSlash.js";
import pathModule from "path";

import { removeTrailingSlash } from "./removeTrailingSlash.js";

/**
* Parses the appName and its path from the user input.
*
Expand Down
1 change: 1 addition & 0 deletions cli/src/utils/renderTitle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gradient from "gradient-string";

import { TITLE_TEXT } from "~/consts.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";

Expand Down
5 changes: 3 additions & 2 deletions cli/src/utils/renderVersionWarning.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getVersion } from "./getT3Version.js";
import { logger } from "./logger.js";
import { execSync } from "child_process";
import https from "https";

import { getVersion } from "./getT3Version.js";
import { logger } from "./logger.js";

export const renderVersionWarning = (npmVersion: string) => {
const currentVersion = getVersion();

Expand Down
1 change: 1 addition & 0 deletions cli/template/base/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type AppType } from "next/dist/shared/lib/utils";

import "~/styles/globals.css";

const MyApp: AppType = ({ Component, pageProps }) => {
Expand Down
3 changes: 2 additions & 1 deletion cli/template/base/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import styles from "./index.module.css";
import Head from "next/head";
import Link from "next/link";

import styles from "./index.module.css";

export default function Home() {
return (
<>
Expand Down
6 changes: 6 additions & 0 deletions cli/template/extras/config/_prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').options} */
const config = {
plugins: ["prettier-plugin-tailwindcss"],
};

export default config;
6 changes: 0 additions & 6 deletions cli/template/extras/config/prettier.config.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions cli/template/extras/src/pages/_app/with-auth-trpc.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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 }> = ({
Expand Down
1 change: 1 addition & 0 deletions cli/template/extras/src/pages/_app/with-auth.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 }> = ({
Expand Down
2 changes: 2 additions & 0 deletions cli/template/extras/src/pages/_app/with-trpc.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type AppType } from "next/app";

import { api } from "~/utils/api";

import "~/styles/globals.css";

const MyApp: AppType = ({ Component, pageProps }) => {
Expand Down
1 change: 1 addition & 0 deletions cli/template/extras/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NextAuth from "next-auth";

import { authOptions } from "~/server/auth";

export default NextAuth(authOptions);
1 change: 1 addition & 0 deletions cli/template/extras/src/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createNextApiHandler } from "@trpc/server/adapters/next";

import { env } from "~/env.mjs";
import { appRouter } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/trpc";
Expand Down
3 changes: 2 additions & 1 deletion cli/template/extras/src/pages/index/with-auth-trpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { signIn, signOut, useSession } from "next-auth/react";
import Head from "next/head";
import Link from "next/link";

import { api } from "~/utils/api";

export default function Home() {
Expand All @@ -13,7 +14,7 @@ export default function Home() {
<meta name="description" content="Generated by create-t3-app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<main className=" flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16 ">
<h1 className="text-5xl font-extrabold tracking-tight text-white sm:text-[5rem]">
Create <span className="text-[hsl(280,100%,70%)]">T3</span> App
Expand Down
3 changes: 2 additions & 1 deletion cli/template/extras/src/pages/index/with-auth-trpc.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import styles from "./index.module.css";
import { signIn, signOut, useSession } from "next-auth/react";
import Head from "next/head";
import Link from "next/link";

import { api } from "~/utils/api";
import styles from "./index.module.css";

export default function Home() {
const hello = api.example.hello.useQuery({ text: "from tRPC" });
Expand Down
1 change: 1 addition & 0 deletions cli/template/extras/src/pages/index/with-trpc-tw.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Head from "next/head";
import Link from "next/link";

import { api } from "~/utils/api";

export default function Home() {
Expand Down
Loading

0 comments on commit ea2a8c6

Please sign in to comment.