-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(release): changelog fixes and updating scssVariables
Not really sure why the config doesn't work when using my custom preset with lerna.
- Loading branch information
Showing
10 changed files
with
337 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,203 @@ | ||
const { createConfig } = require('@mlaursen/changelog-preset/createConfig'); | ||
const { readFileSync } = require('fs'); | ||
const { resolve } = require('path'); | ||
|
||
const { tokens, packages } = require('./changelogData'); | ||
|
||
const PACKAGE_REGEXP = new RegExp(`${packages.join('|')}`); | ||
|
||
module.exports = createConfig({ | ||
tokens, | ||
getCommitScope({ scope }) { | ||
if (PACKAGE_REGEXP.test(scope)) { | ||
return `@react-md/${scope}`; | ||
const GROUPS = [ | ||
'Bug Fixes', | ||
'Features', | ||
'Documentation', | ||
'Performance Improvements', | ||
'Other Internal Changes', | ||
]; | ||
|
||
function getCommitType({ type, scope, revert }) { | ||
if (type === 'revert' || revert) { | ||
return 'Reverts'; | ||
} | ||
|
||
if (scope === 'docs') { | ||
return 'Documentation'; | ||
} | ||
|
||
switch (type) { | ||
case 'feat': | ||
return 'Features'; | ||
case 'fix': | ||
case 'bugfix': | ||
return 'Bug Fixes'; | ||
case 'perf': | ||
return 'Performance Improvements'; | ||
case 'docs': | ||
return 'Documentation'; | ||
default: | ||
return 'Other Internal Changes'; | ||
} | ||
} | ||
|
||
function getCommitScope({ scope }) { | ||
if (PACKAGE_REGEXP.test(scope)) { | ||
return `@react-md/${scope}`; | ||
} | ||
|
||
switch (scope) { | ||
// these are mostly to create the initial changelog | ||
case 'docs': | ||
case 'pages': | ||
case 'sassdoc': | ||
case 'sandbox': | ||
case 'demos': | ||
case 'blog': | ||
case 'indexer': | ||
case 'guides': | ||
return 'react-md.dev'; | ||
case 'slider': | ||
return '@react-md/form'; | ||
case 'grid': | ||
return '@react-md/utils'; | ||
default: | ||
return scope || ''; | ||
} | ||
} | ||
|
||
const TOKEN_REGEXP = new RegExp( | ||
`(?<=\\s|^)(${tokens.join('|')})(?=\\s|$)`, | ||
'g' | ||
); | ||
|
||
function tokenize(subject) { | ||
return subject | ||
.replace(TOKEN_REGEXP, '`$1`') | ||
.replace(/([a-z][A-z]+Props)/g, '`$1`'); | ||
} | ||
|
||
const parserOpts = { | ||
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/, | ||
headerCorrespondence: ['type', 'scope', 'subject'], | ||
noteKeywords: ['BREAKING CHANGE'], | ||
revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i, | ||
revertCorrespondence: ['header', 'hash'], | ||
}; | ||
|
||
const writerOpts = { | ||
transform: (commit, context) => { | ||
// don't want to show the release tag in changelog | ||
if (commit.scope === 'release') { | ||
return; | ||
} | ||
|
||
const issues = []; | ||
let isBreaking = false; | ||
commit.notes.forEach((note) => { | ||
isBreaking = false; | ||
note.title = 'BREAKING CHANGES'; | ||
}); | ||
|
||
commit.type = getCommitType(commit); | ||
commit.scope = getCommitScope(commit); | ||
if (!isBreaking && (!commit.type || commit.scope.includes('deps'))) { | ||
// don't include un-typed commits in changelogs or deps | ||
return; | ||
} | ||
|
||
if (typeof commit.hash === 'string') { | ||
commit.shortHash = commit.hash.substring(0, 7); | ||
} | ||
|
||
switch (scope) { | ||
// these are mostly to create the initial changelog | ||
case 'docs': | ||
case 'pages': | ||
case 'sassdoc': | ||
case 'sandbox': | ||
case 'demos': | ||
case 'blog': | ||
case 'indexer': | ||
case 'guides': | ||
return 'react-md.dev'; | ||
case 'slider': | ||
return '@react-md/form'; | ||
case 'grid': | ||
return '@react-md/utils'; | ||
default: | ||
return scope || ''; | ||
if (typeof commit.subject === 'string') { | ||
let url = context.repository | ||
? `${context.host}/${context.owner}/${context.repository}` | ||
: context.repoUrl; | ||
|
||
if (url) { | ||
url = `${url}/issues/`; | ||
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => { | ||
issues.push(issue); | ||
return `[#${issue}](${url}${issue})`; | ||
}); | ||
} | ||
|
||
commit.subject = tokenize(commit.subject); | ||
} | ||
|
||
// remove references that already appear in the subject | ||
commit.references = commit.references.filter( | ||
(reference) => !issues.includes(reference.issue) | ||
); | ||
|
||
return commit; | ||
}, | ||
groupBy: 'type', | ||
commitGroupsSort: function (a, b) { | ||
const aIndex = GROUPS.indexOf(a.title); | ||
const bIndex = GROUPS.indexOf(b.title); | ||
if (aIndex !== -1 && bIndex !== -1) { | ||
return aIndex - bIndex; | ||
} | ||
|
||
return a.title.localeCompare(b.title); | ||
}, | ||
commitsSort: ['scope', 'subject'], | ||
noteGroupsSort: 'title', | ||
mainTemplate: readFileSync( | ||
resolve(__dirname, './templates/template.hbs'), | ||
'utf-8' | ||
), | ||
headerPartial: readFileSync( | ||
resolve(__dirname, './templates/header.hbs'), | ||
'utf-8' | ||
), | ||
commitPartial: readFileSync( | ||
resolve(__dirname, './templates/commit.hbs'), | ||
'utf-8' | ||
), | ||
footerPartial: readFileSync( | ||
resolve(__dirname, './templates/footer.hbs'), | ||
'utf-8' | ||
), | ||
}; | ||
|
||
/** | ||
* This is basically the conventional-changelog-angular with a few changes to | ||
* allow more commit messages to appear. I also "tokenize" known packages and | ||
* exports from react-md in the changelogs. | ||
*/ | ||
module.exports = { | ||
parserOpts, | ||
writerOpts, | ||
conventionalChangelog: { | ||
writerOpts, | ||
parserOpts, | ||
}, | ||
recommendedBumpOpts: { | ||
config: { | ||
parserOpts, | ||
writerOpts, | ||
}, | ||
|
||
whatBump: (commits) => { | ||
let level = 2; | ||
let breaking = 0; | ||
let features = 0; | ||
commits.forEach((commit) => { | ||
if (commit.notes.length > 0) { | ||
breaking += commit.notes.length; | ||
level = 0; | ||
} else if (commit.type === 'feat') { | ||
features += 1; | ||
if (level === 2) { | ||
level = 1; | ||
} | ||
} | ||
}); | ||
|
||
const verb = breaking === 1 ? 'is' : 'are'; | ||
return { | ||
level, | ||
reason: `There ${verb} ${breaking} BREAKING CHANGES and ${features} features`, | ||
}; | ||
}, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
*{{#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}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{#if noteGroups}} | ||
{{#each noteGroups}} | ||
|
||
### {{title}} | ||
|
||
{{#each notes}} | ||
* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}} | ||
{{/each}} | ||
{{/each}} | ||
|
||
{{/if}} | ||
|
Oops, something went wrong.