Versioning support for Angular.
Script to handle versioning for angular.
- set a version number
- bump version (patch, minor, major)
Automatique update files :
- package.json
- environments/environment
Simply get your application version number into a component from environment variables.
$ git clone https://github.com/Stayfi/ng-versioning.git
$ cd ng-versioning
$ npm install
$ ng serve
Open your browser on http://localhost:4200/
Update version number :
$ npm run version get
App version : 1.0.0
$ npm run version set 2.0.0
App version number in your browser will show 2.0.0-DEV
.
And no suffix in prod : 2.0.0
.
$ npm run version bump minor
App version number in your browser will show 2.1.0-DEV
.
$ npm install --save-dev replace-in-file
$ npm install --save-dev semver
export const environment = {
...,
version: '1.0.0'
};
- Import :
import { environment } from '../environments/environment';
- Into Class Component :
appVersion: String = environment.version;
import { Component } from '@angular/core';
import { environment } from '../environments/environment';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
appVersion: String = environment.version;
title = 'app';
}
App v.{{appVersion}}
$ node ./ng-versioning.js get
App version : 1.0.0
$ node ./ng-versioning.js set 2.0.0
> 2.0.0
$ node ./ng-versioning.js bump patch
> 2.0.1
$ node ./ng-versioning.js bump minor
> 2.1.1
$ node ./ng-versioning.js bump major
> 3.1.1
Or add into 'package.json' :
"scripts": {
...,
"version": "node ./ng-versioning.js"
}
And run it with npm :
$ npm run version get
App version : 1.0.0
$ npm run version set 2.0.0
> 2.0.0
$ npm run version bump patch
> 2.0.1
$ npm run version bump minor
> 2.1.1
$ npm run version bump major
> 3.1.1
Add into 'ng-version.js' :
if (versionNumber) {
...
updateFile("src/environments/environment.hmr.ts", "\"", "HMR");
}
updateFile params :
- "file" : Environment file to update version (src/environments/environment.xxx.ts)
- "Quotation" : "'", "\"" or "" (simple, double, none)
- "Suffix" : suffix addind to the version number (x.x.x-Suffix)
Stayfi B. - [email protected]
Help and minor corrections.
Correct semantic (patch) and vocabulary.
Adding "get" to show actual version number.
Adding check for dependencies.
Fix: README.md.
First version, working.
MIT license