Skip to content

Commit 69ce415

Browse files
committed
refactor: Address PR review comments
- Fix docs: Change 'craft prepare auto' to 'craft prepare' in quick example - Merge first release logic with version calculation: - Use default bump type (minor) instead of hardcoded version - Allow explicit bump types to work for first release (e.g., major -> 1.0.0) - More consistent code flow
1 parent 298a051 commit 69ce415

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

docs/src/content/docs/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { Card, CardGrid } from '@astrojs/starlight/components';
5050
craft init
5151

5252
# Auto-determine version from conventional commits
53-
craft prepare auto
53+
craft prepare
5454

5555
# Or specify a bump type
5656
craft prepare minor

src/__tests__/prepare-dry-run.e2e.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,12 @@ targets: []
586586

587587
const combinedOutput = stdout + stderr;
588588

589-
// Should detect first release and default to 0.1.0
589+
// Should detect first release and default to 0.1.0 (minor bump from 0.0.0)
590590
expect(combinedOutput).toContain('No previous releases found');
591591
expect(combinedOutput).toContain('first release');
592-
expect(combinedOutput).toContain('default first version: 0.1.0');
592+
expect(combinedOutput).toContain(
593+
'default bump type for first release: minor',
594+
);
593595
expect(combinedOutput).toContain('Releasing version 0.1.0');
594596
expect(combinedOutput).toContain('release/0.1.0');
595597
}, 60000);

src/commands/prepare.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ const DEFAULT_BUMP_VERSION_PATH = join('scripts', 'bump-version.sh');
6767
/** Minimum craft version required for auto-versioning */
6868
const AUTO_VERSION_MIN_VERSION = '2.14.0';
6969

70-
/** Default version for first release when no tags exist */
71-
const DEFAULT_FIRST_VERSION = '0.1.0';
70+
/** Default bump type for first release when using auto-versioning */
71+
const DEFAULT_FIRST_RELEASE_BUMP: BumpType = 'minor';
7272

7373
export const builder: CommandBuilder = (yargs: Argv) =>
7474
yargs
@@ -601,30 +601,37 @@ async function resolveVersion(
601601
}
602602

603603
const latestTag = await getLatestTag(git);
604+
const isFirstRelease = !latestTag;
604605

605-
// Handle first release (no existing tags)
606-
if (!latestTag) {
606+
if (isFirstRelease) {
607607
logger.info(
608608
`No previous releases found. This appears to be the first release.`,
609609
);
610-
logger.info(`Using default first version: ${DEFAULT_FIRST_VERSION}`);
611-
return DEFAULT_FIRST_VERSION;
612610
}
613611

614612
// Determine bump type - either from arg or from commit analysis
615613
let bumpType: BumpType;
616614
if (version === 'auto') {
617-
const changelogResult = await getChangelogWithBumpType(git, latestTag);
618-
validateBumpType(changelogResult);
619-
bumpType = changelogResult.bumpType;
615+
if (isFirstRelease) {
616+
// For first release with auto, default to minor bump (0.0.0 -> 0.1.0)
617+
logger.info(
618+
`Using default bump type for first release: ${DEFAULT_FIRST_RELEASE_BUMP}`,
619+
);
620+
bumpType = DEFAULT_FIRST_RELEASE_BUMP;
621+
} else {
622+
const changelogResult = await getChangelogWithBumpType(git, latestTag);
623+
validateBumpType(changelogResult);
624+
bumpType = changelogResult.bumpType;
625+
}
620626
} else {
621627
bumpType = version as BumpType;
622628
}
623629

624-
// Calculate new version from latest tag
625-
const currentVersion = latestTag.replace(/^v/, '').match(/^\d/)
626-
? latestTag.replace(/^v/, '')
627-
: '0.0.0';
630+
// Calculate new version from latest tag (or 0.0.0 for first release)
631+
const currentVersion =
632+
latestTag && latestTag.replace(/^v/, '').match(/^\d/)
633+
? latestTag.replace(/^v/, '')
634+
: '0.0.0';
628635

629636
const newVersion = calculateNextVersion(currentVersion, bumpType);
630637
logger.info(

0 commit comments

Comments
 (0)