Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schematics): ng-add identify the project style extension #3930

Merged
merged 1 commit into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}