-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,54 @@ | ||
import { createExecute } from "./utils/execute-file.js"; | ||
import { formatCommitMessage } from "./utils/format-commit-message.js"; | ||
import type { ForkConfigOptions } from "./configuration.js"; | ||
import type { bumpVersion } from "./version.js"; | ||
import type { BumpVersion } from "./version.js"; | ||
|
||
type TagChanges = { | ||
gitTagOutput: string; | ||
currentBranchName: string; | ||
hasPackageJson: boolean; | ||
pushMessage: string; | ||
publishMessage: string; | ||
}; | ||
|
||
export async function tagChanges( | ||
options: ForkConfigOptions, | ||
bumpResult: Awaited<ReturnType<typeof bumpVersion>>, | ||
) { | ||
bumpResult: BumpVersion, | ||
): Promise<TagChanges> { | ||
const { executeGit } = createExecute(options); | ||
|
||
const shouldSign = options.sign ? "-s" : "-a"; | ||
const tag = `${options.tagPrefix}${bumpResult.next}`; | ||
/** @example "v1.2.3" or "version/1.2.3" */ | ||
const tag = `${options.tagPrefix}${bumpResult.nextVersion}`; | ||
|
||
const gitTagOutput = await executeGit( | ||
"tag", | ||
shouldSign, | ||
tag, | ||
"-m", | ||
formatCommitMessage( | ||
options.changelogPresetConfig?.releaseCommitMessageFormat || "chore(release): {{currentTag}}", | ||
bumpResult.next, | ||
options.changelogPresetConfig?.releaseCommitMessageFormat, | ||
bumpResult.nextVersion, | ||
), | ||
); | ||
|
||
// Get the current branch name | ||
const gitRevParse = await executeGit("rev-parse", "--abbrev-ref", "HEAD"); | ||
const currentBranchName = await executeGit("rev-parse", "--abbrev-ref", "HEAD"); | ||
|
||
const pushMessage = `Run \`git push --follow-tags origin ${currentBranchName.trim()}\` to push the tag.`; | ||
|
||
const hasPackageJson = bumpResult.files.some((file) => file.name === "package.json"); | ||
const isPreRelease = `${bumpResult.releaseType}`.startsWith("pre"); | ||
const publishMessage = isPreRelease | ||
? `Run \`npm publish --tag ${ | ||
typeof options.preReleaseTag === "string" ? options.preReleaseTag : "prerelease" | ||
}\` to publish the package.` | ||
: `Run \`npm publish\` to publish the package.`; | ||
|
||
return { | ||
gitTagOutput, | ||
gitRevParse, | ||
currentBranchName, | ||
hasPackageJson, | ||
pushMessage, | ||
publishMessage, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
export function formatCommitMessage(message: string, newVersion: string): string { | ||
/** | ||
* Formats the commit message by replacing the `{{currentTag}}` placeholder | ||
* globally with the new version. | ||
* | ||
* Falls back to `chore(release): {{currentTag}}` if message is argument is falsy. | ||
*/ | ||
export function formatCommitMessage(message: string | undefined, newVersion: string): string { | ||
if (!message) { | ||
message = "chore(release): {{currentTag}}"; | ||
} | ||
|
||
return message.replace(new RegExp("{{currentTag}}", "g"), newVersion); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters