Skip to content

Commit

Permalink
feat: 🎸 add ability to support writing new scopes during commit
Browse files Browse the repository at this point in the history
  • Loading branch information
StanLindsey committed Apr 29, 2020
1 parent de9128d commit 1345146
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Below is default config:

```js
module.exports = {
enableWritingScopes: false,
"disableEmoji": false,
"list": [
"test",
Expand Down Expand Up @@ -203,6 +204,9 @@ Must be one of the following:
- `ci` — CI related changes
- `perf` — A code change that improves performance

### Scopes
The scope is the scope of changes on the component you are working on. E.g. "Controllers", "API" etc.
By default this list and you must add scopes to the ist. If `enableWritingScopes:true` is set you can input a custom scope during commiting.

### Subject

Expand Down
1 change: 1 addition & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const questions = [
module.exports = {
breakingChangePrefix: '🧨 ',
closedIssuePrefix: '✅ ',
enableWritingScopes: false,
list,
maxMessageLength: 64,
minMessageLength: 3,
Expand Down
27 changes: 19 additions & 8 deletions lib/questions/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@ const findScope = function (substring, scopes) {
};

exports.createQuestion = (state) => {
const {scopes} = state.config;
const {enableWritingScopes, scopes} = state.config;

if (!scopes) {
return null;
}
if (!enableWritingScopes) {
if (!scopes) {
return null;
}

if (!Array.isArray(scopes) && !enableWritingScopes) {
throw new TypeError('scopes must be an array of strings.');
}

if (!Array.isArray(scopes)) {
throw new TypeError('scopes must be an array of strings.');
if (scopes.length < 1) {
return null;
}
}

if (scopes.length < 1) {
return null;
if (!scopes || scopes.length < 1) {
return {
message: 'What scope does this component affect:\n',
name: 'scope',
type: 'input'
};
}

const question = {
maxLength: 8,
message: 'Select the scope this component affects:',
name: 'scope',
source: (_answers, input) => findScope(input, scopes),
Expand Down

0 comments on commit 1345146

Please sign in to comment.