Skip to content

Commit 32f4fe5

Browse files
committed
refactor: update next release version generator
1 parent 1bca4b5 commit 32f4fe5

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

lib/git/changelog.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import GitRelease from "#core/api/git/release";
12
import ejs from "#core/ejs";
23
import Markdown from "#core/markdown";
34
import { resolve } from "#core/utils";
@@ -61,10 +62,6 @@ export default class GitChangelog {
6162
return this.#changes.hasBreakingChanges;
6263
}
6364

64-
get hasFeatureChanges () {
65-
return this.#changes.hasFeatureChanges;
66-
}
67-
6865
// public
6966
async createChangelog ( { currentRelease, header, text, ansi = true } = {} ) {
7067
currentRelease ||= this.#currentRelease;
@@ -164,6 +161,23 @@ export default class GitChangelog {
164161
return text;
165162
}
166163

164+
getNextVersion ( preReleaseTag ) {
165+
const previousRelease = this.previousRelease || GitRelease.initialVersion;
166+
167+
try {
168+
const nextVersion = previousRelease.increment( this.hasBreakingChanges
169+
? "major"
170+
: this.#changes.hasFeatureChanges
171+
? "minor"
172+
: "patch", preReleaseTag );
173+
174+
return result( 200, nextVersion );
175+
}
176+
catch ( e ) {
177+
return result.catch( e, { "log": false } );
178+
}
179+
}
180+
167181
// private
168182
#indexChanges ( commitTypes ) {
169183
this.#changesGroups = [];

lib/package/release.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import childProcess from "node:child_process";
22
import fs from "node:fs";
33
import _path from "node:path";
44
import ansi from "#core/ansi";
5-
import GitRelease from "#core/api/git/release";
65
import GitHub from "#core/api/github";
76
import env from "#core/env";
87
import File from "#core/file";
@@ -73,18 +72,11 @@ export default class Publish {
7372
if ( status.isDirty ) return result( [ 500, `working copy or sub-repositories has uncommited changes or untracked files` ] );
7473

7574
// define new version
76-
try {
77-
this.#currentRelease = ( this.#changelog.previousRelease || GitRelease.initialVersion ).increment( this.#changelog.hasBreakingChanges
78-
? "major"
79-
: this.#changelog.hasFeatureChanges
80-
? "minor"
81-
: "patch", this.#stable
82-
? false
83-
: this.#preRelease );
84-
}
85-
catch ( e ) {
86-
return result.catch( e, { "log": false } );
87-
}
75+
res = this.#changelog.getNextVersion( this.#stable
76+
? false
77+
: this.#preRelease );
78+
if ( !res.ok ) return res;
79+
this.#currentRelease = res.data;
8880

8981
// check version can be released
9082
res = status.releases.canRelease( this.#currentRelease );

0 commit comments

Comments
 (0)