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

Local config

Open JulioC opened this issue 8 years ago • 5 comments

Hello @carloscuesta!

Currently I couldn't find a way to set the config specific for a project or based on command line flags.

It would be useful to have that so one could create standard settings for a given project, across all users.

JulioC avatar Jul 18 '17 03:07 JulioC

+1 And it would be great to have the config automatically loaded from a file as for other projects, loading as per usual order of preferences :

  • /Home/.gitmoji
  • any of gitmoji.conf.js, .gitmojirc.js, .gitmojirc.json or .gitmojirc.yml located in the project directory
  • gitmoji field in package.json
  • command line arguments

romain-gsr avatar Jun 24 '18 05:06 romain-gsr

Here is a potential (but not perfect) implementation which works : Let's say we had a some new load.js where configuration gets inherited and merged.

const config = require('./config')
const constants = require('./constants')
const nconf = require('nconf')
const nconf_yaml = require('nconf-yaml')
const path = require('path')
const keys = ['signedCommit']
const getConfig = () => {
  const store = {}
  if (config.getAutoAdd()) store[constants.AUTO_ADD] = config.getAutoAdd()
  if (config.getSignedCommit()) store[constants.SIGNED_COMMIT] = config.getSignedCommit()
  if (config.getEmojiFormat()) store[constants.EMOJI_FORMAT] = config.getEmojiFormat()
  if (config.getIssueFormat()) store[constants.ISSUE_FORMAT] = config.getIssueFormat()
  return store
}
module.exports = () => {
  nconf.argv({ parseValues: true, transform: object => keys.includes(object.key) ? object : false })
  nconf.file('package.json', { file: path.resolve(process.cwd(), 'package.json') })
  .any(['gitmoji'], function(err, value) {
    if (value) nconf.add('package.json', { type: 'literal', store: value, parseValues: true })
    else nconf.add('package.json', { type: 'literal', store: {} })
  })
  nconf.file('gitmoji.conf.js', { file: path.resolve(process.cwd(), 'gitmoji.conf.js'), parseValues: true })
  nconf.file('.gitmojirc.js', { file: path.resolve(process.cwd(), '.gitmojirc.js'), parseValues: true })
  nconf.file('.gitmojirc.yml', { file: path.resolve(process.cwd(), '.gitmojirc.yml'), format: nconf_yaml, parseValues: true })
  nconf.file('.gitmojirc.json', { file: path.resolve(process.cwd(), '.gitmojirc.json'), parseValues: true })
  nconf.add('config', { type: 'literal', store: getConfig(), parseValues: true })
  return nconf.load()
}

Realized afterwards that it could even be better using cosmiconfig.

romain-gsr avatar Jun 24 '18 10:06 romain-gsr

Gave this one a shot, progress can be found here. Not really happy about it, as detecting the current git repository is done async, hence retrieving config from configurationVault becomes async changing the interface it exposes.

In my attempt I assumed that it would be undesirable to use another library for config handling, as this would either require supporting migrations from the old to the new one, or running them side-by-side causing an increase in complexity.

Right now it lacks:

  • [ ] Indication whether local configuration files are used*
  • [ ] Support for enabling/disabling local config from the CLI**

Alternatively of storing the config in the .git folder, I was thinking about adding all local config in the global configuration and storing some identifier/token in the pre-commit hook. But that would not work for a direct gitmoji -c invocation.

Anyway, I am not sure if this is the way to go, or if it is better to wait for top-level awaits to land and use that. Now a relatively small feature has quite some impact on the overall code base 😒.

For now, not having this feature is not really a deal-breaker for me, there's only one project where the scope prompt would be nice, everything else just uses the global config.

*Had this in a previous version, where I exposed an additional function configurationVault:isLocal which printed whether you are using local config when invoking gitmoji --config.

**For now, this needs to be done manually by initializing the local config yourself, e.g. run this in the root of your Git project:

echo '{"autoAdd": true, "emojiFormat": "emoji", "signedCommit": false, "scopePrompt": false}' > .git/.gitmoji/config.json

Addono avatar Jan 05 '20 10:01 Addono

This is a great idea! I'm not sure if it's really valuable for the cli since we do not have a lot of configuration options however I think it's not that difficult to implement.

Priorities for configuration should be obtained from:

  • gitmoji -g config params
  • gitmojirc local file (not using .dotfile format)
  • gitmoji field on a package.json

carloscuesta avatar Aug 25 '20 14:08 carloscuesta

Minimal support https://github.com/carloscuesta/gitmoji-cli/pull/679

ooga avatar Sep 10 '21 08:09 ooga

👋🏼 Hello everyone

I implemented this in #901, from [email protected] you'll be able to specify the configuration parameters through the package.json, a .gitmojirc.json file or the cli options:

Read more about this in the docs: https://github.com/carloscuesta/gitmoji-cli#config

carloscuesta avatar Aug 20 '22 10:08 carloscuesta