From ed42fb1c070ab86ef70be407028b53bfec9e2105 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Thu, 28 Dec 2023 13:24:38 +0100 Subject: [PATCH] refactor: Misc changes to make new build work --- .github/workflows/release.yml | 9 +- .gitignore | 2 + README.md | 2 +- dist/commit.hbs | 15 +- dist/commit1.hbs | 54 ++++ dist/footer.hbs | 3 +- dist/footer1.hbs | 10 + dist/header.hbs | 32 ++- dist/header1.hbs | 9 + dist/index.js | 470 ++++++++++++++++++++++++++++++- dist/template.hbs | 7 +- dist/template1.hbs | 11 + src/helpers/generateChangelog.js | 3 + 13 files changed, 606 insertions(+), 21 deletions(-) create mode 100644 dist/commit1.hbs create mode 100644 dist/footer1.hbs create mode 100644 dist/header1.hbs create mode 100644 dist/template1.hbs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee039fba..18e88483 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,8 +11,13 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - run: npm ci --prod - - run: git add node_modules -f + - name: Install deps + run: npm ci + + - name: Build + run: npm run build + + - run: git add dist -f - name: Generate changelog id: changelog diff --git a/.gitignore b/.gitignore index 1f8a5be8..18a99ab3 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,5 @@ typings/ # build output lib + +node_modules \ No newline at end of file diff --git a/README.md b/README.md index 57af1e59..a6a86d08 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ If you'd like to contribute to this project, all you need to do is clone and ins > Note: The image used is 18 gb! ```shell -$ yarn install +$ npm install # To run / test one specific job $ act -j -P ubuntu-latest=catthehacker/ubuntu:full-20.04 --quiet diff --git a/dist/commit.hbs b/dist/commit.hbs index 3b2cd685..e10a0d90 100644 --- a/dist/commit.hbs +++ b/dist/commit.hbs @@ -1,7 +1,12 @@ -* {{header}} +*{{#if scope}} **{{scope}}:** +{{~/if}} {{#if subject}} + {{~subject}} +{{~else}} + {{~header}} +{{~/if}} -{{~!-- commit link --}} -{{~#if @root.linkReferences}} ([{{hash}}]( +{{~!-- commit link --}} {{#if @root.linkReferences~}} + ([{{shortHash}}]( {{~#if @root.repository}} {{~#if @root.host}} {{~@root.host}}/ @@ -14,7 +19,9 @@ {{~@root.repoUrl}} {{~/if}}/ {{~@root.commit}}/{{hash}})) -{{~else if hash}} {{hash}}{{~/if}} +{{~else}} + {{~shortHash}} +{{~/if}} {{~!-- commit references --}} {{~#if references~}} diff --git a/dist/commit1.hbs b/dist/commit1.hbs new file mode 100644 index 00000000..3b2cd685 --- /dev/null +++ b/dist/commit1.hbs @@ -0,0 +1,54 @@ +* {{header}} + +{{~!-- commit link --}} +{{~#if @root.linkReferences}} ([{{hash}}]( + {{~#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 if hash}} {{hash}}{{~/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}} + diff --git a/dist/footer.hbs b/dist/footer.hbs index dca482f2..2aa774f5 100644 --- a/dist/footer.hbs +++ b/dist/footer.hbs @@ -4,7 +4,8 @@ ### {{title}} {{#each notes}} -* {{text}} +* {{#if commit.scope}}**{{commit.scope}}:** {{/if}}{{text}} {{/each}} {{/each}} + {{/if}} diff --git a/dist/footer1.hbs b/dist/footer1.hbs new file mode 100644 index 00000000..dca482f2 --- /dev/null +++ b/dist/footer1.hbs @@ -0,0 +1,10 @@ +{{#if noteGroups}} +{{#each noteGroups}} + +### {{title}} + +{{#each notes}} +* {{text}} +{{/each}} +{{/each}} +{{/if}} diff --git a/dist/header.hbs b/dist/header.hbs index 49f56073..fc781c4b 100644 --- a/dist/header.hbs +++ b/dist/header.hbs @@ -1,9 +1,25 @@ -## {{#if isPatch~}} - {{~/if~}} {{version}} - {{~#if title}} "{{title}}" +{{#if isPatch~}} + ## +{{~else~}} + # +{{~/if}} {{#if @root.linkCompare~}} + [{{version}}]( + {{~#if @root.repository~}} + {{~#if @root.host}} + {{~@root.host}}/ + {{~/if}} + {{~#if @root.owner}} + {{~@root.owner}}/ + {{~/if}} + {{~@root.repository}} + {{~else}} + {{~@root.repoUrl}} {{~/if~}} - {{~#if date}} ({{date}}) - {{~/if~}} - {{~#if isPatch~}} - {{~/if}} - + /compare/{{previousTag}}...{{currentTag}}) +{{~else}} + {{~version}} +{{~/if}} +{{~#if title}} "{{title}}" +{{~/if}} +{{~#if date}} ({{date}}) +{{/if}} diff --git a/dist/header1.hbs b/dist/header1.hbs new file mode 100644 index 00000000..49f56073 --- /dev/null +++ b/dist/header1.hbs @@ -0,0 +1,9 @@ +## {{#if isPatch~}} + {{~/if~}} {{version}} + {{~#if title}} "{{title}}" + {{~/if~}} + {{~#if date}} ({{date}}) + {{~/if~}} + {{~#if isPatch~}} + {{~/if}} + diff --git a/dist/index.js b/dist/index.js index 90bed3ab..1bed586f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5329,6 +5329,301 @@ addStream.obj = function (stream, opts) { module.exports = addStream; +/***/ }), + +/***/ 2242: +/***/ ((module) => { + +"use strict"; + +module.exports = function(val) { + return Array.isArray(val) ? val : [val]; +}; + + +/***/ }), + +/***/ 7582: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +"use strict"; + +var arrayify = __nccwpck_require__(2242); +var dotPropGet = (__nccwpck_require__(6352).get); + +function compareFunc(prop) { + return function(a, b) { + var ret = 0; + + arrayify(prop).some(function(el) { + var x; + var y; + + if (typeof el === 'function') { + x = el(a); + y = el(b); + } else if (typeof el === 'string') { + x = dotPropGet(a, el); + y = dotPropGet(b, el); + } else { + x = a; + y = b; + } + + if (x === y) { + ret = 0; + return; + } + + if (typeof x === 'string' && typeof y === 'string') { + ret = x.localeCompare(y); + return ret !== 0; + } + + ret = x < y ? -1 : 1; + return true; + }); + + return ret; + }; +} + +module.exports = compareFunc; + + +/***/ }), + +/***/ 998: +/***/ ((module) => { + +"use strict"; + + +function createConventionalChangelogOpts (parserOpts, writerOpts) { + return { + parserOpts, + writerOpts + } +} + +module.exports.createConventionalChangelogOpts = createConventionalChangelogOpts + + +/***/ }), + +/***/ 9084: +/***/ ((module) => { + +"use strict"; + + +function createConventionalRecommendedBumpOpts (parserOpts) { + return { + 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, + reason: breakings === 1 + ? `There is ${breakings} BREAKING CHANGE and ${features} features` + : `There are ${breakings} BREAKING CHANGES and ${features} features` + } + } + } +} + +module.exports.createConventionalRecommendedBumpOpts = createConventionalRecommendedBumpOpts + + +/***/ }), + +/***/ 6401: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +"use strict"; + + +const { createParserOpts } = __nccwpck_require__(5431) +const { createWriterOpts } = __nccwpck_require__(4613) +const { createConventionalChangelogOpts } = __nccwpck_require__(998) +const { createConventionalRecommendedBumpOpts } = __nccwpck_require__(9084) + +async function createPreset () { + const parserOpts = createParserOpts() + const writerOpts = await createWriterOpts() + const recommendedBumpOpts = createConventionalRecommendedBumpOpts(parserOpts) + const conventionalChangelog = createConventionalChangelogOpts(parserOpts, writerOpts) + + return { + parserOpts, + writerOpts, + recommendedBumpOpts, + conventionalChangelog + } +} + +module.exports = createPreset + + +/***/ }), + +/***/ 5431: +/***/ ((module) => { + +"use strict"; + + +function createParserOpts () { + return { + headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/, + headerCorrespondence: [ + 'type', + 'scope', + 'subject' + ], + noteKeywords: ['BREAKING CHANGE'], + revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i, + revertCorrespondence: ['header', 'hash'] + } +} + +module.exports.createParserOpts = createParserOpts + + +/***/ }), + +/***/ 4613: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +"use strict"; + + +const compareFunc = __nccwpck_require__(7582) +const { readFile } = (__nccwpck_require__(7147).promises) +const { resolve } = __nccwpck_require__(1017) + +async function createWriterOpts () { + const [template, header, commit, footer] = await Promise.all([ + readFile(__nccwpck_require__.ab + "template.hbs", 'utf-8'), + readFile(__nccwpck_require__.ab + "header.hbs", 'utf-8'), + readFile(__nccwpck_require__.ab + "commit.hbs", 'utf-8'), + readFile(__nccwpck_require__.ab + "footer.hbs", 'utf-8') + ]) + const writerOpts = getWriterOpts() + + writerOpts.mainTemplate = template + writerOpts.headerPartial = header + writerOpts.commitPartial = commit + writerOpts.footerPartial = footer + + return writerOpts +} + +module.exports.createWriterOpts = createWriterOpts + +function getWriterOpts () { + return { + transform: (commit, context) => { + let discard = true + const issues = [] + + commit.notes.forEach(note => { + note.title = 'BREAKING CHANGES' + discard = false + }) + + if (commit.type === 'feat') { + commit.type = 'Features' + } else if (commit.type === 'fix') { + commit.type = 'Bug Fixes' + } else if (commit.type === 'perf') { + commit.type = 'Performance Improvements' + } else if (commit.type === 'revert' || commit.revert) { + commit.type = 'Reverts' + } else if (discard) { + return + } else if (commit.type === 'docs') { + commit.type = 'Documentation' + } else if (commit.type === 'style') { + commit.type = 'Styles' + } else if (commit.type === 'refactor') { + commit.type = 'Code Refactoring' + } else if (commit.type === 'test') { + commit.type = 'Tests' + } else if (commit.type === 'build') { + commit.type = 'Build System' + } else if (commit.type === 'ci') { + commit.type = 'Continuous Integration' + } + + if (commit.scope === '*') { + commit.scope = '' + } + + if (typeof commit.hash === 'string') { + commit.shortHash = commit.hash.substring(0, 7) + } + + if (typeof commit.subject === 'string') { + let url = context.repository + ? `${context.host}/${context.owner}/${context.repository}` + : context.repoUrl + if (url) { + url = `${url}/issues/` + // Issue URLs. + commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => { + issues.push(issue) + return `[#${issue}](${url}${issue})` + }) + } + if (context.host) { + // User URLs. + commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => { + if (username.includes('/')) { + return `@${username}` + } + + return `[@${username}](${context.host}/${username})` + }) + } + } + + // remove references that already appear in the subject + commit.references = commit.references.filter(reference => { + if (issues.indexOf(reference.issue) === -1) { + return true + } + + return false + }) + + return commit + }, + groupBy: 'type', + commitGroupsSort: 'title', + commitsSort: ['scope', 'subject'], + noteGroupsSort: 'title', + notesSort: compareFunc + } +} + + /***/ }), /***/ 9854: @@ -6058,10 +6353,10 @@ async function conventionalChangelogWriterInit (context, options) { commitPartial, footerPartial ] = await Promise.all([ - readFile(__nccwpck_require__.ab + "template.hbs", 'utf-8'), - readFile(__nccwpck_require__.ab + "header.hbs", 'utf-8'), - readFile(__nccwpck_require__.ab + "commit.hbs", 'utf-8'), - readFile(__nccwpck_require__.ab + "footer.hbs", 'utf-8') + readFile(__nccwpck_require__.ab + "template1.hbs", 'utf-8'), + readFile(__nccwpck_require__.ab + "header1.hbs", 'utf-8'), + readFile(__nccwpck_require__.ab + "commit1.hbs", 'utf-8'), + readFile(__nccwpck_require__.ab + "footer1.hbs", 'utf-8') ]) options = { @@ -7281,6 +7576,156 @@ async function conventionalRecommendedBump (optionsArgument, parserOptsArgument) module.exports = conventionalRecommendedBump +/***/ }), + +/***/ 6352: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +"use strict"; + +const isObj = __nccwpck_require__(6303); + +const disallowedKeys = [ + '__proto__', + 'prototype', + 'constructor' +]; + +const isValidPath = pathSegments => !pathSegments.some(segment => disallowedKeys.includes(segment)); + +function getPathSegments(path) { + const pathArray = path.split('.'); + const parts = []; + + for (let i = 0; i < pathArray.length; i++) { + let p = pathArray[i]; + + while (p[p.length - 1] === '\\' && pathArray[i + 1] !== undefined) { + p = p.slice(0, -1) + '.'; + p += pathArray[++i]; + } + + parts.push(p); + } + + if (!isValidPath(parts)) { + return []; + } + + return parts; +} + +module.exports = { + get(object, path, value) { + if (!isObj(object) || typeof path !== 'string') { + return value === undefined ? object : value; + } + + const pathArray = getPathSegments(path); + if (pathArray.length === 0) { + return; + } + + for (let i = 0; i < pathArray.length; i++) { + if (!Object.prototype.propertyIsEnumerable.call(object, pathArray[i])) { + return value; + } + + object = object[pathArray[i]]; + + if (object === undefined || object === null) { + // `object` is either `undefined` or `null` so we want to stop the loop, and + // if this is not the last bit of the path, and + // if it did't return `undefined` + // it would return `null` if `object` is `null` + // but we want `get({foo: null}, 'foo.bar')` to equal `undefined`, or the supplied value, not `null` + if (i !== pathArray.length - 1) { + return value; + } + + break; + } + } + + return object; + }, + + set(object, path, value) { + if (!isObj(object) || typeof path !== 'string') { + return object; + } + + const root = object; + const pathArray = getPathSegments(path); + + for (let i = 0; i < pathArray.length; i++) { + const p = pathArray[i]; + + if (!isObj(object[p])) { + object[p] = {}; + } + + if (i === pathArray.length - 1) { + object[p] = value; + } + + object = object[p]; + } + + return root; + }, + + delete(object, path) { + if (!isObj(object) || typeof path !== 'string') { + return false; + } + + const pathArray = getPathSegments(path); + + for (let i = 0; i < pathArray.length; i++) { + const p = pathArray[i]; + + if (i === pathArray.length - 1) { + delete object[p]; + return true; + } + + object = object[p]; + + if (!isObj(object)) { + return false; + } + } + }, + + has(object, path) { + if (!isObj(object) || typeof path !== 'string') { + return false; + } + + const pathArray = getPathSegments(path); + if (pathArray.length === 0) { + return false; + } + + // eslint-disable-next-line unicorn/no-for-loop + for (let i = 0; i < pathArray.length; i++) { + if (isObj(object)) { + if (!(pathArray[i] in object)) { + return false; + } + + object = object[pathArray[i]]; + } else { + return false; + } + } + + return true; + } +}; + + /***/ }), /***/ 8976: @@ -13506,6 +13951,20 @@ module.exports = function isCore(x, nodeVersion) { }; +/***/ }), + +/***/ 6303: +/***/ ((module) => { + +"use strict"; + + +module.exports = value => { + const type = typeof value; + return value !== null && (type === 'object' || type === 'function'); +}; + + /***/ }), /***/ 8369: @@ -22851,6 +23310,9 @@ const fs = __nccwpck_require__(7147) const { Readable } = __nccwpck_require__(2781); const conventionalChangelog = __nccwpck_require__(5867) +// Make sure the angular preset is included +__nccwpck_require__(6401) + /** * Generates a changelog stream with the given arguments * diff --git a/dist/template.hbs b/dist/template.hbs index 2c1349a6..38e15d24 100644 --- a/dist/template.hbs +++ b/dist/template.hbs @@ -1,11 +1,16 @@ {{> header}} {{#each commitGroups}} + +{{#if title}} +### {{title}} + +{{/if}} {{#each commits}} {{> commit root=@root}} {{/each}} -{{/each}} +{{/each}} {{> footer}} diff --git a/dist/template1.hbs b/dist/template1.hbs new file mode 100644 index 00000000..2c1349a6 --- /dev/null +++ b/dist/template1.hbs @@ -0,0 +1,11 @@ +{{> header}} + +{{#each commitGroups}} +{{#each commits}} +{{> commit root=@root}} +{{/each}} +{{/each}} + +{{> footer}} + + diff --git a/src/helpers/generateChangelog.js b/src/helpers/generateChangelog.js index 9b7c22e8..0f6fdeaf 100644 --- a/src/helpers/generateChangelog.js +++ b/src/helpers/generateChangelog.js @@ -2,6 +2,9 @@ const fs = require('fs') const { Readable } = require('stream'); const conventionalChangelog = require('conventional-changelog') +// Make sure the angular preset is included +require('conventional-changelog-angular') + /** * Generates a changelog stream with the given arguments *