diff --git a/src/semver.ts b/src/semver.ts index 3dcd561..49caab3 100644 --- a/src/semver.ts +++ b/src/semver.ts @@ -69,7 +69,7 @@ export async function bumpVersion( const suffix = typeof opts.suffix === "string" ? `-${opts.suffix}` - : `-${Math.round(Date.now() / 1000)}.${commits[0].shortHash}`; + : `+${fmtDate(new Date())}-${commits[0].shortHash}`; pkg.version = config.newVersion = config.newVersion.split("-")[0] + suffix; } @@ -85,3 +85,14 @@ export async function bumpVersion( return pkg.version; } + +function fmtDate(d: Date): string { + // YYMMDD-HHMMSS: 20240919-140954 + const date = joinNumbers([d.getFullYear(), d.getMonth() + 1, d.getDate()]); + const time = joinNumbers([d.getHours(), d.getMinutes(), d.getSeconds()]); + return `${date}-${time}`; +} + +function joinNumbers(items: number[]): string { + return items.map((i) => (i + "").padStart(2, "0")).join(""); +}