Skip to content

Commit

Permalink
feat: add tag template option
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed May 7, 2022
1 parent ab86313 commit 1e047b6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 13 deletions.
32 changes: 26 additions & 6 deletions README.md
Expand Up @@ -89,12 +89,21 @@ Options:
--preid [string] The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver
-c, --commit-message-template [string] A custom commit message template to use.
Defaults to "chore({{name}}): release {{full-name}}@{{new-version}}"
You can use "{{new-version}}" in your template which will be dynamically replaced with whatever the new version is that will be
published.
You can use "{{name}}" in your template, this will be replaced with the name provided through "-n", "--name" or the same value set in
your config file.
You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}"
(when "org" is provided).
You can use "{{new-version}}" in your template which will be dynamically replaced with whatever the new version is that will be published.
You can use "{{name}}" in your template, this will be replaced with the name provided through "-n", "--name" or the same value set in your config
file.
You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}" (when "org" is
provided).
--tag-template [string] A custom tag template to use.
When "org" is provided this will default to "@{{org}}/{{name}}@{{new-version}}", for example "@favware/cliff-jumper@1.0.0"
When "org" is not provided this will default to "v{{new-version}}", for example "v1.0.0"
You can use "{{new-version}}" in your template which will be dynamically replaced with whatever the new version is that will be published.
You can use "{{org}}" in your template, this will be replaced with the org provided through "-o", "--org" or the same value set in your config
file.
You can use "{{name}}" in your template, this will be replaced with the name provided through "-n", "--name" or the same value set in your config
file.
You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}" (when "org" is
provided).
--skip-changelog Whether to skip updating your CHANGELOG.md
default "true" when CI=true, "false" otherwise (default: false)
-t, --skip-tag Whether to skip creating a git tag
Expand All @@ -118,6 +127,7 @@ package). It should be named `.cliff-jumperrc`, optionally suffixed with
- `--org` maps to `org`
- `--preid` maps to `preid`
- `--commit-message-template` maps to `commitMessageTemplate`
- `--tag-template` maps to `tagTemplate`
- `--skip-changelog` maps to `skipChangelog`
- `--skip-tag` maps to `skipTag`
- `--verbose` maps to `verbose`
Expand Down Expand Up @@ -173,6 +183,16 @@ This library has opinionated defaults for its options. These are as follows:
the same value set in your config file
- `{{full-name}}` will be replaced with `{{name}}` (when `org` is not
provided), or `@{{org}}/{{name}}` (when `org` is provided).
- `--tag-template` will default to
`{{full-name}}@{{new-version}}` (when `org` is provided) **or** `v{{new-version}}` (when `org` is not provided)
- `{{new-version}}` will be replaced with the new version that will be
published
- `{{name}}` will be replaced with the name provided through `-n`, `--name` or
the same value set in your config file
- `{{org}}` will be replaced with the org provided through `-o`, `--org` or
the same value set in your config file
- `{{full-name}}` will be replaced with `{{name}}` (when `org` is not
provided), or `@{{org}}/{{name}}` (when `org` is provided).
- `--verbose` will default to `false`.

### Merging of config file, defaults and CLI provided flags
Expand Down
6 changes: 5 additions & 1 deletion assets/cliff-jumper.schema.json
Expand Up @@ -34,7 +34,11 @@
"type": "string"
},
"commitMessageTemplate": {
"description": "A custom commit message template to use.\nDefaults to \"chore({{name}}): release {{full-name}}@{{new-version}}\"\nYou can use \"{{new-version}}\" in your template which will be dynamically replaced with whatever the new version is that will be published.\nYou can use \"{{name}}\" in your template, this will be replaced with the name provided through \"-n\", \"--name\" or the same value set in your config file.\nYou can use \"{{full-name}}\" in your template, this will be replaced \"{{name}}\" (when \"org\" is not provided), or \"@{{org}}/{{name}}\" (when \"org\" is provided).",
"description": "A custom commit message template to use.\nDefaults to \"chore({{name}}): release {{full-name}}@{{new-version}}\"\n\nYou can use \"{{new-version}}\" in your template which will be dynamically replaced with whatever the new version is that will be published.\n\nYou can use \"{{name}}\" in your template, this will be replaced with the name provided through \"-n\", \"--name\" or the same value set in your config file.\n\nYou can use \"{{full-name}}\" in your template, this will be replaced \"{{name}}\" (when \"org\" is not provided), or \"@{{org}}/{{name}}\" (when \"org\" is provided).",
"type": "string"
},
"taTgemplate": {
"description": "A custom tag template to use.\n\nWhen \"org\" is provided this will default to \"@{{org}}/{{name}}@{{new-version}}\", for example \"@favware/cliff-jumper@1.0.0\"\nWhen \"org\" is not provided this will default to \"v{{new-version}}\", for example \"v1.0.0\"\n\nYou can use \"{{new-version}}\" in your template which will be dynamically replaced with whatever the new version is that will be published.\n\nYou can use \"{{org}}\" in your template, this will be replaced with the org provided through \"-o\", \"--org\" or the same value set in your config \nfile.\n\nYou can use \"{{name}}\" in your template, this will be replaced with the name provided through \"-n\", \"--name\" or the same value set in your config \nfile.\n\nYou can use \"{{full-name}}\" in your template, this will be replaced \"{{name}}\" (when \"org\" is not provided), or \"@{{org}}/{{name}}\" (when \"org\" is provided).",
"type": "string"
},
"skipChangelog": {
Expand Down
18 changes: 15 additions & 3 deletions src/cli.ts
Expand Up @@ -50,6 +50,18 @@ const command = new Command()
'You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}" (when "org" is provided).'
].join('\n')
)
.option(
'--tag-template [string]',
[
'A custom tag template to use.',
'When "org" is provided this will default to "@{{org}}/{{name}}@{{new-version}}", for example "@favware/cliff-jumper@1.0.0"',
'When "org" is not provided this will default to "v{{new-version}}", for example "v1.0.0"',
'You can use "{{new-version}}" in your template which will be dynamically replaced with whatever the new version is that will be published.',
'You can use "{{org}}" in your template, this will be replaced with the org provided through "-o", "--org" or the same value set in your config file.',
'You can use "{{name}}" in your template, this will be replaced with the name provided through "-n", "--name" or the same value set in your config file.',
'You can use "{{full-name}}" in your template, this will be replaced "{{name}}" (when "org" is not provided), or "@{{org}}/{{name}}" (when "org" is provided).'
].join('\n')
)
.option(
'--skip-changelog',
[
Expand Down Expand Up @@ -118,16 +130,16 @@ if (!options.dryRun) {

if (!options.skipChangelog) {
const newVersion = await getNewVersion(options);
const tag = options.org && options.monoRepo ? `${getFullPackageName(options)}@${newVersion}` : `v${newVersion}`;
const tagForChangelog = options.org && options.monoRepo ? `${getFullPackageName(options)}@${newVersion}` : `v${newVersion}`;

await updateChangelog(options, tag);
await updateChangelog(options, tagForChangelog);

if (!options.skipTag) {
await stageFiles();

await commitRelease(options, newVersion);

await createTag(tag);
await createTag(options, newVersion);

const hasYarn = await usesModernYarn();

Expand Down
22 changes: 19 additions & 3 deletions src/commands/create-tag.ts
@@ -1,9 +1,25 @@
import { doActionAndLog } from '#lib/utils';
import { doActionAndLog, getFullPackageName } from '#lib/utils';
import { isNullishOrEmpty } from '@sapphire/utilities';
import type { OptionValues } from 'commander';
import { execSync } from 'node:child_process';

export function createTag(tag: string) {
export function createTag(options: OptionValues, newVersion: string) {
if (isNullishOrEmpty(options.tagTemplate)) {
if (isNullishOrEmpty(options.org)) {
options.tagTemplate = 'v{{new-version}}';
} else {
options.tagTemplate = `{{full-name}}@{{new-version}}`;
}
}

options.tagTemplate = options.tagTemplate
.replaceAll('{{new-version}}', newVersion)
.replaceAll('{{org}}', options.org)
.replaceAll('{{name}}', options.name)
.replaceAll('{{full-name}}', getFullPackageName(options));

return doActionAndLog(
'Creating tag', //
execSync(`git tag ${tag}`)
execSync(`git tag ${options.tagTemplate}`)
);
}
1 change: 1 addition & 0 deletions src/lib/interfaces.d.ts
Expand Up @@ -13,5 +13,6 @@ declare module 'commander' {
firstRelease: boolean;
monoRepo: boolean;
commitMessageTemplate: string;
tagTemplate: string;
}
}

0 comments on commit 1e047b6

Please sign in to comment.