Skip to content

Commit

Permalink
fix(schematics): fix setting custom module to add the calendar import…
Browse files Browse the repository at this point in the history
…s to
  • Loading branch information
mattlewis92 committed Mar 1, 2020
1 parent 266e159 commit 24125e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions projects/angular-calendar/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ describe('angular-calendar schematics', () => {
expect(rootModule).contain(calendarModuleImport);
});

it('should import angular-calendar module to root module when passed as an option', async () => {
const rootModulePath = `/projects/${projectName}/src/app/app.module.ts`;
tree = await runner
.runSchematicAsync('ng-add', {
...defaultOptions,
module: 'src/app/app.module.ts'
}, appTree)
.toPromise();
expect(tree.files).contain(rootModulePath);

const rootModule = tree.readContent(rootModulePath);

const calendarModuleImport = `import { CalendarModule, DateAdapter } from 'angular-calendar';`;
expect(rootModule).contain(calendarModuleImport);
});

it('should add angular-calendar css to architect builder', async () => {
tree = await runner
.runSchematicAsync('ng-add', defaultOptions, appTree)
Expand Down
6 changes: 4 additions & 2 deletions projects/angular-calendar/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Rule,
SchematicContext,
Tree,
chain
chain,
} from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { getWorkspace } from '@schematics/angular/utility/config';
Expand All @@ -15,6 +15,7 @@ import {
NodeDependency,
NodeDependencyType
} from '@schematics/angular/utility/dependencies';
import { normalize } from '@angular-devkit/core';

import {
addModuleImportToRootModule,
Expand Down Expand Up @@ -109,8 +110,9 @@ function addModuleToImports(options: Schema): Rule {
);
const mainPath = getProjectMainFile(project);
const appModulePath = options.module
? options.module
? normalize(project.root + '/' + options.module)
: getAppModulePath(host, mainPath);

const moduleName = `CalendarModule.forRoot({ provide: DateAdapter, useFactory: ${
options.dateAdapter === 'moment'
? 'momentAdapterFactory'
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-calendar/schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"module": {
"type": "string",
"description": "Where to add the module import",
"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)"
"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)"
},
"projectName": {
"type": "string",
Expand Down

0 comments on commit 24125e5

Please sign in to comment.