Skip to content

Commit b1c8800

Browse files
committed
build(package): Install git hook
1 parent be7615f commit b1c8800

File tree

7 files changed

+113
-11
lines changed

7 files changed

+113
-11
lines changed

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no -- commitlint --edit $1

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged && npm run lint && npm run test && npm run build

commitlint.config.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const commitlintConfig = {
2+
extends: ["@commitlint/config-conventional"],
3+
rules: {
4+
"type-enum": [
5+
2,
6+
"always",
7+
["feat", "fix", "build", "chore", "ci", "docs", "style", "refactor", "perf", "test"],
8+
],
9+
"scope-empty": [2, "never"],
10+
"subject-case": [2, "always", ["sentence-case"]],
11+
},
12+
}
13+
14+
module.exports = commitlintConfig

cz.config.cjs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { definePrompt } = require("cz-git")
2+
3+
module.exports = definePrompt({
4+
alias: { fd: "docs: fix typos" },
5+
messages: {
6+
type: "Select the type of change that you're committing:",
7+
scope: "Denote the SCOPE of this change (optional):",
8+
customScope: "Denote the SCOPE of this change:",
9+
subject: "Write a SHORT, IMPERATIVE tense description of the change:\n",
10+
body: "Provide a LONGER description of the change (optional). Use "|" to break new line:\n",
11+
breaking: "List any BREAKING CHANGES (optional). Use "|" to break new line:\n",
12+
footerPrefixesSelect: "Select the ISSUES type of changeList by this change (optional):",
13+
customFooterPrefix: "Input ISSUES prefix:",
14+
footer: "List any ISSUES by this change. E.g.: #31, #34:\n",
15+
generatingByAI: "Generating your AI commit subject...",
16+
generatedSelectByAI: "Select suitable subject by AI generated:",
17+
confirmCommit: "Are you sure you want to proceed with the commit above?",
18+
},
19+
types: [
20+
{ value: "feat", name: "feat: A new feature", emoji: ":sparkles:" },
21+
{ value: "fix", name: "fix: A bug fix", emoji: ":bug:" },
22+
{ value: "docs", name: "docs: Documentation only changes", emoji: ":memo:" },
23+
{ value: "style", name: "style: Changes that do not affect the meaning of the code", emoji: ":lipstick:" },
24+
{ value: "refactor", name: "refactor: A code change that neither fixes a bug nor adds a feature", emoji: ":recycle:" },
25+
{ value: "perf", name: "perf: A code change that improves performance", emoji: ":zap:" },
26+
{ value: "test", name: "test: Adding missing tests or correcting existing tests", emoji: ":white_check_mark:" },
27+
{ value: "build", name: "build: Changes that affect the build system or external dependencies", emoji: ":package:" },
28+
{ value: "ci", name: "ci: Changes to our CI configuration files and scripts", emoji: ":ferris_wheel:" },
29+
{ value: "chore", name: "chore: Other changes that don\"t modify src or test files", emoji: ":hammer:" },
30+
{ value: "revert", name: "revert: Reverts a previous commit", emoji: ":rewind:" },
31+
],
32+
useEmoji: false,
33+
emojiAlign: "center",
34+
useAI: false,
35+
aiNumber: 1,
36+
themeColorCode: "",
37+
scopes: [],
38+
allowCustomScopes: true,
39+
allowEmptyScopes: false,
40+
customScopesAlign: "bottom",
41+
customScopesAlias: "custom",
42+
emptyScopesAlias: "empty",
43+
upperCaseSubject: null,
44+
markBreakingChangeMode: false,
45+
allowBreakingChanges: ["feat", "fix"],
46+
breaklineNumber: 100,
47+
breaklineChar: "|",
48+
skipQuestions: ["body", "footer"],
49+
issuePrefixes: [{ value: "closed", name: "closed: ISSUES has been processed" }],
50+
customIssuePrefixAlign: "top",
51+
emptyIssuePrefixAlias: "skip",
52+
customIssuePrefixAlias: "custom",
53+
allowCustomIssuePrefix: true,
54+
allowEmptyIssuePrefix: true,
55+
confirmColorize: true,
56+
maxHeaderLength: Infinity,
57+
maxSubjectLength: Infinity,
58+
minSubjectLength: 0,
59+
scopeOverrides: undefined,
60+
defaultBody: "",
61+
defaultIssues: "",
62+
defaultScope: "",
63+
defaultSubject: "",
64+
})
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// eslint.config.js
2-
import parser from "@typescript-eslint/parser";
3-
import eslintPlugin from "@typescript-eslint/eslint-plugin";
4-
import stylistic from "@stylistic/eslint-plugin"
1+
const parser = require("@typescript-eslint/parser");
2+
const eslintPlugin = require("@typescript-eslint/eslint-plugin");
3+
const stylistic = require("@stylistic/eslint-plugin");
54

6-
export default [
5+
const eslintConfig = [
76
{
87
files: ["**/*.ts", "**/*.tsx"],
98
languageOptions: {
@@ -20,17 +19,20 @@ export default [
2019
},
2120
rules: {
2221
...eslintPlugin.configs.recommended.rules,
23-
"@stylistic/comma-spacing": ["error", { "before": false, "after": true }],
22+
"@stylistic/comma-spacing": ["error", { before: false, after: true }],
2423
"@stylistic/indent": ["error", 4],
2524
"@stylistic/key-spacing": ["error"],
2625
"@stylistic/space-before-blocks": "error",
2726
"@stylistic/quotes": ["error", "double"],
2827
"@stylistic/no-multi-spaces": "error",
2928
"@stylistic/no-trailing-spaces": "error",
3029
"@stylistic/semi": ["error", "never"],
31-
"@stylistic/space-before-function-paren": ["error", {
32-
"asyncArrow": "ignore"
33-
}],
30+
"@stylistic/space-before-function-paren": [
31+
"error",
32+
{ asyncArrow: "ignore" },
33+
],
3434
},
3535
},
3636
];
37+
38+
module.exports = eslintConfig;

lint-staged.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'**/*.{js,ts,tsx}': ['eslint src/ --ext .ts']
3+
};

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"main": "dist/index.js",
55
"scripts": {
66
"lint": "npx eslint src/ --ext .ts",
7+
"commit": "git-cz",
78
"build": "tsc",
89
"test": "jest --coverage",
9-
"clean": "rm -rf node_modules && rm package-lock.json && npm cache clean --force && npm install"
10+
"clean": "rm -rf node_modules && rm package-lock.json && npm cache clean --force && npm install",
11+
"prepare": "husky"
1012
},
1113
"files": [
1214
"dist/",
@@ -20,7 +22,10 @@
2022
"keywords": [
2123
"commitlint",
2224
"commitlintplugin",
23-
"commitlint-plugin"
25+
"commitlint-plugin",
26+
"scope",
27+
"pattern",
28+
"scope-pattern"
2429
],
2530
"author": "Ahmad Yulia Rizqy Fahmi <https://github.com/rizqyfahmi>",
2631
"license": "MIT",
@@ -33,6 +38,8 @@
3338
"homepage": "https://github.com/rizqyfahmi/commitlint-plugin-prevenger#readme",
3439
"description": "A Commitlint plugin that is containing some toolkits for checking the commit message",
3540
"devDependencies": {
41+
"@commitlint/cli": "^19.8.1",
42+
"@commitlint/config-conventional": "^19.8.1",
3643
"@commitlint/types": "^19.8.1",
3744
"@eslint/eslintrc": "^3.3.1",
3845
"@semantic-release/changelog": "^6.0.3",
@@ -46,11 +53,21 @@
4653
"@types/jest": "^30.0.0",
4754
"@typescript-eslint/eslint-plugin": "^8.37.0",
4855
"@typescript-eslint/parser": "^8.37.0",
56+
"commitizen": "^4.3.1",
57+
"cz-conventional-changelog": "^3.3.0",
58+
"cz-git": "^1.12.0",
4959
"eslint": "^9.31.0",
60+
"husky": "^9.1.7",
5061
"jest": "^29.7.0",
62+
"lint-staged": "^16.1.2",
5163
"semantic-release": "^24.2.7",
5264
"ts-jest": "^29.4.0",
5365
"ts-node": "^10.9.2",
5466
"typescript": "^5.8.3"
67+
},
68+
"config": {
69+
"commitizen": {
70+
"path": "./node_modules/cz-git"
71+
}
5572
}
5673
}

0 commit comments

Comments
 (0)