Skip to content

Commit 24125e5

Browse files
committed
fix(schematics): fix setting custom module to add the calendar imports to
1 parent 266e159 commit 24125e5

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

projects/angular-calendar/schematics/ng-add/index.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ describe('angular-calendar schematics', () => {
8787
expect(rootModule).contain(calendarModuleImport);
8888
});
8989

90+
it('should import angular-calendar module to root module when passed as an option', async () => {
91+
const rootModulePath = `/projects/${projectName}/src/app/app.module.ts`;
92+
tree = await runner
93+
.runSchematicAsync('ng-add', {
94+
...defaultOptions,
95+
module: 'src/app/app.module.ts'
96+
}, appTree)
97+
.toPromise();
98+
expect(tree.files).contain(rootModulePath);
99+
100+
const rootModule = tree.readContent(rootModulePath);
101+
102+
const calendarModuleImport = `import { CalendarModule, DateAdapter } from 'angular-calendar';`;
103+
expect(rootModule).contain(calendarModuleImport);
104+
});
105+
90106
it('should add angular-calendar css to architect builder', async () => {
91107
tree = await runner
92108
.runSchematicAsync('ng-add', defaultOptions, appTree)

projects/angular-calendar/schematics/ng-add/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Rule,
44
SchematicContext,
55
Tree,
6-
chain
6+
chain,
77
} from '@angular-devkit/schematics';
88
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
99
import { getWorkspace } from '@schematics/angular/utility/config';
@@ -15,6 +15,7 @@ import {
1515
NodeDependency,
1616
NodeDependencyType
1717
} from '@schematics/angular/utility/dependencies';
18+
import { normalize } from '@angular-devkit/core';
1819

1920
import {
2021
addModuleImportToRootModule,
@@ -109,8 +110,9 @@ function addModuleToImports(options: Schema): Rule {
109110
);
110111
const mainPath = getProjectMainFile(project);
111112
const appModulePath = options.module
112-
? options.module
113+
? normalize(project.root + '/' + options.module)
113114
: getAppModulePath(host, mainPath);
115+
114116
const moduleName = `CalendarModule.forRoot({ provide: DateAdapter, useFactory: ${
115117
options.dateAdapter === 'moment'
116118
? 'momentAdapterFactory'

projects/angular-calendar/schematics/ng-add/schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"module": {
2525
"type": "string",
2626
"description": "Where to add the module import",
27-
"x-prompt": "Please enter a path to the NgModule that will use the calendar (relative to the root project directory, for example src/app/app.module.ts)"
27+
"x-prompt": "Please enter a path to the NgModule that will use the calendar. It should be relative to the root project directory, for example src/app/app.module.ts (optional, will use the root app module if not specified)"
2828
},
2929
"projectName": {
3030
"type": "string",

0 commit comments

Comments
 (0)