Skip to content

Commit

Permalink
feat: Better error message with version.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3xysteak committed Apr 2, 2024
1 parent 7690fc3 commit fe59df7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ const VERSION_OPTIONS = ['patch', 'minor', 'major'] as const
export type VersionOption = typeof VERSION_OPTIONS[number]

export function version(str: string, targetVer: VersionOption | string): string {
if (targetVer === undefined)
throw new Error('Missed version.')

if (!VERSION_OPTIONS.includes(targetVer as VersionOption))
return targetVer

const versionArr = str.split('.').map(v => Number(v))
let versionArr: number[]

try {
versionArr = str.split('.').map(v => Number(v))
}
catch (error) {
throw new Error('Invalid project version.')
}

if (versionArr.length !== 3)
throw new Error('Invalid version')
throw new Error('Invalid project version.')

const versionMap: Record<string, (arr: number[]) => number[]> = {
patch: arr => [arr[0], arr[1], arr[2] + 1],
Expand Down

0 comments on commit fe59df7

Please sign in to comment.