diff --git a/.release-it.js b/.release-it.js index 35e292e31..e11454d26 100644 --- a/.release-it.js +++ b/.release-it.js @@ -5,13 +5,17 @@ module.exports = { hooks: { "before:init": "bash ./build/release/pre-release.sh", "after:version:bump": - "sed -i 's/main\\/AUTHORS.txt/${version}\\/AUTHORS.txt/' package.json", + "sed -i 's/main\\/AUTHORS.txt/${version}\\/AUTHORS.txt/' package.json", "after:bump": "cross-env VERSION=${version} npm run build", - "before:git:release": "git add -f dist/", + "before:git:release": "git add -f dist/ changelog.md", "after:release": "echo 'Run the following to complete the release:' && " + - "echo './build/release/post-release.sh $\{version}'" + "echo './build/release/post-release.sh $\{version}'" }, git: { + + // Use the node script directly to avoid an npm script + // command log entry in the GH release notes + changelog: "node build/release/changelog.mjs ${from} ${to}", commitMessage: "Release: ${version}", getLatestTagFromAllRefs: true, pushRepo: "git@github.com:jquery/jquery-mousewheel.git", diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 7dc2554f6..000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,163 +0,0 @@ -# Mouse Wheel Change Log - -## 3.2.2 - -* Include the minified file in the npm package - -## 3.2.1 - -* Update README - -## 3.2.0 - -* Use `.on()`/`.off()` for event binding where available -* Don't clobber mouse offset properties if we don't adjust them (#165) -* Remove moot `version` property from bower.json (#140) -* Remove the executable bit from the library (#176) -* Add jtr-based tests in GitHub Actions, migrate to ESLint flat config (#247) - -## 3.1.13 - -* Update copyright notice and license to remove years -* Create the correct compressed version -* Remove the obsolete jQuery Plugin Registry file - -## 3.1.12 - -* Fix possible 0 value for line height when in delta mode 1 - -## 3.1.11 - -* Fix version number for package managers... - -## 3.1.10 - -* Fix issue with calculating line height when using older versions of jQuery -* Add offsetX/Y normalization with setting to turn it off -* Cleans up data on teardown - -## 3.1.9 - -* Fix bower.json file -* Updated how the deltas are adjusted for older mousewheel based events that have deltas that are factors of 120. -* Add $.event.special.mousewheel.settings.adjustOldDeltas (defaults to true) to turn off adjusting of old deltas that are factors of 120. You'd turn this off if you want to be as close to native scrolling as possible. - -## 3.1.8 - -* Even better handling of older browsers that use a wheelDelta based on 120 -* And fix version reported by `$.event.special.mousewheel` - -## 3.1.7 - -* Better handle the `deltaMode` values 1 (lines) and 2 (pages) -* Attempt to better handle older browsers that use a wheelDelta based on 120 - -## 3.1.6 - -* Deprecating `delta`, `deltaX`, and `deltaY` event handler arguments -* Update actual event object with normalized `deltaX `and `deltaY` values (`event.deltaX`, `event.deltaY`) -* Add `deltaFactor` to the event object (`event.deltaFactor`) -* Handle `> 0` but `< 1` deltas better -* Do not fire the event if `deltaX` and `deltaY` are `0` -* Better handle different devices that give different `lowestDelta` values -* Add `$.event.special.mousewheel.version` -* Some clean up - -## 3.1.5 - -* Bad release because I did not update the new `$.event.special.mousewheel.version` - -## 3.1.4 - -* Always set the `deltaY` -* Add back in the `deltaX` and `deltaY` support for older Firefox versions - -## 3.1.3 - -* Include `MozMousePixelScroll` in the to fix list to avoid inconsistent behavior in older Firefox - -## 3.1.2 - -* Include grunt utilities for development purposes (jshint and uglify) -* Include support for browserify -* Some basic cleaning up - -## 3.1.1 - -* Fix rounding issue with deltas less than zero - - -## 3.1.0 - -* Fix Firefox 17+ issues by using new wheel event -* Normalize delta values -* Adds horizontal support for IE 9+ by using new wheel event -* Support AMD loaders - - -## 3.0.6 - -* Fix issue with delta being 0 in Firefox - - -## 3.0.5 - -* jQuery 1.7 compatibility - - -## 3.0.4 - -* Fix IE issue - - -## 3.0.3 - -* Added `deltaX` and `deltaY` for horizontal scrolling support (Thanks to Seamus Leahy) - - -## 3.0.2 - -* Fixed delta being opposite value in latest Opera -* No longer fix `pageX`, `pageY` for older Mozilla browsers -* Removed browser detection -* Cleaned up the code - - -## 3.0.1 - -* Bad release... creating a new release due to plugins.jquery.com issue :( - - -## 3.0 - -* Uses new special events API in jQuery 1.2.2+ -* You can now treat `mousewheel` as a normal event and use `.bind`, `.unbind` and `.trigger` -* Using jQuery.data API for expandos - - -## 2.2 - -* Fixed `pageX`, `pageY`, `clientX` and `clientY` event properties for Mozilla based browsers - - -## 2.1.1 - -* Updated to work with jQuery 1.1.3 -* Used one instead of bind to do unload event for clean up - - -## 2.1 - -* Fixed an issue with the unload handler - - -## 2.0 - -* Major reduction in code size and complexity (internals have change a whole lot) - - -## 1.0 - -* Fixed Opera issue -* Fixed an issue with children elements that also have a mousewheel handler -* Added ability to handle multiple handlers diff --git a/build/release/changelog.mjs b/build/release/changelog.mjs new file mode 100644 index 000000000..28c8d2d27 --- /dev/null +++ b/build/release/changelog.mjs @@ -0,0 +1,175 @@ +import { writeFile } from "node:fs/promises"; +import { argv } from "node:process"; +import { exec as nodeExec } from "node:child_process"; +import util from "node:util"; + +const exec = util.promisify( nodeExec ); + +const rbeforeHash = /.#$/; +const rendsWithHash = /#$/; +const rcherry = / \(cherry picked from commit [^)]+\)/; +const rcommit = /Fix(?:e[sd])? ((?:[a-zA-Z0-9_-]{1,39}\/[a-zA-Z0-9_-]{1,100}#)|#|gh-)(\d+)/g; +const rcomponent = /^([^ :]+):\s*([^\n]+)/; +const rnewline = /\r?\n/; + +const prevVersion = argv[ 2 ]; +const nextVersion = argv[ 3 ]; +const blogUrl = process.env.BLOG_URL; + +if ( !prevVersion || !nextVersion ) { + throw new Error( "Usage: `node changelog.js PREV_VERSION NEXT_VERSION`" ); +} + +function ticketUrl( ticketId ) { + return `https://github.com/jquery/jquery-mousewheel/issues/${ ticketId }`; +} + +function getTicketsForCommit( commit ) { + const tickets = []; + + commit.replace( rcommit, function( _match, refType, ticketId ) { + const ticket = { + url: ticketUrl( ticketId ), + label: "#" + ticketId + }; + + // If the refType has anything before the #, assume it's a GitHub ref + if ( rbeforeHash.test( refType ) ) { + + // console.log( refType ); + refType = refType.replace( rendsWithHash, "" ); + ticket.url = `https://github.com/${ refType }/issues/${ ticketId }`; + ticket.label = refType + ticket.label; + } + + tickets.push( ticket ); + } ); + + return tickets; +} + +async function getCommits() { + const format = + "__COMMIT__%n%s (__TICKETREF__[%h](https://github.com/jquery/jquery-mousewheel/commit/%H))%n%b"; + const { stdout } = await exec( + `git log --format="${ format }" ${ prevVersion }..${ nextVersion }` + ); + const commits = stdout.split( "__COMMIT__" ).slice( 1 ); + + return removeReverts( commits.map( parseCommit ).sort( sortCommits ) ); +} + +function parseCommit( commit ) { + const tickets = getTicketsForCommit( commit ) + .map( ( ticket ) => { + return `[${ ticket.label }](${ ticket.url })`; + } ) + .join( ", " ); + + // Drop the commit message body + let message = `${ commit.trim().split( rnewline )[ 0 ] }`; + + // Add any ticket references + message = message.replace( "__TICKETREF__", tickets ? `${ tickets }, ` : "" ); + + // Remove cherry-pick references + message = message.replace( rcherry, "" ); + + return message; +} + +function sortCommits( a, b ) { + const aComponent = rcomponent.exec( a ); + const bComponent = rcomponent.exec( b ); + + if ( aComponent && bComponent ) { + if ( aComponent[ 1 ] < bComponent[ 1 ] ) { + return -1; + } + if ( aComponent[ 1 ] > bComponent[ 1 ] ) { + return 1; + } + return 0; + } + + if ( a < b ) { + return -1; + } + if ( a > b ) { + return 1; + } + return 0; +} + +/** + * Remove all revert commits and the commit it is reverting + */ +function removeReverts( commits ) { + const remove = []; + + commits.forEach( function( commit ) { + const match = /\*\s*Revert "([^"]*)"/.exec( commit ); + + // Ignore double reverts + if ( match && !/^Revert "([^"]*)"/.test( match[ 0 ] ) ) { + remove.push( commit, match[ 0 ] ); + } + } ); + + remove.forEach( function( message ) { + const index = commits.findIndex( ( commit ) => commit.includes( message ) ); + if ( index > -1 ) { + + // console.log( "Removing", commits[ index ] ); + commits.splice( index, 1 ); + } + } ); + + return commits; +} + +function addHeaders( commits ) { + const components = {}; + let markdown = ""; + + commits.forEach( function( commit ) { + const match = rcomponent.exec( commit ); + if ( match ) { + let component = match[ 1 ]; + if ( !/^[A-Z]/.test( component ) ) { + component = + component.slice( 0, 1 ).toUpperCase() + + component.slice( 1 ).toLowerCase(); + } + if ( !components[ component.toLowerCase() ] ) { + markdown += "\n## " + component + "\n\n"; + components[ component.toLowerCase() ] = true; + } + markdown += `- ${ match[ 2 ] }\n`; + } else { + markdown += `- ${ commit }\n`; + } + } ); + + return markdown; +} + +async function generate() { + const commits = await getCommits(); + + let changelog = "# Changelog\n"; + if ( blogUrl ) { + changelog += `\n${ blogUrl }\n`; + } + changelog += addHeaders( commits ); + + // Write markdown to changelog.md + await writeFile( "changelog.md", changelog ); + + // Log regular changelog for release-it + console.log( changelog ); + + return changelog; +} + +generate(); diff --git a/build/release/pre-release.sh b/build/release/pre-release.sh index 7e6b6cfce..04aa24b9c 100644 --- a/build/release/pre-release.sh +++ b/build/release/pre-release.sh @@ -2,8 +2,6 @@ set -euo pipefail -read -p "Press enter if you updated CHANGELOG.md; abort otherwise" - # Install dependencies npm ci diff --git a/package.json b/package.json index 570c3905b..2f0a84099 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "browser" ], "files": [ - "CHANGELOG.md", + "changelog.md", "dist/jquery.mousewheel.js", "dist/jquery.mousewheel.min.js", "README.md",