Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CLI up-to-date #2007

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"package.json"
],
"engines": {
"node": ">=18.17.0"
"node": ">=20.18.0"
ahkhanjani marked this conversation as resolved.
Show resolved Hide resolved
},
"scripts": {
"typecheck": "tsc",
Expand All @@ -52,7 +52,7 @@
"dependencies": {
"@clack/core": "^0.3.4",
"@clack/prompts": "^0.6.3",
"@ianvs/prettier-plugin-sort-imports": "^4.2.1",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
"chalk": "5.2.0",
"commander": "^10.0.1",
"execa": "^7.2.0",
Expand All @@ -66,33 +66,33 @@
"@auth/prisma-adapter": "^1.6.0",
"@libsql/client": "^0.9.0",
"@planetscale/database": "^1.19.0",
"@prisma/adapter-planetscale": "^5.14.0",
"@prisma/client": "^5.14.0",
"@t3-oss/env-nextjs": "^0.10.1",
"@tanstack/react-query": "^5.49.2",
"@trpc/client": "11.0.0-rc.441",
"@trpc/next": "11.0.0-rc.441",
"@trpc/react-query": "11.0.0-rc.441",
"@trpc/server": "11.0.0-rc.441",
"@prisma/adapter-planetscale": "^5.21.1",
"@prisma/client": "^5.21.1",
"@t3-oss/env-nextjs": "^0.11.1",
"@tanstack/react-query": "^5.59.16",
"@trpc/client": "11.0.0-rc.604",
"@trpc/next": "11.0.0-rc.604",
"@trpc/react-query": "11.0.0-rc.604",
"@trpc/server": "11.0.0-rc.604",
"@types/fs-extra": "^11.0.4",
"@types/gradient-string": "^1.1.6",
"@types/node": "^20.14.10",
"drizzle-kit": "^0.24.0",
"@types/node": "^20.17.1",
"drizzle-kit": "^0.24.2",
"drizzle-orm": "^0.33.0",
"mysql2": "^3.11.0",
"next": "^14.2.4",
"next-auth": "^4.24.7",
"postgres": "^3.4.4",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"prisma": "^5.14.0",
"react": "^18.3.0",
"react-dom": "^18.3.0",
"next": "^15.0.2",
"next-auth": "^4.24.10",
ahkhanjani marked this conversation as resolved.
Show resolved Hide resolved
"postgres": "^3.4.5",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.8",
"prisma": "^5.21.1",
"react": "rc",
"react-dom": "rc",
"superjson": "^2.2.1",
"tailwindcss": "^3.4.3",
"tailwindcss": "^3.4.14",
"tsup": "^6.7.0",
"type-fest": "^3.13.1",
"typescript": "^5.5.3",
"typescript": "^5.6.3",
"zod": "^3.23.8"
}
}
2 changes: 1 addition & 1 deletion cli/src/helpers/installDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
const runInstallCommand = async (
pkgManager: PackageManager,
projectDir: string
): Promise<Ora | null> => {

Check failure on line 40 in cli/src/helpers/installDependencies.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Delete `<Ora·|·null>`
switch (pkgManager) {
// When using npm, inherit the stderr stream so that the progress bar is shown
case "npm":
Expand All @@ -55,7 +55,7 @@

if (text.includes("Progress")) {
spinner.text = text.includes("|")
? text.split(" | ")[1] ?? ""
? (text.split(" | ")[1] ?? "")

Check failure on line 58 in cli/src/helpers/installDependencies.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Replace `(text.split("·|·")[1]·??·"")` with `text.split("·|·")[1]·??·""`
: text;
}
},
Expand Down
58 changes: 44 additions & 14 deletions cli/src/installers/eslint.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,62 @@
import path from "path";
import fs from "fs-extra";
import { format } from "prettier";

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 });
const imports = getImports(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;",
const eslintConfig = getEslintConfig(usingDrizzle);
const stringifiedConfig = JSON.stringify(eslintConfig, null, 2).replace(
/"%%|%%"/g,
""
);

// Convert config from _eslint.js to eslint.config.js
const eslintConfigFileContents = [
...imports,
"",
"export default tseslint.config(",
stringifiedConfig,
");",
].join("\n");

const eslintConfigDest = path.join(projectDir, ".eslintrc.cjs");
fs.writeFileSync(eslintConfigDest, eslintrcFileContents, "utf-8");
format(eslintConfigFileContents, { parser: "typescript" })
.then((content) => {
const eslintConfigDest = path.join(projectDir, "eslint.config.js");
fs.writeFileSync(eslintConfigDest, content, "utf-8");
})
.catch((error) => {
console.error("Invalid 'eslint.config.js'.", error);
});
};

const getEslintConfig = ({ usingDrizzle }: { usingDrizzle: boolean }) => {
function getImports(usingDrizzle: boolean) {
const imports = [
'import nextPlugin from "@next/eslint-plugin-next"',
'import tseslint from "typescript-eslint"',
];

if (usingDrizzle) {
imports.unshift('import drizzlePlugin from "eslint-plugin-drizzle"');
}

return imports;
}

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

if (usingDrizzle) {
eslintConfig.plugins = [...(eslintConfig.plugins ?? []), "drizzle"];
Object.assign(eslintConfig.plugins, {
drizzle: "%%drizzlePlugin%%",
});

eslintConfig.rules = {
...eslintConfig.rules,
Object.assign(eslintConfig.rules, {
"drizzle/enforce-delete-with-where": [
"error",
{ drizzleObjectName: ["db", "ctx.db"] },
Expand All @@ -36,7 +65,8 @@ const getEslintConfig = ({ usingDrizzle }: { usingDrizzle: boolean }) => {
"error",
{ drizzleObjectName: ["db", "ctx.db"] },
],
};
});
}

return eslintConfig;
};
}
1 change: 0 additions & 1 deletion cli/template/base/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const config = {
locales: ["en"],
defaultLocale: "en",
},
transpilePackages: ["geist"],
};

export default config;
35 changes: 19 additions & 16 deletions cli/template/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"private": true,
"scripts": {
"dev": "next dev --turbo",
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand All @@ -14,22 +14,25 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@t3-oss/env-nextjs": "^0.10.1",
"geist": "^1.3.0",
"next": "^15.0.1",
"react": "^18.3.1",
ahkhanjani marked this conversation as resolved.
Show resolved Hide resolved
"react-dom": "^18.3.1",
"zod": "^3.23.3"
"@t3-oss/env-nextjs": "^0.11.1",
"geist": "^1.3.1",
"next": "^15.0.2",
"react": "rc",
"react-dom": "rc",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/eslint": "^8.56.10",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"eslint": "^8.57.0",
"eslint-config-next": "^15.0.1",
"typescript": "^5.5.3"
"@next/eslint-plugin-next": "^15.0.2",
"@types/node": "^20.17.1",
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc",
"eslint": "^9.13.0",
"eslint-config-next": "^15.0.2",
ahkhanjani marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "^5.6.3",
"typescript-eslint": "^8.12.2"
},
"overrides": {
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc"
}
}
2 changes: 1 addition & 1 deletion cli/template/base/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
},
"include": [
".eslintrc.cjs",
"eslint.config.js",
ahkhanjani marked this conversation as resolved.
Show resolved Hide resolved
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
Expand Down
18 changes: 11 additions & 7 deletions cli/template/extras/config/_eslint.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/** @type {import("eslint").Linter.Config} */
export const _initialConfig = {
parser: "@typescript-eslint/parser",
parserOptions: { project: true },
plugins: ["@typescript-eslint"],
plugins: {
"@next/next": "%%nextPlugin%%",
"@typescript-eslint": "%%tseslint.plugin%%",
},
extends: [
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"%%...nextPlugin.configs['core-web-vitals'].rules%%",
"%%...tseslint.configs.recommendedTypeChecked%%",
"%%...tseslint.configs.stylisticTypeChecked%%",
],
languageOptions: {
parser: "%%tseslint.parser%%",
parserOptions: { project: true },
},
rules: {
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
Expand Down
Loading
Loading