Skip to content

Commit

Permalink
major: next major, resolves #69 (#70)
Browse files Browse the repository at this point in the history
Monorepo support. 
Part of standard-release/cli#1 and
standard-release/app#25
 
resolves #69.
  • Loading branch information
Charlike Mike Reagent authored Jan 31, 2019
1 parent 249f9a9 commit cae0822
Show file tree
Hide file tree
Showing 10 changed files with 1,221 additions and 664 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
command: yarn run build || echo "No build step."
- run:
name: Releasing and publishing
command: yarn run release || (yarn global add @tunnckocore/release-cli && yarn run release)
command: yarn run release || (yarn global add new-release@4 && yarn run release)

workflows:
version: 2
Expand Down
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
'use strict';

module.exports = require('@tunnckocore/config/eslint');
module.exports = {
extends: 'tunnckocore',
rules: {
'jest/expect-expect': 'off',
},
};
14 changes: 9 additions & 5 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "./node_modules/@tunnckocore/config/nyc.json",
"exclude": [
"test",
"src/semver-inc/**/*"
]
"statements": 0,
"branches": 0,
"functions": 0,
"lines": 0,
"cache": true,
"check-coverage": true,
"reporter": ["lcov", "text"],
"include": ["src/**/*.js"],
"exclude": ["test", "src/semver-inc/**/*"]
}
35 changes: 34 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
'use strict';

module.exports = require('@tunnckocore/config/prettier');
module.exports = {
printWidth: 80,

// That actually is enforced by AirBnB Style anyway.
// Enforce 2 spaces, because JavaScript is always different
// then the rest of the languages.
tabWidth: 2,

// That actually is enforced by AirBnB Style anyway.
// Explicitness is the most important thing:
// - Always is visible that this is function (because the parens).
// - If you first write single param and decide to add new one,
// then you should also add a parens around the both - that's mess.
arrowParens: 'always',

// Enforce single-quotes, because industry standard.
singleQuote: true,

// That actually is enforced by AirBnB Style anyway.
// Always useful. And guaranteed that you won't see boring errors,
// that eats your time, because of nothing real.
trailingComma: 'all',

// That actually is enforced by AirBnB Style anyway.
// Enforce more clear object literals.
// As seen in this example https://github.com/airbnb/javascript#objects--rest-spread
bracketSpacing: true,

// That actually is enforced by AirBnB Style anyway.
// Enforcing bracket on the next line makes differentiate
// where ends the tag and its properties and where starts the content of the tag.
// https://prettier.io/docs/en/options.html#jsx-brackets
jsxBracketSameLine: false,
};
71 changes: 58 additions & 13 deletions .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,56 @@ _We highly recommend to use Yarn when you think to contribute to this project._
$ yarn add {%= name %}
```

## Monorepo support

For making it work on monorepo setups, you should pass `options.packages` - an array
of package names that are changes and a `options.cwd` - the root of the monorepo.
Usually this can be extracted from commit message or the response of `lerna changed`.

```js
import detectNextVersion from 'detect-next-version';

async function main() {
// e.g. /home/charlike/develop/some-monorepo
const cwd = process.cwd();

// try using `git-commits-since` for getting all commits
// it returns an object with `rawCommits` property
const commits = ['feat: foo bar', 'chore(ok): qux okey'];
const packages = ['@tunnckocore/qq5', 'foo-bar-baz-qux'];

const results = await detectNextVersion(commits, { packages, cwd });
console.log(results);

const [itemOne, itemTwo] = results;
console.log(itemOne.name); // => '@tunnckocore/qq5'
console.log(itemOne.path); // => '@tunnckocore/qq5'
console.log(itemOne.increment); // => 'minor'
console.log(itemOne.lastVersion); // => '0.1.0'
console.log(itemOne.nextVersion); // => '0.2.0'
console.log(itemOne.cwd); // => /home/charlike/develop/some-monorepo

console.log(itemTwo.name); // => 'foo-bar-baz-qux'
console.log(itemTwo.path); // => 'packages/foo-bar-baz-qux'
console.log(itemTwo.increment); // => 'minor'
console.log(itemTwo.lastVersion); // => '1.0.4'
console.log(itemTwo.nextVersion); // => '1.1.0'
console.log(itemTwo.cwd); // => /home/charlike/develop/some-monorepo
}

main().catch(console.error);
```

## API

<!-- docks-start -->

_Generated using [docks](http://npm.im/docks)._

### [src/index.js](/src/index.js)

#### [detectNextVersion](/src/index.js#L72)
#### [detectNextVersion](/src/index.js#L75)

Calculates next version of given package with `name`,
based given `commitMessages` which should follow
the [Conventional Commits Specification](https://www.conventionalcommits.org/).
Expand All @@ -73,16 +115,18 @@ returned result won't have `nextVersion` and `increment` will be `false`.
ProTip: See [parse-commit-message types](https://github.com/tunnckoCoreLabs/parse-commit-message#type-definitions) documentation!

**Params**
- `name` **{string}** a package name which you looking to update

- `commits` **{string|}** directly passed to [recommended-bump][]
May be one of `string`, `Array<string>` or `Array<Commit>`
May be one of `string`, `Array<string>` or `Array<Commit>`
- `[options]` **{object}** optional, passed to above mentioned packages.

**Returns**
- `object` an object which is basically the return of [recommended-bump][]
plus `{ pkg, lastVersion, nextVersion? }`.

- `Array<object>` an array of objects where each is basically the return of [recommended-bump][]
plus `{ pkg, name, cwd, path, lastVersion, nextVersion? }`.

**Examples**

```ts
type Commit = {
header: Header;
Expand All @@ -93,14 +137,15 @@ type Commit = {
mentions?: Array<Mention>;
};
```

```javascript
import detector from 'detect-next-version';

async function main() {
const commits = ['chore(ci): some build tweaks', 'fix(cli): foo bar'];

// consider `my-npm-package` is version 0.1.0
const result = await detector('my-npm-package', commits);
const [result] = await detector(commits, { name: 'my-npm-package' });
console.log(result.increment); // => 'patch'
console.log(result.pkg); // => package's latest package.json metadata
console.log(result.lastVersion); // => '0.1.0'
Expand All @@ -113,6 +158,7 @@ async function main() {

main().catch(console.error);
```

```javascript
import { parse } from 'parse-commit-message';
import detector from 'detect-next-version';
Expand All @@ -121,7 +167,11 @@ async function main() {
const commitOne = parse('fix: foo bar');
const commitTwo = parse('feat: some feature subject');

const result = await detector('@my-org/my-awesomepkg', [commitOne, commitTwo]);
// always an array, but we can destruct it here,
// because we know that it has only one item
const [result] = await detector([commitOne, commitTwo], {
name: '@my-org/my-awesomepkg',
});
console.log(result.increment); // => 'minor'
}

Expand Down Expand Up @@ -198,24 +248,20 @@ Released under the [Apache-2.0 License][license-url].

[ghrelease-url]: https://github.com/tunnckoCoreLabs/detect-next-version/releases/latest
[ghrelease-img]: https://badgen.net/github/release/tunnckoCoreLabs/detect-next-version?icon=github

[license-url]: https://github.com/tunnckoCoreLabs/detect-next-version/blob/master/LICENSE

[license-img]: https://badgen.net/npm/license/{%= name %}

<!-- Front line badges -->

[codestyle-url]: https://github.com/airbnb/javascript
[codestyle-img]: https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb

[linuxbuild-url]: https://circleci.com/gh/tunnckoCoreLabs/detect-next-version/tree/master
[linuxbuild-img]: https://badgen.net/circleci/github/tunnckoCoreLabs/detect-next-version/master?label=build&icon=circleci

[codecoverage-url]: https://codecov.io/gh/tunnckoCoreLabs/detect-next-version
[codecoverage-img]: https://badgen.net/codecov/c/github/tunnckoCoreLabs/detect-next-version?icon=codecov

[dependencies-url]: https://david-dm.org/tunnckoCoreLabs/detect-next-version
[dependencies-img]: https://badgen.net/david/dep/tunnckoCoreLabs/detect-next-version?label=deps

[ccommits-url]: https://conventionalcommits.org/
[ccommits-img]: https://badgen.net/badge/conventional%20commits/v1.0.0/dfb317
[new-release-url]: https://ghub.io/new-release
Expand All @@ -234,7 +280,6 @@ Released under the [Apache-2.0 License][license-url].
[patreon-url]: https://www.patreon.com/bePatron?u=5579781
[patreon-img]: https://badgen.net/badge/patreon/tunnckoCore/F96854?icon=patreon
[patreon-sponsor-img]: https://badgen.net/badge/become/a%20sponsor/F96854?icon=patreon

[shareu]: https://twitter.com/intent/tweet?text=https://github.com/tunnckoCoreLabs/detect-next-version&via=tunnckoCore
[shareb]: https://badgen.net/badge/twitter/share/1da1f2?icon=twitter
[open-issue-url]: https://github.com/tunnckoCoreLabs/detect-next-version/issues/new
Loading

0 comments on commit cae0822

Please sign in to comment.