|
| 1 | +const chalk = require('chalk'); |
| 2 | +const spawn = require('cross-spawn'); |
| 3 | +const defaultConfig = require('cz-customizable'); |
| 4 | +const { getChangedPackages } = require('./utils'); |
| 5 | + |
| 6 | +const typesConfig = [ |
| 7 | + { value: 'feat', name: 'A new feature' }, |
| 8 | + { value: 'fix', name: 'A bug fix' }, |
| 9 | + { value: 'docs', name: 'Documentation only changes' }, |
| 10 | + { |
| 11 | + value: 'style', |
| 12 | + name: 'Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)', |
| 13 | + }, |
| 14 | + { |
| 15 | + value: 'refactor', |
| 16 | + name: 'A code change that neither fixes a bug nor adds a feature', |
| 17 | + }, |
| 18 | + { |
| 19 | + value: 'perf', |
| 20 | + name: 'A code change that improves performance', |
| 21 | + }, |
| 22 | + { value: 'test', name: 'Adding missing tests' }, |
| 23 | + { |
| 24 | + value: 'chore', |
| 25 | + name: 'Changes to the build process or auxiliary tools', |
| 26 | + }, |
| 27 | + { |
| 28 | + value: 'build', |
| 29 | + name: 'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)', |
| 30 | + }, |
| 31 | + { |
| 32 | + value: 'ci', |
| 33 | + name: 'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)', |
| 34 | + }, |
| 35 | + { |
| 36 | + value: 'revert', |
| 37 | + name: 'Reverts a previous commit', |
| 38 | + }, |
| 39 | +]; |
| 40 | + |
| 41 | +const { stdout = '' } = spawn.sync(`git diff --staged --name-only`, { |
| 42 | + shell: true, |
| 43 | + encoding: 'utf8', |
| 44 | + stdio: 'pipe', |
| 45 | +}); |
| 46 | +const changedFiles = stdout.split('\n').filter(Boolean); |
| 47 | +const changeSet = getChangedPackages(changedFiles); |
| 48 | + |
| 49 | +if (changeSet.size > 1) { |
| 50 | + process.stderr.write( |
| 51 | + `${[ |
| 52 | + chalk.yellow( |
| 53 | + `Multiple packages detected in current commit, please consider splitting into smaller commits`, |
| 54 | + ), |
| 55 | + ].join('\n')}\n`, |
| 56 | + ); |
| 57 | + |
| 58 | + changeSet.clear(); |
| 59 | + changeSet.add('multiple'); |
| 60 | +} |
| 61 | + |
| 62 | +const changedScopes = [...changeSet]; |
| 63 | + |
| 64 | +module.exports = { |
| 65 | + ...defaultConfig, |
| 66 | + types: typesConfig.map(({ value, name }) => { |
| 67 | + return { |
| 68 | + name: `${value}:${new Array(10 - value.length) |
| 69 | + .fill(' ') |
| 70 | + .join('')}${name}`, |
| 71 | + value, |
| 72 | + }; |
| 73 | + }), |
| 74 | + messages: { |
| 75 | + ...defaultConfig.messages, |
| 76 | + type: "Select the type of change that you're committing", |
| 77 | + scope: 'Ensure the scope of this change', |
| 78 | + subject: 'Write a short, imperative tense description of the change', |
| 79 | + body: 'Provide a longer description of the change. Use "|" to break new line:\n', |
| 80 | + breaking: 'List any BREAKING CHANGES (optional):\n', |
| 81 | + confirmCommit: 'Are you sure you want to proceed with the commit above?', |
| 82 | + }, |
| 83 | + scopes: changedScopes.join(','), |
| 84 | + allowCustomScopes: false, |
| 85 | + skipQuestions: ['customScope', 'footer', 'body'], |
| 86 | + allowBreakingChanges: ['feat', 'fix'], |
| 87 | +}; |
0 commit comments