From 3edcbf0918be48e01e3cb3a52b330cb7dca41da6 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 22:25:53 +0200 Subject: [PATCH 1/2] Show the version of the current build, distinguishing between development and production builds. The layout needs to be refined, it's still quite ugly as of now. --- src/app/app.component.html | 1 + src/app/app.component.ts | 2 ++ src/environments/environment.prod.ts | 3 ++- src/environments/environment.ts | 3 ++- src/tsconfig.app.json | 4 +++- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 4c88d65..f5211f1 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -14,4 +14,5 @@
+Version: {{VERSION}} diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1ec7c84..eeab833 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,6 +3,7 @@ import {ConverterRegistryService} from './converterregistry.service'; import {InputComponentManagerService} from './inputcomponentmanager.service'; import {Step} from './step'; import {Converter} from './converter/converter'; +import {environment} from '../environments/environment'; @Component({ selector: 'app-root', @@ -10,6 +11,7 @@ import {Converter} from './converter/converter'; styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { + public readonly VERSION: string = environment.appVersion; public steps: Step[] = []; public converters: Converter[] = []; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 3612073..d8516dc 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,3 +1,4 @@ export const environment = { - production: true + production: true, + appVersion: require('../../package.json').version }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 600fdaf..1e580fa 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -3,7 +3,8 @@ // The list of file replacements can be found in `angular.json`. export const environment = { - production: false + production: false, + appVersion: `${require('../../package.json').version} (development build)` }; /* diff --git a/src/tsconfig.app.json b/src/tsconfig.app.json index 190fd30..c27166e 100644 --- a/src/tsconfig.app.json +++ b/src/tsconfig.app.json @@ -2,7 +2,9 @@ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", - "types": [] + "types": [ + "node" + ] }, "exclude": [ "test.ts", From 2c50fa071370565c35ebaf2a0bb22ea30b1bff2f Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Fri, 31 Aug 2018 22:43:21 +0200 Subject: [PATCH 2/2] Use dedicated component to display the version. --- angular.json | 6 +++++- src/app/app.component.html | 2 +- src/app/app.component.ts | 2 -- src/app/app.module.ts | 10 +++++++-- src/app/version/version.component.html | 1 + src/app/version/version.component.scss | 10 +++++++++ src/app/version/version.component.spec.ts | 25 +++++++++++++++++++++++ src/app/version/version.component.ts | 15 ++++++++++++++ src/environments/environment.ts | 2 +- 9 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 src/app/version/version.component.html create mode 100644 src/app/version/version.component.scss create mode 100644 src/app/version/version.component.spec.ts create mode 100644 src/app/version/version.component.ts diff --git a/angular.json b/angular.json index e52d019..eae0de1 100644 --- a/angular.json +++ b/angular.json @@ -8,7 +8,11 @@ "sourceRoot": "src", "projectType": "application", "prefix": "app", - "schematics": {}, + "schematics": { + "@schematics/angular:component": { + "styleext": "scss" + } + }, "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", diff --git a/src/app/app.component.html b/src/app/app.component.html index f5211f1..c96ed95 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -14,5 +14,5 @@
-Version: {{VERSION}} + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index eeab833..1ec7c84 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,7 +3,6 @@ import {ConverterRegistryService} from './converterregistry.service'; import {InputComponentManagerService} from './inputcomponentmanager.service'; import {Step} from './step'; import {Converter} from './converter/converter'; -import {environment} from '../environments/environment'; @Component({ selector: 'app-root', @@ -11,7 +10,6 @@ import {environment} from '../environments/environment'; styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { - public readonly VERSION: string = environment.appVersion; public steps: Step[] = []; public converters: Converter[] = []; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3734a54..7ef864d 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,16 +5,22 @@ import {ConverterRegistryService} from './converterregistry.service'; import {InputComponentManagerService} from './inputcomponentmanager.service'; import {NativeLibraryWrapperService} from './nativelibrarywrapper.service'; import {FormsModule} from '@angular/forms'; +import {VersionComponent} from './version/version.component'; @NgModule({ declarations: [ - AppComponent + AppComponent, + VersionComponent ], imports: [ BrowserModule, FormsModule ], - providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService], + providers: [ + ConverterRegistryService, + InputComponentManagerService, + NativeLibraryWrapperService + ], bootstrap: [AppComponent] }) export class AppModule { diff --git a/src/app/version/version.component.html b/src/app/version/version.component.html new file mode 100644 index 0000000..566bf3c --- /dev/null +++ b/src/app/version/version.component.html @@ -0,0 +1 @@ +
Version: {{VERSION}}
diff --git a/src/app/version/version.component.scss b/src/app/version/version.component.scss new file mode 100644 index 0000000..46b3ceb --- /dev/null +++ b/src/app/version/version.component.scss @@ -0,0 +1,10 @@ +div { + font-size: smaller; + color: gray; + display: block; + text-align: right; + margin-right: 2em; + &.dev { + color: red; + } +} diff --git a/src/app/version/version.component.spec.ts b/src/app/version/version.component.spec.ts new file mode 100644 index 0000000..fcd0475 --- /dev/null +++ b/src/app/version/version.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { VersionComponent } from './version.component'; + +describe('VersionComponent', () => { + let component: VersionComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ VersionComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(VersionComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/version/version.component.ts b/src/app/version/version.component.ts new file mode 100644 index 0000000..53d2c1a --- /dev/null +++ b/src/app/version/version.component.ts @@ -0,0 +1,15 @@ +import {Component} from '@angular/core'; +import {environment} from '../../environments/environment'; + +@Component({ + selector: 'app-version', + templateUrl: './version.component.html', + styleUrls: ['./version.component.scss'] +}) +export class VersionComponent { + public readonly PROD: boolean = environment.production; + public readonly VERSION: string = environment.appVersion + (this.PROD ? '' : ' (development build)'); + + constructor() { + } +} diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 1e580fa..70b66dd 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { production: false, - appVersion: `${require('../../package.json').version} (development build)` + appVersion: require('../../package.json').version }; /*