Skip to content

Commit

Permalink
✨ Add support for versions with no zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
priestine committed Jul 3, 2020
1 parent 1aed845 commit 847e00c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ ExtendPipe.empty<IAppCtx, Partial<IAppCtx>>()
transport: 'github',
customUrl: '',
prefixReset: false,
noTrailingZeroes: false,
conventions: [
{
match: ['^:ambulance:', '^:bug:', '^:lock:'],
Expand Down
16 changes: 13 additions & 3 deletions src/pure/getters/get-latest-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ interface IDeps {
logWarning: LogFunction
}

type Ctx = Pick<IAppCtx, 'latestVersion' | 'allTags'>
type Ctx = Pick<IAppCtx, 'latestVersion' | 'allTags' | 'noTrailingZeroes'>

export const getLatestVersion = ({ logWarning }: IDeps) => ({ latestVersion, allTags }: Ctx) => ({
export const getLatestVersion = ({ logWarning }: IDeps) => ({
latestVersion,
allTags,
noTrailingZeroes,
}: Ctx) => ({
latestVersion:
latestVersion ||
Either.fromNullable(allTags.find((tag) => /^(\w+)?\.?\d+\.\d+\.\d+$/.test(tag)))
Either.fromNullable(
allTags.find((tag) =>
noTrailingZeroes
? /^(\w+)?\d+\.?(\d+)?\.?(\d+)?$/.test(tag)
: /^(\w+)?\d+\.\d+\.\d+$/.test(tag),
),
)
.leftMap(
() => logWarning`Could not find previous semantic versions. Using ${({ y }) => y('0.0.0')}.`,
)
Expand Down
3 changes: 2 additions & 1 deletion src/pure/make-new-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export const makeNewVersion = ({
bumpMajor,
}: Ctx) => ({
newVersion: Either.fromNullable(extractVersionTuple(latestVersion))
.map((tuple) => tuple.slice(2, 5))
.map((tuple) => tuple.slice(1, 4))
.map((tuple) => tuple.map(Number))
.map((tuple) => tuple.map((x) => (Number.isNaN(x) ? 0 : x)))
.map(([major, minor, patch]) => [major, minor, bumpPatch ? patch + 1 : patch])
.map(([major, minor, patch]) => (bumpMinor ? [major, minor + 1, 0] : [major, minor, patch]))
.map(([major, minor, patch]) =>
Expand Down
8 changes: 8 additions & 0 deletions src/types/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,12 @@ export interface IAppConfig {
* @default false
*/
prefixReset: boolean

/**
* Remove trailing zeroes when creating new versions. E.g. `1.1.0` -> `1.1` or `14.0.0` -> `14`.
* This is not compliant with Semantic Versioning!
*
* @default false
*/
noTrailingZeroes: boolean
}
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) =>
/^(\w+)?\.?(\d+)\.(\d+)\.(\d+)/.exec(versionString)
/\.?(\d+)\.?(\d+)?\.?(\d+)?/.exec(versionString)

0 comments on commit 847e00c

Please sign in to comment.