Skip to content

Custom component suffix --suffix=Route #15680

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

Closed
leon opened this issue Sep 26, 2019 · 8 comments
Closed

Custom component suffix --suffix=Route #15680

leon opened this issue Sep 26, 2019 · 8 comments
Labels
Milestone

Comments

@leon
Copy link
Contributor

leon commented Sep 26, 2019

🚀 Feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [x] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Description

I would like to be able to change the default .component suffix to something more descriptive.

As most of apps are comprised of components, it would be of more use to easily be able to separate the components into their different type.

nav-bar.ui.ts // presentational component
invoices.container.ts // smart component
users.route.ts // route component

The Style guide mentions that you can add your own types

Do use consistent type names for all components following a pattern that describes the component's feature then its type. A recommended pattern is feature.type.ts.

Do use conventional type names including .service, .component, .pipe, .module, and .directive. Invent additional type names if you must but take care not to create too many.

And I think we should enable people to choose their own file layouts.
This simple addition to the component generator would make this possible without having to resort to manually rename all the source files after generating a new component.

I did previously suggest it here #3913 but the timing was not right and it fell through.

Describe the solution you'd like

To be able to supply the suffix for the component generator

ng g component Users --suffix=Route

I will gladly submit a pull request if you agree that it would be a good feature.

Describe alternatives you've considered

Rename files manually

Manually renaming all files. Extremely tedious and boring

Creating a custom schematic

Yes I've done this, but because different projects use different base schematics, some cli some nx, I find I usually don't bother.
It could get better with #12157
Then people could create special schematics and you could simply add your favorite generators to your project.

@alan-agius4 alan-agius4 added the needs: discussion On the agenda for team meeting to determine next steps label Sep 26, 2019
@vikerman vikerman removed the needs: discussion On the agenda for team meeting to determine next steps label Sep 26, 2019
@vikerman
Copy link
Contributor

We still want to stick to the Angular styleguide in the CLI schematics. It is easy to rename components in the IDE.

Creating a custom schematics might be the way to go here if you really wanted this behavior.

Thanks

@vikerman vikerman added the needs: discussion On the agenda for team meeting to determine next steps label Sep 26, 2019
@leon
Copy link
Contributor Author

leon commented Sep 28, 2019

The styleguide says "Invent additional type names if you must but take care not to create too many." which to me sounds like if we find new types which makes sense to us, it's okey.

I think this would enable us to better state our intent and by looking at the file we can clearly see that it's a component, so why do we need to keep it in the filenames?

I have multiple sub types of components that I build my apps from:

.dialog
.form
.ui
.container

at the moment I'm naming the classes that way

RemoveProjectDialogComponent
AddUserFormComponent
UserCardUIComponent

Which also leads to really long filenames

remove-project-dialog.component.ts
add-user-form.component.ts
...

I find it would be more pleasing to have:

remove-project.dialog.ts
add-user.form.ts
user-card.ui.ts

and the same goes for the imports which are really long and hard to eye over.

I cannot be the only one not loving the overly complex names.
I hope you can see it from my point of view and take this into consideration.

@vikerman
Copy link
Contributor

vikerman commented Oct 3, 2019

@leon - The class schematics already has a --type options which is similar to what you are requesting. Is it possible for you to create a PR to add a similar option to the component schematics? All the css, html, spec will also need to have the same type suffix.

@alan-agius4 alan-agius4 added area: @schematics/angular help wanted feature Issue that requests a new feature and removed needs: discussion On the agenda for team meeting to determine next steps labels Oct 3, 2019
@ngbot ngbot bot modified the milestone: Backlog Oct 3, 2019
@leon
Copy link
Contributor Author

leon commented Oct 3, 2019

I will add a PR to add a --type option that will set all all spec, class and filenames accordingly.

leon added a commit to leon/angular-cli that referenced this issue Oct 3, 2019
the type option allows you to change the default .component.ts suffix to new types.
such as

Route
Dialog
UI
Container

angular#15680
leon added a commit to leon/angular-cli that referenced this issue Oct 4, 2019
the type option allows you to change the default .component.ts suffix to new types.
such as

Route
Dialog
UI
Container

angular#15680
@leon
Copy link
Contributor Author

leon commented Oct 7, 2019

The PR is complete with all tests passing.
Is there anywhere else that I need to add the option so that documentation is up to date?

@clydin
Copy link
Member

clydin commented Oct 7, 2019

Documentation will be automatically generated once the version is released.

@leon
Copy link
Contributor Author

leon commented Oct 10, 2019

My PR got merged, so I'll close this :)

🎆

@leon leon closed this as completed Oct 10, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants