Skip to content

Commit

Permalink
feat: add identifier base
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Sep 20, 2023
1 parent 46993f1 commit e2a3dde
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Options:
Defaults to "true" when "org" is set, false otherwise
-o, --org <string> The NPM org scope that should be used WITHOUT "@" sign or trailing "/"
--preid [string] The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver
--identifier-base <string> The base number (0 or 1) to be used for the prerelease identifier.
--no-identifier-base Do not use a base number for the prerelease identifier.
-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.
Expand Down Expand Up @@ -136,6 +138,7 @@ package). It should be named `.cliff-jumperrc`, optionally suffixed with
- `--mono-repo` and `--no-mono-repo` map to `monoRepo`
- `--org` maps to `org`
- `--preid` maps to `preid`
- `--identifier-base` and `--no-identifier-base` map to `identifierBase`
- `--commit-message-template` maps to `commitMessageTemplate`
- `--tag-template` maps to `tagTemplate`
- `--install` map to `install`
Expand Down Expand Up @@ -188,6 +191,8 @@ This library has opinionated defaults for its options. These are as follows:
- `--first-release` will default to `undefined`.
- `--org` will default to `undefined`.
- `--preid` will default to `undefined`.
- `--identifier-base` will default to `undefined`. Alternatively, you can force
this to `false` by providing `--no-identifier-base`.
- `--install` will default to `undefined`.
- `--skip-changelog` will default to `false` (`true` when `CI` environment
variable is `'true'`). Alternatively you can force this to false by providing
Expand Down
4 changes: 4 additions & 0 deletions assets/cliff-jumper.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"description": "The \"prerelease identifier\" to use as a prefix for the \"prerelease\" part of a semver",
"type": "string"
},
"identifierBase": {
"description": "The base number (0 or 1) to be used for the \"prerelease identifier\". Supply `false` to not use one.",
"type": ["boolean", "string"]
},
"commitMessageTemplate": {
"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"
Expand Down
8 changes: 7 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '#lib/utils';
import { isNullishOrEmpty } from '@sapphire/utilities';
import { blue, blueBright, cyan, green, yellow } from 'colorette';
import { Command } from 'commander';
import { Command, InvalidArgumentError } from 'commander';
import { readFile } from 'node:fs/promises';
import { URL } from 'node:url';

Expand Down Expand Up @@ -58,6 +58,11 @@ const command = new Command()
.option('--no-mono-repo', monoRepoDescription)
.option('-o, --org <string>', 'The NPM org scope that should be used WITHOUT "@" sign or trailing "/"')
.option('--preid [string]', 'The "prerelease identifier" to use as a prefix for the "prerelease" part of a semver')
.option('--identifier-base <number>', 'The base number (0 or 1) to be used for the prerelease identifier.', (input) => {
if (input === '0' || input === '1') return input;
throw new InvalidArgumentError('Not a number of 0 or 1.');
})
.option('--no-identifier-base', 'Do not use a base number for the prerelease identifier.')
.option(
'-c, --commit-message-template [string]',
[
Expand Down Expand Up @@ -103,6 +108,7 @@ logVerboseInfo(
`${indent}mono repo: ${JSON.stringify(options.monoRepo)}`,
`${indent}npm org: ${JSON.stringify(options.org)}`,
`${indent}preid: ${JSON.stringify(options.preid)}`,
`${indent}identifier base: ${JSON.stringify(options.identifierBase)}`,
`${indent}commit message template: ${JSON.stringify(options.commitMessageTemplate)}`,
`${indent}tag template: ${JSON.stringify(options.tagTemplate)}`,
`${indent}install: ${JSON.stringify(options.install)}`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/bump-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function bumpVersion(options: Options, releaseType: Recommendation.Releas
});
}

const newVersion = Semver.inc(currentClean, `${getReleaseType(options, releaseType)}`, options.preid ?? '');
const newVersion = Semver.inc(currentClean, `${getReleaseType(options, releaseType)}`, options.preid ?? '', options.identifierBase);

if (isNullishOrEmpty(newVersion)) {
return logVerboseError({
Expand Down
3 changes: 3 additions & 0 deletions src/lib/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { IdentifierBase } from 'semver/functions/inc.js';

export default undefined;

declare module 'commander' {
Expand All @@ -6,6 +8,7 @@ declare module 'commander' {
org: string;
packagePath: string;
preid: string;
identifierBase: IdentifierBase | false;
dryRun: boolean;
verbose: boolean;
skipChangelog: boolean;
Expand Down

0 comments on commit e2a3dde

Please sign in to comment.