Skip to content

fix(schematics): add app prefix to components #11738

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

Merged
merged 1 commit into from
Jun 13, 2018
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: 4 additions & 4 deletions src/lib/schematics/utils/devkit-utils/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ function addDeclarationToNgModule(options: any): Rule {
};
}


function buildSelector(options: any) {
function buildSelector(options: any, projectPrefix: string) {
let selector = strings.dasherize(options.name);
if (options.prefix) {
selector = `${options.prefix}-${selector}`;
} else if (options.prefix === undefined && projectPrefix) {
selector = `${projectPrefix}-${selector}`;
}

return selector;
}


export function buildComponent(options: any): Rule {
return (host: Tree, context: SchematicContext) => {
const workspace = getWorkspace(host);
Expand All @@ -105,7 +105,7 @@ export function buildComponent(options: any): Rule {
options.path = `/${project.root}/src/app`;
}

options.selector = options.selector || buildSelector(options);
options.selector = options.selector || buildSelector(options, project.prefix);
options.module = findModuleFromOptions(host, options);

const parsedPath = parseName(options.path, options.name);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/schematics/utils/devkit-utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export interface Workspace {
export interface Project {
name: string;

/** Application prefix. */
prefix: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this is part of the Angular CLI's actual project schema, we can't add this extra property here without also making it non-enumerable because we reserialize this object and write it to disk when we're e.g. adding a theme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is in the actual schema. I pulled this code from official component schematic - https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/component/index.ts#L116-L125


/** Project type. */
projectType: 'application' | 'library';
/** Root of the project sourcefiles. */
Expand Down