Skip to content

Commit

Permalink
feat: move global styles to a library
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitsinghkaler committed Sep 23, 2021
1 parent bfcf051 commit 8a2169d
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 265 deletions.
43 changes: 42 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"tsConfig": "apps/devto/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": ["apps/devto/src/favicon.ico", "apps/devto/src/assets"],
"styles": ["apps/devto/src/styles.scss"],
"styles": ["libs/styles/src/index.scss"],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -436,6 +436,47 @@
}
}
},
"styles": {
"projectType": "library",
"root": "libs/styles",
"sourceRoot": "libs/styles/src",
"prefix": "devto",
"architect": {
"build": {
"builder": "@nrwl/angular:ng-packagr-lite",
"outputs": ["dist/libs/styles"],
"options": {
"project": "libs/styles/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "libs/styles/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "libs/styles/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/styles"],
"options": {
"jestConfig": "libs/styles/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/styles/src/**/*.ts",
"libs/styles/src/**/*.html"
]
}
}
}
},
"user-profile": {
"projectType": "library",
"root": "libs/user-profile",
Expand Down
15 changes: 0 additions & 15 deletions apps/devto/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,4 @@ describe('AppComponent', () => {
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it(`should have as title 'devto'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('devto');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain(
'devto app is running!'
);
});
});
4 changes: 1 addition & 3 deletions apps/devto/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ import { Component } from '@angular/core';
selector: 'app-root',
template: '<app-header></app-header> <router-outlet></router-outlet>',
})
export class AppComponent {
title = 'devto';
}
export class AppComponent {}
36 changes: 36 additions & 0 deletions libs/styles/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "devto",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "devto",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/styles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# styles

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

## Running unit tests

Run `nx test styles` to execute the unit tests.
20 changes: 20 additions & 0 deletions libs/styles/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
displayName: 'styles',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
},
coverageDirectory: '../../coverage/libs/styles',
transform: {
'^.+\\.(ts|js|html)$': 'jest-preset-angular',
},
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 libs/styles/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/libs/styles",
"lib": {
"entryFile": "src/index.ts"
}
}
11 changes: 11 additions & 0 deletions libs/styles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@devto/styles",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^12.1.1",
"@angular/core": "^12.1.1"
},
"dependencies": {
"tslib": "^2.2.0"
}
}
3 changes: 3 additions & 0 deletions libs/styles/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "./lib/global";
@import "./lib/article-detail";
@import "./lib/comments";
1 change: 1 addition & 0 deletions libs/styles/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/styles.module';
Loading

0 comments on commit 8a2169d

Please sign in to comment.