Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
feat(stats): separate stats into a lib
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Apr 17, 2021
1 parent 0c09ff3 commit a371d24
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 27 deletions.
37 changes: 37 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,43 @@
}
}
}
},
"core-stats": {
"projectType": "library",
"root": "packages/core/stats",
"sourceRoot": "packages/core/stats/src",
"prefix": "ngt",
"architect": {
"build": {
"builder": "@nrwl/angular:package",
"options": {
"tsConfig": "packages/core/stats/tsconfig.lib.json",
"project": "packages/core/stats/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "packages/core/stats/tsconfig.lib.prod.json"
}
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"packages/core/stats/src/**/*.ts",
"packages/core/stats/src/**/*.html"
]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/packages/core/stats"],
"options": {
"jestConfig": "packages/core/stats/jest.config.js",
"passWithNoTests": true
}
}
}
}
},
"cli": {
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
'<rootDir>/packages/core/meshes',
'<rootDir>/packages/core/lights',
'<rootDir>/packages/core/loaders',
'<rootDir>/packages/core/stats',
],
};
35 changes: 9 additions & 26 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
{
"npmScope": "angular-three",
"affected": {
"defaultBase": "master"
},
"affected": { "defaultBase": "master" },
"implicitDependencies": {
"package.json": {
"dependencies": "*",
"devDependencies": "*"
},
"package.json": { "dependencies": "*", "devDependencies": "*" },
".eslintrc.json": "*"
},
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/workspace/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"]
}
"options": { "cacheableOperations": ["build", "lint", "test", "e2e"] }
}
},
"projects": {
"core": {
"tags": ["scope:core", "type:library"]
},
"core": { "tags": ["scope:core", "type:library"] },
"core-typings": {
"tags": ["scope:core", "type:library", "context:typings"]
},
Expand All @@ -31,21 +22,13 @@
"core-geometries": {
"tags": ["scope:core", "type:library", "context:geometries"]
},
"core-meshes": {
"tags": ["scope:core", "type:library", "context:meshes"]
},
"core-lights": {
"tags": ["scope:core", "type:library", "context:lights"]
},
"core-meshes": { "tags": ["scope:core", "type:library", "context:meshes"] },
"core-lights": { "tags": ["scope:core", "type:library", "context:lights"] },
"core-loaders": {
"tags": ["scope:core", "type:library", "context:loaders"]
},
"demo": {
"tags": []
}
"demo": { "tags": [] },
"core-stats": { "tags": ["scope:core", "type:library", "context:stats"] }
},
"workspaceLayout": {
"appsDir": "packages",
"libsDir": "packages"
}
"workspaceLayout": { "appsDir": "packages", "libsDir": "packages" }
}
29 changes: 29 additions & 0 deletions packages/core/stats/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"parserOptions": { "project": ["packages/core/stats/tsconfig.*?.json"] },
"rules": {
"@angular-eslint/directive-selector": [
"error",
{ "type": "attribute", "prefix": "ngt", "style": "camelCase" }
],
"@angular-eslint/component-selector": [
"error",
{ "type": "element", "prefix": "ngt", "style": "kebab-case" }
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/core/stats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# core-stats

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

## Running unit tests

Run `nx test core-stats` to execute the unit tests.
23 changes: 23 additions & 0 deletions packages/core/stats/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
displayName: 'core-stats',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
astTransformers: {
before: [
'jest-preset-angular/build/InlineFilesTransformer',
'jest-preset-angular/build/StripStylesTransformer',
],
},
},
},
coverageDirectory: '../../../coverage/packages/core/stats',
snapshotSerializers: [
'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
'jest-preset-angular/build/AngularSnapshotSerializer.js',
'jest-preset-angular/build/HTMLCommentSerializer.js',
],
};
10 changes: 10 additions & 0 deletions packages/core/stats/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/packages/core/stats",
"lib": {
"entryFile": "src/index.ts",
"umdModuleIds": {
"three": "three"
}
}
}
11 changes: 11 additions & 0 deletions packages/core/stats/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@angular-three/core/stats",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^11.2.10",
"@angular/core": "^11.2.10"
},
"dependencies": {
"tslib": "^2.0.0"
}
}
2 changes: 2 additions & 0 deletions packages/core/stats/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './lib/core-stats.module';
export * from './lib/stats.directive';
14 changes: 14 additions & 0 deletions packages/core/stats/src/lib/core-stats.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StatsDirective } from './stats.directive';

@NgModule({
imports: [CommonModule],
declarations: [
StatsDirective
],
exports: [
StatsDirective
],
})
export class CoreStatsModule {}
8 changes: 8 additions & 0 deletions packages/core/stats/src/lib/stats.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { StatsDirective } from './stats.directive';

describe('StatsDirective', () => {
it('should create an instance', () => {
const directive = new StatsDirective();
expect(directive).toBeTruthy();
});
});
29 changes: 29 additions & 0 deletions packages/core/stats/src/lib/stats.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { AnimationStore } from '@angular-three/core';
import { DOCUMENT } from '@angular/common';
import { Directive, Inject, OnDestroy, OnInit } from '@angular/core';
import Stats from 'three/examples/jsm/libs/stats.module';

@Directive({
selector: 'ngt-stats',
exportAs: 'ngtStats',
})
export class StatsDirective implements OnInit, OnDestroy {
private stats!: Stats;

constructor(
private readonly animationStore: AnimationStore,
@Inject(DOCUMENT) private readonly document: Document
) {}

ngOnInit() {
this.stats = Stats();
this.document.body.appendChild(this.stats.dom);
this.animationStore.registerAnimation(() => {
this.stats.update();
});
}

ngOnDestroy() {
this.stats.end();
}
}
1 change: 1 addition & 0 deletions packages/core/stats/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'jest-preset-angular';
26 changes: 26 additions & 0 deletions packages/core/stats/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "../../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.lib.prod.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictTemplates": true
}
}
19 changes: 19 additions & 0 deletions packages/core/stats/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": ["src/test-setup.ts", "**/*.spec.ts"],
"include": ["**/*.ts"]
}
10 changes: 10 additions & 0 deletions packages/core/stats/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
}
10 changes: 10 additions & 0 deletions packages/core/stats/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
3 changes: 2 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
],
"@angular-three/core/meshes": ["packages/core/meshes/src/index.ts"],
"@angular-three/core/lights": ["packages/core/lights/src/index.ts"],
"@angular-three/core/loaders": ["packages/core/loaders/src/index.ts"]
"@angular-three/core/loaders": ["packages/core/loaders/src/index.ts"],
"@angular-three/core/stats": ["packages/core/stats/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
Expand Down

0 comments on commit a371d24

Please sign in to comment.