Skip to content

Commit e1cf6c7

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
feat(core): generate core
1 parent f1e1f3e commit e1cf6c7

25 files changed

+13463
-2065
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": ["**/*"],
4+
"plugins": ["@nx"],
5+
"overrides": [
6+
{
7+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8+
"rules": {
9+
"@nx/enforce-module-boundaries": [
10+
"error",
11+
{
12+
"enforceBuildableLibDependency": true,
13+
"allow": [],
14+
"depConstraints": [
15+
{
16+
"sourceTag": "*",
17+
"onlyDependOnLibsWithTags": ["*"]
18+
}
19+
]
20+
}
21+
]
22+
}
23+
},
24+
{
25+
"files": ["*.ts", "*.tsx"],
26+
"extends": ["plugin:@nx/typescript"],
27+
"rules": {}
28+
},
29+
{
30+
"files": ["*.js", "*.jsx"],
31+
"extends": ["plugin:@nx/javascript"],
32+
"rules": {}
33+
},
34+
{
35+
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
36+
"env": {
37+
"jest": true
38+
},
39+
"rules": {}
40+
}
41+
]
42+
}

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Add files here to ignore them from prettier formatting
2+
/dist
3+
/coverage
4+
.angular

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

.vscode/extensions.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"recommendations": [
3-
43
"nrwl.angular-console",
5-
"esbenp.prettier-vscode"
4+
"esbenp.prettier-vscode",
5+
"firsttris.vscode-jest-runner",
6+
"dbaeumer.vscode-eslint"
67
]
78
}

jest.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { getJestProjects } from '@nx/jest';
2+
3+
export default {
4+
projects: getJestProjects(),
5+
};

jest.preset.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const nxPreset = require('@nx/jest/preset').default;
2+
3+
module.exports = { ...nxPreset };

libs/core/.eslintrc.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"rules": {
8+
"@angular-eslint/directive-selector": [
9+
"error",
10+
{
11+
"type": "attribute",
12+
"prefix": "ngt",
13+
"style": "camelCase"
14+
}
15+
],
16+
"@angular-eslint/component-selector": [
17+
"error",
18+
{
19+
"type": "element",
20+
"prefix": "ngt",
21+
"style": "kebab-case"
22+
}
23+
]
24+
},
25+
"extends": [
26+
"plugin:@nx/angular",
27+
"plugin:@angular-eslint/template/process-inline-templates"
28+
]
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}

libs/core/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# core
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test core` to execute the unit tests.

libs/core/jest.config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'core',
4+
preset: '../../jest.preset.js',
5+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
6+
coverageDirectory: '../../coverage/libs/core',
7+
transform: {
8+
'^.+\\.(ts|mjs|js|html)$': [
9+
'jest-preset-angular',
10+
{
11+
tsconfig: '<rootDir>/tsconfig.spec.json',
12+
stringifyContentPathRegex: '\\.(html|svg)$',
13+
},
14+
],
15+
},
16+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17+
snapshotSerializers: [
18+
'jest-preset-angular/build/serializers/no-ng-attributes',
19+
'jest-preset-angular/build/serializers/ng-snapshot',
20+
'jest-preset-angular/build/serializers/html-comment',
21+
],
22+
};

libs/core/ng-package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../dist/libs/core",
4+
"lib": {
5+
"entryFile": "src/index.ts"
6+
}
7+
}

libs/core/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "angular-three",
3+
"version": "0.0.1",
4+
"peerDependencies": {
5+
"@angular/common": "^16.0.0",
6+
"@angular/core": "^16.0.0"
7+
},
8+
"dependencies": {
9+
"tslib": "^2.3.0"
10+
},
11+
"sideEffects": false
12+
}

libs/core/project.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "core",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/core/src",
5+
"prefix": "ngt",
6+
"tags": [],
7+
"projectType": "library",
8+
"targets": {
9+
"build": {
10+
"executor": "@nx/angular:package",
11+
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
12+
"options": {
13+
"project": "libs/core/ng-package.json"
14+
},
15+
"configurations": {
16+
"production": {
17+
"tsConfig": "libs/core/tsconfig.lib.prod.json"
18+
},
19+
"development": {
20+
"tsConfig": "libs/core/tsconfig.lib.json"
21+
}
22+
},
23+
"defaultConfiguration": "production"
24+
},
25+
"test": {
26+
"executor": "@nx/jest:jest",
27+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
28+
"options": {
29+
"jestConfig": "libs/core/jest.config.ts",
30+
"passWithNoTests": true
31+
},
32+
"configurations": {
33+
"ci": {
34+
"ci": true,
35+
"codeCoverage": true
36+
}
37+
}
38+
},
39+
"lint": {
40+
"executor": "@nx/linter:eslint",
41+
"outputs": ["{options.outputFile}"],
42+
"options": {
43+
"lintFilePatterns": ["libs/core/**/*.ts", "libs/core/**/*.html"]
44+
}
45+
}
46+
}
47+
}

libs/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/core/core.component';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { CoreComponent } from './core.component';
3+
4+
describe('CoreComponent', () => {
5+
let component: CoreComponent;
6+
let fixture: ComponentFixture<CoreComponent>;
7+
8+
beforeEach(async () => {
9+
await TestBed.configureTestingModule({
10+
imports: [CoreComponent],
11+
}).compileComponents();
12+
13+
fixture = TestBed.createComponent(CoreComponent);
14+
component = fixture.componentInstance;
15+
fixture.detectChanges();
16+
});
17+
18+
it('should create', () => {
19+
expect(component).toBeTruthy();
20+
});
21+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
@Component({
5+
selector: 'ngt-core',
6+
standalone: true,
7+
imports: [CommonModule],
8+
template: `<p>core works!</p>`,
9+
styles: [],
10+
})
11+
export class CoreComponent {}

libs/core/src/test-setup.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
2+
globalThis.ngJest = {
3+
testEnvironmentOptions: {
4+
errorOnUnknownElements: true,
5+
errorOnUnknownProperties: true,
6+
},
7+
};
8+
import 'jest-preset-angular/setup-jest';

libs/core/tsconfig.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2022",
4+
"useDefineForClassFields": false,
5+
"forceConsistentCasingInFileNames": true,
6+
"strict": true,
7+
"noImplicitOverride": true,
8+
"noPropertyAccessFromIndexSignature": true,
9+
"noImplicitReturns": true,
10+
"noFallthroughCasesInSwitch": true
11+
},
12+
"files": [],
13+
"include": [],
14+
"references": [
15+
{
16+
"path": "./tsconfig.lib.json"
17+
},
18+
{
19+
"path": "./tsconfig.spec.json"
20+
}
21+
],
22+
"extends": "../../tsconfig.base.json",
23+
"angularCompilerOptions": {
24+
"enableI18nLegacyMessageIdFormat": false,
25+
"strictInjectionParameters": true,
26+
"strictInputAccessModifiers": true,
27+
"strictTemplates": true
28+
}
29+
}

libs/core/tsconfig.lib.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"declaration": true,
6+
"declarationMap": true,
7+
"inlineSources": true,
8+
"types": []
9+
},
10+
"exclude": [
11+
"src/**/*.spec.ts",
12+
"src/test-setup.ts",
13+
"jest.config.ts",
14+
"src/**/*.test.ts"
15+
],
16+
"include": ["src/**/*.ts"]
17+
}

libs/core/tsconfig.lib.prod.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.lib.json",
3+
"compilerOptions": {
4+
"declarationMap": false
5+
},
6+
"angularCompilerOptions": {
7+
"compilationMode": "partial"
8+
}
9+
}

libs/core/tsconfig.spec.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"target": "es2016",
7+
"types": ["jest", "node"]
8+
},
9+
"files": ["src/test-setup.ts"],
10+
"include": [
11+
"jest.config.ts",
12+
"src/**/*.test.ts",
13+
"src/**/*.spec.ts",
14+
"src/**/*.d.ts"
15+
]
16+
}

nx.json

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,50 @@
44
"default": {
55
"runner": "nx/tasks-runners/default",
66
"options": {
7-
"cacheableOperations": [
8-
"build",
9-
"lint",
10-
"test",
11-
"e2e"
12-
]
7+
"cacheableOperations": ["build", "lint", "test", "e2e"]
138
}
149
}
1510
},
1611
"targetDefaults": {
1712
"build": {
18-
"dependsOn": [
19-
"^build"
20-
],
13+
"dependsOn": ["^build"],
14+
"inputs": ["production", "^production"]
15+
},
16+
"test": {
17+
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"]
18+
},
19+
"lint": {
2120
"inputs": [
22-
"production",
23-
"^production"
21+
"default",
22+
"{workspaceRoot}/.eslintrc.json",
23+
"{workspaceRoot}/.eslintignore"
2424
]
2525
}
2626
},
2727
"namedInputs": {
28-
"default": [
29-
"{projectRoot}/**/*",
30-
"sharedGlobals"
31-
],
28+
"default": ["{projectRoot}/**/*", "sharedGlobals"],
3229
"production": [
33-
"default"
30+
"default",
31+
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
32+
"!{projectRoot}/tsconfig.spec.json",
33+
"!{projectRoot}/jest.config.[jt]s",
34+
"!{projectRoot}/.eslintrc.json"
3435
],
3536
"sharedGlobals": []
37+
},
38+
"generators": {
39+
"@nx/angular:application": {
40+
"style": "css",
41+
"linter": "eslint",
42+
"unitTestRunner": "jest",
43+
"e2eTestRunner": "none"
44+
},
45+
"@nx/angular:library": {
46+
"linter": "eslint",
47+
"unitTestRunner": "jest"
48+
},
49+
"@nx/angular:component": {
50+
"style": "css"
51+
}
3652
}
3753
}

0 commit comments

Comments
 (0)