Skip to content

Commit

Permalink
Merge pull request #1065 from snypy/git-based-build-version
Browse files Browse the repository at this point in the history
Update foorter build version based on git
  • Loading branch information
nezhar authored Mar 31, 2022
2 parents 19effc3 + f1252d5 commit ccd020c
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"root": true,
"ignorePatterns": [
"projects/**/*",
"index.html"
"index.html",
"src/environments/version.ts"
],
"extends": ["prettier"],
"plugins": [
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ testem.log
# System Files
.DS_Store
Thumbs.db

# git-describe
src/environments/version.ts
22 changes: 22 additions & 0 deletions helpers/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { gitDescribeSync } = require('git-describe');
const { resolve, relative } = require('path');
const { writeFileSync } = require('fs-extra');

const gitInfo = gitDescribeSync({
dirtyMark: false,
dirtySemver: false,
longSemver: true,
match: '[0-9]*'
});

gitInfo.date = new Date();

const file = resolve(__dirname, '..', 'src', 'environments', 'version.ts');
writeFileSync(file,
`// AUTO GENERATED FILE
/* tslint:disable */
export const VERSION = ${JSON.stringify(gitInfo, null, 4)};
/* tslint:enable */
`, { encoding: 'utf-8' });

console.log(`Wrote version info ${gitInfo.raw} to ${relative(resolve(__dirname, '..'), file)}`);
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test": "ng test --watch=false",
"coverage": "ng test --codeCoverage=true --watch=false",
"lint": "ng lint",
"e2e": "ng e2e"
"e2e": "ng e2e",
"postinstall": "node helpers/version.js"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -69,6 +70,7 @@
"eslint": "^8.12.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"git-describe": "^4.1.0",
"jasmine-core": "~4.0.1",
"jasmine-spec-reporter": "~7.0.0",
"karma": "^6.3.17",
Expand Down
5 changes: 4 additions & 1 deletion src/app/components/footer/footer.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<div class="footer text-end">
<small> <b>V1.0-beta.7</b> | <a target="_BLANK" href="https:/snypy/snypy-frontend">Contribute</a> </small>
<small>
<b>{{ version.tag }}</b> <small *ngIf="version.distance > 0">({{ version.suffix }})</small> |
<a target="_BLANK" href="https:/snypy/snypy-frontend">Contribute</a>
</small>
</div>
5 changes: 4 additions & 1 deletion src/app/components/footer/footer.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Component } from '@angular/core';
import { VERSION } from '../../../environments/version';

@Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss'],
})
export class FooterComponent {}
export class FooterComponent {
version = VERSION;
}

0 comments on commit ccd020c

Please sign in to comment.