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

Commit

Permalink
feat(template): update to husky v6 (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo authored Apr 2, 2021
1 parent 8c9b77d commit 5ee3feb
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 374 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@nuxtjs/eslint-config": "^6.0.0",
"ava": "^3.15.0",
"eslint": "^7.22.0",
"husky": "^5.1.3",
"husky": "^6.0.0",
"lerna": "^4.0.0",
"stylelint": "^13.12.0",
"stylelint-config-standard": "^21.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/cna-template/template/nuxt/.husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions packages/cna-template/template/nuxt/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

<%= pmRun %> commitlint --edit $1
4 changes: 4 additions & 0 deletions packages/cna-template/template/nuxt/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

<%= pmRun %> lint-staged
7 changes: 4 additions & 3 deletions packages/cna-template/template/nuxt/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,10 +51,13 @@ 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']
}
if (!lintStaged && !commitlint) {
delete pkg.devDependencies.husky
delete pkg.scripts.postinstall
}

const lintScript = Object.values(lintScripts).join(' && ')
if (lintScript) {
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",
"postinstall": "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
22 changes: 21 additions & 1 deletion packages/create-nuxt-app/lib/saofile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const { dirname, join, relative } = require('path')
const fs = require('fs')
const spawn = require('cross-spawn')
const validate = require('validate-npm-package-name')
const pkg = require('./package')

const cnaTemplateDir = join(dirname(require.resolve('cna-template/package.json')))
const templateDir = join(cnaTemplateDir, 'template')
const frameworksDir = join(templateDir, 'frameworks')
const addExecutable = filename => new Promise(
resolve => fs.chmod(filename, 0o755, resolve)
)

module.exports = {
prompts: require('./prompts'),
Expand Down Expand Up @@ -50,14 +54,22 @@ module.exports = {
})
validation.errors && validation.errors.length && process.exit(1)

const { linter } = this.answers
const eslint = linter.includes('eslint')
const lintStaged = eslint && linter.includes('lintStaged')
const commitlint = linter.includes('commitlint')

const actions = [{
type: 'add',
files: '**',
templateDir: join(templateDir, 'nuxt'),
filters: {
'static/icon.png': 'features.includes("pwa")',
'content/hello.md': 'features.includes("content")',
'pages/content.vue': 'features.includes("content")'
'pages/content.vue': 'features.includes("content")',
'.husky/.gitignore': lintStaged || commitlint,
'.husky/commit-msg': commitlint,
'.husky/pre-commit': lintStaged
}
}]

Expand Down Expand Up @@ -144,6 +156,14 @@ module.exports = {
this.gitInit()
}

const huskyDir = join(this.outDir, '.husky')
if (this.answers.linter.includes('lintStaged')) {
await addExecutable(join(huskyDir, 'pre-commit'))
}
if (this.answers.linter.includes('commitlint')) {
await addExecutable(join(huskyDir, 'commit-msg'))
}

await this.npmInstall({ npmClient: this.answers.pm })

if (this.answers.linter.includes('eslint')) {
Expand Down
Loading

0 comments on commit 5ee3feb

Please sign in to comment.