Skip to content

Commit

Permalink
✨ Add support for resetting versions
Browse files Browse the repository at this point in the history
  • Loading branch information
priestine committed Jul 3, 2020
1 parent 86212fb commit 46b3e3c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/pure/getters/get-latest-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ interface IDeps {
type Ctx = Pick<IAppCtx, 'latestVersion' | 'allTags'>

export const getLatestVersion = ({ logWarning }: IDeps) => ({ latestVersion, allTags }: Ctx) => ({
latestVersion: latestVersion
? latestVersion
: Either.fromNullable(allTags.find((tag) => /^(\w+)?\d+\.\d+\.\d+$/.test(tag)))
.leftMap(
() => logWarning`Could not find previous semantic versions. Using ${({ y }) => y('0.0.0')}.`,
)
.fold(
() => '0.0.0',
(latestVersion) => latestVersion,
),
latestVersion:
latestVersion ||
Either.fromNullable(allTags.find((tag) => /^(\w+)?\.?\d+\.\d+\.\d+$/.test(tag)))
.leftMap(
() => logWarning`Could not find previous semantic versions. Using ${({ y }) => y('0.0.0')}.`,
)
.fold(
() => '0.0.0',
(latestVersion) => latestVersion,
),
})
6 changes: 4 additions & 2 deletions src/pure/make-new-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import type { BumpKey } from '../types/common-types'
import { Either } from '../utils/either'
import { extractVersionTuple } from '../utils/helpers'

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

export const makeNewVersion = ({
latestVersion,
public: isPublic,
prefixReset,
bumpPatch,
bumpMinor,
bumpMajor,
}: Ctx) => ({
newVersion: Either.fromNullable(extractVersionTuple(latestVersion))
.map((tuple) => tuple.slice(1, 4))
.map((tuple) => tuple.slice(2, 5))
.map((tuple) => tuple.map(Number))
.map(([major, minor, patch]) => [major, minor, bumpPatch ? patch + 1 : patch])
.map(([major, minor, patch]) => (bumpMinor ? [major, minor + 1, 0] : [major, minor, patch]))
Expand All @@ -24,6 +25,7 @@ export const makeNewVersion = ({
? [major, bumpMajor ? minor : minor + 1, 0]
: [major, minor, patch],
)
.map((result) => (prefixReset ? [1, 0, 0] : result))
.map((tuple) => tuple.join('.'))
.fold(
() => `${isPublic ? '1.0' : '0.1'}.0`,
Expand Down
2 changes: 1 addition & 1 deletion src/pure/normalizers/normalize-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const validatePublic = ({ latestVersion, public: isPublic, prefixReset }:
public:
isPublic ||
Either.fromNullable(extractVersionTuple(latestVersion))
.map(([_, major]) => major)
.map(([_, __, major]) => major)
.map(Number)
.fold(
() => prefixReset,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export const tap = <TArg>(f: Unary<TArg, any>) => (x: TArg): TArg => {
}

export const extractVersionTuple = (versionString: string) =>
/(\d+)\.(\d+)\.(\d+)/.exec(versionString)
/^(\w+)?\.?(\d+)\.(\d+)\.(\d+)/.exec(versionString)

0 comments on commit 46b3e3c

Please sign in to comment.