From cd8e346afedd2ee74cce1217d19aa6987e61cb03 Mon Sep 17 00:00:00 2001 From: muhammedaltug Date: Tue, 22 Jun 2021 16:04:46 +0300 Subject: [PATCH] create account core package and create services --- npm/ng-packs/angular.json | 40 +++++++++++++++++ npm/ng-packs/packages/account-core/README.md | 24 ++++++++++ .../packages/account-core/karma.conf.js | 44 +++++++++++++++++++ .../packages/account-core/ng-package.json | 8 ++++ .../packages/account-core/package.json | 18 ++++++++ .../src/lib/auth-wrapper.service.spec.ts | 16 +++++++ .../src/lib/auth-wrapper.service.ts} | 16 +++---- .../src/lib/tenant-box.service.spec.ts | 16 +++++++ .../src/lib/tenant-box.service.ts} | 13 ++---- .../packages/account-core/src/public-api.ts | 6 +++ .../packages/account-core/src/test.ts | 26 +++++++++++ .../packages/account-core/tsconfig.lib.json | 20 +++++++++ .../account-core/tsconfig.lib.prod.json | 6 +++ .../packages/account-core/tsconfig.spec.json | 17 +++++++ .../packages/account-core/tslint.json | 17 +++++++ npm/ng-packs/tsconfig.json | 1 + 16 files changed, 268 insertions(+), 20 deletions(-) create mode 100644 npm/ng-packs/packages/account-core/README.md create mode 100644 npm/ng-packs/packages/account-core/karma.conf.js create mode 100644 npm/ng-packs/packages/account-core/ng-package.json create mode 100644 npm/ng-packs/packages/account-core/package.json create mode 100644 npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.spec.ts rename npm/ng-packs/packages/{account/src/lib/components/auth-wrapper/auth-wrapper.component.ts => account-core/src/lib/auth-wrapper.service.ts} (67%) create mode 100644 npm/ng-packs/packages/account-core/src/lib/tenant-box.service.spec.ts rename npm/ng-packs/packages/{account/src/lib/components/tenant-box/tenant-box.component.ts => account-core/src/lib/tenant-box.service.ts} (84%) create mode 100644 npm/ng-packs/packages/account-core/src/public-api.ts create mode 100644 npm/ng-packs/packages/account-core/src/test.ts create mode 100644 npm/ng-packs/packages/account-core/tsconfig.lib.json create mode 100644 npm/ng-packs/packages/account-core/tsconfig.lib.prod.json create mode 100644 npm/ng-packs/packages/account-core/tsconfig.spec.json create mode 100644 npm/ng-packs/packages/account-core/tslint.json diff --git a/npm/ng-packs/angular.json b/npm/ng-packs/angular.json index 69119cdb64..cc797d42ef 100644 --- a/npm/ng-packs/angular.json +++ b/npm/ng-packs/angular.json @@ -541,6 +541,46 @@ } } } + }, + "account-core": { + "projectType": "library", + "root": "packages/account-core", + "sourceRoot": "packages/account-core/src", + "prefix": "lib", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:ng-packagr", + "options": { + "tsConfig": "packages/account-core/tsconfig.lib.json", + "project": "packages/account-core/ng-package.json" + }, + "configurations": { + "production": { + "tsConfig": "packages/account-core/tsconfig.lib.prod.json" + } + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "packages/account-core/src/test.ts", + "tsConfig": "packages/account-core/tsconfig.spec.json", + "karmaConfig": "packages/account-core/karma.conf.js" + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "packages/account-core/tsconfig.lib.json", + "packages/account-core/tsconfig.spec.json" + ], + "exclude": [ + "**/node_modules/**" + ] + } + } + } } }, "cli": { diff --git a/npm/ng-packs/packages/account-core/README.md b/npm/ng-packs/packages/account-core/README.md new file mode 100644 index 0000000000..ddde2c2757 --- /dev/null +++ b/npm/ng-packs/packages/account-core/README.md @@ -0,0 +1,24 @@ +# AccountCore + +This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.1.2. + +## Code scaffolding + +Run `ng generate component component-name --project account-core` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project account-core`. +> Note: Don't forget to add `--project account-core` or else it will be added to the default project in your `angular.json` file. + +## Build + +Run `ng build account-core` to build the project. The build artifacts will be stored in the `dist/` directory. + +## Publishing + +After building your library with `ng build account-core`, go to the dist folder `cd dist/account-core` and run `npm publish`. + +## Running unit tests + +Run `ng test account-core` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. diff --git a/npm/ng-packs/packages/account-core/karma.conf.js b/npm/ng-packs/packages/account-core/karma.conf.js new file mode 100644 index 0000000000..50d6dac6ed --- /dev/null +++ b/npm/ng-packs/packages/account-core/karma.conf.js @@ -0,0 +1,44 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + jasmine: { + // you can add configuration options for Jasmine here + // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html + // for example, you can disable the random execution with `random: false` + // or set a specific seed with `seed: 4321` + }, + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + jasmineHtmlReporter: { + suppressAll: true // removes the duplicated traces + }, + coverageReporter: { + dir: require('path').join(__dirname, '../../coverage/account-core'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' } + ] + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/npm/ng-packs/packages/account-core/ng-package.json b/npm/ng-packs/packages/account-core/ng-package.json new file mode 100644 index 0000000000..35f4b81860 --- /dev/null +++ b/npm/ng-packs/packages/account-core/ng-package.json @@ -0,0 +1,8 @@ +{ + "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", + "dest": "../../dist/account-core", + "lib": { + "entryFile": "src/public-api.ts" + }, + "allowedNonPeerDependencies": ["@abp/ng.core", "@abp/ng.theme.shared"] +} diff --git a/npm/ng-packs/packages/account-core/package.json b/npm/ng-packs/packages/account-core/package.json new file mode 100644 index 0000000000..7928d8005e --- /dev/null +++ b/npm/ng-packs/packages/account-core/package.json @@ -0,0 +1,18 @@ +{ + "name": "@abp/ng.account-core", + "version": "0.0.1", + "homepage": "https://abp.io", + "repository": { + "type": "git", + "url": "https://github.com/abpframework/abp.git" + }, + "peerDependencies": { + "@angular/common": "^11.1.2", + "@angular/core": "^11.1.2" + }, + "dependencies": { + "tslib": "^2.0.0", + "@abp/ng.core": "~4.3.3", + "@abp/ng.theme.shared": "~4.3.3" + } +} diff --git a/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.spec.ts b/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.spec.ts new file mode 100644 index 0000000000..c09dfff769 --- /dev/null +++ b/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { AuthWrapperService } from './auth-wrapper.service'; + +describe('AuthWrapperService', () => { + let service: AuthWrapperService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(AuthWrapperService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/npm/ng-packs/packages/account/src/lib/components/auth-wrapper/auth-wrapper.component.ts b/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts similarity index 67% rename from npm/ng-packs/packages/account/src/lib/components/auth-wrapper/auth-wrapper.component.ts rename to npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts index b436d23e95..44f53c7eef 100644 --- a/npm/ng-packs/packages/account/src/lib/components/auth-wrapper/auth-wrapper.component.ts +++ b/npm/ng-packs/packages/account-core/src/lib/auth-wrapper.service.ts @@ -1,17 +1,11 @@ -import { ConfigStateService, MultiTenancyService, SubscriptionService } from '@abp/ng.core'; -import { Component, Injector } from '@angular/core'; +import { Injectable, Injector } from '@angular/core'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { eAccountComponents } from '../../enums/components'; import { ActivatedRoute } from '@angular/router'; +import { ConfigStateService, MultiTenancyService } from '@abp/ng.core'; -@Component({ - selector: 'abp-auth-wrapper', - templateUrl: './auth-wrapper.component.html', - exportAs: 'abpAuthWrapper', - providers: [SubscriptionService], -}) -export class AuthWrapperComponent { +@Injectable() +export class AuthWrapperService { isMultiTenancyEnabled$ = this.configState.getDeep$('multiTenancy.isEnabled'); get enableLocalLogin$(): Observable { @@ -20,7 +14,7 @@ export class AuthWrapperComponent { .pipe(map(value => value?.toLowerCase() !== 'false')); } - tenantBoxKey = eAccountComponents.TenantBox; + tenantBoxKey = 'Account.TenantBoxComponent'; route: ActivatedRoute; private _tenantBoxVisible = true; diff --git a/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.spec.ts b/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.spec.ts new file mode 100644 index 0000000000..521623f116 --- /dev/null +++ b/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { TenantBoxService } from './tenant-box.service'; + +describe('TenantBoxService', () => { + let service: TenantBoxService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(TenantBoxService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.ts b/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts similarity index 84% rename from npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.ts rename to npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts index 81819b9e95..ef0a71a245 100644 --- a/npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.ts +++ b/npm/ng-packs/packages/account-core/src/lib/tenant-box.service.ts @@ -1,3 +1,5 @@ +import { Injectable } from '@angular/core'; +import { ToasterService } from '@abp/ng.theme.shared'; import { AbpApplicationConfigurationService, AbpTenantService, @@ -5,17 +7,10 @@ import { CurrentTenantDto, SessionStateService, } from '@abp/ng.core'; -import { ToasterService } from '@abp/ng.theme.shared'; -import { Component } from '@angular/core'; import { finalize } from 'rxjs/operators'; -import { Account } from '../../models/account'; -@Component({ - selector: 'abp-tenant-box', - templateUrl: './tenant-box.component.html', -}) -export class TenantBoxComponent - implements Account.TenantBoxComponentInputs, Account.TenantBoxComponentOutputs { +@Injectable() +export class TenantBoxService { currentTenant$ = this.sessionState.getTenant$(); name: string; diff --git a/npm/ng-packs/packages/account-core/src/public-api.ts b/npm/ng-packs/packages/account-core/src/public-api.ts new file mode 100644 index 0000000000..b9aacd8a89 --- /dev/null +++ b/npm/ng-packs/packages/account-core/src/public-api.ts @@ -0,0 +1,6 @@ +/* + * Public API Surface of account-core + */ + +export * from './lib/auth-wrapper.service'; +export * from './lib/tenant-box.service'; diff --git a/npm/ng-packs/packages/account-core/src/test.ts b/npm/ng-packs/packages/account-core/src/test.ts new file mode 100644 index 0000000000..303b32a220 --- /dev/null +++ b/npm/ng-packs/packages/account-core/src/test.ts @@ -0,0 +1,26 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/dist/zone'; +import 'zone.js/dist/zone-testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: { + context(path: string, deep?: boolean, filter?: RegExp): { + keys(): string[]; + (id: string): T; + }; +}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/npm/ng-packs/packages/account-core/tsconfig.lib.json b/npm/ng-packs/packages/account-core/tsconfig.lib.json new file mode 100644 index 0000000000..e837bdcce7 --- /dev/null +++ b/npm/ng-packs/packages/account-core/tsconfig.lib.json @@ -0,0 +1,20 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "../../tsconfig.prod.json", + "compilerOptions": { + "outDir": "../../out-tsc/lib", + "target": "es2015", + "declaration": true, + "inlineSources": true, + "types": [], + "lib": ["dom", "es2018"] + }, + "angularCompilerOptions": { + "skipTemplateCodegen": true, + "strictMetadataEmit": true, + "fullTemplateTypeCheck": true, + "strictInjectionParameters": true, + "enableResourceInlining": true + }, + "exclude": ["src/test.ts", "**/*.spec.ts"] +} diff --git a/npm/ng-packs/packages/account-core/tsconfig.lib.prod.json b/npm/ng-packs/packages/account-core/tsconfig.lib.prod.json new file mode 100644 index 0000000000..cbae794224 --- /dev/null +++ b/npm/ng-packs/packages/account-core/tsconfig.lib.prod.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.lib.json", + "angularCompilerOptions": { + "enableIvy": false + } +} diff --git a/npm/ng-packs/packages/account-core/tsconfig.spec.json b/npm/ng-packs/packages/account-core/tsconfig.spec.json new file mode 100644 index 0000000000..715dd0a5d2 --- /dev/null +++ b/npm/ng-packs/packages/account-core/tsconfig.spec.json @@ -0,0 +1,17 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/spec", + "types": [ + "jasmine" + ] + }, + "files": [ + "src/test.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/npm/ng-packs/packages/account-core/tslint.json b/npm/ng-packs/packages/account-core/tslint.json new file mode 100644 index 0000000000..124133f849 --- /dev/null +++ b/npm/ng-packs/packages/account-core/tslint.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tslint.json", + "rules": { + "directive-selector": [ + true, + "attribute", + "lib", + "camelCase" + ], + "component-selector": [ + true, + "element", + "lib", + "kebab-case" + ] + } +} diff --git a/npm/ng-packs/tsconfig.json b/npm/ng-packs/tsconfig.json index ca40efc770..08a79361e0 100644 --- a/npm/ng-packs/tsconfig.json +++ b/npm/ng-packs/tsconfig.json @@ -25,6 +25,7 @@ "@abp/ng.components/page": ["packages/components/page/src/public-api.ts"], "@abp/ng.theme.basic": ["packages/theme-basic/src/public-api.ts"], "@abp/ng.account": ["packages/account/src/public-api.ts"], + "@abp/ng.account-core": ["packages/account-core/src/public-api.ts"], "@abp/ng.account/config": ["packages/account/config/src/public-api.ts"], "@abp/ng.identity": ["packages/identity/src/public-api.ts"], "@abp/ng.identity/config": ["packages/identity/config/src/public-api.ts"],