Skip to content

Commit 6cc0ce6

Browse files
Domainvvalorkin
authored andcommitted
fix(schematics): fix component option (#4892)
1 parent 9671c7e commit 6cc0ce6

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

schematics/src/ng-add/index.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ describe('ng-add schematic', () => {
3535
const packageJson = JSON.parse(getFileContent(tree, '/package.json'));
3636
const dependencies = packageJson.dependencies;
3737

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

4241
expect(Object.keys(dependencies)).toEqual(Object.keys(dependencies).sort(),

schematics/src/ng-add/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ const datePickerStylePath = `./node_modules/ngx-bootstrap/datepicker/bs-datepic
3030
/* tslint:disable-next-line: no-default-export */
3131
export default function (options: Schema): Rule {
3232
return chain([
33-
addStyles(options),
3433
addPackageJsonDependencies(),
3534
installPackageJsonDependencies(),
36-
options.component ? addModuleOfComponent(options.project, options.component) : noop()
35+
!options.component || options.component === 'datepicker'
36+
? addStyles(options, insertCommonStyles)
37+
: addStyles(options, insertBootstrapStyles),
38+
options.component
39+
? addModuleOfComponent(options.project, options.component)
40+
: noop()
3741
]);
3842
}
3943

@@ -97,7 +101,7 @@ function addPackageJsonDependencies(): Rule {
97101
};
98102
}
99103

100-
export function addStyles(options: Schema): (host: Tree) => Tree {
104+
export function addStyles(options: Schema, insertStyle: Function): (host: Tree) => Tree {
101105
return function (host: Tree): Tree {
102106
const workspace = getWorkspace(host);
103107
const project = getProjectFromWorkspace(workspace, options.project);
@@ -108,9 +112,14 @@ export function addStyles(options: Schema): (host: Tree) => Tree {
108112
};
109113
}
110114

111-
function insertStyle(project: WorkspaceProject, host: Tree, workspace: WorkspaceSchema) {
112-
addStyleToTarget(project, 'build', host, datePickerStylePath, workspace);
113-
addStyleToTarget(project, 'test', host, datePickerStylePath, workspace);
115+
function insertBootstrapStyles(project: WorkspaceProject, host: Tree, workspace: WorkspaceSchema) {
114116
addStyleToTarget(project, 'build', host, bootstrapStylePath, workspace);
115117
addStyleToTarget(project, 'test', host, bootstrapStylePath, workspace);
116118
}
119+
120+
function insertCommonStyles(project: WorkspaceProject, host: Tree, workspace: WorkspaceSchema) {
121+
addStyleToTarget(project, 'build', host, datePickerStylePath, workspace);
122+
addStyleToTarget(project, 'test', host, datePickerStylePath, workspace);
123+
124+
insertBootstrapStyles(project, host, workspace);
125+
}

0 commit comments

Comments
 (0)