0.3.10 • Published 2 years ago

auto-version-js v0.3.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Auto Version JS

npm version npm downloads

auto-version-js is a light & fast NPM library to automatically increase the version number of a package.

Installation

First, install the npm package :

npm i -D auto-version-js

Then to increment the version number, simply run :

npx auto-version --patch  # +0.0.1
npx auto-version --minor  # +0.1.0
npx auto-version --major  # +1.0.0
npx auto-version          # no args is equivalent to --patch

To implement it in your package.json file :

"scripts": {
    "publish": "npx auto-version && npm publish"
}

Documentation

In this library, versionString represents a version as a string : '1.2.3' and versionObject represents a version as an object : { major: 1, minor: 2, patch: 3 }

Classes

Typedefs

AutoVersion

AutoVersion.getLocalPath() ⇒ string

Return the path of the project

Returns: string - the path of the project where the package.json is located

AutoVersion.getPackageJSON(pathname) ⇒ JSON

Return the package.json file of the project

Returns: JSON - the package.json

ParamTypeDescription
pathnamestringthe path of the package.json

AutoVersion.getVersion(pathname) ⇒ string

Return the current version of the project

Returns: string - the version number

ParamTypeDescription
pathnamestringthe path of the package.json

Example

AutoVersion.getVersion()              // --> the version of the current project | ex : 0.5.2
AutoVersion.getVersion('../any/dir')  // --> the version of the project in this directory

AutoVersion.setVersion(version, pathname, indentation)

Write the version number into package.json

ParamTypeDefaultDescription
versionstringthe version number
pathnamestringthe path of the package.json
indentationnumber4the number of space to pretty print the package.json file

Example

AutoVersion.setVersion('0.2.3')
AutoVersion.setVersion('0.2.3', '../any/dir')
AutoVersion.setVersion('0.2.3', '../any/dir', 4)  // the package.json will be indented with 4 spaces

AutoVersion.parse(versionString) ⇒ VersionObject

Extract the major, minor & patch number from a semver version number

Param
versionString

Example

AutoVersion.parse('1.4.2')  // --> {major: 1, minor: 4, patch: 2}

AutoVersion.stringify(versionObject) ⇒ string

Stringify a versionObject

Returns: string - the version representation of the string

Param
versionObject

Example

AutoVersion.stringify({major: 1, minor: 4, patch: 2})  // --> '1.4.2'

AutoVersion.toSemver(versionString) ⇒ string

Convert a version into semver standard

Returns: string - the semver version number

Param
versionString

Example

AutoVersion.toSemver('1.3.5')      // --> '1.3.5'
AutoVersion.toSemver('1.3')        // --> '1.3.0'
AutoVersion.toSemver('v1.3.5')     // -->  '1.3.5'
AutoVersion.toSemver('version 3')  // -->  '3.0.0'

AutoVersion.increment(version, level) ⇒ string

Increment the version number

Returns: string - the incremented version number

ParamTypeDescription
versionstring
levelstringmajorminorpatch

Example

AutoVersion.increment('0.4.7', 'patch')  // --> '0.4.8'
AutoVersion.increment('0.4.7', 'minor')  // --> '0.5.0'
AutoVersion.increment('0.4.7', 'major')  // --> '1.0.0'

AutoVersion.major(version) ⇒ string

Update the version number for a major update

Returns: string - the new version number

ParamType
versionstring

Example

AutoVersion.major('1.0.0')  // --> '2.0.0'
AutoVersion.major('0.5.9')  // --> '1.0.0'

AutoVersion.minor(version) ⇒ string

Update the version number for a minor update

Returns: string - the new version number

ParamType
versionstring

Example

AutoVersion.minor('1.0.0')  // --> '1.1.0'
AutoVersion.minor('0.5.8')  // --> '0.6.0'

AutoVersion.patch(version) ⇒ string

Update the version number for a patch update

Returns: string - the new version number

ParamType
versionstring

Example

AutoVersion.patch('1.0.0')  // --> '1.0.1'
AutoVersion.patch('0.5.9')  // --> '0.5.10'

VersionObject : Object

Properties

NameType
majornumber
minornumber
patchnumber

Example

{major: 1, minor: 3, patch: 7}  // represents 1.3.7

2020 © Dorian Beauchesne