|
| 1 | +// NOTE: need to keep types and scope consistent with commitlint.config.js |
| 2 | +// https://commitizen.github.io/cz-cli/ |
| 3 | +const types = [ |
| 4 | + { value: "feature", name: "feature: ✨ A new feature" }, |
| 5 | + { |
| 6 | + value: "enhancement", |
| 7 | + name: "enhancement: 💪 A code change that neither fixes a bug nor adds a feature", |
| 8 | + }, |
| 9 | + { value: "fix", name: "fix: 🐛 A bug fix" }, |
| 10 | + { value: "docs", name: "docs: 📚 Docs or guides content changes" }, |
| 11 | + { value: "content", name: "content: 📝 Copy only changes or blog posts" }, |
| 12 | + { value: "chore", name: "chore: 🛠 Other changes that don't modify src files" }, |
| 13 | + { value: "revert", name: "revert: 🗑 Reverts a previous commit" }, |
| 14 | +]; |
| 15 | + |
| 16 | +export default { |
| 17 | + prompter: async (cz, commit) => { |
| 18 | + const { type } = await cz.prompt([ |
| 19 | + { |
| 20 | + type: "list", |
| 21 | + name: "type", |
| 22 | + message: "Select the type of the change", |
| 23 | + choices: types, |
| 24 | + }, |
| 25 | + ]); |
| 26 | + |
| 27 | + const { subject } = await cz.prompt([ |
| 28 | + { |
| 29 | + type: "input", |
| 30 | + name: "subject", |
| 31 | + message: "Write a short, imperative description of the change", |
| 32 | + validate: (input) => { |
| 33 | + if (input.length === 0) { |
| 34 | + return "Subject is required"; |
| 35 | + } |
| 36 | + |
| 37 | + return true; |
| 38 | + }, |
| 39 | + }, |
| 40 | + ]); |
| 41 | + |
| 42 | + const { issue } = await cz.prompt([ |
| 43 | + { |
| 44 | + type: "input", |
| 45 | + name: "issue", |
| 46 | + message: "Enter the issue associated with this change (e.g. 123)", |
| 47 | + validate: (input) => { |
| 48 | + if (input.startsWith("#")) { |
| 49 | + return "Please do not include the #"; |
| 50 | + } |
| 51 | + |
| 52 | + return true; |
| 53 | + }, |
| 54 | + }, |
| 55 | + ]); |
| 56 | + |
| 57 | + const issueFormat = issue === "" ? "" : `#${issue} `; |
| 58 | + const message = `${type}: ${issueFormat}${subject}`; |
| 59 | + |
| 60 | + commit(message); |
| 61 | + }, |
| 62 | +}; |
0 commit comments