Skip to content

Commit

Permalink
fix(schematics): fix component option
Browse files Browse the repository at this point in the history
  • Loading branch information
Domainv committed Dec 5, 2018
1 parent 3a17cc3 commit 84d3cf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions schematics/src/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ describe('ng-add schematic', () => {
const packageJson = JSON.parse(getFileContent(tree, '/package.json'));
const dependencies = packageJson.dependencies;

/* tslint:disable-next-line: no-string-literal */
expect(dependencies['bootstrap']).toBeDefined();
expect(dependencies.bootstrap).toBeDefined();
expect(dependencies['ngx-bootstrap']).toBeDefined();

expect(Object.keys(dependencies)).toEqual(Object.keys(dependencies).sort(),
Expand Down
21 changes: 15 additions & 6 deletions schematics/src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ const datePickerStylePath = `./node_modules/ngx-bootstrap/datepicker/bs-datepic
/* tslint:disable-next-line: no-default-export */
export default function (options: Schema): Rule {
return chain([
addStyles(options),
addPackageJsonDependencies(),
installPackageJsonDependencies(),
options.component ? addModuleOfComponent(options.project, options.component) : noop()
!options.component || options.component === 'datepicker'
? addStyles(options, insertCommonStyles)
: addStyles(options, insertBootstrapStyles),
options.component
? addModuleOfComponent(options.project, options.component)
: noop()
]);
}

Expand Down Expand Up @@ -97,7 +101,7 @@ function addPackageJsonDependencies(): Rule {
};
}

export function addStyles(options: Schema): (host: Tree) => Tree {
export function addStyles(options: Schema, insertStyle: Function): (host: Tree) => Tree {
return function (host: Tree): Tree {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
Expand All @@ -108,9 +112,14 @@ export function addStyles(options: Schema): (host: Tree) => Tree {
};
}

function insertStyle(project: WorkspaceProject, host: Tree, workspace: WorkspaceSchema) {
addStyleToTarget(project, 'build', host, datePickerStylePath, workspace);
addStyleToTarget(project, 'test', host, datePickerStylePath, workspace);
function insertBootstrapStyles(project: WorkspaceProject, host: Tree, workspace: WorkspaceSchema) {
addStyleToTarget(project, 'build', host, bootstrapStylePath, workspace);
addStyleToTarget(project, 'test', host, bootstrapStylePath, workspace);
}

function insertCommonStyles(project: WorkspaceProject, host: Tree, workspace: WorkspaceSchema) {
addStyleToTarget(project, 'build', host, datePickerStylePath, workspace);
addStyleToTarget(project, 'test', host, datePickerStylePath, workspace);

insertBootstrapStyles(project, host, workspace);
}

0 comments on commit 84d3cf9

Please sign in to comment.