Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
🔨 use semver from default theme for release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeFitz authored and kodiakhq[bot] committed May 1, 2021
1 parent 699c5bc commit f2f4b5d
Show file tree
Hide file tree
Showing 3 changed files with 1,017 additions and 32 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
},
"devDependencies": {
"@jeromefitz/codestyle": "1.1.1",
"@semantic-release/git": "9.0.0",
"@jeromefitz/semantic-release-git": "10.0.0-develop.2",
"@semantic-release/commit-analyzer": "8.0.1",
"@semantic-release/exec": "5.0.0",
"@semantic-release/github": "7.2.1",
"@semantic-release/npm": "7.1.1",
"@semantic-release/release-notes-generator": "9.0.2",
"any-shell-escape": "0.1.1",
"browserify": "17.0.0",
Expand All @@ -80,6 +84,7 @@
"eslint-plugin-unicorn": "31.0.0",
"fuzzy": "0.1.3",
"global": "4.4.0",
"grapheme-splitter": "1.0.4",
"husky": "6.0.0",
"inquirer": "8.0.0",
"inquirer-list-search-prompt": "1.0.2",
Expand All @@ -94,6 +99,7 @@
"pkg": "5.1.0",
"rimraf": "3.0.2",
"semantic-release": "17.4.2",
"semantic-release-commit-filter": "1.0.2",
"signale": "1.4.0",
"spawncommand": "2.2.0",
"word-wrap": "1.2.3"
Expand Down
124 changes: 115 additions & 9 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,129 @@
/* eslint-disable object-property-newline */
/* eslint-disable indent */
/* eslint-disable operator-linebreak */
const types = require('@jeromefitz/git-cz/data/gitmoji').types
const GraphemeSplitter = require('grapheme-splitter')
const isCI = require('is-ci')
// eslint-disable-next-line id-match
const _pullAt = require('lodash/pullAt')
// eslint-disable-next-line global-require, no-unused-expressions
!isCI && require('dotenv').config({ path: './.env' })

const splitter = new GraphemeSplitter()

const typeSpecs = []
const releaseRules = []

Object.keys(types).map((type) => {
typeSpecs.push({
emoji: types[type].emoji,
section: types[type].section,
semver: types[type].semver,
type: types[type].value,
value: types[type].value,
})
releaseRules.push({
release: types[type].release,
type: types[type].emoji,
})

return true
})

// // semver: major, minor, patch, null
// // sort by above
// typeSpecs = _orderBy(typeSpecs, ['semver'], ['desc'])

const parserOpts = {
headerPattern: /^(.*?)(?:\((.*)\))?:?\s(.*)$/,
referenceActions: typeSpecs.map(({ type }) => type),
revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./,
}

const writerOpts = {
// eslint-disable-next-line complexity
transform: (commit) => {
const { type } = commit

// Rewrite types
const typeSpecIndex = typeSpecs.findIndex(
// eslint-disable-next-line id-length
({ emoji: e, type: t, value: v }) => type === e || type === t || type === v
)

// eslint-disable-next-line curly, nonblock-statement-body-position
if (typeSpecIndex === -1) return

const typeSpec = typeSpecs[typeSpecIndex]

commit.type = `${typeSpec.emoji} ${typeSpec.section}`
commit.typeSpecIndex = typeSpecIndex

// @note(semver)
if (typeSpec.semver === 'major' || typeSpec.semver === 'breaking') {
commit.order = 1
}
if (typeSpec.semver === 'minor' || typeSpec.semver === 'feature') {
commit.order = 3
}
if (typeSpec.semver === 'patch') {
commit.order = 5
}
if (typeSpec.semver === null) {
commit.order = 7
}
if (!Boolean(typeSpec.semver)) {
commit.order = 9
}

if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7)
}

const subjectTemp = splitter.splitGraphemes(commit.subject)
const isEmojiMatch = subjectTemp[0] === typeSpec.emoji
const subject = isEmojiMatch
? commit.subject
.replace(_pullAt(subjectTemp, [0]), '')
.replace(_pullAt(subjectTemp, [0]), '')
: commit.subject

commit.subject = subject

// eslint-disable-next-line consistent-return
return commit
},
// eslint-disable-next-line sort-keys
commitsSort: ['order'],
}

module.exports = {
// eslint-disable-next-line object-property-newline
branches: [{ name: 'main' }, { name: 'canary', prerelease: 'canary' }],
extends: [],
extends: ['semantic-release-commit-filter'],
plugins: [
[
'@semantic-release/commit-analyzer',
{
parserOpts: {
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING'],
},
parserOpts,
releaseRules,
},
],
[
'@semantic-release/release-notes-generator',
{
parserOpts,
writerOpts,
},
],
['@semantic-release/npm'],
['@semantic-release/github'],
[
'@jeromefitz/semantic-release-git',
{
assets: ['package.json'],
// eslint-disable-next-line quotes
message: `🔖️ {RELEASE_TAG} [skip ci]\n\n{RELEASE_URL}/releases/tag/{RELEASE_TAG}\n\n{RELEASE_NOTES}`,
},
],
'@semantic-release/release-notes-generator',
'@semantic-release/npm',
'@semantic-release/github',
'@semantic-release/git',
],
}
Loading

0 comments on commit f2f4b5d

Please sign in to comment.