From d62917f2b75f534ceb1e04b943355d0088dc162e Mon Sep 17 00:00:00 2001 From: aidansunbury Date: Sat, 9 Nov 2024 17:20:30 -0800 Subject: [PATCH] added package.json scripts for biome --- cli/src/cli/index.ts | 8 +- cli/src/installers/biome.ts | 20 ++- cli/src/installers/dependencyVersionMap.ts | 6 +- cli/src/installers/drizzle.ts | 1 - cli/src/installers/eslint.ts | 6 +- cli/src/installers/index.ts | 2 +- cli/src/installers/tailwind.ts | 5 +- cli/template/extras/config/biome.jsonc | 152 ++++----------------- 8 files changed, 51 insertions(+), 149 deletions(-) diff --git a/cli/src/cli/index.ts b/cli/src/cli/index.ts index 4093272e15..4a0e236a37 100644 --- a/cli/src/cli/index.ts +++ b/cli/src/cli/index.ts @@ -211,7 +211,7 @@ export const runCli = async (): Promise => { if (cliResults.flags.biome && cliResults.flags.eslint) { logger.warn("Incompatible combination Biome + ESLint. Exiting."); process.exit(0); - }; + } if (databaseProviders.includes(cliResults.flags.dbProvider) === false) { logger.warn( `Incompatible database provided. Use: ${databaseProviders.join(", ")}. Exiting.` @@ -324,7 +324,8 @@ export const runCli = async (): Promise => { }, linter: () => { return p.select({ - message: "Would you like to use ESLint and Prettier or Biome for linting and formatting?", + message: + "Would you like to use ESLint and Prettier or Biome for linting and formatting?", options: [ { value: "eslint", label: "ESLint/Prettier" }, { value: "biome", label: "Biome" }, @@ -373,7 +374,8 @@ export const runCli = async (): Promise => { if (project.authentication === "next-auth") packages.push("nextAuth"); if (project.database === "prisma") packages.push("prisma"); if (project.database === "drizzle") packages.push("drizzle"); - //* TODO may need to add something here? not sure + if (project.linter === "eslint") packages.push("eslint"); + if (project.linter === "biome") packages.push("biome"); return { appName: project.name ?? cliResults.appName, diff --git a/cli/src/installers/biome.ts b/cli/src/installers/biome.ts index 8bb8686593..e31de626db 100644 --- a/cli/src/installers/biome.ts +++ b/cli/src/installers/biome.ts @@ -1,16 +1,15 @@ 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"; -import { PKG_ROOT } from "~/consts.js"; export const biomeInstaller: Installer = ({ projectDir }) => { addPackageDependency({ projectDir, - dependencies: [ - "@biomejs/biome", - ], + dependencies: ["@biomejs/biome"], devMode: true, }); @@ -19,4 +18,17 @@ export const biomeInstaller: Installer = ({ projectDir }) => { const biomeConfigDest = path.join(projectDir, "biome.jsonc"); fs.copySync(biomeConfigSrc, biomeConfigDest); + + // add format:* scripts to package.json + const packageJsonPath = path.join(projectDir, "package.json"); + const packageJsonContent = fs.readJSONSync(packageJsonPath) as PackageJson; + packageJsonContent.scripts = { + ...packageJsonContent.scripts, + "format:write": 'biome format --write "**/*.{ts,tsx,js,jsx,mdx}"', + "format:check": 'biome format --check "**/*.{ts,tsx,js,jsx,mdx}"', + }; + + fs.writeJSONSync(packageJsonPath, packageJsonContent, { + spaces: 2, + }); }; diff --git a/cli/src/installers/dependencyVersionMap.ts b/cli/src/installers/dependencyVersionMap.ts index e250b0afe1..b95d246220 100644 --- a/cli/src/installers/dependencyVersionMap.ts +++ b/cli/src/installers/dependencyVersionMap.ts @@ -23,7 +23,7 @@ export const dependencyVersionMap = { // TailwindCSS tailwindcss: "^3.4.3", - postcss: "^8.4.39", + postcss: "^8.4.39", // tRPC "@trpc/client": "^11.0.0-rc.446", @@ -40,13 +40,11 @@ export const dependencyVersionMap = { // eslint / prettier prettier: "^3.3.2", "prettier-plugin-tailwindcss": "^0.6.5", - "eslint": "^8.57.0", + eslint: "^8.57.0", "eslint-config-next": "^15.0.1", "eslint-plugin-drizzle": "^0.2.3", "@types/eslint": "^8.56.10", "@typescript-eslint/eslint-plugin": "^8.1.0", "@typescript-eslint/parser": "^8.1.0", - //* TODO make sure all these are install normally when eslint is selected - } as const; export type AvailableDependencies = keyof typeof dependencyVersionMap; diff --git a/cli/src/installers/drizzle.ts b/cli/src/installers/drizzle.ts index bd90ee0c79..5b9ad9bcd0 100644 --- a/cli/src/installers/drizzle.ts +++ b/cli/src/installers/drizzle.ts @@ -12,7 +12,6 @@ export const drizzleInstaller: Installer = ({ scopedAppName, databaseProvider, }) => { - addPackageDependency({ projectDir, dependencies: ["drizzle-kit"], diff --git a/cli/src/installers/eslint.ts b/cli/src/installers/eslint.ts index 549a23f16e..e317d44939 100644 --- a/cli/src/installers/eslint.ts +++ b/cli/src/installers/eslint.ts @@ -2,13 +2,12 @@ import path from "path"; import fs from "fs-extra"; import { type PackageJson } from "type-fest"; -import { PKG_ROOT } from "~/consts.js"; import { _initialConfig } from "~/../template/extras/config/_eslint.js"; +import { PKG_ROOT } from "~/consts.js"; import { type Installer } from "~/installers/index.js"; import { addPackageDependency } from "~/utils/addPackageDependency.js"; import { type AvailableDependencies } from "./dependencyVersionMap.js"; - // Also installs prettier export const dynamicEslintInstaller: Installer = ({ projectDir, packages }) => { const devPackages: AvailableDependencies[] = [ @@ -38,8 +37,7 @@ export const dynamicEslintInstaller: Installer = ({ projectDir, packages }) => { let prettierSrc: string; if (packages?.tailwind.inUse) { prettierSrc = path.join(extrasDir, "config/_tailwind.prettier.config.js"); - } - else { + } else { prettierSrc = path.join(extrasDir, "config/_prettier.config.js"); } const prettierDest = path.join(projectDir, "prettier.config.js"); diff --git a/cli/src/installers/index.ts b/cli/src/installers/index.ts index 77809f1195..366760a23b 100644 --- a/cli/src/installers/index.ts +++ b/cli/src/installers/index.ts @@ -4,10 +4,10 @@ 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 { biomeInstaller } from "./biome.js"; import { dbContainerInstaller } from "./dbContainer.js"; import { drizzleInstaller } from "./drizzle.js"; import { dynamicEslintInstaller } from "./eslint.js"; -import { biomeInstaller } from "./biome.js"; // Turning this into a const allows the list to be iterated over for programmatically creating prompt options // Should increase extensibility in the future diff --git a/cli/src/installers/tailwind.ts b/cli/src/installers/tailwind.ts index 559150def2..3df90bfa66 100644 --- a/cli/src/installers/tailwind.ts +++ b/cli/src/installers/tailwind.ts @@ -8,10 +8,7 @@ import { addPackageDependency } from "~/utils/addPackageDependency.js"; export const tailwindInstaller: Installer = ({ projectDir }) => { addPackageDependency({ projectDir, - dependencies: [ - "tailwindcss", - "postcss", - ], + dependencies: ["tailwindcss", "postcss"], devMode: true, }); diff --git a/cli/template/extras/config/biome.jsonc b/cli/template/extras/config/biome.jsonc index 7ffee4f439..adb632dfa2 100644 --- a/cli/template/extras/config/biome.jsonc +++ b/cli/template/extras/config/biome.jsonc @@ -1,129 +1,25 @@ { - "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", - "vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false }, - "files": { "ignoreUnknown": false, "ignore": [] }, - "formatter": { - "enabled": true, - "useEditorconfig": true, - "formatWithErrors": false, - "indentStyle": "space", - "indentWidth": 2, - "lineEnding": "lf", - "lineWidth": 80, - "attributePosition": "auto", - "bracketSpacing": true - }, - "organizeImports": { "enabled": true }, - "linter": { - "enabled": true, - "rules": { - "recommended": false, - "complexity": { - "noUselessTypeConstraint": "error", - "useLiteralKeys": "error", - "useOptionalChain": "error" - }, - "correctness": { "noUnusedVariables": "off", "useArrayLiterals": "off" }, - "style": { - "noInferrableTypes": "error", - "noNamespace": "error", - "useAsConstAssertion": "error", - "useConsistentArrayType": "off", - "useForOf": "error", - "useShorthandFunctionType": "error" - }, - "suspicious": { - "noEmptyBlockStatements": "error", - "noExplicitAny": "error", - "noExtraNonNullAssertion": "error", - "noMisleadingInstantiator": "error", - "noUnsafeDeclarationMerging": "error", - "useAwait": "off", - "useNamespaceKeyword": "error" - } - } - }, - "javascript": { - "formatter": { - "jsxQuoteStyle": "double", - "quoteProperties": "asNeeded", - "trailingCommas": "all", - "semicolons": "asNeeded", - "arrowParentheses": "always", - "bracketSameLine": false, - "quoteStyle": "single", - "attributePosition": "auto", - "bracketSpacing": true - } - }, - "overrides": [ - { - "include": ["*.ts", "*.tsx", "*.mts", "*.cts"], - "linter": { - "rules": { - "correctness": { - "noConstAssign": "off", - "noGlobalObjectCalls": "off", - "noInvalidBuiltinInstantiation": "off", - "noInvalidConstructorSuper": "off", - "noNewSymbol": "off", - "noSetterReturn": "off", - "noUndeclaredVariables": "off", - "noUnreachable": "off", - "noUnreachableSuper": "off" - }, - "style": { - "noArguments": "error", - "noVar": "error", - "useConst": "error" - }, - "suspicious": { - "noClassAssign": "off", - "noDuplicateClassMembers": "off", - "noDuplicateObjectKeys": "off", - "noDuplicateParameters": "off", - "noFunctionAssign": "off", - "noImportAssign": "off", - "noRedeclare": "off", - "noUnsafeNegation": "off", - "useGetterReturn": "off" - } - } - } - }, - { - "include": ["*.ts", "*.tsx", "*.mts", "*.cts"], - "linter": { - "rules": { - "correctness": { - "noConstAssign": "off", - "noGlobalObjectCalls": "off", - "noInvalidBuiltinInstantiation": "off", - "noInvalidConstructorSuper": "off", - "noNewSymbol": "off", - "noSetterReturn": "off", - "noUndeclaredVariables": "off", - "noUnreachable": "off", - "noUnreachableSuper": "off" - }, - "style": { - "noArguments": "error", - "noVar": "error", - "useConst": "error" - }, - "suspicious": { - "noClassAssign": "off", - "noDuplicateClassMembers": "off", - "noDuplicateObjectKeys": "off", - "noDuplicateParameters": "off", - "noFunctionAssign": "off", - "noImportAssign": "off", - "noRedeclare": "off", - "noUnsafeNegation": "off", - "useGetterReturn": "off" - } - } - } - } - ] -} + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { "ignoreUnknown": false, "ignore": [] }, + "formatter": { "enabled": true, "indentStyle": "space", "indentWidth": 2 }, + "organizeImports": { "enabled": true }, + "linter": { + "enabled": true, + "rules": { + "nursery": { + "useSortedClasses": { + "level": "error", + "options": { + "functions": ["clsx", "cva", "cn"] + } + } + }, + "recommended": true } + }, + "javascript": { "formatter": { "quoteStyle": "double" } } +} \ No newline at end of file