Skip to content

Commit 5983703

Browse files
committed
Angular src restructured as modular as per angular official guidelines, .travis.yml support added for node 12
1 parent 956381c commit 5983703

26 files changed

+184
-63
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ os:
33
- osx
44
language: node_js
55
node_js:
6+
- '12'
67
- '11'
78
- '10'
89
dist: xenial

Diff for: .vscode/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"activityBar.background": "#c26c93",
4+
"activityBar.foreground": "#15202b",
5+
"activityBar.inactiveForeground": "#15202b99",
6+
"activityBarBadge.background": "#acd08e",
7+
"activityBarBadge.foreground": "#15202b"
8+
}
9+
}

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"electron:mac": "npm run build:prod && electron-builder build --mac",
3636
"test": "npm run postinstall:web && ng test",
3737
"e2e": "npm run build:prod && mocha --timeout 300000 --require ts-node/register e2e/**/*.spec.ts",
38-
"version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md"
38+
"version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
39+
"lint": "ng lint"
3940
},
4041
"devDependencies": {
4142
"@angular-devkit/build-angular": "0.800.0",

Diff for: src/app/app-routing.module.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { HomeComponent } from './components/home/home.component';
21
import { NgModule } from '@angular/core';
32
import { Routes, RouterModule } from '@angular/router';
3+
import { PageNotFoundComponent } from './shared/components';
44

55
const routes: Routes = [
6-
{
7-
path: '',
8-
component: HomeComponent
9-
}
6+
{
7+
path: '',
8+
redirectTo: 'home',
9+
pathMatch: 'full'
10+
},
11+
{
12+
path: '**',
13+
component: PageNotFoundComponent
14+
}
1015
];
1116

1217
@NgModule({
13-
imports: [RouterModule.forRoot(routes, {useHash: true})],
14-
exports: [RouterModule]
18+
imports: [RouterModule.forRoot(routes, { useHash: true })],
19+
exports: [RouterModule]
1520
})
16-
export class AppRoutingModule { }
21+
export class AppRoutingModule {}

Diff for: src/app/app.component.spec.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@ import { TestBed, async } from '@angular/core/testing';
22
import { RouterTestingModule } from '@angular/router/testing';
33
import { AppComponent } from './app.component';
44
import { TranslateModule } from '@ngx-translate/core';
5-
import { ElectronService } from './providers/electron.service';
5+
import { ElectronService } from './core/services';
66

77
describe('AppComponent', () => {
88
beforeEach(async(() => {
99
TestBed.configureTestingModule({
10-
declarations: [
11-
AppComponent
12-
],
13-
providers: [
14-
ElectronService
15-
],
16-
imports: [
17-
RouterTestingModule,
18-
TranslateModule.forRoot()
19-
]
10+
declarations: [AppComponent],
11+
providers: [ElectronService],
12+
imports: [RouterTestingModule, TranslateModule.forRoot()]
2013
}).compileComponents();
2114
}));
2215

@@ -28,6 +21,5 @@ describe('AppComponent', () => {
2821
});
2922

3023
class TranslateServiceStub {
31-
setDefaultLang(lang: string): void {
32-
}
24+
setDefaultLang(lang: string): void {}
3325
}

Diff for: src/app/app.component.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { ElectronService } from './providers/electron.service';
2+
import { ElectronService } from './core/services';
33
import { TranslateService } from '@ngx-translate/core';
44
import { AppConfig } from '../environments/environment';
55

@@ -9,13 +9,14 @@ import { AppConfig } from '../environments/environment';
99
styleUrls: ['./app.component.scss']
1010
})
1111
export class AppComponent {
12-
constructor(public electronService: ElectronService,
13-
private translate: TranslateService) {
14-
12+
constructor(
13+
public electronService: ElectronService,
14+
private translate: TranslateService
15+
) {
1516
translate.setDefaultLang('en');
1617
console.log('AppConfig', AppConfig);
1718

18-
if (electronService.isElectron()) {
19+
if (electronService.isElectron) {
1920
console.log('Mode electron');
2021
console.log('Electron ipcRenderer', electronService.ipcRenderer);
2122
console.log('NodeJS childProcess', electronService.childProcess);

Diff for: src/app/app.module.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
import 'reflect-metadata';
22
import '../polyfills';
3+
34
import { BrowserModule } from '@angular/platform-browser';
45
import { NgModule } from '@angular/core';
56
import { FormsModule } from '@angular/forms';
6-
77
import { HttpClientModule, HttpClient } from '@angular/common/http';
8+
import { CoreModule } from './core/core.module';
9+
import { SharedModule } from './shared/shared.module';
810

911
import { AppRoutingModule } from './app-routing.module';
1012

1113
// NG Translate
1214
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
1315
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
1416

15-
import { ElectronService } from './providers/electron.service';
16-
17-
import { WebviewDirective } from './directives/webview.directive';
17+
import { HomeModule } from './home/home.module';
1818

1919
import { AppComponent } from './app.component';
20-
import { HomeComponent } from './components/home/home.component';
2120

2221
// AoT requires an exported function for factories
2322
export function HttpLoaderFactory(http: HttpClient) {
2423
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
2524
}
2625

2726
@NgModule({
28-
declarations: [
29-
AppComponent,
30-
HomeComponent,
31-
WebviewDirective
32-
],
27+
declarations: [AppComponent],
3328
imports: [
3429
BrowserModule,
3530
FormsModule,
3631
HttpClientModule,
32+
CoreModule,
33+
SharedModule,
34+
HomeModule,
3735
AppRoutingModule,
3836
TranslateModule.forRoot({
3937
loader: {
4038
provide: TranslateLoader,
41-
useFactory: (HttpLoaderFactory),
39+
useFactory: HttpLoaderFactory,
4240
deps: [HttpClient]
4341
}
4442
})
4543
],
46-
providers: [ElectronService],
44+
providers: [],
4745
bootstrap: [AppComponent]
4846
})
49-
export class AppModule { }
47+
export class AppModule {}

Diff for: src/app/core/core.module.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
@NgModule({
5+
declarations: [],
6+
imports: [
7+
CommonModule
8+
]
9+
})
10+
export class CoreModule { }
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { ElectronService } from './electron.service';
4+
5+
describe('ElectronService', () => {
6+
beforeEach(() => TestBed.configureTestingModule({}));
7+
8+
it('should be created', () => {
9+
const service: ElectronService = TestBed.get(ElectronService);
10+
expect(service).toBeTruthy();
11+
});
12+
});

Diff for: src/app/providers/electron.service.ts renamed to src/app/core/services/electron/electron.service.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ import { ipcRenderer, webFrame, remote } from 'electron';
66
import * as childProcess from 'child_process';
77
import * as fs from 'fs';
88

9-
@Injectable()
9+
@Injectable({
10+
providedIn: 'root'
11+
})
1012
export class ElectronService {
11-
1213
ipcRenderer: typeof ipcRenderer;
1314
webFrame: typeof webFrame;
1415
remote: typeof remote;
1516
childProcess: typeof childProcess;
1617
fs: typeof fs;
1718

19+
get isElectron() {
20+
return window && window.process && window.process.type;
21+
}
22+
1823
constructor() {
1924
// Conditional imports
20-
if (this.isElectron()) {
25+
if (this.isElectron) {
2126
this.ipcRenderer = window.require('electron').ipcRenderer;
2227
this.webFrame = window.require('electron').webFrame;
2328
this.remote = window.require('electron').remote;
@@ -26,9 +31,4 @@ export class ElectronService {
2631
this.fs = window.require('fs');
2732
}
2833
}
29-
30-
isElectron = () => {
31-
return window && window.process && window.process.type;
32-
}
33-
3434
}

Diff for: src/app/core/services/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './electron/electron.service';

Diff for: src/app/home/home-routing.module.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { Routes, RouterModule } from '@angular/router';
4+
import { HomeComponent } from './home.component';
5+
6+
const routes: Routes = [
7+
{
8+
path: 'home',
9+
component: HomeComponent
10+
}
11+
];
12+
13+
@NgModule({
14+
declarations: [],
15+
imports: [CommonModule, RouterModule.forChild(routes)],
16+
exports: [RouterModule]
17+
})
18+
export class HomeRoutingModule {}
File renamed without changes.

Diff for: src/app/components/home/home.component.scss renamed to src/app/home/home.component.scss

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
align-items: center;
55
justify-content: center;
66

7-
background: url(../../../assets/background.jpg) no-repeat center fixed;
7+
background: url(/assets/background.jpg) no-repeat center fixed;
88
-webkit-background-size: cover; /* pour anciens Chrome et Safari */
99
background-size: cover; /* version standardisée */
1010

1111
.title {
1212
color: white;
13-
margin:0;
14-
padding:50px 20px;
13+
margin: 0;
14+
padding: 50px 20px;
1515
}
16-
1716
}

Diff for: src/app/components/home/home.component.spec.ts renamed to src/app/home/home.component.spec.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ describe('HomeComponent', () => {
99

1010
beforeEach(async(() => {
1111
TestBed.configureTestingModule({
12-
declarations: [ HomeComponent ],
13-
imports: [
14-
TranslateModule.forRoot()
15-
]
16-
})
17-
.compileComponents();
12+
declarations: [HomeComponent],
13+
imports: [TranslateModule.forRoot()]
14+
}).compileComponents();
1815
}));
1916

2017
beforeEach(() => {
@@ -29,6 +26,8 @@ describe('HomeComponent', () => {
2926

3027
it('should render title in a h1 tag', async(() => {
3128
const compiled = fixture.debugElement.nativeElement;
32-
expect(compiled.querySelector('h1').textContent).toContain('PAGES.HOME.TITLE');
29+
expect(compiled.querySelector('h1').textContent).toContain(
30+
'PAGES.HOME.TITLE'
31+
);
3332
}));
3433
});
File renamed without changes.

Diff for: src/app/home/home.module.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
import { HomeRoutingModule } from './home-routing.module';
5+
6+
import { HomeComponent } from './home.component';
7+
import { SharedModule } from '../shared/shared.module';
8+
9+
@NgModule({
10+
declarations: [HomeComponent],
11+
imports: [CommonModule, SharedModule, HomeRoutingModule]
12+
})
13+
export class HomeModule {}

Diff for: src/app/shared/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './page-not-found/page-not-found.component';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<p>
2+
page-not-found works!
3+
</p>

Diff for: src/app/shared/components/page-not-found/page-not-found.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { PageNotFoundComponent } from './page-not-found.component';
4+
5+
describe('PageNotFoundComponent', () => {
6+
let component: PageNotFoundComponent;
7+
let fixture: ComponentFixture<PageNotFoundComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ PageNotFoundComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(PageNotFoundComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-page-not-found',
5+
templateUrl: './page-not-found.component.html',
6+
styleUrls: ['./page-not-found.component.scss']
7+
})
8+
export class PageNotFoundComponent implements OnInit {
9+
constructor() {}
10+
11+
ngOnInit() {}
12+
}

Diff for: src/app/shared/directives/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './webview/webview.directive';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { WebviewDirective } from './webview.directive';
2+
3+
describe('WebviewDirective', () => {
4+
it('should create an instance', () => {
5+
const directive = new WebviewDirective();
6+
expect(directive).toBeTruthy();
7+
});
8+
});
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Directive } from '@angular/core';
22

33
@Directive({
4-
selector: 'webview'
4+
selector: '[webview]'
55
})
66
export class WebviewDirective {
7-
8-
constructor() { }
9-
7+
constructor() {}
108
}

0 commit comments

Comments
 (0)