Skip to content

Commit f986a0a

Browse files
authored
Merge pull request #349 from arunredhu/master
Angular src restructured as modular
2 parents 956381c + a284c23 commit f986a0a

27 files changed

+197
-85
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ src/**/*.js
2525

2626
# IDE - VSCode
2727
.vscode/*
28-
!.vscode/settings.json
28+
.vscode/settings.json
2929
!.vscode/tasks.json
3030
!.vscode/launch.json
3131
!.vscode/extensions.json

.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

package.json

+21-20
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
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": {
41-
"@angular-devkit/build-angular": "0.800.0",
42-
"@angular/cli": "8.0.1",
42+
"@angular-devkit/build-angular": "0.800.2",
43+
"@angular/cli": "8.0.2",
4344
"@angular/common": "8.0.0",
4445
"@angular/compiler": "8.0.0",
4546
"@angular/compiler-cli": "8.0.0",
@@ -51,33 +52,33 @@
5152
"@angular/router": "8.0.0",
5253
"@ngx-translate/core": "11.0.1",
5354
"@ngx-translate/http-loader": "4.0.0",
54-
"@types/jasmine": "2.8.7",
55-
"@types/jasminewd2": "2.0.3",
56-
"@types/mocha": "5.2.6",
57-
"@types/node": "8.9.4",
55+
"@types/jasmine": "3.3.13",
56+
"@types/jasminewd2": "2.0.6",
57+
"@types/mocha": "5.2.7",
58+
"@types/node": "12.0.7",
5859
"chai": "4.2.0",
59-
"codelyzer": "5.0.1",
60-
"conventional-changelog-cli": "2.0.11",
61-
"core-js": "2.6.1",
62-
"electron": "5.0.2",
63-
"electron-builder": "20.41.0",
60+
"codelyzer": "5.1.0",
61+
"conventional-changelog-cli": "2.0.21",
62+
"core-js": "3.1.3",
63+
"electron": "5.0.3",
64+
"electron-builder": "20.43.0",
6465
"electron-reload": "1.4.0",
65-
"jasmine-core": "3.3.0",
66+
"jasmine-core": "3.4.0",
6667
"jasmine-spec-reporter": "4.2.1",
67-
"karma": "3.1.1",
68+
"karma": "4.1.0",
6869
"karma-chrome-launcher": "2.2.0",
69-
"karma-coverage-istanbul-reporter": "2.0.4",
70+
"karma-coverage-istanbul-reporter": "2.0.5",
7071
"karma-jasmine": "2.0.1",
71-
"karma-jasmine-html-reporter": "1.4.0",
72-
"mocha": "6.1.2",
72+
"karma-jasmine-html-reporter": "1.4.2",
73+
"mocha": "6.1.4",
7374
"npm-run-all": "4.1.5",
7475
"rxjs": "6.5.2",
7576
"spectron": "5.0.0",
76-
"ts-node": "7.0.1",
77+
"ts-node": "8.2.0",
7778
"tslint": "5.17.0",
78-
"typescript": "3.4.5",
79+
"typescript": "~3.4.5",
7980
"wait-on": "3.2.0",
80-
"webdriver-manager": "12.1.0",
81+
"webdriver-manager": "12.1.5",
8182
"zone.js": "0.9.1"
8283
},
8384
"engines": {

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 {}

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
}

src/app/app.component.ts

+7-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,15 @@ 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) {
20+
console.log(process.env);
1921
console.log('Mode electron');
2022
console.log('Electron ipcRenderer', electronService.ipcRenderer);
2123
console.log('NodeJS childProcess', electronService.childProcess);

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 {}

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 { }
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+
});

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
}

src/app/core/services/index.ts

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

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 {}

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
}

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
});

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 {}

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>

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

Whitespace-only changes.

0 commit comments

Comments
 (0)