Skip to content

Commit

Permalink
chore:🌻 extract demo component into a separate library
Browse files Browse the repository at this point in the history
  • Loading branch information
NsdHSO committed Oct 30, 2023
1 parent 0dd2623 commit 5975387
Show file tree
Hide file tree
Showing 51 changed files with 325 additions and 63 deletions.
36 changes: 36 additions & 0 deletions ftx-demo/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../.eslintrc.base.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "coagulu",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "coagulu",
"style": "kebab-case"
}
]
},
"extends": [
"plugin:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
]
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions ftx-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ftx-demo

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test ftx-demo` to execute the unit tests.
22 changes: 22 additions & 0 deletions ftx-demo/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'ftx-demo',
preset: '../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../coverage/ftx-demo',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
7 changes: 7 additions & 0 deletions ftx-demo/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../dist/ftx-demo",
"lib": {
"entryFile": "src/index.ts"
}
}
12 changes: 12 additions & 0 deletions ftx-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ngx-demo",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^16.1.0",
"@angular/core": "^16.1.0"
},
"dependencies": {
"tslib": "^2.3.0"
},
"sideEffects": false
}
47 changes: 47 additions & 0 deletions ftx-demo/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "ftx-demo",
"$schema": "../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "ftx-demo/src",
"prefix": "coagulu",
"tags": [],
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/angular:package",
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
"options": {
"project": "ftx-demo/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "ftx-demo/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "ftx-demo/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "ftx-demo/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["ftx-demo/**/*.ts", "ftx-demo/**/*.html"]
}
}
}
}
1 change: 1 addition & 0 deletions ftx-demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/ftx-demo/demo-core.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {
@apply w-full;
}
22 changes: 22 additions & 0 deletions ftx-demo/src/lib/ftx-demo/demo-core.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
ModuleWithProviders,
NgModule,
Optional,
SkipSelf,
} from '@angular/core';
import { DemoModule } from './demo.module';

@NgModule({})
export class DemoCoreModule {
constructor(@Optional() @SkipSelf() parentModule: DemoModule) {
if (parentModule) {
throw new Error(`Demo module Is already loaded`);
}
}

static forRoot(): ModuleWithProviders<DemoModule> {
return {
ngModule: DemoModule,
};
}
}
8 changes: 8 additions & 0 deletions ftx-demo/src/lib/ftx-demo/demo.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { demoRouting } from './demo.routing';

@NgModule({
imports: [RouterModule.forChild(demoRouting)],
})
export class DemoModule {}
69 changes: 69 additions & 0 deletions ftx-demo/src/lib/ftx-demo/demo.routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { NavigationEnd, Route, Router } from '@angular/router';
import { inject } from '@angular/core';
import { catchError, filter, map, of, tap } from 'rxjs';
import { StepperService } from '../components/services/stepper.service';

export const demoRouting: Route[] = [
{
path: '',
loadComponent: () =>
import('./../components/stepper/stepper.component').then(
(c) => c.StepperComponent
),
resolve: [
() => {
const stepperService = inject(StepperService);
const router = inject(Router);
router.events
.pipe(
filter((event: any) => event instanceof NavigationEnd), //eslint-disable-line
map((v: NavigationEnd) => v.url.split('/')[1]),
tap((url) => stepperService.flagUrl$.next(url)),
catchError((err) => {
console.warn(err);
return of(false);
})
)
.subscribe();
},
],
children: [
{
path: 'intro',
loadComponent: () =>
import('./../components/contentSteps/intro/intro.component').then(
(c) => c.IntroComponent
),
},
{
path: 'infoUser',
loadComponent: () =>
import(
'./../components/contentSteps/infoUser/info-user.component'
).then((c) => c.InfoUserComponent),
},
{
path: 'spendMoney',
loadComponent: () =>
import(
'./../components/contentSteps/spendMoney/spend-money.component'
).then((c) => c.SpendMoneyComponent),
},
{
path: 'reserveBook',
loadComponent: () =>
import(
'./../components/contentSteps/reserveBook/reserve-book.component'
).then((c) => c.ReserveBookComponent),
},
{
path: '**',
redirectTo: 'spendMoney',
},
],
},
{
path: '**',
redirectTo: '',
},
];
8 changes: 8 additions & 0 deletions ftx-demo/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
globalThis.ngJest = {
testEnvironmentOptions: {
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
},
};
import 'jest-preset-angular/setup-jest';
29 changes: 29 additions & 0 deletions ftx-demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
17 changes: 17 additions & 0 deletions ftx-demo/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": []
},
"exclude": [
"src/**/*.spec.ts",
"src/test-setup.ts",
"jest.config.ts",
"src/**/*.test.ts"
],
"include": ["src/**/*.ts"]
}
9 changes: 9 additions & 0 deletions ftx-demo/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"compilationMode": "partial"
}
}
16 changes: 16 additions & 0 deletions ftx-demo/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc",
"module": "commonjs",
"target": "es2016",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
64 changes: 4 additions & 60 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,10 @@
import { NavigationEnd, Route, Router } from '@angular/router';
import { inject } from '@angular/core';
import { catchError, filter, map, of, tap } from 'rxjs';
import { StepperService } from './components/services/stepper.service';
import { Route } from '@angular/router';

export const appRoutes: Route[] = [
{
path: '',
loadComponent: () =>
import('./components/stepper/stepper.component').then(
(c) => c.StepperComponent
),
resolve: [
() => {
const stepperService = inject(StepperService);
const router = inject(Router);
router.events
.pipe(
filter((event: any) => event instanceof NavigationEnd), //eslint-disable-line
map((v: NavigationEnd) => v.url.split('/')[1]),
tap((url) => stepperService.flagUrl$.next(url)),
catchError((err) => {
console.warn(err);
return of(false);
})
)
.subscribe();
},
],
children: [
{
path: 'intro',
loadComponent: () =>
import('./components/contentSteps/intro/intro.component').then(
(c) => c.IntroComponent
),
},
{
path: 'infoUser',
loadComponent: () =>
import('./components/contentSteps/infoUser/info-user.component').then(
(c) => c.InfoUserComponent
),
},
{
path: 'spendMoney',
loadComponent: () =>
import(
'./components/contentSteps/spendMoney/spend-money.component'
).then((c) => c.SpendMoneyComponent),
},
{
path: 'reserveBook',
loadComponent: () =>
import(
'./components/contentSteps/reserveBook/reserve-book.component'
).then((c) => c.ReserveBookComponent),
},
{
path: '**',
redirectTo: 'spendMoney',
},
],
path: 'demo',
loadChildren: () =>
import('./loaders/demo-loader.module').then((m) => m.DemoLoaderModule),
},
{
path: '**',
Expand Down
Loading

0 comments on commit 5975387

Please sign in to comment.