diff --git a/package.json b/package.json index 8f11afcef..6954a0334 100644 --- a/package.json +++ b/package.json @@ -149,6 +149,7 @@ "cross-env": "^7.0.0", "css-loader": "^5.0.0", "css-minimizer-webpack-plugin": "^3.0.0", + "cz-git": "^1.3.8", "date-fns": "^2.24.0", "diacritics": "^1.3.0", "docsearch.js": "^2.6.3", @@ -298,5 +299,11 @@ "tags": "vetur/tags.json", "attributes": "vetur/attributes.json" }, + "config": { + "commitizen": { + "path": "node_modules/cz-git", + "czConfig": "./scripts/commitizen.js" + } + }, "web-types": "vetur/web-types.json" } diff --git a/scripts/commitizen.js b/scripts/commitizen.js new file mode 100644 index 000000000..a5f9b82e4 --- /dev/null +++ b/scripts/commitizen.js @@ -0,0 +1,25 @@ +'use strict'; + +const { execSync } = require('child_process'); +const fg = require('fast-glob'); + +const components = fg.sync('*', { cwd: 'components', onlyDirectories: true }); +// precomputed scope +const scopeComplete = execSync('git status --porcelain || true') + .toString() + .trim() + .split('\n') + .find(r => ~r.indexOf('M ')) + ?.replace(/(\/)/g, '%%') + ?.match(/components%%((\w|-)*)/)?.[1]; + +/** @type {import('cz-git').CommitizenGitOptions} */ +module.exports = { + scopes: ['site', 'util', 'script', 'tool', ...components], + scopeFilters: ['__tests__', '_util'], + customScopesAlign: !scopeComplete ? 'top' : 'bottom', + defaultScope: scopeComplete, + maxHeaderLength: 100, + allowEmptyIssuePrefixs: false, + allowCustomIssuePrefixs: false, +};