Skip to content

Commit

Permalink
feat: generate changelog and copy old CHANGEFILE (#1805)
Browse files Browse the repository at this point in the history
* feat: changelog command

* chore: add old changelog

* chore: new changelog version

* chore: don't bump pkg version

* chore: remove chore and tests from changelog

Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
  • Loading branch information
evenstensberg and rishabh3112 committed Sep 19, 2020
1 parent 4dc6dfb commit b238bce
Show file tree
Hide file tree
Showing 8 changed files with 1,402 additions and 1,806 deletions.
1,277 changes: 1,023 additions & 254 deletions CHANGELOG.md

Large diffs are not rendered by default.

1,541 changes: 0 additions & 1,541 deletions CHANGELOG_v3.md

This file was deleted.

93 changes: 93 additions & 0 deletions build/changelog-generator/index.js
@@ -0,0 +1,93 @@
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
* Based on: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
*/
'use strict';
const readFileSync = require('fs').readFileSync;
const resolve = require('path').resolve;
const mainTemplate = readFileSync(resolve(__dirname, 'templates/template.hbs')).toString();
const headerPartial = readFileSync(resolve(__dirname, 'templates/header.hbs')).toString();
const commitPartial = readFileSync(resolve(__dirname, 'templates/commit.hbs')).toString();

const pullRequestRegex = /\(#(\d+)\)$/;
const parserOpts = {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['type', 'scope', 'message'],
};

process.stderr.write(`
> Be sure to have the latest git tags locally:
git fetch --tags
`);

const writerOpts = {
mainTemplate,
headerPartial,
commitPartial,
transform: (commit) => {
if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}

if (commit.type === 'test') {
commit.type = 'tests';
} else if (commit.type === 'cli') {
commit.type = 'CLI';
} else if (commit.type === 'new_feature' || commit.type === 'feat') {
commit.type = 'New Features';
}

if (commit.type) {
commit.type = commit.type.replace(/_/g, ' ');
commit.type = commit.type.substring(0, 1).toUpperCase() + commit.type.substring(1);
} else {
commit.type = 'Misc';
}

let pullRequestMatch = commit.header.match(pullRequestRegex);
// if header does not provide a PR we try the message
if (!pullRequestMatch && commit.message) {
pullRequestMatch = commit.message.match(pullRequestRegex);
}

if (pullRequestMatch) {
commit.header = commit.header.replace(pullRequestMatch[0], '').trim();
if (commit.message) {
commit.message = commit.message.replace(pullRequestMatch[0], '').trim();
}

commit.PR = pullRequestMatch[1];
}

return commit;
},
groupBy: 'type',
commitGroupsSort: (a, b) => {
// put new feature on the top
if (a.title === 'New Features') {
return -1;
}
if (b.title === 'New Features') {
return 1;
}

// put misc on the bottom
if (a.title === 'Misc') {
return 1;
}
if (b.title === 'Misc') {
return -1;
}

return a.title.localeCompare(b.title);
},
commitsSort: ['type', 'scope'],
};

module.exports = {
writerOpts,
parserOpts,
};
28 changes: 28 additions & 0 deletions build/changelog-generator/templates/commit.hbs
@@ -0,0 +1,28 @@
{{!--
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
From: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
--}}
* {{#if scope}}{{scope}}: {{/if~}}
{{#if message ~}}
{{~message~}}
{{~else~}}
{{~header~}}
{{~/if ~}}
{{~!-- PR number/commit hash --}}
{{~#if @root.linkReferences~}}
{{~#if PR}} ([#{{PR}}](
{{~#if @root.host}}{{~@root.host}}/{{/if~}}
{{~#if @root.owner ~}}{{@root.owner}}/{{/if~}}
{{~@root.repository}}/pull/{{PR}}))
{{~else}} ([{{hash}}](
{{~#if @root.host}}{{~@root.host}}/{{/if~}}
{{~#if @root.owner ~}}{{@root.owner}}/{{/if~}}
{{~@root.repository}}/{{@root.commit}}/{{hash}}))
{{~/if~}}
{{~else~}}
{{~hash~}}
{{~/if~}}
13 changes: 13 additions & 0 deletions build/changelog-generator/templates/header.hbs
@@ -0,0 +1,13 @@
{{!--
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
From: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
--}}
<a name="{{version}}"></a>
# {{version}} ({{date}})
{{#if @root.linkCompare~}}
[Full Changelog]({{~@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}})
{{~/if}}
22 changes: 22 additions & 0 deletions build/changelog-generator/templates/template.hbs
@@ -0,0 +1,22 @@
{{!--
/**
* @license Copyright 2017 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
From: https://github.com/GoogleChrome/lighthouse/blob/master/build/changelog-generator/
--}}
{{> header}}

{{#each commitGroups}}

{{#if title~}}
## {{title}}

{{/if}}
{{#each commits}}
{{~> commit root=@root}}

{{/each}}
{{/each}}

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -30,6 +30,7 @@
"watch": "tsc --build --watch",
"prepsuite": "node scripts/prepareSuite.js",
"commit": "git-cz",
"changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile CHANGELOG.md --same-file",
"lint:prettier": "prettier --list-different . \"!**/*.{js,ts}\" ",
"lint:eslint": "eslint --cache --ext .js --ext .ts .",
"lint": "yarn lint:eslint && yarn lint:prettier",
Expand Down Expand Up @@ -128,6 +129,7 @@
"ts-jest": "^25.5.1",
"typescript": "^3.9.7",
"webpack": "^4.44.1",
"yeoman-test": "^2.7.0"
"yeoman-test": "^2.7.0",
"conventional-changelog-cli": "^2.1.0"
}
}

0 comments on commit b238bce

Please sign in to comment.