Skip to content

Commit

Permalink
Merge branch 'main' into feat/portable-shebangs-in-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
thecmdrunner committed Mar 8, 2024
2 parents 0c020ec + 60bd52d commit ae2a742
Show file tree
Hide file tree
Showing 20 changed files with 483 additions and 393 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-actors-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": minor
---

Include ESLlint rules for `drizzle-orm`.
4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"drizzle-kit": "^0.20.14",
"drizzle-orm": "^0.29.4",
"mysql2": "^3.9.1",
"next": "^14.1.0",
"next": "^14.1.3",
"next-auth": "^4.24.6",
"postgres": "^3.4.3",
"prettier": "^3.2.5",
Expand All @@ -93,7 +93,7 @@
"tailwindcss": "^3.4.1",
"tsup": "^6.7.0",
"type-fest": "^3.7.0",
"typescript": "^5.3.3",
"typescript": "^5.4.2",
"zod": "^3.22.4"
}
}
6 changes: 0 additions & 6 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ const main = async () => {
await installDependencies({ projectDir });
}

// 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 (!noGit) {
await initializeGit(projectDir);
}
Expand Down
1 change: 1 addition & 0 deletions cli/src/installers/dependencyVersionMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const dependencyVersionMap = {
// Drizzle
"drizzle-orm": "^0.29.4",
"drizzle-kit": "^0.20.14",
"eslint-plugin-drizzle": "^0.2.3",
mysql2: "^3.9.1",
"@planetscale/database": "^1.16.0",
postgres: "^3.4.3",
Expand Down
5 changes: 4 additions & 1 deletion cli/src/installers/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export const drizzleInstaller: Installer = ({
scopedAppName,
databaseProvider,
}) => {
const devPackages: AvailableDependencies[] = ["drizzle-kit"];
const devPackages: AvailableDependencies[] = [
"drizzle-kit",
"eslint-plugin-drizzle",
];
if (databaseProvider === "planetscale") devPackages.push("mysql2");
if (databaseProvider === "sqlite") devPackages.push("@types/better-sqlite3");
if (databaseProvider === "postgres") devPackages.push("pg");
Expand Down
36 changes: 36 additions & 0 deletions cli/src/installers/eslint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import path from "path";
import fs from "fs-extra";

import { _initialConfig } from "~/../template/extras/config/_eslint.js";
import { type Installer } from "~/installers/index.js";

export const dynamicEslintInstaller: Installer = ({ projectDir, packages }) => {
const usingDrizzle = !!packages?.drizzle?.inUse;

const eslintConfig = getEslintConfig({ usingDrizzle });

// Convert config from _eslint.config.json to .eslintrc.cjs
const eslintrcFileContents = [
'/** @type {import("eslint").Linter.Config} */',
`const config = ${JSON.stringify(eslintConfig, null, 2)}`,
"module.exports = config;",
].join("\n");

const eslintConfigDest = path.join(projectDir, ".eslintrc.cjs");
fs.writeFileSync(eslintConfigDest, eslintrcFileContents, "utf-8");
};

const getEslintConfig = ({ usingDrizzle }: { usingDrizzle: boolean }) => {
const eslintConfig = _initialConfig;

if (usingDrizzle) {
eslintConfig.plugins = [...(eslintConfig.plugins ?? []), "drizzle"];

eslintConfig.rules = {
...eslintConfig.rules,
"drizzle/enforce-delete-with-where": "error",
"drizzle/enforce-update-with-where": "error",
};
}
return eslintConfig;
};
6 changes: 6 additions & 0 deletions cli/src/installers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { trpcInstaller } from "~/installers/trpc.js";
import { type PackageManager } from "~/utils/getUserPkgManager.js";
import { dbContainerInstaller } from "./dbContainer.js";
import { drizzleInstaller } from "./drizzle.js";
import { dynamicEslintInstaller } from "./eslint.js";

// Turning this into a const allows the list to be iterated over for programatically creating prompt options
// Should increase extensability in the future
Expand All @@ -16,6 +17,7 @@ export const availablePackages = [
"tailwind",
"trpc",
"envVariables",
"eslint",
"dbContainer",
] as const;
export type AvailablePackages = (typeof availablePackages)[number];
Expand Down Expand Up @@ -80,4 +82,8 @@ export const buildPkgInstallerMap = (
inUse: true,
installer: envVariablesInstaller,
},
eslint: {
inUse: true,
installer: dynamicEslintInstaller,
},
});
12 changes: 6 additions & 6 deletions cli/template/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@t3-oss/env-nextjs": "^0.9.2",
"next": "^14.1.0",
"next": "^14.1.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"zod": "^3.22.4"
Expand All @@ -21,10 +21,10 @@
"@types/node": "^20.11.20",
"@types/react": "^18.2.57",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"eslint": "^8.56.0",
"eslint-config-next": "^14.1.0",
"typescript": "^5.3.3"
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint": "^8.57.0",
"eslint-config-next": "^14.1.3",
"typescript": "^5.4.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
/** @type {import("eslint").Linter.Config} */
const config = {
export const _initialConfig = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
parserOptions: { project: true },
plugins: ["@typescript-eslint"],
extends: [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
],
rules: {
// These opinionated rules are enabled in stylistic-type-checked above.
// Feel free to reconfigure them to your own preference.
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",

"@typescript-eslint/consistent-type-imports": [
"warn",
{
prefer: "type-imports",
fixStyle: "inline-type-imports",
},
{ prefer: "type-imports", fixStyle: "inline-type-imports" },
],
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: { attributes: false },
},
{ checksVoidReturn: { attributes: false } },
],
},
};

module.exports = config;
2 changes: 1 addition & 1 deletion cli/template/extras/prisma/schema/base-planetscale.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ datasource db {
provider = "mysql"
url = env("DATABASE_URL")
// Do not use foreign keys (PlanetScale does not support them)
// If you have enabled foreign key constraints for your database, remove this line.
relationMode = "prisma"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ datasource db {
provider = "mysql"
url = env("DATABASE_URL")
// Do not use foreign keys (PlanetScale does not support them)
// If you have enabled foreign key constraints for your database, remove this line.
relationMode = "prisma"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as schema from "./schema";
* update.
*/
const globalForDb = globalThis as unknown as {
conn: Database | undefined;
conn: Database.Database | undefined;
};

export const conn =
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/start-database/mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ fi

docker run --name $DB_CONTAINER_NAME -e MYSQL_ROOT_PASSWORD=$DB_PASSWORD -e MYSQL_DATABASE=project1 -d -p 3306:3306 docker.io/mysql

echo "Database container was succesfuly created"
echo "Database container was successfully created"
2 changes: 1 addition & 1 deletion cli/template/extras/start-database/postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ fi

docker run --name $DB_CONTAINER_NAME -e POSTGRES_PASSWORD=$DB_PASSWORD -e POSTGRES_DB=project1 -d -p 5432:5432 docker.io/postgres

echo "Database container was succesfuly created"
echo "Database container was successfully created"
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"@total-typescript/ts-reset": "^0.3.7",
"@types/eslint": "^8.56.2",
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "7.0.2",
"@typescript-eslint/parser": "7.0.2",
"eslint": "^8.56.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-turbo": "^0.0.9",
"eslint-plugin-import": "^2.27.5",
Expand All @@ -63,6 +63,6 @@
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^3.2.5",
"turbo": "^1.9.6",
"typescript": "^5.3.3"
"typescript": "^5.4.2"
}
}
Loading

0 comments on commit ae2a742

Please sign in to comment.