Skip to content

Commit

Permalink
✨ Add support for --prefix-reset option
Browse files Browse the repository at this point in the history
  • Loading branch information
priestine committed Jul 3, 2020
1 parent d21758d commit 94ab6ab
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Check out the [roadmap for the project](https://github.com/priestine/versions/pr
- [Bump Minor](#bump-minor)
- [Bump Major](#bump-major)
- [Public](#public)
- [Prefix Reset](#prefix-reset)
- [Dry Run](#dry-run)
- [Show Changelog](#show-changelog)
- [Conventions](#conventions)
Expand Down Expand Up @@ -134,6 +135,7 @@ All options that accept `true` or `false` as a value are **false** by default.
| [Bump Minor](#bump-minor) | **--bump-minor**[=\<true \| false>] | **PRIESTINE_VERSIONS_BUMP_MINOR**=\<true \| false> | `false` |
| [Bump Major](#bump-major) | **--bump-patch**[=\<true \| false>] | **PRIESTINE_VERSIONS_BUMP_MAJOR**=\<true \| false> | `false` |
| [Public](#public) | **--public**[=\<true \| false>] | **PRIESTINE_VERSIONS_PUBLIC**=\<true \| false> | `false` |
| [Prefix Reset](#prefix-reset) | **--prefix-reset**[=\<true \| false>] | **PRIESTINE_VERSIONS_PREFIX_RESET**=\<true \| false> | `false` |
| [Dry Run](#dry-run) | **--dry-run**[=\<true \| false>] | **PRIESTINE_VERSIONS_DRY_RUN**=\<true \| false> | `false` |
| [Show Changelog](#show-changelog) | **--show-changelog**[=\<true \| false>] | **PRIESTINE_VERSIONS_SHOW_CHANGELOG**=[=\<true \| false>] | `false` |

Expand Down Expand Up @@ -197,6 +199,10 @@ According to the Semantic Versioning specification, releases that have a MAJOR v

Applying this option is irreversible. This option is only applicable if you don't have releases with MAJOR version higher than **0**. Otherwise, your project is considered to have public API declared already and you cannot publish `0.x.x` versions anymore.

#### Prefix Reset

Setting this option to true will reset major version to **1** if the prefix changes. This option does not affect the versioning process if prefix is not provided. This option requires declaring public API. If major version was `0`, this option will force it to be set to `1`.

#### Dry Run

Execute the command but skip publishing the release. May be useful for debugging or just to check what version your application is going to have next.
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ ${({ g }) => g('--bump-patch')}[=<true|false>] Force bumping patch version
${({ g }) => g('--bump-minor')}[=<true|false>] Force bumping minor version
${({ g }) => g('--bump-major')}[=<true|false>] Force bumping major version
${({ g }) => g('--public')}[=<true|false>] Declare public API (allow bumping major versions)
${({ g }) => g('--prefix-reset')}[=<true|false>] Reset major version on prefix change
${({ g }) => g('--dry-run')}[=<true|false>] Skip publishing new release
${({ g }) => g('--debug')}[=<true|false>] Run the app in debug mode
--version Display current @priestine/versions version
--help Show usage help message (this one)
`
Expand Down Expand Up @@ -105,6 +107,7 @@ ExtendPipe.empty<IAppCtx, Partial<IAppCtx>>()
preRelease: '',
transport: 'github',
customUrl: '',
prefixReset: false,
conventions: [
{
match: ['^:ambulance:', '^:bug:', '^:lock:'],
Expand Down
22 changes: 11 additions & 11 deletions src/pure/normalizers/normalize-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import type { IAppCtx } from '../../types/app-ctx'
import { Either } from '../../utils/either'
import { extractVersionTuple } from '../../utils/helpers'

type Ctx = Pick<IAppCtx, 'latestVersion' | 'public'>
type Ctx = Pick<IAppCtx, 'latestVersion' | 'public' | 'prefixReset'>

export const validatePublic = ({ latestVersion, public: isPublic }: Ctx) => ({
public: isPublic
? isPublic
: Either.fromNullable(extractVersionTuple(latestVersion))
.map(([_, major]) => major)
.map(Number)
.fold(
() => isPublic,
(major) => major > 0,
),
export const validatePublic = ({ latestVersion, public: isPublic, prefixReset }: Ctx) => ({
public:
isPublic ||
Either.fromNullable(extractVersionTuple(latestVersion))
.map(([_, major]) => major)
.map(Number)
.fold(
() => prefixReset,
(major) => prefixReset || major > 0,
),
})
15 changes: 8 additions & 7 deletions src/types/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,7 @@ export interface IAppConfig {

/**
* Build metadata to be associated with the release, e.g. +1fabaf1,
* 01012020, etc. The + sign at the beginning is optional. If it is
* not there, @priestine/versioning will add it automatically.
* @priestine/versioning also automatically adds .# at the end of the
* build metadata so provided build metadata "01012020" becomes
* "+01012020.1". If subsequent releases get the same version and the
* same build metadata, the number increments ("+01012020.1" ->
* "+01012020.2").
* +01012020, etc.
*
* @see https://semver.org/#spec-item-10
*
Expand Down Expand Up @@ -211,4 +205,11 @@ export interface IAppConfig {
* @default false
*/
showChangelog: boolean

/**
* Force resetting major version to 1 on prefix change.
*
* @default false
*/
prefixReset: boolean
}

0 comments on commit 94ab6ab

Please sign in to comment.