conventional-changelog-archived-repos / validate-commit-msg

DEPRECATED. Use https://github.com/marionebl/commitlint instead. githook to validate commit messages are up to standard
http://conventionalcommits.org/
MIT License
556 stars 101 forks source link

Fallback to finding config in same folder as node modules #25

Closed Pajn closed 6 years ago

Pajn commented 8 years ago

We have multiple projects in a single repository, I placed a package.json in the root which runs installs this package, but as it checks for a config in the cwd rather than the package.json it's installed from I can't set any config.

Something like this

function getConfig() {
  var pkgFile = findup.sync(process.cwd(), 'package.json');
  var pkg = JSON.parse(fs.readFileSync(resolve(pkgFile, 'package.json')));

  if (pkg && pkg.config && pkg.config['validate-commit-msg']) {
    return pkg.config['validate-commit-msg'];
  }

  var fallbackPath = resolve(__dirname, '..', '..', 'package.json');
  try {
    fs.accessSync(fallbackPath, fs.R_OK);
    pkg = JSON.parse(fs.readFileSync(fallbackPath));
    return pkg && pkg.config && pkg.config['validate-commit-msg'] || {};
  } catch {
    return {};
  }
}
kentcdodds commented 8 years ago

Makes sense. I'd actually like to allow for configuring this with an rc file like .validate-commit-msgrc or something like that... Either way, I'd be interested to see a PR for this :+1:

spirosikmd commented 7 years ago

@kentcdodds I like your idea using an rc file. I was thinking we could support .vcmrc, and package.json. In the order that if rc is not present, then package.json is used. What do you think?

kentcdodds commented 7 years ago

Sounds great to me!

spirosikmd commented 7 years ago

Ok great! I will take a look and submit a PR.

stevemao commented 7 years ago

What about using https://www.npmjs.com/package/cosmiconfig?

hutson commented 6 years ago

This package has been deprecated. Please use https://github.com/marionebl/commitlint instead.