Skip to content

Commit 1ff45d8

Browse files
committed
Fix git hooks
1 parent c6dd8be commit 1ff45d8

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/modules/copy-template.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import fs from 'fs'
1+
import fs, { WriteFileOptions } from 'fs'
22
import ejs from 'ejs'
33
import path from 'path'
44

55
export default function copyTemplate(
66
templatePath: string,
77
projectPath: string,
8-
ejsConfig: any
8+
ejsConfig: any,
9+
writeFileOptions?: WriteFileOptions
910
) {
1011
const filesToCreate = fs.readdirSync(templatePath)
1112

@@ -23,15 +24,16 @@ export default function copyTemplate(
2324
? path.join(projectPath, '.gitignore')
2425
: path.join(projectPath, file)
2526

26-
fs.writeFileSync(writePath, contents, 'utf8')
27+
fs.writeFileSync(writePath, contents, writeFileOptions ?? 'utf8')
2728
}
2829

2930
if (stats.isDirectory()) {
3031
fs.mkdirSync(path.join(projectPath, file))
3132
copyTemplate(
3233
path.join(templatePath, file),
3334
path.join(projectPath, file),
34-
ejsConfig
35+
ejsConfig,
36+
file === '.husky' ? { encoding: 'utf8', mode: 0o0755 } : undefined // make all hook files executable
3537
)
3638
}
3739
})

src/modules/init-git-repository.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ shell.cd = jest.fn()
1010
describe('init-git repository module', () => {
1111
const testProjectPath = '/project-path'
1212

13-
it('logs info about initalization', () => {
13+
it('logs info about initialization', () => {
1414
initGitRepository(testProjectPath)
1515

1616
expect(log.info).toBeCalled()
@@ -27,4 +27,10 @@ describe('init-git repository module', () => {
2727

2828
expect(exec).toBeCalledWith('git init')
2929
})
30+
31+
it('prepares git hooks', () => {
32+
initGitRepository(testProjectPath)
33+
34+
expect(exec).toBeCalledWith('npm run prepare')
35+
})
3036
})

src/modules/init-git-repository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default function initGitRepository(projectPath: string) {
55
log.info('Initializing a new git repository...')
66
shell.cd(projectPath)
77
exec('git init')
8+
exec('npm run prepare') // run husky install (set up git hooks)
89
exec('git add .')
910
exec('git commit -m "Initial commit"')
1011
}

0 commit comments

Comments
 (0)