Skip to content

Commit

Permalink
Merge pull request #349 from arunredhu/master
Browse files Browse the repository at this point in the history
Angular src restructured as modular
  • Loading branch information
maximegris authored Jul 29, 2019
2 parents 956381c + a284c23 commit f986a0a
Show file tree
Hide file tree
Showing 27 changed files with 197 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ src/**/*.js

# IDE - VSCode
.vscode/*
!.vscode/settings.json
.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ os:
- osx
language: node_js
node_js:
- '12'
- '11'
- '10'
dist: xenial
Expand Down
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
"electron:mac": "npm run build:prod && electron-builder build --mac",
"test": "npm run postinstall:web && ng test",
"e2e": "npm run build:prod && mocha --timeout 300000 --require ts-node/register e2e/**/*.spec.ts",
"version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md"
"version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"lint": "ng lint"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.800.0",
"@angular/cli": "8.0.1",
"@angular-devkit/build-angular": "0.800.2",
"@angular/cli": "8.0.2",
"@angular/common": "8.0.0",
"@angular/compiler": "8.0.0",
"@angular/compiler-cli": "8.0.0",
Expand All @@ -51,33 +52,33 @@
"@angular/router": "8.0.0",
"@ngx-translate/core": "11.0.1",
"@ngx-translate/http-loader": "4.0.0",
"@types/jasmine": "2.8.7",
"@types/jasminewd2": "2.0.3",
"@types/mocha": "5.2.6",
"@types/node": "8.9.4",
"@types/jasmine": "3.3.13",
"@types/jasminewd2": "2.0.6",
"@types/mocha": "5.2.7",
"@types/node": "12.0.7",
"chai": "4.2.0",
"codelyzer": "5.0.1",
"conventional-changelog-cli": "2.0.11",
"core-js": "2.6.1",
"electron": "5.0.2",
"electron-builder": "20.41.0",
"codelyzer": "5.1.0",
"conventional-changelog-cli": "2.0.21",
"core-js": "3.1.3",
"electron": "5.0.3",
"electron-builder": "20.43.0",
"electron-reload": "1.4.0",
"jasmine-core": "3.3.0",
"jasmine-core": "3.4.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "3.1.1",
"karma": "4.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "2.0.4",
"karma-coverage-istanbul-reporter": "2.0.5",
"karma-jasmine": "2.0.1",
"karma-jasmine-html-reporter": "1.4.0",
"mocha": "6.1.2",
"karma-jasmine-html-reporter": "1.4.2",
"mocha": "6.1.4",
"npm-run-all": "4.1.5",
"rxjs": "6.5.2",
"spectron": "5.0.0",
"ts-node": "7.0.1",
"ts-node": "8.2.0",
"tslint": "5.17.0",
"typescript": "3.4.5",
"typescript": "~3.4.5",
"wait-on": "3.2.0",
"webdriver-manager": "12.1.0",
"webdriver-manager": "12.1.5",
"zone.js": "0.9.1"
},
"engines": {
Expand Down
21 changes: 13 additions & 8 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { HomeComponent } from './components/home/home.component';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PageNotFoundComponent } from './shared/components';

const routes: Routes = [
{
path: '',
component: HomeComponent
}
{
path: '',
redirectTo: 'home',
pathMatch: 'full'
},
{
path: '**',
component: PageNotFoundComponent
}
];

@NgModule({
imports: [RouterModule.forRoot(routes, {useHash: true})],
exports: [RouterModule]
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule]
})
export class AppRoutingModule { }
export class AppRoutingModule {}
18 changes: 5 additions & 13 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { TranslateModule } from '@ngx-translate/core';
import { ElectronService } from './providers/electron.service';
import { ElectronService } from './core/services';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
providers: [
ElectronService
],
imports: [
RouterTestingModule,
TranslateModule.forRoot()
]
declarations: [AppComponent],
providers: [ElectronService],
imports: [RouterTestingModule, TranslateModule.forRoot()]
}).compileComponents();
}));

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

class TranslateServiceStub {
setDefaultLang(lang: string): void {
}
setDefaultLang(lang: string): void {}
}
12 changes: 7 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { ElectronService } from './providers/electron.service';
import { ElectronService } from './core/services';
import { TranslateService } from '@ngx-translate/core';
import { AppConfig } from '../environments/environment';

Expand All @@ -9,13 +9,15 @@ import { AppConfig } from '../environments/environment';
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(public electronService: ElectronService,
private translate: TranslateService) {

constructor(
public electronService: ElectronService,
private translate: TranslateService
) {
translate.setDefaultLang('en');
console.log('AppConfig', AppConfig);

if (electronService.isElectron()) {
if (electronService.isElectron) {
console.log(process.env);
console.log('Mode electron');
console.log('Electron ipcRenderer', electronService.ipcRenderer);
console.log('NodeJS childProcess', electronService.childProcess);
Expand Down
24 changes: 11 additions & 13 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
import 'reflect-metadata';
import '../polyfills';

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { HttpClientModule, HttpClient } from '@angular/common/http';
import { CoreModule } from './core/core.module';
import { SharedModule } from './shared/shared.module';

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

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

import { ElectronService } from './providers/electron.service';

import { WebviewDirective } from './directives/webview.directive';
import { HomeModule } from './home/home.module';

import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component';

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

@NgModule({
declarations: [
AppComponent,
HomeComponent,
WebviewDirective
],
declarations: [AppComponent],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
CoreModule,
SharedModule,
HomeModule,
AppRoutingModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (HttpLoaderFactory),
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
],
providers: [ElectronService],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {}
10 changes: 10 additions & 0 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class CoreModule { }
12 changes: 12 additions & 0 deletions src/app/core/services/electron/electron.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';

import { ElectronService } from './electron.service';

describe('ElectronService', () => {
beforeEach(() => TestBed.configureTestingModule({}));

it('should be created', () => {
const service: ElectronService = TestBed.get(ElectronService);
expect(service).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import { ipcRenderer, webFrame, remote } from 'electron';
import * as childProcess from 'child_process';
import * as fs from 'fs';

@Injectable()
@Injectable({
providedIn: 'root'
})
export class ElectronService {

ipcRenderer: typeof ipcRenderer;
webFrame: typeof webFrame;
remote: typeof remote;
childProcess: typeof childProcess;
fs: typeof fs;

get isElectron() {
return window && window.process && window.process.type;
}

constructor() {
// Conditional imports
if (this.isElectron()) {
if (this.isElectron) {
this.ipcRenderer = window.require('electron').ipcRenderer;
this.webFrame = window.require('electron').webFrame;
this.remote = window.require('electron').remote;
Expand All @@ -26,9 +31,4 @@ export class ElectronService {
this.fs = window.require('fs');
}
}

isElectron = () => {
return window && window.process && window.process.type;
}

}
1 change: 1 addition & 0 deletions src/app/core/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './electron/electron.service';
18 changes: 18 additions & 0 deletions src/app/home/home-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home.component';

const routes: Routes = [
{
path: 'home',
component: HomeComponent
}
];

@NgModule({
declarations: [],
imports: [CommonModule, RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class HomeRoutingModule {}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
align-items: center;
justify-content: center;

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

.title {
color: white;
margin:0;
padding:50px 20px;
margin: 0;
padding: 50px 20px;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ describe('HomeComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HomeComponent ],
imports: [
TranslateModule.forRoot()
]
})
.compileComponents();
declarations: [HomeComponent],
imports: [TranslateModule.forRoot()]
}).compileComponents();
}));

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

it('should render title in a h1 tag', async(() => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('PAGES.HOME.TITLE');
expect(compiled.querySelector('h1').textContent).toContain(
'PAGES.HOME.TITLE'
);
}));
});
File renamed without changes.
13 changes: 13 additions & 0 deletions src/app/home/home.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { HomeRoutingModule } from './home-routing.module';

import { HomeComponent } from './home.component';
import { SharedModule } from '../shared/shared.module';

@NgModule({
declarations: [HomeComponent],
imports: [CommonModule, SharedModule, HomeRoutingModule]
})
export class HomeModule {}
1 change: 1 addition & 0 deletions src/app/shared/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './page-not-found/page-not-found.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
page-not-found works!
</p>
Empty file.
Loading

0 comments on commit f986a0a

Please sign in to comment.