diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-19 01:00:39 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-19 05:08:33 +0800 |
commit | 3e64b3da398a90e6ddfc287ebf28ec780b64b56f (patch) | |
tree | c1788d98471b58f90d99fa8bedb1553725cec4b6 /packages/monorepo-scripts/src/utils | |
parent | 9a748c8bf1dfd1a090e3d44a4cbebb59bcedd5e6 (diff) | |
download | dexon-0x-contracts-3e64b3da398a90e6ddfc287ebf28ec780b64b56f.tar dexon-0x-contracts-3e64b3da398a90e6ddfc287ebf28ec780b64b56f.tar.gz dexon-0x-contracts-3e64b3da398a90e6ddfc287ebf28ec780b64b56f.tar.bz2 dexon-0x-contracts-3e64b3da398a90e6ddfc287ebf28ec780b64b56f.tar.lz dexon-0x-contracts-3e64b3da398a90e6ddfc287ebf28ec780b64b56f.tar.xz dexon-0x-contracts-3e64b3da398a90e6ddfc287ebf28ec780b64b56f.tar.zst dexon-0x-contracts-3e64b3da398a90e6ddfc287ebf28ec780b64b56f.zip |
Use semver library instead of semverUtils
Diffstat (limited to 'packages/monorepo-scripts/src/utils')
-rw-r--r-- | packages/monorepo-scripts/src/utils/changelog_utils.ts | 5 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/utils/semver_utils.ts | 56 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/utils/utils.ts | 7 |
3 files changed, 2 insertions, 66 deletions
diff --git a/packages/monorepo-scripts/src/utils/changelog_utils.ts b/packages/monorepo-scripts/src/utils/changelog_utils.ts index 4e09fc842..a589fe985 100644 --- a/packages/monorepo-scripts/src/utils/changelog_utils.ts +++ b/packages/monorepo-scripts/src/utils/changelog_utils.ts @@ -3,13 +3,12 @@ import * as _ from 'lodash'; import * as moment from 'moment'; import * as path from 'path'; import { exec as execAsync } from 'promisify-child-process'; +import semver = require('semver'); import semverSort = require('semver-sort'); import { constants } from '../constants'; import { Change, Changelog, VersionChangelog } from '../types'; -import { semverUtils } from './semver_utils'; - const CHANGELOG_MD_HEADER = ` <!-- This file is auto-generated using the monorepo-scripts package. Don't edit directly. @@ -56,7 +55,7 @@ export const changelogUtils = { return true; } const lastEntry = changelog[0]; - if (semverUtils.lessThan(lastEntry.version, currentVersion)) { + if (semver.lt(lastEntry.version, currentVersion)) { throw new Error( `Found CHANGELOG version lower then current package version. ${packageName} current: ${currentVersion}, Changelog: ${ lastEntry.version diff --git a/packages/monorepo-scripts/src/utils/semver_utils.ts b/packages/monorepo-scripts/src/utils/semver_utils.ts deleted file mode 100644 index d5c6b2d17..000000000 --- a/packages/monorepo-scripts/src/utils/semver_utils.ts +++ /dev/null @@ -1,56 +0,0 @@ -import * as _ from 'lodash'; -import semverSort = require('semver-sort'); - -// Regex that matches semantic versions only including digits and dots. -const SEM_VER_REGEX = /^(\d+\.){1}(\d+\.){1}(\d+){1}$/gm; - -export const semverUtils = { - /** - * Checks whether version a is lessThan version b. Supplied versions must be - * Semantic Versions containing only numbers and dots (e.g 1.4.0). - * @param a version of interest - * @param b version to compare a against - * @return Whether version a is lessThan version b - */ - lessThan(a: string, b: string): boolean { - this.assertValidSemVer('a', a); - this.assertValidSemVer('b', b); - if (a === b) { - return false; - } - const sortedVersions = semverSort.desc([a, b]); - const isALessThanB = sortedVersions[0] === b; - return isALessThanB; - }, - /** - * Checks whether version a is greaterThan version b. Supplied versions must be - * Semantic Versions containing only numbers and dots (e.g 1.4.0). - * @param a version of interest - * @param b version to compare a against - * @return Whether version a is greaterThan version b - */ - greaterThan(a: string, b: string): boolean { - this.assertValidSemVer('a', a); - this.assertValidSemVer('b', b); - if (a === b) { - return false; - } - const sortedVersions = semverSort.desc([a, b]); - const isAGreaterThanB = sortedVersions[0] === a; - return isAGreaterThanB; - }, - assertValidSemVer(variableName: string, version: string): void { - if (!version.match(SEM_VER_REGEX)) { - throw new Error( - `SemVer versions should only contain numbers and dots. Encountered: ${variableName} = ${version}`, - ); - } - }, - getLatestVersion(versions: string[]): string { - _.each(versions, version => { - this.assertValidSemVer('version', version); - }); - const sortedVersions = semverSort.desc(versions); - return sortedVersions[0]; - }, -}; diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 93de0d940..16a84b869 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -11,13 +11,6 @@ export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, - getNextPatchVersion(currentVersion: string): string { - const versionSegments = currentVersion.split('.'); - const patch = _.parseInt(_.last(versionSegments) as string); - const newPatch = patch + 1; - const newPatchVersion = `${versionSegments[0]}.${versionSegments[1]}.${newPatch}`; - return newPatchVersion; - }, async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise<LernaPackage[]> { const updatedPublicPackages = await this.getLernaUpdatedPackagesAsync(shouldIncludePrivate); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); |