Skip to content

Commit

Permalink
fix(husky): stdin is not a tty in git bash (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo authored Apr 15, 2021
1 parent a77b284 commit 807546d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/cna-template/template/nuxt/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

<%= pmRun %> commitlint --edit $1
10 changes: 10 additions & 0 deletions packages/cna-template/template/nuxt/.husky/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%_ if (isWindows === true) { _%>
command_exists () {
command -v "$1" >/dev/null 2>&1
}

# Workaround for Windows 10, Git Bash and Yarn
if command_exists winpty && test -t 1; then
exec < /dev/tty
fi
<%_ } _%>
1 change: 1 addition & 0 deletions packages/cna-template/template/nuxt/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

<%= pmRun %> lint-staged
11 changes: 7 additions & 4 deletions packages/create-nuxt-app/lib/saofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const validate = require('validate-npm-package-name')
const pkg = require('./package')

const cnaTemplateDir = join(dirname(require.resolve('cna-template/package.json')))
const isWindows = process.platform === 'win32'
const templateDir = join(cnaTemplateDir, 'template')
const frameworksDir = join(templateDir, 'frameworks')
const addExecutable = filename => new Promise(
Expand All @@ -25,7 +26,6 @@ module.exports = {
const content = this.answers.features.includes('content')
const pm = this.answers.pm === 'yarn' ? 'yarn' : 'npm'
const pmRun = this.answers.pm === 'yarn' ? 'yarn' : 'npm run'

const { cliOptions = {} } = this.sao.opts
const edge = cliOptions.edge ? '-edge' : ''

Expand All @@ -41,7 +41,8 @@ module.exports = {
edge,
pm,
pmRun,
content
content,
isWindows
}
},
actions () {
Expand All @@ -58,6 +59,7 @@ module.exports = {
const eslint = linter.includes('eslint')
const lintStaged = eslint && linter.includes('lintStaged')
const commitlint = linter.includes('commitlint')
const husky = lintStaged || commitlint

const actions = [{
type: 'add',
Expand All @@ -67,9 +69,10 @@ module.exports = {
'static/icon.png': 'features.includes("pwa")',
'content/hello.md': 'features.includes("content")',
'pages/content.vue': 'features.includes("content")',
'.husky/.gitignore': lintStaged || commitlint,
'.husky/.gitignore': husky,
'.husky/commit-msg': commitlint,
'.husky/pre-commit': lintStaged
'.husky/pre-commit': lintStaged,
'.husky/common.sh': husky
}
}]

Expand Down
2 changes: 2 additions & 0 deletions packages/create-nuxt-app/test/snapshots/index.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,7 @@ Generated by [AVA](https://avajs.dev).
'.gitignore',
'.husky/.gitignore',
'.husky/commit-msg',
'.husky/common.sh',
'.husky/pre-commit',
'.prettierrc',
'README.md',
Expand Down Expand Up @@ -2778,6 +2779,7 @@ Generated by [AVA](https://avajs.dev).
'.gitignore',
'.husky/.gitignore',
'.husky/commit-msg',
'.husky/common.sh',
'README.md',
'assets/README.md',
'commitlint.config.js',
Expand Down
Binary file modified packages/create-nuxt-app/test/snapshots/index.test.js.snap
Binary file not shown.

0 comments on commit 807546d

Please sign in to comment.