├── src
├── assets
│ └── .gitkeep
├── app
│ ├── app.component.scss
│ ├── feature-a
│ │ ├── components
│ │ │ ├── feature-a
│ │ │ │ ├── feature-a.component.scss
│ │ │ │ ├── feature-a.component.html
│ │ │ │ ├── feature-a.component.ts
│ │ │ │ └── feature-a.component.spec.ts
│ │ │ ├── feature-a-component-a
│ │ │ │ ├── feature-a-component-a.component.scss
│ │ │ │ ├── feature-a-component-a.component.html
│ │ │ │ ├── feature-a-component-a.component.ts
│ │ │ │ └── feature-a-component-a.component.spec.ts
│ │ │ ├── feature-a-component-b
│ │ │ │ ├── feature-a-component-b.component.scss
│ │ │ │ ├── feature-a-component-b.component.html
│ │ │ │ ├── feature-a-component-b.component.ts
│ │ │ │ └── feature-a-component-b.component.spec.ts
│ │ │ └── index.ts
│ │ ├── feature-a-routing.module.ts
│ │ └── feature-a.module.ts
│ ├── shared
│ │ ├── components
│ │ │ ├── button-a
│ │ │ │ ├── button-a.component.html
│ │ │ │ ├── button-a.component.scss
│ │ │ │ ├── button-a.component.ts
│ │ │ │ └── button-a.component.spec.ts
│ │ │ ├── button-b
│ │ │ │ ├── button-b.component.html
│ │ │ │ ├── button-b.component.scss
│ │ │ │ ├── button-b.component.ts
│ │ │ │ └── button-b.component.spec.ts
│ │ │ └── index.ts
│ │ └── shared.module.ts
│ ├── app.component.html
│ ├── core
│ │ ├── services
│ │ │ ├── auth.service.ts
│ │ │ ├── local-storage.service.ts
│ │ │ ├── index.ts
│ │ │ ├── auth.service.spec.ts
│ │ │ └── local-storage.service.spec.ts
│ │ └── core.module.ts
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── app-routing.module.ts
│ └── app.component.spec.ts
├── styles.scss
├── favicon.ico
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── styles
│ └── variables.scss
├── tsconfig.app.json
├── tsconfig.spec.json
├── index.html
├── tslint.json
├── main.ts
├── test.ts
├── karma.conf.js
└── polyfills.ts
├── e2e
├── tsconfig.e2e.json
├── src
│ ├── app.po.ts
│ └── app.e2e-spec.ts
└── protractor.conf.js
├── .editorconfig
├── browserslist
├── tsconfig.json
├── .gitignore
├── README.md
├── package.json
├── tslint.json
└── angular.json
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a/feature-a.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-a/feature-a-component-a.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-b/feature-a-component-b.component.scss:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-a/button-a.component.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-b/button-b.component.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/styles.scss:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RikdeVos/angular-scalable-project-structure/HEAD/src/favicon.ico
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true,
3 | foo: 'bar'
4 | };
5 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/styles/variables.scss:
--------------------------------------------------------------------------------
1 | $accent: #0093ff;
2 |
3 | %uppercase {
4 | text-transform: uppercase;
5 | letter-spacing: 0.3em;
6 | }
7 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-a/feature-a-component-a.component.html:
--------------------------------------------------------------------------------
1 |
2 | feature-a-component-a works!
3 |
4 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-b/feature-a-component-b.component.html:
--------------------------------------------------------------------------------
1 |
2 | feature-a-component-b works!
3 |
4 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-b/button-b.component.scss:
--------------------------------------------------------------------------------
1 | @import 'variables.scss';
2 |
3 | button {
4 | background: $accent;
5 | }
6 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-a/button-a.component.scss:
--------------------------------------------------------------------------------
1 | @import '../../../../styles/variables.scss';
2 |
3 | button {
4 | background: $accent;
5 | }
6 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "types": []
6 | },
7 | "exclude": [
8 | "test.ts",
9 | "**/*.spec.ts"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/core/services/auth.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 |
3 | @Injectable({
4 | providedIn: 'root'
5 | })
6 | export class AuthService {
7 | constructor() {
8 | console.log('Hello from AuthService');
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/core/services/local-storage.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 |
3 | @Injectable({
4 | providedIn: 'root'
5 | })
6 | export class LocalStorageService {
7 | constructor() {
8 | console.log('Hello from LocalStorageService');
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.scss']
7 | })
8 | export class AppComponent {
9 | title = 'best-practices-app';
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/core/services/index.ts:
--------------------------------------------------------------------------------
1 | import { AuthService } from './auth.service';
2 | import { LocalStorageService } from './local-storage.service';
3 |
4 | export const services: any[] = [AuthService, LocalStorageService];
5 |
6 | export * from './auth.service';
7 | export * from './local-storage.service';
8 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a/feature-a.component.html:
--------------------------------------------------------------------------------
1 |
2 | environment.foo: {{ foo | json }}
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get(browser.baseUrl) as Promise;
6 | }
7 |
8 | getTitleText() {
9 | return element(by.css('app-root h1')).getText() as Promise;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/app/core/core.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { HttpClientModule } from '@angular/common/http';
4 |
5 | @NgModule({
6 | declarations: [],
7 | imports: [CommonModule, HttpClientModule]
8 | })
9 | export class CoreModule {}
10 |
--------------------------------------------------------------------------------
/src/app/shared/components/index.ts:
--------------------------------------------------------------------------------
1 | import { ButtonAComponent } from './button-a/button-a.component';
2 | import { ButtonBComponent } from './button-b/button-b.component';
3 |
4 | export const components: any[] = [ButtonAComponent, ButtonBComponent];
5 |
6 | export * from './button-a/button-a.component';
7 | export * from './button-b/button-b.component';
8 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "test.ts",
12 | "polyfills.ts"
13 | ],
14 | "include": [
15 | "**/*.spec.ts",
16 | "**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-a/button-a.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-button-a',
5 | templateUrl: './button-a.component.html',
6 | styleUrls: ['./button-a.component.scss']
7 | })
8 | export class ButtonAComponent implements OnInit {
9 | constructor() {}
10 |
11 | ngOnInit() {}
12 | }
13 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-b/button-b.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-button-b',
5 | templateUrl: './button-b.component.html',
6 | styleUrls: ['./button-b.component.scss']
7 | })
8 | export class ButtonBComponent implements OnInit {
9 | constructor() {}
10 |
11 | ngOnInit() {}
12 | }
13 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | BestPracticesApp
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "app",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "app",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/core/services/auth.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { AuthService } from './auth.service';
4 |
5 | describe('AuthService', () => {
6 | beforeEach(() => TestBed.configureTestingModule({}));
7 |
8 | it('should be created', () => {
9 | const service: AuthService = TestBed.get(AuthService);
10 | expect(service).toBeTruthy();
11 | });
12 | });
13 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/browserslist:
--------------------------------------------------------------------------------
1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 | #
5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed
6 |
7 | > 0.5%
8 | last 2 versions
9 | Firefox ESR
10 | not dead
11 | not IE 9-11
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-a/feature-a-component-a.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-feature-a-component-a',
5 | templateUrl: './feature-a-component-a.component.html',
6 | styleUrls: ['./feature-a-component-a.component.scss']
7 | })
8 | export class FeatureAComponentAComponent implements OnInit {
9 | constructor() {}
10 |
11 | ngOnInit() {}
12 | }
13 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-b/feature-a-component-b.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-feature-a-component-b',
5 | templateUrl: './feature-a-component-b.component.html',
6 | styleUrls: ['./feature-a-component-b.component.scss']
7 | })
8 | export class FeatureAComponentBComponent implements OnInit {
9 | constructor() {}
10 |
11 | ngOnInit() {}
12 | }
13 |
--------------------------------------------------------------------------------
/src/app/shared/shared.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { FormsModule } from '@angular/forms';
3 | import { CommonModule } from '@angular/common';
4 |
5 | import * as fromComponents from './components';
6 |
7 | @NgModule({
8 | declarations: [...fromComponents.components],
9 | imports: [CommonModule, FormsModule],
10 | exports: [FormsModule, ...fromComponents.components]
11 | })
12 | export class SharedModule {}
13 |
--------------------------------------------------------------------------------
/src/app/core/services/local-storage.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { LocalStorageService } from './local-storage.service';
4 |
5 | describe('LocalStorageService', () => {
6 | beforeEach(() => TestBed.configureTestingModule({}));
7 |
8 | it('should be created', () => {
9 | const service: LocalStorageService = TestBed.get(LocalStorageService);
10 | expect(service).toBeTruthy();
11 | });
12 | });
13 |
--------------------------------------------------------------------------------
/src/app/feature-a/feature-a-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 | import { FeatureAComponent } from './components';
5 |
6 | const routes: Routes = [
7 | {
8 | path: '',
9 | component: FeatureAComponent
10 | }
11 | ];
12 |
13 | @NgModule({
14 | imports: [RouterModule.forChild(routes)],
15 | exports: [RouterModule]
16 | })
17 | export class FeatureARoutingModule {}
18 |
--------------------------------------------------------------------------------
/src/app/feature-a/feature-a.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { CommonModule } from '@angular/common';
3 | import { SharedModule } from '@shared/shared.module';
4 |
5 | import * as fromComponents from './components';
6 |
7 | import { FeatureARoutingModule } from './feature-a-routing.module';
8 |
9 | @NgModule({
10 | declarations: [fromComponents.components],
11 | imports: [CommonModule, SharedModule, FeatureARoutingModule]
12 | })
13 | export class FeatureAModule {}
14 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 | import { CoreModule } from '@core/core.module';
4 |
5 | import { AppRoutingModule } from './app-routing.module';
6 | import { AppComponent } from './app.component';
7 |
8 | @NgModule({
9 | declarations: [AppComponent],
10 | imports: [BrowserModule, AppRoutingModule, CoreModule],
11 | providers: [],
12 | bootstrap: [AppComponent]
13 | })
14 | export class AppModule {}
15 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 | const routes: Routes = [
5 | {
6 | path: 'feature',
7 | loadChildren: () => import('./feature-a/feature-a.module').then(m => m.FeatureAModule)
8 | },
9 | {
10 | path: '',
11 | redirectTo: 'feature',
12 | pathMatch: 'full'
13 | }
14 | ];
15 |
16 | @NgModule({
17 | imports: [RouterModule.forRoot(routes)],
18 | exports: [RouterModule]
19 | })
20 | export class AppRoutingModule {}
21 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/index.ts:
--------------------------------------------------------------------------------
1 | import { FeatureAComponent } from './feature-a/feature-a.component';
2 | import { FeatureAComponentAComponent } from './feature-a-component-a/feature-a-component-a.component';
3 | import { FeatureAComponentBComponent } from './feature-a-component-b/feature-a-component-b.component';
4 |
5 | export const components: any[] = [
6 | FeatureAComponent,
7 | FeatureAComponentAComponent,
8 | FeatureAComponentBComponent
9 | ];
10 |
11 | export * from './feature-a/feature-a.component';
12 | export * from './feature-a-component-a/feature-a-component-a.component';
13 | export * from './feature-a-component-b/feature-a-component-b.component';
14 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a/feature-a.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | import { LocalStorageService, AuthService } from '@core/services';
4 | import { environment } from '@env';
5 |
6 | @Component({
7 | selector: 'app-feature-a',
8 | templateUrl: './feature-a.component.html',
9 | styleUrls: ['./feature-a.component.scss']
10 | })
11 | export class FeatureAComponent implements OnInit {
12 | public foo: string;
13 |
14 | constructor(
15 | private localStorageService: LocalStorageService,
16 | private authService: AuthService
17 | ) {}
18 |
19 | ngOnInit() {
20 | this.foo = environment.foo;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "src",
5 | "downlevelIteration": true,
6 | "paths": {
7 | "@env": ["environments/environment"],
8 | "@shared/*": ["app/shared/*"],
9 | "@core/*": ["app/core/*"]
10 | },
11 | "outDir": "./dist/out-tsc",
12 | "sourceMap": true,
13 | "declaration": false,
14 | "module": "esnext",
15 | "moduleResolution": "node",
16 | "emitDecoratorMetadata": true,
17 | "experimentalDecorators": true,
18 | "importHelpers": true,
19 | "target": "es2015",
20 | "typeRoots": ["node_modules/@types"],
21 | "lib": ["es2018", "dom"]
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 | import { browser, logging } from 'protractor';
3 |
4 | describe('workspace-project App', () => {
5 | let page: AppPage;
6 |
7 | beforeEach(() => {
8 | page = new AppPage();
9 | });
10 |
11 | it('should display welcome message', () => {
12 | page.navigateTo();
13 | expect(page.getTitleText()).toEqual('Welcome to best-practices-app!');
14 | });
15 |
16 | afterEach(async () => {
17 | // Assert that there are no errors emitted from the browser
18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19 | expect(logs).not.toContain(jasmine.objectContaining({
20 | level: logging.Level.SEVERE,
21 | }));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false,
7 | foo: 'bar'
8 | };
9 |
10 | /*
11 | * For easier debugging in development mode, you can import the following file
12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
13 | *
14 | * This import should be commented out in production mode because it will have a negative impact
15 | * on performance if an error is thrown.
16 | */
17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 |
8 | # dependencies
9 | /node_modules
10 |
11 | # profiling files
12 | chrome-profiler-events.json
13 | speed-measure-plugin.json
14 |
15 | # IDEs and editors
16 | /.idea
17 | .project
18 | .classpath
19 | .c9/
20 | *.launch
21 | .settings/
22 | *.sublime-workspace
23 |
24 | # IDE - VSCode
25 | .vscode/*
26 | !.vscode/settings.json
27 | !.vscode/tasks.json
28 | !.vscode/launch.json
29 | !.vscode/extensions.json
30 | .history/*
31 |
32 | # misc
33 | /.sass-cache
34 | /connect.lock
35 | /coverage
36 | /libpeerconnection.log
37 | npm-debug.log
38 | yarn-error.log
39 | testem.log
40 | /typings
41 |
42 | # System Files
43 | .DS_Store
44 | Thumbs.db
45 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-a/button-a.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { ButtonAComponent } from './button-a.component';
4 |
5 | describe('ButtonAComponent', () => {
6 | let component: ButtonAComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ ButtonAComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(ButtonAComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/shared/components/button-b/button-b.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { ButtonBComponent } from './button-b.component';
4 |
5 | describe('ButtonBComponent', () => {
6 | let component: ButtonBComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ ButtonBComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(ButtonBComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a/feature-a.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { FeatureAComponent } from './feature-a.component';
4 |
5 | describe('FeatureAComponent', () => {
6 | let component: FeatureAComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ FeatureAComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(FeatureAComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './src/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: require('path').join(__dirname, './tsconfig.e2e.json')
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-a/feature-a-component-a.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { FeatureAComponentAComponent } from './feature-a-component-a.component';
4 |
5 | describe('FeatureAComponentAComponent', () => {
6 | let component: FeatureAComponentAComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ FeatureAComponentAComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(FeatureAComponentAComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/app/feature-a/components/feature-a-component-b/feature-a-component-b.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { FeatureAComponentBComponent } from './feature-a-component-b.component';
4 |
5 | describe('FeatureAComponentBComponent', () => {
6 | let component: FeatureAComponentBComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ FeatureAComponentBComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(FeatureAComponentBComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/src/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, '../coverage/best-practices-app'),
20 | reports: ['html', 'lcovonly', 'text-summary'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false
30 | });
31 | };
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Tips & Best Practices to Organize your Angular Project
2 |
3 | This project was created to demonstrate [5 Tips & Best Practices to Organize your Angular Project](https://medium.com/dev-jam/5-tips-best-practices-to-organize-your-angular-project-e900db08702e).
4 |
5 | ## Development server
6 |
7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8 |
9 | ## Code scaffolding
10 |
11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12 |
13 | ## Build
14 |
15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
16 |
17 | ## Running unit tests
18 |
19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20 |
21 | ## Running end-to-end tests
22 |
23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24 |
25 | ## Further help
26 |
27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
28 |
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { RouterTestingModule } from '@angular/router/testing';
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async(() => {
7 | TestBed.configureTestingModule({
8 | imports: [
9 | RouterTestingModule
10 | ],
11 | declarations: [
12 | AppComponent
13 | ],
14 | }).compileComponents();
15 | }));
16 |
17 | it('should create the app', () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.debugElement.componentInstance;
20 | expect(app).toBeTruthy();
21 | });
22 |
23 | it(`should have as title 'best-practices-app'`, () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | const app = fixture.debugElement.componentInstance;
26 | expect(app.title).toEqual('best-practices-app');
27 | });
28 |
29 | it('should render title in a h1 tag', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | fixture.detectChanges();
32 | const compiled = fixture.debugElement.nativeElement;
33 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to best-practices-app!');
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "best-practices-app",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "~8.2.14",
15 | "@angular/common": "~8.2.14",
16 | "@angular/compiler": "~8.2.14",
17 | "@angular/core": "~8.2.14",
18 | "@angular/forms": "~8.2.14",
19 | "@angular/platform-browser": "~8.2.14",
20 | "@angular/platform-browser-dynamic": "~8.2.14",
21 | "@angular/router": "~8.2.14",
22 | "core-js": "^2.5.4",
23 | "rxjs": "~6.5.3",
24 | "tslib": "^1.9.0",
25 | "zone.js": "~0.9.1"
26 | },
27 | "devDependencies": {
28 | "@angular-devkit/build-angular": "~0.803.20",
29 | "@angular/cli": "~8.3.20",
30 | "@angular/compiler-cli": "~8.2.14",
31 | "@angular/language-service": "~8.2.14",
32 | "@types/node": "~8.9.4",
33 | "@types/jasmine": "~2.8.8",
34 | "@types/jasminewd2": "~2.0.3",
35 | "codelyzer": "^5.0.1",
36 | "jasmine-core": "~2.99.1",
37 | "jasmine-spec-reporter": "~4.2.1",
38 | "karma": "^4.4.1",
39 | "karma-chrome-launcher": "~2.2.0",
40 | "karma-coverage-istanbul-reporter": "~2.0.1",
41 | "karma-jasmine": "~1.1.2",
42 | "karma-jasmine-html-reporter": "^0.2.2",
43 | "protractor": "~5.4.0",
44 | "ts-node": "~7.0.0",
45 | "tslint": "~5.11.0",
46 | "typescript": "~3.5.3"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tslint:recommended",
3 | "rulesDirectory": [
4 | "codelyzer"
5 | ],
6 | "rules": {
7 | "array-type": false,
8 | "arrow-parens": false,
9 | "deprecation": {
10 | "severity": "warn"
11 | },
12 | "import-blacklist": [
13 | true,
14 | "rxjs/Rx"
15 | ],
16 | "interface-name": false,
17 | "max-classes-per-file": false,
18 | "max-line-length": [
19 | true,
20 | 140
21 | ],
22 | "member-access": false,
23 | "member-ordering": [
24 | true,
25 | {
26 | "order": [
27 | "static-field",
28 | "instance-field",
29 | "static-method",
30 | "instance-method"
31 | ]
32 | }
33 | ],
34 | "no-consecutive-blank-lines": false,
35 | "no-console": [
36 | true,
37 | "debug",
38 | "info",
39 | "time",
40 | "timeEnd",
41 | "trace"
42 | ],
43 | "no-empty": false,
44 | "no-inferrable-types": [
45 | true,
46 | "ignore-params"
47 | ],
48 | "no-non-null-assertion": true,
49 | "no-redundant-jsdoc": true,
50 | "no-switch-case-fall-through": true,
51 | "no-use-before-declare": true,
52 | "no-var-requires": false,
53 | "object-literal-key-quotes": [
54 | true,
55 | "as-needed"
56 | ],
57 | "object-literal-sort-keys": false,
58 | "ordered-imports": false,
59 | "quotemark": [
60 | true,
61 | "single"
62 | ],
63 | "trailing-comma": false,
64 | "no-output-on-prefix": true,
65 | "no-inputs-metadata-property": true,
66 | "no-outputs-metadata-property": true,
67 | "no-host-metadata-property": true,
68 | "no-input-rename": true,
69 | "no-output-rename": true,
70 | "use-lifecycle-interface": true,
71 | "use-pipe-transform-interface": true,
72 | "component-class-suffix": true,
73 | "directive-class-suffix": true
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags.ts';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "best-practices-app": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {
12 | "@schematics/angular:component": {
13 | "style": "scss"
14 | }
15 | },
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "dist/best-practices-app",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "src/tsconfig.app.json",
25 | "assets": ["src/favicon.ico", "src/assets"],
26 | "styles": ["src/styles.scss"],
27 | "stylePreprocessorOptions": {
28 | "includePaths": ["src/styles"]
29 | },
30 | "scripts": [],
31 | "es5BrowserSupport": true
32 | },
33 | "configurations": {
34 | "production": {
35 | "fileReplacements": [
36 | {
37 | "replace": "src/environments/environment.ts",
38 | "with": "src/environments/environment.prod.ts"
39 | }
40 | ],
41 | "optimization": true,
42 | "outputHashing": "all",
43 | "sourceMap": false,
44 | "extractCss": true,
45 | "namedChunks": false,
46 | "aot": true,
47 | "extractLicenses": true,
48 | "vendorChunk": false,
49 | "buildOptimizer": true,
50 | "budgets": [
51 | {
52 | "type": "initial",
53 | "maximumWarning": "2mb",
54 | "maximumError": "5mb"
55 | }
56 | ]
57 | }
58 | }
59 | },
60 | "serve": {
61 | "builder": "@angular-devkit/build-angular:dev-server",
62 | "options": {
63 | "browserTarget": "best-practices-app:build"
64 | },
65 | "configurations": {
66 | "production": {
67 | "browserTarget": "best-practices-app:build:production"
68 | }
69 | }
70 | },
71 | "extract-i18n": {
72 | "builder": "@angular-devkit/build-angular:extract-i18n",
73 | "options": {
74 | "browserTarget": "best-practices-app:build"
75 | }
76 | },
77 | "test": {
78 | "builder": "@angular-devkit/build-angular:karma",
79 | "options": {
80 | "main": "src/test.ts",
81 | "polyfills": "src/polyfills.ts",
82 | "tsConfig": "src/tsconfig.spec.json",
83 | "karmaConfig": "src/karma.conf.js",
84 | "styles": ["src/styles.scss"],
85 | "stylePreprocessorOptions": {
86 | "includePaths": ["src/styles"]
87 | },
88 | "scripts": [],
89 | "assets": ["src/favicon.ico", "src/assets"]
90 | }
91 | },
92 | "lint": {
93 | "builder": "@angular-devkit/build-angular:tslint",
94 | "options": {
95 | "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
96 | "exclude": ["**/node_modules/**"]
97 | }
98 | }
99 | }
100 | },
101 | "best-practices-app-e2e": {
102 | "root": "e2e/",
103 | "projectType": "application",
104 | "prefix": "",
105 | "architect": {
106 | "e2e": {
107 | "builder": "@angular-devkit/build-angular:protractor",
108 | "options": {
109 | "protractorConfig": "e2e/protractor.conf.js",
110 | "devServerTarget": "best-practices-app:serve"
111 | },
112 | "configurations": {
113 | "production": {
114 | "devServerTarget": "best-practices-app:serve:production"
115 | }
116 | }
117 | },
118 | "lint": {
119 | "builder": "@angular-devkit/build-angular:tslint",
120 | "options": {
121 | "tsConfig": "e2e/tsconfig.e2e.json",
122 | "exclude": ["**/node_modules/**"]
123 | }
124 | }
125 | }
126 | }
127 | },
128 | "defaultProject": "best-practices-app"
129 | }
130 |
--------------------------------------------------------------------------------