Skip to content

Commit

Permalink
Merge pull request #43 from HiDeoo/hd-husky-v9
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Feb 2, 2024
2 parents 916985f + 679314f commit f22ec04
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ async function install(appPath: string) {
async function addGitHooks(appPath: string) {
logStepWithProgress('Configuring Git hooks…')

return executePackageManagerCommand(appPath, ['husky', 'add', '.husky/pre-commit', 'pnpx lint-staged'], true)
await executePackageManagerCommand(appPath, ['husky', 'init'], true)

const fileName = '.husky/pre-commit'
const template = await getTemplateContent(getTemplatePath(fileName))

return writeAppFile(appPath, fileName, template)
}

async function prettify(appPath: string, isNew: boolean) {
Expand Down Expand Up @@ -236,7 +241,7 @@ async function stageBootstrapFiles(appPath: string) {
const templatePaths = await getTemplatePaths(false)

const filesToStage = templatePaths.map(({ destination }) => destination)
filesToStage.push('.husky/pre-commit', 'pnpm-lock.yaml')
filesToStage.push('pnpm-lock.yaml')

await stageFiles(appPath, filesToStage)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NODE_VERSION, PACKAGE_MANAGER, USER_MAIL, USER_NAME, USER_SITE } from '
import { getPkgManagerLatestVersion } from './pm'

// A set of templates which will not be automatically processed and requires special handling.
const specialTemplates = new Set(['package.json', 'tsconfig.json', '.eslintrc.json'])
const specialTemplates = new Set(['package.json', 'tsconfig.json', '.eslintrc.json', '.husky/pre-commit'])

const templateVariableKeys = [
'APP_NAME',
Expand Down
1 change: 1 addition & 0 deletions templates/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpx lint-staged
9 changes: 2 additions & 7 deletions tests/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,7 @@ describe.each(testScenarios)('$description', ({ appName, options, setup }) => {
})

test('should configure Git hooks', () => {
expectSpawnToHaveBeenNthCalledWith(PACKAGE_MANAGER_EXECUTE, [
'husky',
'add',
'.husky/pre-commit',
'pnpx lint-staged',
])
expectSpawnToHaveBeenNthCalledWith(PACKAGE_MANAGER_EXECUTE, ['husky', 'init'])
})

test('should run ESLint when updating an existing app', () => {
Expand Down Expand Up @@ -368,12 +363,12 @@ describe.each(testScenarios)('$description', ({ appName, options, setup }) => {
'.github/workflows/integration.yml',
'.github/workflows/release.yml',
'.gitignore',
'.husky/pre-commit',
'.prettierignore',
'LICENSE',
'README.md',
'package.json',
'tsconfig.json',
'.husky/pre-commit',
'pnpm-lock.yaml',
])
})
Expand Down

0 comments on commit f22ec04

Please sign in to comment.