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: allows configuration of standard-version and submodules using package.json or a provided --config file #278

Conversation

jbottigliero
Copy link
Member

feat: allows configuration of standard-version and submodules using package.json or a provided --config fileackage.json or a provided --config file

see #169, #154

--

I threw together this POC based on comment I came across while looking into the next steps for basic customization in the conventional-changelog ecosystem.

Our team is currently using standard-version and we have been adhering to the angular preset for some time... we'd like to be able to swap this preset for our own, but continue to use standard-version.

I started this PR only supporting the standard-version key in package.json, but quickly saw the need for additional allowed types (whatBump in conventional-recommended-bump). This resulted in the addition of the --config flag.

Again, this is just a POC and I've only updated bump – would love to hear the current stance on this type of update!

Examples:

package.json : Basic standard-version Configuration

// package.json
  "standard-version": {
    "infile": "01-CHANGELOG.md"
  }
$ node bin/cli.js --dry-run 
✔ bumping version in package.json from 5.0.0 to 6.0.0
✔ created 01-CHANGELOG.md
✔ outputting changes to 01-CHANGELOG.md

---
...

package.json : standard-version "Module" Configuration

// package.json
  "standard-version": {
    "modules": {
      "conventional-recommended-bump": {
        "preset": "foobar"
      }
    }
  }
$ node bin/cli.js --dry-run 
Unable to load the "foobar" preset package. Please make sure it's installed.

--config : Custom Configuration*

// test.config.js


module.exports = {
  infile: `CHANGELOG-${new Date().valueOf()}.md`,
  'modules': {
    'conventional-recommended-bump': {
      whatBump: function (commit) {
        console.log('hello, world:', commit[0].subject);
      }
    }
  }
}
$ node bin/cli.js --dry-run --config=test.config.js 
hello, world: allows configuration of standard-version and submodules using package.json or a provided --config file
✔ bumping version in package.json from 5.0.0 to null
✔ created CHANGELOG-1542829185913.md
✔ outputting changes to CHANGELOG-1542829185913.md

---
...

@jbottigliero
Copy link
Member Author

jbottigliero commented Nov 21, 2018

It does look like this change causes some issues with the current test suite – I can continue to look into that if this seems like something that you would want to move forward with. This has been resolved.

Along with the Object.assign order... this seems wrong, but is required based on defaults coming from both ./defaults and in argv via ./command in this file.

@jbottigliero jbottigliero force-pushed the feat-configuration branch 2 times, most recently from 7b3cbaa to db70dc6 Compare November 22, 2018 07:21
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 99.74% when pulling a6a0109 on jbottigliero:feat-configuration into 844cde6 on conventional-changelog:master.

@coveralls
Copy link

coveralls commented Nov 22, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling a27ded2 on jbottigliero:feat-configuration into 387eaae on conventional-changelog:master.

@bcoe
Copy link
Member

bcoe commented Feb 14, 2019

@jbottigliero sorry for dropping this on the floor forever, this project is definitely in need of a couple more maintainers. If you'd still like to work on seeing this over the finish line, you can find me here:

http://devtoolscommunity.herokuapp.com/

It's a good place to prod me, and make sure that we're moving features forward.

@bcoe
Copy link
Member

bcoe commented Feb 19, 2019

@jbottigliero reading through your pull request a bit, I'm a strong 👍 on this functionality. I believe we might be able to use yargs directly for some of the feature set though, see:

https://github.com/yargs/yargs/blob/master/docs/api.md#configobject

https://github.com/yargs/yargs/blob/master/docs/api.md#pkgconfkey-cwd

and finally,

https://github.com/yargs/yargs/blob/master/docs/advanced.md#building-configurable-cli-apps

My goal with standard-version and nyc has been to use them as testing grounds to help drive development on yargs (the goal being to ensure yargs provides a lot of the functionality you'd commonly want in a CLI in an elegant way).

@bcoe
Copy link
Member

bcoe commented Feb 19, 2019

@jbottigliero please feel free to message me here to help coordinate landing this.

@jbottigliero
Copy link
Member Author

@bcoe – I've updated the PR to utilize yargs.config.

I'm still opting for a custom parseFn at the moment based on configuration properties allowing functions (ie. whatBump in conventional-recommended-bump) – let me know if I'm missing something in the yargs docs, but this seems like the best way to handle it.

I've also added a few tests for preset configuration cases. These should cover the new --preset flag and this configuration.

I'll catch up with you on chat, but here is what I'm thinking:

  • This PR:

    • Add test(s) for conventional-recommended-bump option(s)
    • Update documentation (README.md) to include --config
  • Follow-Up PR:

    • Move all pass-thru configurations to a default --config handled value.
    • Remove pass-thru configuration yargs params (ie. --preset)

@bcoe
Copy link
Member

bcoe commented Feb 20, 2019

@jbottigliero I'm happy with this compromise 👍

Looks like the tests failing are just a linting issue.

@jbottigliero
Copy link
Member Author

The tests should now pass, but I've run into a bit of a predicament around the best way to pass options to conventional-changelog(-core).

The "problem" is that preset is a special case configuration option that alters the configuration that is actually passed to conventional-changelog-core (https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog/index.js#L9-L11).

In my latest update, I'm passing along the options as both options and context to act as a sort of override...

It seems like the "right" answer might be to explicitly pass conventional-changelog-core options as context to conventional-changelog via (conventionalChangelog) requiring the configuration object to look something like:

{
  "standard-version": {
    "modules": {
      "conventional-changelog": {
        "preset": "@some/preset"
      },
      "conventional-changelog-core": {
        "host": "gitlab"
      }
    }
  }
}

Additionally, I'd guess that tagPrefix isn't working in some cases (in conjunction with a preset) based on how is currently being passed.

edit not passing on Node 6 due to the spread operator, I'll swap this for Object.assign based on a decision on direction.

@bcoe
Copy link
Member

bcoe commented Feb 22, 2019

@jbottigliero what's preventing us from the right solution right now, do we need to change the API surface in some of the dependent libraries? I don't think we should be shy about making any changes that you need in conventional-commits, we have the commit bit.

@jbottigliero
Copy link
Member Author

@bcoe – I think it's really just my understanding/expectation of how the configurations are actually being merged in conventional-changelog-core.

I've updated the PR to pass along conventional-changelog configuration as options and conventional-changelog-core configuration as context and added a few tests scenarios -- things are passing. But I think I need to read through the mergeOptions a bit more to feel confident in this solution.

Joe Bottigliero and others added 11 commits March 15, 2019 15:45
…e reference (package.json) is not augmented.
- The `changelog` lifecyle now passes along `conventional-changelog` configuration as `options` and `conventional-changelog-core` configuration as `context`.
- Updates the passing of configurations to lifecycles to be consistent (the entire `modules` object).
- Adds tests to cover `conventional-changelog-core` options, `--tagPrefix` and a few permutations.
@bcoe
Copy link
Member

bcoe commented Mar 16, 2019

@jbottigliero thanks for updating, I'll make an effort to start looking at some of the outstanding issues on standard-version soon (hopefully this weekend). There are a bunch of issues open related to making the library more easily configurable, I'll do my best to find a common thread between them all, and to start landing some patches.

@bcoe
Copy link
Member

bcoe commented Mar 16, 2019

@jbottigliero this is the conversation specifically on my mind:

#195 (comment)

I would like it to be easier to configure CHANGELOG generation and bump criteria, furthermore I'd like to move towards using a convention based on conventionalcommits.org.

@bcoe
Copy link
Member

bcoe commented Apr 10, 2019

@jbottigliero mind if I use this as a bases for adding in the new configurable conventionalcommits preset? or do you have the cycles to do so right now?

@jbottigliero
Copy link
Member Author

@bcoe – I should be able to make this switch!

@bcoe
Copy link
Member

bcoe commented Apr 10, 2019

@jbottigliero let me flag you on a PR with some thoughts I have, now that you've done work to standardize our config format, my preference would be that we load configuration from an rc file demonstrated here:

https://github.com/bcoe/c8/blob/master/lib/parse-args.js#L86

@bcoe bcoe closed this Apr 10, 2019
@bcoe
Copy link
Member

bcoe commented Apr 10, 2019

@jbottigliero only closed this momentarily, will have a new PR open in a sec we can collaborate on -- I have some thoughts about how we might use the spec you're writing.

@bcoe
Copy link
Member

bcoe commented Apr 10, 2019

@jbottigliero don't suppose I could convince you to join this slack:

http://devtoolscommunity.herokuapp.com/

so that we can coordinate work in real time?

@JounQin
Copy link

JounQin commented Jul 18, 2019

Any update on this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants