Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): add support for custom scopes option #216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,36 @@ Like commitizen, you specify the configuration of cz-conventional-changelog thro
"title": "Features"
},
...
}
},
"scopes": {}
}
}
// ...
}
```

#### Custom Scopes

Following the example for custom types, you can build custom scopes in the package.json's `config.commitizen` key.

```json5
{
// ...
"config": {
"commitizen": {
"scopes": {
...
"config": {
"description": "A configuration level change",
"title": "Configuration"
},
...
}
}
}
}
```

### Environment variables

The following environment variables can be used to override any default configuration or package.json based configuration.
Expand Down
31 changes: 19 additions & 12 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ var filterSubject = function(subject, disableSubjectLowerCase) {
return subject;
};

var mapToInquirerChoices = function (definitions) {
var maxLength = longest(Object.keys(definitions)).length + 1;
return map(definitions, function (definition, key) {
return {
name: (key + ':').padEnd(maxLength) + ' ' + definition.description,
value: key,
}
});
};

// This can be any kind of SystemJS compatible module.
// We use Commonjs here, but ES6 or AMD would do just
// fine.
module.exports = function(options) {
var types = options.types;

var length = longest(Object.keys(types)).length + 1;
var choices = map(types, function(type, key) {
return {
name: (key + ':').padEnd(length) + ' ' + type.description,
value: key
};
});

var isUsingCustomScopes = options.scopes && Object.keys(options.scopes).length > 0;
return {
// When a user runs `git cz`, prompter will
// be executed. We pass you cz, which currently
Expand All @@ -72,10 +73,16 @@ module.exports = function(options) {
type: 'list',
name: 'type',
message: "Select the type of change that you're committing:",
choices: choices,
choices: mapToInquirerChoices(options.types),
default: options.defaultType
},
{
isUsingCustomScopes ? {
type: 'list',
name: 'scope',
message: "Select the scope of the change that you're committing:",
choices: mapToInquirerChoices(options.scopes),
default: options.defaultScope
} : {
type: 'input',
name: 'scope',
message:
Expand Down
15 changes: 15 additions & 0 deletions engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ describe('prompts', function() {
});
});

describe('scope', function () {
it('commit scope prompts with input when scopes option is undefined', function () {
expect(getQuestion('scope', { types })).to.have.property('type', 'input');
});
it('commit scope prompts with list when scopes option is defined', function () {
var scopes = {
config: {
description: 'Configuration',
title: 'Configuration',
}
};
expect(getQuestion('scope', { types, scopes })).to.have.property('type', 'list');
});
});

describe('transformation', function() {
it('subject w/ character count', () =>
expect(
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var options = {
(process.env.CZ_MAX_LINE_WIDTH &&
parseInt(process.env.CZ_MAX_LINE_WIDTH)) ||
config.maxLineWidth ||
100
100,
scopes: config.scopes || {}
};

(function(options) {
Expand Down
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,21 @@
},
"config": {
"commitizen": {
"path": "./index.js"
"path": "./index.js",
"scopes": {
"deps": {
"description": "Depedency changes",
"title": "Dependencies"
},
"engine": {
"description": "Engine-level changes",
"title": "Engine"
},
"readme": {
"description": "README changes",
"title": "README"
}
}
}
}
}