Skip to content

Commit

Permalink
feat: change to @favware/conventional-changelog-angular to solve issu…
Browse files Browse the repository at this point in the history
…e with breaking change headers
  • Loading branch information
favna committed Jan 8, 2023
1 parent dcc8bde commit 96c885b
Show file tree
Hide file tree
Showing 27 changed files with 971 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
@@ -0,0 +1,5 @@
CHANGELOG.md
.turbo
dist/
coverage/
conventional-changelog-angular-custom/
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -2,3 +2,4 @@ CHANGELOG.md
.turbo
dist/
coverage/
conventional-changelog-angular-custom/templates/
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Expand Up @@ -7,5 +7,7 @@ plugins:
spec: '@yarnpkg/plugin-interactive-tools'
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: '@yarnpkg/plugin-typescript'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'

yarnPath: .yarn/releases/yarn-3.3.1.cjs
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -21,8 +21,9 @@ the release flow for every package. This is where [cliff-jumper] comes in.
### How this works

[cliff-jumper] uses a combination of [conventional-recommended-bump] and
[git-cliff] to bump your package using semantic versioning (following the
[Angular preset][angular-preset]). It will:
[git-cliff] to bump your package using semantic versioning (following a
variation of the [Angular preset][angular-preset] (seen
[here][angular-preset-custom])). It will:

1. Perform preflight checks to verify that the tool can run
1. Resolve which bump strategy should be used by using
Expand Down Expand Up @@ -341,3 +342,4 @@ specification. Contributions of any kind welcome!
https://github.com/favware/esbuild-plugin-version-injector
[discordjs]:
https://github.com/discordjs/discord.js/tree/main/packages/discord.js
[angular-preset-custom]: ./conventional-changelog-angular-custom/
16 changes: 16 additions & 0 deletions conventional-changelog-angular-custom/LICENSE.md
@@ -0,0 +1,16 @@
### ISC License

Copyright ©
[conventional-changelog team](https://github.com/conventional-changelog)

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
128 changes: 128 additions & 0 deletions conventional-changelog-angular-custom/README.md
@@ -0,0 +1,128 @@
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]

> [conventional-changelog](https://github.com/ajoslin/conventional-changelog) >
> [angular](https://github.com/angular/angular) preset
**Issues with the convention itself should be reported on the Angular issue
tracker.**

## Angular Convention

Angular's
[commit message guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit).

### Examples

Appears under "Features" header, pencil subheader:

```
feat(pencil): add 'graphiteWidth' option
```

Appears under "Bug Fixes" header, graphite subheader, with a link to issue #28:

```
fix(graphite): stop graphite breaking when width < 0.1
Closes #28
```

Appears under "Performance Improvements" header, and under "Breaking Changes"
with the breaking change explanation:

```
perf(pencil): remove graphiteWidth option
BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reason.
```

The following commit and commit `667ecc1` do not appear in the changelog if they
are under the same release. If not, the revert commit appears under the
"Reverts" header.

```
revert: feat(pencil): add 'graphiteWidth' option
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
```

### Commit Message Format

A commit message consists of a **header**, **body** and **footer**. The header
has a **type**, **scope** and **subject**:

```
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```

The **header** is mandatory and the **scope** of the header is optional.

### Revert

If the commit reverts a previous commit, it should begin with `revert: `,
followed by the header of the reverted commit. In the body it should say:
`This reverts commit <hash>.`, where the hash is the SHA of the commit being
reverted.

### Type

If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog.
However if there is any [BREAKING CHANGE](#footer), the commit will always
appear in the changelog.

Other prefixes are up to your discretion. Suggested prefixes are `build`, `ci`,
`docs` ,`style`, `refactor`, and `test` for non-changelog related tasks.

Details regarding these types can be found in the official
[Angular Contributing Guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#type).

### Scope

The scope could be anything specifying place of the commit change. For example
`$location`, `$browser`, `$compile`, `$rootScope`, `ngHref`, `ngClick`,
`ngView`, etc...

### Subject

The subject contains succinct description of the change:

- use the imperative, present tense: "change" not "changed" nor "changes"
- don't capitalize first letter
- no dot (.) at the end

### Body

Just as in the **subject**, use the imperative, present tense: "change" not
"changed" nor "changes". The body should include the motivation for the change
and contrast this with previous behavior.

### Footer

The footer should contain any information about **Breaking Changes** and is also
the place to reference GitHub issues that this commit **Closes**.

**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space
or two newlines. The rest of the commit message is then used for this.

A detailed explanation can be found in this [document](#commit-message-format).

[npm-image]: https://badge.fury.io/js/conventional-changelog-angular.svg
[npm-url]: https://npmjs.org/package/conventional-changelog-angular
[travis-image]:
https://travis-ci.org/conventional-changelog/conventional-changelog-angular.svg?branch=master
[travis-url]:
https://travis-ci.org/conventional-changelog/conventional-changelog-angular
[daviddm-image]:
https://david-dm.org/conventional-changelog/conventional-changelog-angular.svg?theme=shields.io
[daviddm-url]:
https://david-dm.org/conventional-changelog/conventional-changelog-angular
[coveralls-image]:
https://coveralls.io/repos/conventional-changelog/conventional-changelog-angular/badge.svg
[coveralls-url]:
https://coveralls.io/r/conventional-changelog/conventional-changelog-angular
[commit-message-format]:
https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#
@@ -0,0 +1,9 @@
'use strict';

const Q = require('q');
const parserOpts = require('./parser-opts');
const writerOpts = require('./writer-opts');

module.exports = Q.all([parserOpts, writerOpts]).spread((parserOpts, writerOpts) => {
return { parserOpts, writerOpts };
});
@@ -0,0 +1,33 @@
'use strict';

const parserOpts = require('./parser-opts');

module.exports = {
parserOpts,

whatBump: (commits) => {
let level = 2;
let breakings = 0;
let features = 0;

commits.forEach((commit) => {
if (commit.notes.length > 0) {
breakings += commit.notes.length;
level = 0;
} else if (commit.type === 'feat') {
features += 1;
if (level === 2) {
level = 1;
}
}
});

return {
level: level,
reason:
breakings === 1
? `There is ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`
};
}
};
12 changes: 12 additions & 0 deletions conventional-changelog-angular-custom/index.js
@@ -0,0 +1,12 @@
'use strict';
const Q = require('q');
const conventionalChangelog = require('./conventional-changelog');
const parserOpts = require('./parser-opts');
const recommendedBumpOpts = require('./conventional-recommended-bump');
const writerOpts = require('./writer-opts');

module.exports = Q.all([conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts]).spread(
(conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => {
return { conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts };
}
);
41 changes: 41 additions & 0 deletions conventional-changelog-angular-custom/package.json
@@ -0,0 +1,41 @@
{
"name": "@favware/conventional-changelog-angular",
"version": "5.0.13",
"description": "conventional-changelog angular preset",
"main": "index.js",
"scripts": {
"test-windows": "mocha --timeout 30000",
"prepack": "node patches/custom-changes.patch",
"postpack": "node patches/restore-changes.patch"
},
"repository": {
"type": "git",
"url": "https://github.com/conventional-changelog/conventional-changelog.git"
},
"keywords": [
"conventional-changelog",
"angular",
"preset"
],
"files": [
"conventional-changelog.js",
"conventional-recommended-bump.js",
"index.js",
"parser-opts.js",
"writer-opts.js",
"templates"
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/conventional-changelog/conventional-changelog/issues"
},
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular#readme",
"dependencies": {
"compare-func": "^2.0.0",
"q": "^1.5.1"
}
}
9 changes: 9 additions & 0 deletions conventional-changelog-angular-custom/parser-opts.js
@@ -0,0 +1,9 @@
'use strict';

module.exports = {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE'],
revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i,
revertCorrespondence: ['header', 'hash']
};
15 changes: 15 additions & 0 deletions conventional-changelog-angular-custom/patches/custom-changes.js
@@ -0,0 +1,15 @@
const parserOpts = require('../parser-opts.js');
const { writeFileSync } = require('node:fs');
const { inspect } = require('node:util');
const { resolve } = require('node:path');

Reflect.set(parserOpts, 'breakingHeaderPattern', /^(\w*)(?:\((.*)\))?!: (.*)$/);

const pathToParserOpts = resolve(__dirname, '../parser-opts.js');

const content = `'use strict';
module.exports = ${inspect(parserOpts)};
`;

writeFileSync(pathToParserOpts, content);
15 changes: 15 additions & 0 deletions conventional-changelog-angular-custom/patches/restore-changes.js
@@ -0,0 +1,15 @@
const parserOpts = require('../parser-opts.js');
const { writeFileSync } = require('node:fs');
const { inspect } = require('node:util');
const { resolve } = require('node:path');

Reflect.deleteProperty(parserOpts, 'breakingHeaderPattern');

const pathToParserOpts = resolve(__dirname, '../parser-opts.js');

const content = `'use strict';
module.exports = ${inspect(parserOpts)};
`;

writeFileSync(pathToParserOpts, content);
64 changes: 64 additions & 0 deletions conventional-changelog-angular-custom/templates/commit.hbs
@@ -0,0 +1,64 @@
*{{#if scope}}
**{{scope}}:**
{{~/if}}
{{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}

{{~! commit link }}
{{#if @root.linkReferences~}}
([{{shortHash}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.commit}}/{{hash}}))
{{~else}}
{{~shortHash}}
{{~/if}}

{{~! commit references }}
{{~#if references~}}
, closes
{{~#each references}}
{{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}](
{{~#if @root.repository}}
{{~#if @root.host}}
{{~@root.host}}/
{{~/if}}
{{~#if this.repository}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}
{{~else}}
{{~#if @root.owner}}
{{~@root.owner}}/
{{~/if}}
{{~@root.repository}}
{{~/if}}
{{~else}}
{{~@root.repoUrl}}
{{~/if}}/
{{~@root.issue}}/{{this.issue}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}#{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}

0 comments on commit 96c885b

Please sign in to comment.