1.0.0-beta.3 • Published 10 months ago

autovs-scripts v1.0.0-beta.3

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

Automatic Versioning Scripts

Build Status NPM Version NPM Downloads

A node.js package that contains functions to manage versions.

Installation

npm install autovs-scripts

Usage

After you have installed the autovs-scripts, you can use it on your code. Follow the code below.

// Initialize the versions component
const versions = require('autovs-scripts');

// Create a version object based on the given string
var myVersion = versions.parseVersion('v1.2.3-alpha.1+001250');

console.log(`Current major is: ${myVersion.major}`);
// Current major is: 1

console.log(`Current firm version is: ${myVersion.firmVersion().formattedVersion()}`);
// Current firm version is: v1.2.3

// Bump version
var myBumpedVersion = versions.bumpVersion('v1.2.3-alpha.1+001250', 'major', 2000);

console.log(`Bumped version is: ${myBumpedVersion.formattedVersion()}`);
// Bumped version is: v2.0.0-alpha.1+002000

The versions object will expose the following methods:

MethodDescription
parseVersion()Parses a string into a version object
bumpVersion()Bump the given version to the next level
newVersionObject()Creates a version object based on the given input

Version Object

Both parseVersion() and bumpVersion() return a version object. This object is composed of the following members:

MemberDescription
majorThe version major
minorThe version minor
patchThe version patch
preReleaseIdentifierThe pre-release identifier (alpha, beta, rc)
preReleaseVersionThe pre-release version
preReleaseBuildThe build number (only for pre-releases)
formattedVersion()Returns the formatted version (Example: v1.2.0-alpha.1+001210)
firmVersion()Returns the firm version (Example: for v1.2.0-alpha.1+001210, this method will return v1.2.0)

You can manually create a Version Object by calling the newVersionObject().

Parse Version - parseVersion()

The parseVersion() method will convert a string into a Version Object.

Input Parameters

namerequireddescription
versionyesA string containing the version to be parsed. Example v1.2.0-alpha.1+001210.

Output

The function returns a Version Object containing the individual components of a version.

Bump Version - bumpVersion()

The bumpVersion() method will move the current version into the next level, and return a Version Object.

Input Parameters

namerequireddescription
currentVersionyesA string containing the current version to be bumped. Example v1.2.0-alpha.1+001210.
levelyesThe level that needs to be bumped for the version. Valid values are: major, minor, patch, prerelease-identifier, prerelease-version.
buildNumbernoA number representing the build number to be added to the end of the version.

Output

The function returns a Version Object containing the bumped version.