auto-version-js
is a light & fast NPM library to automatically increase the version number of a package.
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"
}
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 }
-
VersionObject :
Object
-
AutoVersion
-
.getLocalPath() ⇒
string
-
.getPackageJSON([pathname]) ⇒
JSON
-
.getVersion([pathname]) ⇒
string
- .setVersion(version, [pathname], [indentation])
-
.parse(versionString) ⇒
VersionObject
-
.stringify(versionObject) ⇒
string
-
.toSemver(versionString) ⇒
string
-
.increment(version, level) ⇒
string
-
.major(version) ⇒
string
-
.minor(version) ⇒
string
-
.patch(version) ⇒
string
-
.getLocalPath() ⇒
Return the path of the project
Returns: string
- the path of the project where the package.json is located
Return the package.json file of the project
Returns: JSON
- the package.json
Param | Type | Description |
---|---|---|
[pathname] | string |
the path of the package.json |
Return the current version of the project
Returns: string
- the version number
Param | Type | Description |
---|---|---|
[pathname] | string |
the 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
Write the version number into package.json
Param | Type | Default | Description |
---|---|---|---|
version | string |
the version number | |
[pathname] | string |
the path of the package.json | |
[indentation] | number |
4 |
the 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}
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'
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'
Increment the version number
Returns: string
- the incremented version number
Param | Type | Description |
---|---|---|
version | string |
|
level | string |
major |
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'
Update the version number for a major update
Returns: string
- the new version number
Param | Type |
---|---|
version | string |
Example
AutoVersion.major('1.0.0') // --> '2.0.0'
AutoVersion.major('0.5.9') // --> '1.0.0'
Update the version number for a minor update
Returns: string
- the new version number
Param | Type |
---|---|
version | string |
Example
AutoVersion.minor('1.0.0') // --> '1.1.0'
AutoVersion.minor('0.5.8') // --> '0.6.0'
Update the version number for a patch update
Returns: string
- the new version number
Param | Type |
---|---|
version | string |
Example
AutoVersion.patch('1.0.0') // --> '1.0.1'
AutoVersion.patch('0.5.9') // --> '0.5.10'
Properties
Name | Type |
---|---|
major | number |
minor | number |
patch | number |
Example
{major: 1, minor: 3, patch: 7} // represents 1.3.7
2020 © Dorian Beauchesne