Home Manual Reference Source
import {VersionUtils} from 'projext/src/services/common/versionUtils.js'
public class | source

VersionUtils

A set of utilities to work with the version of the project.

Constructor Summary

Public Constructor
public

constructor(environmentUtils: EnvironmentUtils, appLogger: Logger, pathUtils: PathUtils)

Class constructor.

Member Summary

Public Members
public

A local reference for the appLogger service.

public

A local reference for the environmentUtils service.

public

The default fallback version in case none can be retrieved.

public

A local reference for the pathUtils service.

Method Summary

Public Methods
public

createRevisionFile(revisionFilename: string, environmentVariable: string): Promise<string, Error>

Create the revision file with either the version from the environment or, if the project is on a GIT repository, with the first 7 letters of the last commit hash.

public

getEnvironmentVersion(environmentVariable: string, withFallback: boolean): string

Get the version from an environment variable.

public

getVersion(revisionFilename: string, environmentVariable: string): string

Look for a version on both the revision file and the environment variable.

public

Get the version from the revision file.

Public Constructors

public constructor(environmentUtils: EnvironmentUtils, appLogger: Logger, pathUtils: PathUtils) source

Class constructor.

Params:

NameTypeAttributeDescription
environmentUtils EnvironmentUtils

To read the environment variables.

appLogger Logger

To inform the user if something goes wrong.

pathUtils PathUtils

To build paths for the revision file.

Public Members

public appLogger: Logger source

A local reference for the appLogger service.

public environmentUtils: EnvironmentUtils source

A local reference for the environmentUtils service.

public fallbackVersion: string source

The default fallback version in case none can be retrieved.

public pathUtils: PathUtils source

A local reference for the pathUtils service.

Public Methods

public createRevisionFile(revisionFilename: string, environmentVariable: string): Promise<string, Error> source

Create the revision file with either the version from the environment or, if the project is on a GIT repository, with the first 7 letters of the last commit hash.

Params:

NameTypeAttributeDescription
revisionFilename string

The path to where the revision file will be created.

environmentVariable string

The name of the environment variable.

Return:

Promise<string, Error>

If everything goes well, the promise will resolve with the version the method wrote on the file.

public getEnvironmentVersion(environmentVariable: string, withFallback: boolean): string source

Get the version from an environment variable.

Params:

NameTypeAttributeDescription
environmentVariable string

The name of the environment variable.

withFallback boolean
  • optional
  • default: true

If true and there's no version on the variable, it will return the fallback version.

Return:

string

public getVersion(revisionFilename: string, environmentVariable: string): string source

Look for a version on both the revision file and the environment variable.

Params:

NameTypeAttributeDescription
revisionFilename string

The path to the revision file.

environmentVariable string

The name of the environment variable.

Return:

string

public getVersionFromFile(filename: string): string source

Get the version from the revision file. If the revision file doesn't exist or can't be loaded, it will return an empty string.

Params:

NameTypeAttributeDescription
filename string

The path to the revision file.

Return:

string