cz-cli icon indicating copy to clipboard operation
cz-cli copied to clipboard

Provide easier access to commitizen config to prompters

Open ThisIsMissEm opened this issue 5 years ago • 2 comments

Currently when writing a prompter, e.g., cz-conventional-commit, if you wish to integrate with commitizen configuration then you need to do the following:

var configLoader = require('commitizen').configLoader;
configLoader.load() // synchronous, not a promise

I think it'd be nicer to actually have commitizen inject said configuration into prompters, e.g.,

module.exports = {
  prompter: function myAdapter(inquirer, config, commit) {
  }
}

This would remove the backwards dependency from prompters to commitizen, and reduce the need to test that config actually was loaded correctly when testing prompters, and allow for standardised configuration between all prompters. It could also be done in a backwards compatible manner by checking the length of the prompter function (that tells you how many arguments it expects)

ThisIsMissEm avatar Jul 28 '20 23:07 ThisIsMissEm

I agree. I think this is a good idea. It'd be a breaking change but certainly would be an improvement.

jimthedev avatar Aug 31 '20 14:08 jimthedev

@jimthedev I don't think it'd be a breaking change, as you can check if the prompter function has an arity of 2 or 3, by using function#length, e.g.,

function current(cz, commit) { }
function proposed(inquirer, config, commit) { }

console.log(current.length == 2)
console.log(proposed.length == 3)

Allowing you to switch between the previous API and the new one.

ThisIsMissEm avatar Sep 01 '20 09:09 ThisIsMissEm