Browse Source

feat: create libraries in the module-template #1652

pull/1867/head
mehmet-erim 7 years ago
parent
commit
7856b22353
  1. 6
      npm/ng-packs/packages/account/src/lib/services/account.service.ts
  2. 70
      templates/module/angular/angular.json
  3. 3
      templates/module/angular/package.json
  4. 1
      templates/module/angular/projects/my-project-name-config/README.md
  5. 32
      templates/module/angular/projects/my-project-name-config/karma.conf.js
  6. 7
      templates/module/angular/projects/my-project-name-config/ng-package.json
  7. 7
      templates/module/angular/projects/my-project-name-config/package.json
  8. 10
      templates/module/angular/projects/my-project-name-config/src/lib/my-project-name-config.module.ts
  9. 16
      templates/module/angular/projects/my-project-name-config/src/lib/services/my-project-name-config.service.ts
  10. 2
      templates/module/angular/projects/my-project-name-config/src/public-api.ts
  11. 21
      templates/module/angular/projects/my-project-name-config/src/test.ts
  12. 26
      templates/module/angular/projects/my-project-name-config/tsconfig.lib.json
  13. 17
      templates/module/angular/projects/my-project-name-config/tsconfig.spec.json
  14. 17
      templates/module/angular/projects/my-project-name-config/tslint.json
  15. 1
      templates/module/angular/projects/my-project-name/README.md
  16. 32
      templates/module/angular/projects/my-project-name/karma.conf.js
  17. 8
      templates/module/angular/projects/my-project-name/ng-package.json
  18. 8
      templates/module/angular/projects/my-project-name/package.json
  19. 24
      templates/module/angular/projects/my-project-name/src/lib/components/my-project-name.component.spec.ts
  20. 19
      templates/module/angular/projects/my-project-name/src/lib/components/my-project-name.component.ts
  21. 20
      templates/module/angular/projects/my-project-name/src/lib/my-project-name-routing.module.ts
  22. 12
      templates/module/angular/projects/my-project-name/src/lib/my-project-name.module.ts
  23. 2
      templates/module/angular/projects/my-project-name/src/public-api.ts
  24. 21
      templates/module/angular/projects/my-project-name/src/test.ts
  25. 26
      templates/module/angular/projects/my-project-name/tsconfig.lib.json
  26. 17
      templates/module/angular/projects/my-project-name/tsconfig.spec.json
  27. 17
      templates/module/angular/projects/my-project-name/tslint.json
  28. 4
      templates/module/angular/src/app/app-routing.module.ts
  29. 2
      templates/module/angular/src/app/app.module.ts
  30. 7
      templates/module/angular/src/app/lazy-libs/my-project-name-wrapper.module.ts
  31. 18
      templates/module/angular/tsconfig.json

6
npm/ng-packs/packages/account/src/lib/services/account.service.ts

@ -4,7 +4,7 @@ import { RestService, Rest } from '@abp/ng.core';
import { RegisterResponse, RegisterRequest, TenantIdResponse } from '../models';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class AccountService {
constructor(private rest: RestService) {}
@ -12,7 +12,7 @@ export class AccountService {
findTenant(tenantName: string): Observable<TenantIdResponse> {
const request: Rest.Request<null> = {
method: 'GET',
url: `/api/abp/multi-tenancy/tenants/by-name/${tenantName}`
url: `/api/abp/multi-tenancy/tenants/by-name/${tenantName}`,
};
return this.rest.request<null, TenantIdResponse>(request);
@ -22,7 +22,7 @@ export class AccountService {
const request: Rest.Request<RegisterRequest> = {
method: 'POST',
url: '/api/account/register',
body
body,
};
return this.rest.request<RegisterRequest, RegisterResponse>(request, { skipHandleError: true });

70
templates/module/angular/angular.json

@ -130,6 +130,76 @@
}
}
}
},
"my-project-name": {
"projectType": "library",
"root": "projects/my-project-name",
"sourceRoot": "projects/my-project-name/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/my-project-name/tsconfig.lib.json",
"project": "projects/my-project-name/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/my-project-name/src/test.ts",
"tsConfig": "projects/my-project-name/tsconfig.spec.json",
"karmaConfig": "projects/my-project-name/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/my-project-name/tsconfig.lib.json",
"projects/my-project-name/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"my-project-name-config": {
"projectType": "library",
"root": "projects/my-project-name-config",
"sourceRoot": "projects/my-project-name-config/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/my-project-name-config/tsconfig.lib.json",
"project": "projects/my-project-name-config/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/my-project-name-config/src/test.ts",
"tsConfig": "projects/my-project-name-config/tsconfig.spec.json",
"karmaConfig": "projects/my-project-name-config/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/my-project-name-config/tsconfig.lib.json",
"projects/my-project-name-config/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "myProjectName"

3
templates/module/angular/package.json

@ -32,6 +32,7 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.6",
"@angular-devkit/build-ng-packagr": "~0.803.6",
"@angular/cli": "~8.3.6",
"@angular/compiler-cli": "~8.2.8",
"@angular/language-service": "~8.2.8",
@ -46,9 +47,11 @@
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"ng-packagr": "^5.4.0",
"ngxs-schematic": "^1.1.9",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tsickle": "^0.37.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
}

1
templates/module/angular/projects/my-project-name-config/README.md

@ -0,0 +1 @@
# MyProjectNameConfig

32
templates/module/angular/projects/my-project-name-config/karma.conf.js

@ -0,0 +1,32 @@
// 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-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/my-project-name-config'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};

7
templates/module/angular/projects/my-project-name-config/ng-package.json

@ -0,0 +1,7 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/my-project-name-config",
"lib": {
"entryFile": "src/public-api.ts"
}
}

7
templates/module/angular/projects/my-project-name-config/package.json

@ -0,0 +1,7 @@
{
"name": "my-project-name.config",
"version": "0.0.1",
"peerDependencies": {
"@abp/ng.core": ">=0.9.0"
}
}

10
templates/module/angular/projects/my-project-name-config/src/lib/my-project-name-config.module.ts

@ -0,0 +1,10 @@
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { MyProjectNameConfigService } from './services/my-project-name-config.service';
import { noop } from '@abp/ng.core';
@NgModule({
declarations: [],
providers: [{ provide: APP_INITIALIZER, deps: [MyProjectNameConfigService], multi: true, useFactory: noop }],
exports: [],
})
export class MyProjectNameConfigModule {}

16
templates/module/angular/projects/my-project-name-config/src/lib/services/my-project-name-config.service.ts

@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { eLayoutType, addAbpRoutes, ABP } from '@abp/ng.core';
@Injectable({
providedIn: 'root',
})
export class MyProjectNameConfigService {
constructor() {
addAbpRoutes({
name: 'MyProjectName',
path: 'my-project-name',
layout: eLayoutType.application,
order: 2,
} as ABP.FullRoute);
}
}

2
templates/module/angular/projects/my-project-name-config/src/public-api.ts

@ -0,0 +1,2 @@
export * from './lib/services/my-project-name-config.service';
export * from './lib/my-project-name-config.module';

21
templates/module/angular/projects/my-project-name-config/src/test.ts

@ -0,0 +1,21 @@
// 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: any;
// 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);

26
templates/module/angular/projects/my-project-name-config/tsconfig.lib.json

@ -0,0 +1,26 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

17
templates/module/angular/projects/my-project-name-config/tsconfig.spec.json

@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

17
templates/module/angular/projects/my-project-name-config/tslint.json

@ -0,0 +1,17 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"lib",
"camelCase"
],
"component-selector": [
true,
"element",
"lib",
"kebab-case"
]
}
}

1
templates/module/angular/projects/my-project-name/README.md

@ -0,0 +1 @@
# MyProjectName

32
templates/module/angular/projects/my-project-name/karma.conf.js

@ -0,0 +1,32 @@
// 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-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/my-project-name'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};

8
templates/module/angular/projects/my-project-name/ng-package.json

@ -0,0 +1,8 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/my-project-name",
"lib": {
"entryFile": "src/public-api.ts"
},
"whitelistedNonPeerDependencies": ["@abp/ng.theme.shared", "my-project-name.config"]
}

8
templates/module/angular/projects/my-project-name/package.json

@ -0,0 +1,8 @@
{
"name": "my-project-name",
"version": "0.0.1",
"dependencies": {
"@abp/ng.theme.shared": "^0.9.0",
"my-project-name.config": "^0.0.1"
}
}

24
templates/module/angular/projects/my-project-name/src/lib/components/my-project-name.component.spec.ts

@ -0,0 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MyProjectNameComponent } from './my-project-name.component';
describe('MyProjectNameComponent', () => {
let component: MyProjectNameComponent;
let fixture: ComponentFixture<MyProjectNameComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyProjectNameComponent],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyProjectNameComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

19
templates/module/angular/projects/my-project-name/src/lib/components/my-project-name.component.ts

@ -0,0 +1,19 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'lib-my-project-name',
template: `
<p>
my-project-name works!
</p>
`,
styles: []
})
export class MyProjectNameComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

20
templates/module/angular/projects/my-project-name/src/lib/my-project-name-routing.module.ts

@ -0,0 +1,20 @@
import { AuthGuard, DynamicLayoutComponent, PermissionGuard } from '@abp/ng.core';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MyProjectNameComponent } from './components/my-project-name.component';
const routes: Routes = [
{
path: '',
component: DynamicLayoutComponent,
canActivate: [AuthGuard, PermissionGuard],
data: { requiredPolicy: '' },
children: [{ path: '', component: MyProjectNameComponent }],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class MyProjectNameRoutingModule {}

12
templates/module/angular/projects/my-project-name/src/lib/my-project-name.module.ts

@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { MyProjectNameComponent } from './components/my-project-name.component';
import { MyProjectNameRoutingModule } from './my-project-name-routing.module';
import { ThemeSharedModule } from '@abp/ng.theme.shared';
import { CoreModule } from '@abp/ng.core';
@NgModule({
declarations: [MyProjectNameComponent],
imports: [CoreModule, ThemeSharedModule, MyProjectNameRoutingModule],
exports: [MyProjectNameComponent],
})
export class MyProjectNameModule {}

2
templates/module/angular/projects/my-project-name/src/public-api.ts

@ -0,0 +1,2 @@
export * from './lib/components/my-project-name.component';
export * from './lib/my-project-name.module';

21
templates/module/angular/projects/my-project-name/src/test.ts

@ -0,0 +1,21 @@
// 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: any;
// 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);

26
templates/module/angular/projects/my-project-name/tsconfig.lib.json

@ -0,0 +1,26 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

17
templates/module/angular/projects/my-project-name/tsconfig.spec.json

@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

17
templates/module/angular/projects/my-project-name/tslint.json

@ -0,0 +1,17 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"lib",
"camelCase"
],
"component-selector": [
true,
"element",
"lib",
"kebab-case"
]
}
}

4
templates/module/angular/src/app/app-routing.module.ts

@ -16,6 +16,10 @@ const routes: Routes = [
path: 'account',
loadChildren: () => import('./lazy-libs/account-wrapper.module').then(m => m.AccountWrapperModule),
},
{
path: 'my-project-name',
loadChildren: () => import('./lazy-libs/my-project-name-wrapper.module').then(m => m.MyProjectNameWrapperModule),
},
];
@NgModule({

2
templates/module/angular/src/app/app.module.ts

@ -12,6 +12,7 @@ import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module';
import { ThemeSharedModule } from '@abp/ng.theme.shared';
import { AccountConfigModule } from '@abp/ng.account.config';
import { MyProjectNameConfigModule } from '../../projects/my-project-name-config/src/public-api';
@NgModule({
declarations: [AppComponent],
@ -26,6 +27,7 @@ import { AccountConfigModule } from '@abp/ng.account.config';
OAuthModule.forRoot(),
NgxsModule.forRoot([]),
AccountConfigModule.forRoot({ redirectUrl: '/' }),
MyProjectNameConfigModule,
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,

7
templates/module/angular/src/app/lazy-libs/my-project-name-wrapper.module.ts

@ -0,0 +1,7 @@
import { NgModule } from '@angular/core';
import { MyProjectNameModule } from '../../../projects/my-project-name/src/public-api';
@NgModule({
imports: [MyProjectNameModule],
})
export class MyProjectNameWrapperModule {}

18
templates/module/angular/tsconfig.json

@ -18,6 +18,20 @@
"lib": [
"es2018",
"dom"
]
],
"paths": {
"my-project-name": [
"dist/my-project-name"
],
"my-project-name/*": [
"dist/my-project-name/*"
],
"my-project-name-config": [
"dist/my-project-name-config"
],
"my-project-name-config/*": [
"dist/my-project-name-config/*"
]
}
}
}
}
Loading…
Cancel
Save