Skip to content

Commit 6966b74

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 68670f9 commit 6966b74

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

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
@@ -76,8 +76,8 @@ const AUTO_VERSION_MIN_VERSION = '2.14.0';
7676
/** Minimum craft version required for automatic version bumping from targets */
7777
const AUTO_BUMP_MIN_VERSION = '2.21.0';
7878

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

8282
export const builder: CommandBuilder = (yargs: Argv) =>
8383
yargs
@@ -665,30 +665,37 @@ async function resolveVersion(
665665
}
666666

667667
const latestTag = await getLatestTag(git);
668+
const isFirstRelease = !latestTag;
668669

669-
// Handle first release (no existing tags)
670-
if (!latestTag) {
670+
if (isFirstRelease) {
671671
logger.info(
672672
`No previous releases found. This appears to be the first release.`,
673673
);
674-
logger.info(`Using default first version: ${DEFAULT_FIRST_VERSION}`);
675-
return DEFAULT_FIRST_VERSION;
676674
}
677675

678676
// Determine bump type - either from arg or from commit analysis
679677
let bumpType: BumpType;
680678
if (version === 'auto') {
681-
const changelogResult = await getChangelogWithBumpType(git, latestTag);
682-
validateBumpType(changelogResult);
683-
bumpType = changelogResult.bumpType;
679+
if (isFirstRelease) {
680+
// For first release with auto, default to minor bump (0.0.0 -> 0.1.0)
681+
logger.info(
682+
`Using default bump type for first release: ${DEFAULT_FIRST_RELEASE_BUMP}`,
683+
);
684+
bumpType = DEFAULT_FIRST_RELEASE_BUMP;
685+
} else {
686+
const changelogResult = await getChangelogWithBumpType(git, latestTag);
687+
validateBumpType(changelogResult);
688+
bumpType = changelogResult.bumpType;
689+
}
684690
} else {
685691
bumpType = version as BumpType;
686692
}
687693

688-
// Calculate new version from latest tag
689-
const currentVersion = latestTag.replace(/^v/, '').match(/^\d/)
690-
? latestTag.replace(/^v/, '')
691-
: '0.0.0';
694+
// Calculate new version from latest tag (or 0.0.0 for first release)
695+
const currentVersion =
696+
latestTag && latestTag.replace(/^v/, '').match(/^\d/)
697+
? latestTag.replace(/^v/, '')
698+
: '0.0.0';
692699

693700
const newVersion = calculateNextVersion(currentVersion, bumpType);
694701
logger.info(

0 commit comments

Comments
 (0)