Skip to content

Commit

Permalink
added package.json scripts for biome
Browse files Browse the repository at this point in the history
  • Loading branch information
aidansunbury committed Nov 10, 2024
1 parent bafb814 commit d62917f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 149 deletions.
8 changes: 5 additions & 3 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const runCli = async (): Promise<CliResults> => {
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.`
Expand Down Expand Up @@ -324,7 +324,8 @@ export const runCli = async (): Promise<CliResults> => {
},
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" },
Expand Down Expand Up @@ -373,7 +374,8 @@ export const runCli = async (): Promise<CliResults> => {
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,
Expand Down
20 changes: 16 additions & 4 deletions cli/src/installers/biome.ts
Original file line number Diff line number Diff line change
@@ -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,
});

Expand All @@ -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,
});
};
6 changes: 2 additions & 4 deletions cli/src/installers/dependencyVersionMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
1 change: 0 additions & 1 deletion cli/src/installers/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const drizzleInstaller: Installer = ({
scopedAppName,
databaseProvider,
}) => {

addPackageDependency({
projectDir,
dependencies: ["drizzle-kit"],
Expand Down
6 changes: 2 additions & 4 deletions cli/src/installers/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion cli/src/installers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions cli/src/installers/tailwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
152 changes: 24 additions & 128 deletions cli/template/extras/config/biome.jsonc
Original file line number Diff line number Diff line change
@@ -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" } }
}

0 comments on commit d62917f

Please sign in to comment.