Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

feat: add support for husky v6 #765

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

<%= pmRun %> commitlint --edit $1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

<%= pmRun %> lint:js
<%= pmRun %> lint:style
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

<%= pmRun %> lint:js
<%= pmRun %> lint:style
13 changes: 9 additions & 4 deletions packages/cna-template/template/nuxt/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
pkg.dependencies['nuxt-edge'] = 'latest'
}

const { features, language = [], linter = [] } = generator.answers
const { features, language = [], linter = [], devTools = [] } = generator.answers

// Linter
const eslint = linter.includes('eslint')
Expand All @@ -32,9 +32,7 @@ module.exports = {
delete pkg.devDependencies['eslint-plugin-vue']
}
if (!lintStaged) {
delete pkg.husky
delete pkg['lint-staged']
delete pkg.devDependencies.husky
delete pkg.devDependencies['lint-staged']
}
if (!stylelint) {
Expand All @@ -53,7 +51,6 @@ module.exports = {
delete pkg.devDependencies.prettier
}
if (!commitlint) {
lintStaged && delete pkg.husky.hooks['commit-msg']
delete pkg.devDependencies['@commitlint/config-conventional']
delete pkg.devDependencies['@commitlint/cli']
}
Expand All @@ -63,6 +60,14 @@ module.exports = {
pkg.scripts.lint = lintScript
}

// Dev Tools
const husky = devTools.includes('husky')

if (!husky) {
delete pkg.devDependencies.husky
delete pkg.scripts.prepare
}

// Modules
if (!features.includes('axios')) {
delete pkg.dependencies['@nuxtjs/axios']
Expand Down
11 changes: 3 additions & 8 deletions packages/cna-template/template/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
"start": "nuxt start",
"generate": "nuxt generate",
"lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .",
"lint:style": "stylelint \"**/*.{vue,css}\" --ignore-path .gitignore"
"lint:style": "stylelint \"**/*.{vue,css}\" --ignore-path .gitignore",
"prepare": "husky install"
},
"lint-staged": {
"*.{js,vue}": "eslint",
"*.{css,vue}": "stylelint"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
},
"dependencies": {
"@nuxt/content": "^1.14.0",
"@nuxtjs/axios": "^5.13.1",
Expand All @@ -39,7 +34,7 @@
"eslint-plugin-nuxt": "^2.0.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.7.0",
"husky": "^4.3.8",
"husky": "^6.0.0",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"stylelint": "^13.12.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/create-nuxt-app/lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ module.exports = [
choices: [
{ name: 'jsconfig.json (Recommended for VS Code if you\'re not using typescript)', value: 'jsconfig.json' },
{ name: 'Semantic Pull Requests', value: 'semantic-pull-requests' },
{ name: 'Dependabot (For auto-updating dependencies, GitHub only)', value: 'dependabot' }
{ name: 'Dependabot (For auto-updating dependencies, GitHub only)', value: 'dependabot' },
{ name: 'Git Hooks (via husky)', value: 'husky' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure if this is a good idea as actually we’re using husky only for lint in git but not provide any other special hooks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use git-notify internally at GeoSpoc, and I thought adding husky as a devtool choice would provide devs with much more flexibility than just using husky for performing lint or test checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally leave it upto you & the Nuxt team to decide on the approach, I'm just happy I get to contribute :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think create-nuxt-app is more a nuxt template generater instead of generic application solution, so it makes sense to use lint-stage and husky to run vue and nuxt lint rules. And having hubsky as separeted may have some confilcts like:

  • Select lint-stage/commitlint but not husky
  • Select husky but not lint-stage/commitlint which is just adding husky as dep but no usage at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielroe What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clarkdo I tend to agree with you. Anyway, it's a separate question from upgrading Husky to v6. Maybe merge #765 and then make this PR about reconsidering role of Husky?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielroe We could, but current pr is adding husky as a new selection Git Hooks (via husky)

Copy link
Member

@danielroe danielroe Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant merge the previous PR #715 and then make this one about reconsidering the role of Husky. Your call though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinayakkulkarni Original pr has been merged, can you please update the pr add title ?

],
default: []
},
Expand Down
12 changes: 12 additions & 0 deletions packages/create-nuxt-app/lib/saofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
const lintStaged = eslint && this.answers.linter.includes('lintStaged')
const stylelint = this.answers.linter.includes('stylelint')
const commitlint = this.answers.linter.includes('commitlint')
const husky = this.answers.devTools.includes('husky')
const axios = this.answers.features.includes('axios')
const content = this.answers.features.includes('content')
const pm = this.answers.pm === 'yarn' ? 'yarn' : 'npm'
Expand All @@ -33,6 +34,7 @@ module.exports = {
lintStaged,
stylelint,
commitlint,
husky,
axios,
edge,
pm,
Expand Down Expand Up @@ -85,6 +87,16 @@ module.exports = {
})
}

if (this.answers.devTools && this.answers.devTools !== 'none') {
this.answers.devTools.forEach((tool) => {
actions.push({
type: 'add',
files: '**',
templateDir: join(frameworksDir, tool)
})
})
}

actions.push({
type: 'add',
files: '*',
Expand Down
112 changes: 103 additions & 9 deletions packages/create-nuxt-app/test/snapshots/index.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,99 @@ Generated by [AVA](https://avajs.dev).
}␊
`

## verify devTools: Git Hooks (via husky)

> Generated files

[
'.editorconfig',
'.gitignore',
'.husky/.gitignore',
'.husky/_/husky.sh',
'.husky/commit-msg',
'.husky/pre-commit',
'.husky/pre-push',
'README.md',
'assets/README.md',
'components/Logo.vue',
'components/README.md',
'layouts/README.md',
'layouts/default.vue',
'middleware/README.md',
'nuxt.config.js',
'package.json',
'pages/README.md',
'pages/index.vue',
'plugins/README.md',
'static/README.md',
'static/favicon.ico',
'store/README.md',
]

> package.json

{
dependencies: {
'core-js': '^3.9.1',
nuxt: '^2.15.3',
},
devDependencies: {
husky: '^6.0.0',
},
private: true,
scripts: {
build: 'nuxt build',
dev: 'nuxt',
generate: 'nuxt generate',
prepare: 'husky install',
start: 'nuxt start',
},
}

> Generated nuxt.config.js

`export default {␊
// Global page headers: https://go.nuxtjs.dev/config-head␊
head: {␊
title: 'output',␊
htmlAttrs: {␊
lang: 'en'␊
},␊
meta: [␊
{ charset: 'utf-8' },␊
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
{ hid: 'description', name: 'description', content: '' }␊
],␊
link: [␊
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
]␊
},␊
// Global CSS: https://go.nuxtjs.dev/config-css␊
css: [␊
],␊
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins␊
plugins: [␊
],␊
// Auto import components: https://go.nuxtjs.dev/config-components␊
components: true,␊
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules␊
buildModules: [␊
],␊
// Modules: https://go.nuxtjs.dev/config-modules␊
modules: [␊
],␊
// Build Configuration: https://go.nuxtjs.dev/config-build␊
build: {␊
}␊
}␊
`

## verify devTools: Semantic Pull Requests

> Generated files
Expand Down Expand Up @@ -687,7 +780,7 @@ Generated by [AVA](https://avajs.dev).
}␊
`

## verify devTools: jsconfig.json (Recommended for VS Code if you're not using typescript), Semantic Pull Requests, Dependabot (For auto-updating dependencies, GitHub only)
## verify devTools: jsconfig.json (Recommended for VS Code if you're not using typescript), Semantic Pull Requests, Dependabot (For auto-updating dependencies, GitHub only), Git Hooks (via husky)

> Generated files

Expand All @@ -696,6 +789,11 @@ Generated by [AVA](https://avajs.dev).
'.github/dependabot.yml',
'.github/semantic.yml',
'.gitignore',
'.husky/.gitignore',
'.husky/_/husky.sh',
'.husky/commit-msg',
'.husky/pre-commit',
'.husky/pre-push',
'README.md',
'assets/README.md',
'components/Logo.vue',
Expand All @@ -721,12 +819,15 @@ Generated by [AVA](https://avajs.dev).
'core-js': '^3.9.1',
nuxt: '^2.15.3',
},
devDependencies: {},
devDependencies: {
husky: '^6.0.0',
},
private: true,
scripts: {
build: 'nuxt build',
dev: 'nuxt',
generate: 'nuxt generate',
prepare: 'husky install',
start: 'nuxt start',
},
}
Expand Down Expand Up @@ -1566,19 +1667,12 @@ Generated by [AVA](https://avajs.dev).
'eslint-plugin-nuxt': '^2.0.0',
'eslint-plugin-prettier': '^3.3.1',
'eslint-plugin-vue': '^7.7.0',
husky: '^4.3.8',
'lint-staged': '^10.5.4',
prettier: '^2.2.1',
stylelint: '^13.12.0',
'stylelint-config-prettier': '^8.0.2',
'stylelint-config-standard': '^21.0.0',
},
husky: {
hooks: {
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
'pre-commit': 'lint-staged',
},
},
'lint-staged': {
'*.{css,vue}': 'stylelint',
'*.{js,vue}': 'eslint',
Expand Down
Binary file modified packages/create-nuxt-app/test/snapshots/index.test.js.snap
Binary file not shown.