Skip to content

Commit

Permalink
Adding version popup. Fixes #204.
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Sep 26, 2018
1 parent a7f8f09 commit e7811f4
Show file tree
Hide file tree
Showing 10 changed files with 1,180 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
before_install:
- psql -c "create user flowchat with password 'asdf' superuser" -U postgres
- psql -c 'create database flowchat;' -U postgres
- cd ui; npm i -g @angular/cli; yarn; ng build --prod --aot;
- cd ui; yarn; yarn build --prod --aot;
- cp -R dist/ ../service/src/main/resources
- cd ../service
- echo -e 'jdbc.url=jdbc\:postgresql\://127.0.0.1/flowchat\njdbc.username=flowchat\njdbc.password=asdf\nsorting_created_weight=86400\nsorting_number_of_votes_weight=0.001\nsorting_avg_rank_weight=0.01\nreddit_client_id=\nreddit_client_secret=\nreddit_username=\nreddit_password='>flowchat.properties
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
FROM node:9 as node-builder

# Hacky workaround for installing @angular/cli
RUN chmod a+w /usr/local/lib/node_modules && chmod a+w /usr/local/bin
USER node
RUN npm i -g @angular/cli@latest
# RUN chmod a+w /usr/local/lib/node_modules && chmod a+w /usr/local/bin
# USER node
# RUN npm i -g @angular/cli@latest

# Build front end resources
USER root
Expand All @@ -17,7 +17,7 @@ RUN echo "ENDPOINT_NAME is ${ENDPOINT_NAME}"
RUN echo "export const environment = {production: true,endpoint: '${ENDPOINT_NAME}/',websocket: 'ws`echo ${ENDPOINT_NAME}|cut -b 5-999`/poll'};" > src/environments/environment.prod.ts
RUN cat src/environments/environment.prod.ts
RUN yarn
RUN ng build --prod --aot
RUN yarn build --prod --aot


FROM maven:3.5-jdk-8 as java-builder
Expand Down
3 changes: 1 addition & 2 deletions install_dev.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Building the front end
cd ui
#npm i -g @angular/cli
yarn
ng build --aot
yarn build --aot
cp -R dist/ ../service/src/main/resources
cd ..

Expand Down
3 changes: 1 addition & 2 deletions install_prod.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Building the front end
cd ui
npm i -g @angular/cli
yarn
ng build --prod --aot
yarn build --prod --aot
cp -R dist/ ../service/src/main/resources
cd ..
echo $PWD
51 changes: 51 additions & 0 deletions ui/git.version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fs = require('fs');
import { Observable, combineLatest } from 'rxjs';

let exec = require('child_process').exec;

const revision = new Observable<string>(s => {
exec('git rev-parse --short HEAD',
function (error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});

const branch = new Observable<string>(s => {
exec('git rev-parse --abbrev-ref HEAD',
function (error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});

const tag = new Observable<string>(s => {
exec('git describe --abbrev=0 --tags',
function (error: Error, stdout: Buffer, stderr: Buffer) {
if (error !== null) {
console.log('git error: ' + error + stderr);
}
s.next(stdout.toString().trim());
s.complete();
});
});

combineLatest(revision, branch, tag)
.subscribe(([revision, branch, tag]) => {
console.log(`version: '${process.env.npm_package_version}', revision: '${revision}', branch: '${branch}', tag: '${tag}'`);

const content = '// this file is automatically generated by git.version.ts script\n' +
`export const versions = {version: '${process.env.npm_package_version}', revision: '${revision}', branch: '${branch}', tag: '${tag}'};`;

fs.writeFileSync(
'src/environments/versions.ts',
content,
{ encoding: 'utf8' }
);
});
5 changes: 4 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"license": "MIT",
"angular-cli": {},
"scripts": {
"prestart": "ts-node git.version.ts",
"start": "ng serve",
"prebuild": "ts-node git.version.ts",
"build": "ng build",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
Expand Down Expand Up @@ -58,7 +61,7 @@
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.3.2",
"ts-node": "~2.0.0",
"ts-node": "^7.0.1",
"tslint": "~4.5.0",
"typescript": "2.7.2"
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/components/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<button role="button" class="btn btn-outline-primary mr-2" (click)="createCommunity()">Create a community</button>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/dessalines/flowchat" target="_blank">about</a>
<a class="nav-link" href="https://github.com/dessalines/flowchat" target="_blank" placement="bottom" [tooltip]="version">about</a>
</li>
<li class="nav-item">
<a role="button" class="nav-link" href="https://github.com/dessalines/flowchat" placement="bottom" target="_blank">
Expand Down
3 changes: 3 additions & 0 deletions ui/src/app/components/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Router } from '@angular/router';
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import { ToasterService } from 'angular2-toaster';
import { versions } from 'environments/versions';

declare var Favico: any;

Expand Down Expand Up @@ -35,6 +36,8 @@ export class NavbarComponent implements OnInit {

public collapseNavbar: boolean = true;

public version: string = JSON.stringify(versions, null, 2);

constructor(public userService: UserService,
private loginService: LoginService,
private router: Router,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/environments/versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this file is automatically generated by git.version.ts script
export const versions = {version: '0.0.0', revision: 'a7f8f09', branch: 'master', tag: 'v0.3.2.6'};
Loading

0 comments on commit e7811f4

Please sign in to comment.