Skip to content

Commit

Permalink
feat: add release type command
Browse files Browse the repository at this point in the history
  • Loading branch information
bconnorwhite committed Jan 7, 2023
1 parent d2e232b commit 628dd57
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions source/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { lint } from "./lint/index.js";
import { open } from "./open/index.js";
import { test } from "./test/index.js";
import { typecheck } from "./typecheck.js";
import { release } from "./release.js";
import { release } from "./release/index.js";

export const autorepo = clee("autorepo")
.title({ font: "slant" })
Expand All @@ -37,5 +37,5 @@ export * from "./dev.js";
export * from "./lint/index.js";
export * from "./test/index.js";
export * from "./typecheck.js";
export * from "./release.js";
export * from "./release/index.js";
export * from "./update/index.js";
35 changes: 12 additions & 23 deletions source/commands/release.ts → source/commands/release/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import clee, { parseString } from "clee";
import conventionalRecommendedBump from "conventional-recommended-bump";
import { inc as increment } from "semver";
import { updateChangelog } from "./update/changelog.js";
import { push } from "./push.js";
import { structure } from "../structure.js";
import { updateChangelog } from "../update/changelog.js";
import { releaseType } from "./type.js";
import { push } from "../push.js";
import { structure } from "../../structure.js";
import {
getOctoKit,
parseRepositoryURL,
Expand All @@ -17,36 +17,25 @@ import {
getNextChangelog,
tag,
getChangelogSegmentBody
} from "../utils/index.js";

function getReleaseType() {
return new Promise<conventionalRecommendedBump.Callback.Recommendation.ReleaseType>((resolve, reject) => {
conventionalRecommendedBump({ preset: "conventionalcommits" }, (error, { releaseType }) => {
if(error) {
reject(error);
} else {
resolve(releaseType ?? "patch");
}
});
});
}
} from "../../utils/index.js";

async function getNextVersion(currentVersion: string, stable = false) {
let releaseType = await getReleaseType();
let type = await releaseType();
if(currentVersion.startsWith("0.")) {
if(stable) {
return "1.0.0";
} else if(releaseType === "major") {
releaseType = "minor";
} else if(releaseType === "minor") {
releaseType = "patch";
} else if(type === "major") {
type = "minor";
} else if(type === "minor") {
type = "patch";
}
}
return increment(currentVersion, releaseType) ?? currentVersion;
return increment(currentVersion, type) ?? currentVersion;
}

export const release = clee("release")
.description("Bump the version, update the changelog, commit, and tag")
.command(releaseType)
.option("-c", "--cwd", "[path]", "Path to root of the package", parseString)
.option("-s", "--stable", "Bump to 1.0.0")
.option("-f", "--force", "Force the release")
Expand Down
16 changes: 16 additions & 0 deletions source/commands/release/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import clee from "clee";
import conventionalRecommendedBump from "conventional-recommended-bump";

export const releaseType = clee("type")
.description("Output the recommended release type")
.action(async () => {
return new Promise<conventionalRecommendedBump.Callback.Recommendation.ReleaseType>((resolve, reject) => {
conventionalRecommendedBump({ preset: "conventionalcommits" }, (error, result) => {
if(error) {
reject(error);
} else {
resolve(result.releaseType ?? "patch");
}
});
});
});

0 comments on commit 628dd57

Please sign in to comment.