Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import path from 'path'
import fs from 'node:fs'
import path from 'node:path'
import type { GitCraftConfig, Plugin } from './plugins'
import { ChangelogPlugin } from './plugins/changelog'

Expand Down
19 changes: 14 additions & 5 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@ program
filterPath: opts.path,
})

const label = result.dryRun ? ' [dry-run]' : ''
let label: string
if (result.published) {
label = ' [published]'
} else if (result.dryRun) {
label = ' [dry-run]'
} else {
label = ' [tag]'
}
console.log(`\nGitCraft Release${label}`)
console.log(` ${result.previousVersion} → ${result.nextVersion} (${result.bumpType})`)
console.log(` Tag: ${result.tag}`)
console.log(` Commits: ${result.commitCount}`)
if (result.published) console.log(` Published: ${result.tag} pushed to origin`)

if (result.dryRun) {
console.log('\nDry run — no plugins ran, no files were written.')
if (result.published) {
console.log(`\nPublished: ${result.tag} pushed to origin`)
} else if (result.nextVersion === result.previousVersion) {
console.log('\nNo version bump needed based on commit messages')
} else if (result.dryRun) {
console.log('\nThis was a dry run — no changes were made')
}
} catch (err) {
console.error(`\nError: ${(err as Error).message}`)
Expand Down
5 changes: 4 additions & 1 deletion cli/src/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { BumpType } from './analyzer'

export function bumpVersion(current: string, type: BumpType): string {
const next = semver.inc(current, type)
if (!next) throw new Error(`Cannot increment invalid version: "${current}"`)
if (!next) {
throw new Error(`Cannot increment invalid version: "${current}"`)
}

return next
}
10 changes: 7 additions & 3 deletions cli/src/tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync } from 'child_process'
import { execSync } from 'node:child_process'
import semver from 'semver'

export interface TagResolution {
Expand All @@ -22,7 +22,9 @@ export function resolveLatestTag(prefix: string = 'v'): TagResolution {
return makeInitial(prefix)
}

if (!rawOutput) return makeInitial(prefix)
if (!rawOutput) {
return makeInitial(prefix)
}

const candidates = rawOutput
.split('\n')
Expand All @@ -35,7 +37,9 @@ export function resolveLatestTag(prefix: string = 'v'): TagResolution {
})
.filter((e): e is { tag: string; latest: string } => e !== null)

if (candidates.length === 0) return makeInitial(prefix)
if (candidates.length === 0) {
return makeInitial(prefix)
}

// Sort descending so index 0 is the highest version
candidates.sort((a, b) => semver.rcompare(a.latest, b.latest))
Expand Down