Skip to content

Commit ed61bd7

Browse files
committed
extract the button into a publishable library
1 parent 63e8285 commit ed61bd7

23 files changed

+278
-15
lines changed

angular.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"app2-e2e": "apps/app2-e2e",
88
"lib1": "libs/lib1",
99
"lib2": "libs/lib2",
10+
"lib3": "libs/lib3",
1011
"tailwind-preset": "libs/tailwind-preset"
1112
}
1213
}

libs/lib2/src/lib/card/card.component.html

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
<p class="card-content">
44
<ng-content></ng-content>
55
</p>
6-
<a
7-
class="py-sm px-md bg-primary-dark hover:bg-primary text-white flex self-end"
8-
href="{{ url }}"
9-
target="_blank"
10-
rel="noopener noreferrer"
11-
>
6+
<angular-tailwind-nx-button class="flex self-end" [href]="url">
127
Show me!
13-
</a>
8+
</angular-tailwind-nx-button>
149
</div>

libs/lib2/src/lib/lib2.module.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { CardComponent } from './card/card.component';
4+
import { Lib3Module } from '@angular-tailwind-nx/lib3';
45

56
@NgModule({
6-
imports: [CommonModule],
7-
declarations: [
8-
CardComponent
9-
],
10-
exports: [
11-
CardComponent
12-
],
7+
imports: [CommonModule, Lib3Module],
8+
declarations: [CardComponent],
9+
exports: [CardComponent],
1310
})
1411
export class Lib2Module {}

libs/lib3/.browserslistrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2+
# For additional information regarding the format and rule options, please see:
3+
# https://github.com/browserslist/browserslist#queries
4+
5+
# For the full list of supported browsers by the Angular framework, please see:
6+
# https://angular.io/guide/browser-support
7+
8+
# You can see what browsers were selected by your queries by running:
9+
# npx browserslist
10+
11+
last 1 Chrome version
12+
last 1 Firefox version
13+
last 2 Edge major versions
14+
last 2 Safari major versions
15+
last 2 iOS major versions
16+
Firefox ESR

libs/lib3/.eslintrc.json

+36
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+
"extends": [
8+
"plugin:@nrwl/nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "angularTailwindNx",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "angular-tailwind-nx",
25+
"style": "kebab-case"
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nrwl/nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}

libs/lib3/README.md

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

libs/lib3/jest.config.js

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

libs/lib3/ng-package.json

+7
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/lib3",
4+
"lib": {
5+
"entryFile": "src/index.ts"
6+
}
7+
}

libs/lib3/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@angular-tailwind-nx/lib3",
3+
"version": "0.0.1",
4+
"peerDependencies": {
5+
"@angular/common": "^13.1.0",
6+
"@angular/core": "^13.1.0"
7+
},
8+
"dependencies": {
9+
"tslib": "^2.3.0"
10+
}
11+
}

libs/lib3/project.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"projectType": "library",
3+
"root": "libs/lib3",
4+
"sourceRoot": "libs/lib3/src",
5+
"prefix": "angular-tailwind-nx",
6+
"targets": {
7+
"build": {
8+
"executor": "@nrwl/angular:package",
9+
"outputs": ["dist/libs/lib3"],
10+
"options": {
11+
"project": "libs/lib3/ng-package.json",
12+
"tailwindConfig": "libs/lib3/tailwind.config.js"
13+
},
14+
"configurations": {
15+
"production": {
16+
"tsConfig": "libs/lib3/tsconfig.lib.prod.json"
17+
},
18+
"development": {
19+
"tsConfig": "libs/lib3/tsconfig.lib.json"
20+
}
21+
},
22+
"defaultConfiguration": "production"
23+
},
24+
"test": {
25+
"executor": "@nrwl/jest:jest",
26+
"outputs": ["coverage/libs/lib3"],
27+
"options": {
28+
"jestConfig": "libs/lib3/jest.config.js",
29+
"passWithNoTests": true
30+
}
31+
},
32+
"lint": {
33+
"executor": "@nrwl/linter:eslint",
34+
"options": {
35+
"lintFilePatterns": ["libs/lib3/src/**/*.ts", "libs/lib3/src/**/*.html"]
36+
}
37+
}
38+
},
39+
"tags": []
40+
}

libs/lib3/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './lib/lib3.module';
2+
export * from './lib/button/button.component';

libs/lib3/src/lib/button/button.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<a
2+
class="py-sm px-md bg-primary-dark hover:bg-primary text-white"
3+
href="{{ href }}"
4+
target="_blank"
5+
rel="noopener noreferrer"
6+
>
7+
<ng-content></ng-content>
8+
</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ButtonComponent } from './button.component';
4+
5+
describe('ButtonComponent', () => {
6+
let component: ButtonComponent;
7+
let fixture: ComponentFixture<ButtonComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ ButtonComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ButtonComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component, Input } from '@angular/core';
2+
3+
@Component({
4+
selector: 'angular-tailwind-nx-button',
5+
templateUrl: './button.component.html',
6+
styleUrls: ['./button.component.css'],
7+
})
8+
export class ButtonComponent {
9+
@Input() href?: string;
10+
}

libs/lib3/src/lib/lib3.module.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { ButtonComponent } from './button/button.component';
4+
5+
@NgModule({
6+
imports: [CommonModule],
7+
declarations: [
8+
ButtonComponent
9+
],
10+
exports: [
11+
ButtonComponent
12+
],
13+
})
14+
export class Lib3Module {}

libs/lib3/src/test-setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'jest-preset-angular/setup-jest';

libs/lib3/tailwind.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { createGlobPatternsForDependencies } = require('@nrwl/angular/tailwind');
2+
const { join } = require('path');
3+
const sharedTailwindConfig = require('../../libs/tailwind-preset/tailwind.config');
4+
5+
module.exports = {
6+
presets: [sharedTailwindConfig],
7+
content: [
8+
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'),
9+
...createGlobPatternsForDependencies(__dirname),
10+
],
11+
};

libs/lib3/tsconfig.json

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

libs/lib3/tsconfig.lib.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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": ["src/test-setup.ts", "**/*.spec.ts", "**/*.test.ts"],
11+
"include": ["**/*.ts"]
12+
}

libs/lib3/tsconfig.lib.prod.json

+9
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/lib3/tsconfig.spec.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"module": "commonjs",
6+
"types": ["jest", "node"]
7+
},
8+
"files": ["src/test-setup.ts"],
9+
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
10+
}

tsconfig.base.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"baseUrl": ".",
1717
"paths": {
1818
"@angular-tailwind-nx/lib1": ["libs/lib1/src/index.ts"],
19-
"@angular-tailwind-nx/lib2": ["libs/lib2/src/index.ts"]
19+
"@angular-tailwind-nx/lib2": ["libs/lib2/src/index.ts"],
20+
"@angular-tailwind-nx/lib3": ["libs/lib3/src/index.ts"]
2021
}
2122
},
2223
"exclude": ["node_modules", "tmp"]

0 commit comments

Comments
 (0)