Skip to content

Commit

Permalink
improve format
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 19, 2024
1 parent 1adc342 commit 3c38a83
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ export async function bumpVersion(
}

if (opts.suffix) {
const date = new Date();
// YYMMDD-HHMMSS: 2024819-135530
const dateStr = `${date.getFullYear()}${date.getMonth()}${date.getDate()}-${date.getHours()}${date.getMinutes()}${date.getSeconds()}`;
const suffix =
typeof opts.suffix === "string"
? `-${opts.suffix}`
: `+${dateStr}-${commits[0].shortHash}`;
: `+${fmtDate(new Date())}-${commits[0].shortHash}`;
pkg.version = config.newVersion = config.newVersion.split("-")[0] + suffix;
}

Expand All @@ -88,3 +85,14 @@ export async function bumpVersion(

return pkg.version;
}

function fmtDate(d: Date): string {
// YYMMDD-HHMMSS: 2024819-135530
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("");
}

0 comments on commit 3c38a83

Please sign in to comment.