@freddydrodev/auto-version
v0.0.4
Published
An auto version library for NPM
Downloads
1
Maintainers
Readme
Auto Version JS
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
- .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
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
| Param | Type | Description | | --- | --- | --- | | [pathname] | string | the path of the package.json |
AutoVersion.getVersion([pathname]) ⇒ string
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
AutoVersion.setVersion(version, [pathname], [indentation])
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}
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
| Param | Type | Description | | --- | --- | --- | | version | string | | | level | string | major | minor | patch |
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
| Param | Type | | --- | --- | | version | string |
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
| Param | Type | | --- | --- | | version | string |
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
| Param | Type | | --- | --- | | version | string |
Example
AutoVersion.patch('1.0.0') // --> '1.0.1'
AutoVersion.patch('0.5.9') // --> '0.5.10'
VersionObject : Object
Properties
| Name | Type | | --- | --- | | major | number | | minor | number | | patch | number |
Example
{major: 1, minor: 3, patch: 7} // represents 1.3.7
2020 © Dorian Beauchesne