Fix version levels and normalize version strings

This commit is contained in:
Sam Carlton 2022-04-28 16:45:21 -05:00
parent e3a93b209d
commit ec8eee6386

View file

@ -35,7 +35,26 @@ const cliOptions = {
}
function normalizeVersion ( rawVersion ) {
const containsNumbers = /\d+/.test( rawVersion )
if ( !containsNumbers ) {
return '0.0.0'
}
let version = rawVersion
// Parse each part
version = version
.split('.')
.map( part => {
// Trim leading zeros
return part.replace(/^0+/, '')
} )
.join('.')
return semver.coerce(version)
}
class BuildLists {
constructor () {
@ -193,18 +212,24 @@ class BuildLists {
}
sortBundleVersions ( bundles ) {
return mapValues( bundles, ( unsortedVersions ) => {
// console.log( 'unsortedVersions', Object.entries( unsortedVersions )[0] )
return bundles.map( bundle => {
const [
bundleIdentifier,
versionsObject
] = bundle
// Sort versions by semver
const versions = Object.entries( unsortedVersions ).sort( ( [ aVersionRaw ], [ bVersionRaw ] ) => {
const aVersion = semver.coerce( aVersionRaw )
const bVersion = semver.coerce( bVersionRaw )
const versions = Object.entries( versionsObject ).sort( ( [ aVersionRaw ], [ bVersionRaw ] ) => {
const aVersion = normalizeVersion( aVersionRaw )
const bVersion = normalizeVersion( bVersionRaw )
return semver.compare( bVersion, aVersion )
} )
return versions
return [
bundleIdentifier,
versions
]
} )
}