Skip to content

Commit

Permalink
feat(schematics): use the project's style extension (#3930)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz authored and Wendell committed Aug 9, 2019
1 parent ac866ce commit 84b0355
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { NodePackageInstallTask, RunSchematicTask } from '@angular-devkit/schematics/tasks';
import { getProjectFromWorkspace } from '@angular/cdk/schematics';
import { getWorkspace } from '@schematics/angular/utility/config';
import { addPackageToPackageJson } from '../utils/package-config';
import { getProjectStyle } from '../utils/project-style';
import { hammerjsVersion, zorroVersion } from '../utils/version-names';
import { Schema } from './schema';

Expand All @@ -18,7 +21,10 @@ export default function(options: Schema): Rule {
context.addTask(new RunSchematicTask('ng-add-setup-project', options), [installTaskId]);

if (options.template) {
context.addTask(new RunSchematicTask(options.template, options));
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const style = getProjectStyle(project);
context.addTask(new RunSchematicTask(options.template, {...options, style: style}));
}

};
Expand Down
7 changes: 2 additions & 5 deletions schematics/ng-generate/side-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Tree
} from '@angular-devkit/schematics';
import { getProjectFromWorkspace } from '@angular/cdk/schematics';
import { Style } from '@schematics/angular/application/schema';
import { getWorkspace } from '@schematics/angular/utility/config';
import { addModule } from '../../utils/root-module';

Expand All @@ -24,16 +23,14 @@ export default function(options: Schema): Rule {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const prefix = options.prefix || project.prefix;
const style = options.style || Style.Css;
return chain([
mergeWith(
apply(
url('./files/src'), [
applyTemplates({
prefix,
style,
...strings,
...options
...options,
prefix
}),
move(project.sourceRoot as string),
forEach((fileEntry: FileEntry) => {
Expand Down
9 changes: 9 additions & 0 deletions schematics/utils/project-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { WorkspaceProject } from '@angular-devkit/core/src/experimental/workspace';
import { getProjectStyleFile } from '@angular/cdk/schematics';
import { Style } from '@schematics/angular/application/schema';

export function getProjectStyle(project: WorkspaceProject): Style {
const stylesPath = getProjectStyleFile(project);
const style = stylesPath ? stylesPath.split('.').pop() : Style.Css;
return style as Style;
}

0 comments on commit 84b0355

Please sign in to comment.