@@ -15,18 +15,21 @@ export async function setupGitHooks(config: ProjectConfig) {
1515
1616 if ( gitHooks === "none" ) return ;
1717
18- // Determine which linter is selected from addons
19- let linter : "biome" | "oxlint" | undefined ;
20- if ( addons . includes ( "oxlint" ) ) {
21- linter = "oxlint" ;
22- } else if ( addons . includes ( "biome" ) ) {
23- linter = "biome" ;
24- }
18+ // Determine which linters are selected from addons
19+ const hasBiome = addons . includes ( "biome" ) ;
20+ const hasOxlint = addons . includes ( "oxlint" ) ;
2521
2622 if ( gitHooks === "husky" ) {
23+ // For husky, we still use the old linter logic since it needs lint-staged
24+ let linter : "biome" | "oxlint" | undefined ;
25+ if ( hasOxlint ) {
26+ linter = "oxlint" ;
27+ } else if ( hasBiome ) {
28+ linter = "biome" ;
29+ }
2730 await setupHusky ( projectDir , linter ) ;
2831 } else if ( gitHooks === "lefthook" ) {
29- await setupLefthook ( projectDir , linter ) ;
32+ await setupLefthook ( projectDir , hasBiome , hasOxlint ) ;
3033 }
3134}
3235
@@ -63,9 +66,9 @@ export async function setupHusky(projectDir: string, linter?: "biome" | "oxlint"
6366 }
6467}
6568
66- export async function setupLefthook ( projectDir : string , linter ?: "biome" | " oxlint" ) {
69+ export async function setupLefthook ( projectDir : string , biome ?: boolean , oxlint ?: boolean ) {
6770 await addPackageDependency ( {
68- devDependencies : [ "lefthook" , "lint-staged" ] ,
71+ devDependencies : [ "lefthook" ] ,
6972 projectDir,
7073 } ) ;
7174
@@ -78,35 +81,18 @@ export async function setupLefthook(projectDir: string, linter?: "biome" | "oxli
7881 prepare : "lefthook install" ,
7982 } ;
8083
81- if ( linter === "oxlint" ) {
82- packageJson [ "lint-staged" ] = {
83- "**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,vue,astro,svelte}" : "oxlint" ,
84- } ;
85- } else if ( linter === "biome" ) {
86- packageJson [ "lint-staged" ] = {
87- "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}" : [ "biome check --write ." ] ,
88- } ;
89- } else {
90- packageJson [ "lint-staged" ] = {
91- "**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,vue,astro,svelte}" : "" ,
92- } ;
93- }
94-
9584 await fs . writeJson ( packageJsonPath , packageJson , { spaces : 2 } ) ;
9685 }
9786
98- // Only create lefthook.yml if there's a linter configured
99- // Otherwise, let lefthook use its default configuration
100- if ( linter ) {
101- // Read and compile Handlebars template
102- const templatePath = path . join ( PKG_ROOT , "templates/git-hooks/lefthook/lefthook.yml.hbs" ) ;
103- const templateContent = await fs . readFile ( templatePath , "utf-8" ) ;
104- const template = Handlebars . compile ( templateContent ) ;
87+ // Always create lefthook.yml with the template
88+ // Read and compile Handlebars template
89+ const templatePath = path . join ( PKG_ROOT , "templates/git-hooks/lefthook/lefthook.yml.hbs" ) ;
90+ const templateContent = await fs . readFile ( templatePath , "utf-8" ) ;
91+ const template = Handlebars . compile ( templateContent ) ;
10592
106- // Generate lefthook.yml content using template
107- const lefthookYmlContent = template ( { linter } ) ;
93+ // Generate lefthook.yml content using template
94+ const lefthookYmlContent = template ( { biome , oxlint } ) ;
10895
109- const lefthookYmlPath = path . join ( projectDir , "lefthook.yml" ) ;
110- await fs . writeFile ( lefthookYmlPath , lefthookYmlContent ) ;
111- }
96+ const lefthookYmlPath = path . join ( projectDir , "lefthook.yml" ) ;
97+ await fs . writeFile ( lefthookYmlPath , lefthookYmlContent ) ;
11298}
0 commit comments