-
Notifications
You must be signed in to change notification settings - Fork 12k
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
Rename / remove / move components #900
Comments
ember-cli has And there's an |
|
Here's a bit of further feedback. The current way that CLI creates new components and other pieces has the merit of following the nascent style guide. So perhaps this feedback is really for the style guide. It certainly creates quite a lot of duplication and naming. For everything that we add using this tooling, we get N copies of its name across multiple directories and files, with two different variations of the name. When the time comes to rename (which happens quite often in real applications), this adds lots of friction. I suppose there is nothing to be done about it; the decision has already been made that the official style will be to use two different variations of every name (or more) and to spray them across many files. But there certainly is an opportunity for the CLI to ease the trouble that this decision creates. |
Somewhat related issue: #357 @kylecordes overall refactoring of typescript projects is quite well supported across different IDEs via typescript services. Refactoring a name should operate correctly across the project, and disregarding other variables with the same name. I'm also not too clear what you mean by "N copies of its name" and "two different variations of every name", but you are right that those are style guide decisions and not CLI decisions - the CLI merely implements the style guide to the best of it's ability. |
Renaming a component would be very useful to have CLI feature. I was expecting this feature to be there and saw the CLI help and was disappointed because it wasn't. I have to rename atleast 5-6 files (*.component.ts, *.scss, *spec.ts, *.service.ts, etc) and then update those files where the component was imported or used. (e.g. app.routes.ts and other files). A quick CLI command for this would be a big timesaver. |
I didn't get the solution for - how to remove component by angular-cli . I was tried my examples but still get nothing ! rm and mv didn't worked ? |
A |
I as well believe a ng destroy would be quite usefull |
+1 to ng destroy or ng remove |
Just ran into this where I had created a component, imported packages that had the same named components and I was left having to tediously update all the files connected to my previously generated component. A rename would be a godsend. |
How do we distroy component as when I try to use ng d c or ng r c it throws the following error: The destroy command is not supported by Angular CLI. |
It will be very useful if we get commands for remove/rename components. |
As a temporary solution, if you have a clean repository and you want to remove, you can use: https://git-scm.com/docs/git-reset |
+1 to have this feature in the CLI |
Remove option is a must. |
+1 to have this! |
+1 Strongly suggest to add ng remove r or ng destroy d component/service/pipe and etc. |
+1 for this |
I can't believe this has been open so long. If you have code to generate, certainly you can delete those same file locations. Manually removing a botched naming of a generated component is a pain. |
People that demanding on the feature - you don't realize how complicated it would be to implement. Even advanced IDEs do mistakes when moving components to other folders. Path become rewritten mistakenly broken. Or when doing delete - IDE found too much dependent relation which it cannot handle automatically - so it asks developer to review. Expecting this feature from cli is very optimistic. Theoretically it would be easier if let's say absolutely prohibit developers to manually edit imports/exports. But who wants frozen file system in their project? And who will really keep this rule in 100% of cases? |
Fair enough. I dont pretend to know how complicated Angular setup is. But Rails has had this since its inception so I imagine there must be a solution. Isn't the most common use case of using destroy right after generate? I'm not a proponent of rename as much as I am basic destroy functionality. |
Exactly. I assume that this use case is much easier then 'create component, use if for 2 years, destroy component'. |
+infinity! It would be a great improvement to add this feature! |
Hey guys! I'd appreciate if anyone could tell me some - I hope, good - news! |
+1! I couldn't actually believe this isn't available yet! |
Would definitely be a very nice feature to have, make it possible! |
I'm waiting for it as well! :) |
Here is a bash script I wrote to remove components. It is run like This has only been tested with Angular 6
|
ng add not only installs but also edit project files. For example, if you add @angular/pwa, A remove should not only remode the package from node_modules but also under all these changes on project files. You get a fair idea how difficult that is. |
(node:7652) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded |
The issue must be there ; describe('ModifierComponent', () => { beforeEach(async(() => { beforeEach(() => { it('should create', () => { |
+1 |
1 similar comment
+1 |
+1 I just started using angular, coming from ember.js and that's literally the first thing I was searching for, on how to manipulate components using the cli. That's sad, I hope it will be added |
it has been almost 4 years and still no |
Forilla my Gorilla? This isn't a command? |
@MA-Agent I see you mentionned considering to write a script yourself. Do you have any news on that ? I am pretty sure a few people here might be interested 👀 |
It's pointless really am just gonna right that script myself since they're not considering this as a must need command... |
+1 |
It seems easy but it has a big scope. When you remove a component then you will have to visit all files to check if it's component use anywhere else or not. While we add a component we mention module same we will have to do while removing. |
And what will you do if the component is moved in the directory of another module. Maybe you have modules in nested directories, or maybe you use some constants in order to avoid copy/paste between the declarations and exports of the What will you do with page components? What about dialog that are used at runtime, that used to be in entryComponents, like dialogs. And then, what do you do with CSS classes and related things? Here's an old "recursive rename" script of mine, it only updates content in the directory that you give it, and that directory needs to contain a single component (and with extra related things like component specific services) My feeling is that this story is very much out of the scope for the Angular CLI. Each project has it's own unique structure and if you really want to. You can implement your own schematic or maybe a 3rd party library could implement some generic schematics. But I think that it will be to much work for the Angular CLI team to maintain. There will be way to many issues reported regarding this feature. So: 👎 |
We discussed this issue within the CLI team today and had a few thoughts. This issue seems to cover multiple use cases, so to address them individually: Delete componentThere is not much the CLI can do in order to more intelligently delete an Angular component. We can't intelligently remove all references to a component, so it's up to the user to refactor their app such that a component isn't used. That is 90% of the meaningful effort around deleting a component, so manually deleting multiple files isn't consuming a critical amount of time. A trivially simple command to do this would be: rm foo.component.*
# OR
rm foo.service.* The Angular CLI can't really be much more intelligent than this, so implementing it doesn't provide much value to users. Move component(In this context, I'm defining "moving" a component as moving it into a different directory with the same name, as opposed to "renaming" a component which stays in the same directory.) Moving a component is quite tricky due to the way Alternatively, the CLI could ignore mv foo.component.* bar/
# OR
mv foo.service.* bar/ IDEs can be a bit smarter about this and update imports to use the new path, but there's not much the CLI itself can do that would be better than that. Rename component(In this context, I'm defining "renaming" a component as staying in the same directory, as opposed to "moving" it into a different directory.) If we only rename a component and keep it in the same directory, then that dodges a lot of the
All of these are more of an IDE feature than a CLI feature. After some discussion among the CLI team, we feel that these features make more sense in the Angular language service than they do in the CLI itself. I believe there are often hooks to handle file renaming, where these features could be directly implemented. Through the language service, it could also provide these same features when moving across directories (ignoring the I filed angular/vscode-ng-language-service#815 for the language service to make the changes there. However, we don't think it makes sense to include this kind of feature in the CLI itself. All these use cases are either handled just as well by existing well-known and supported tools, or would be better served in the language service than in the CLI. |
I agree with your opinions, this is really hard to let Angular CLI do this. The IDE should be more intelligent and can help refactor instead of Angular CLI. Thank for answer |
Hope there will be a language server for Angular left to implement this, seems like they lack manpower? angular/vscode-ng-language-service#335 |
It will be nice-to-have rm remove command as some time we just create angular components and need to rename them. As this rename command is not there, deleting the created angular component, directive, etc and again running the command to create the component is a pain. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ng --version
. If there's nothing outputted, pleaseangular-cli: 1.0.0-beta.1
node: 5.7.0
os: darwin x64
It would be really usefull to add cli commands for:
Unless I am missing it, I don't see that this exists and it would be really useful during refactoring to avoid all the manual updates that come with this process.
Thoughts?
The text was updated successfully, but these errors were encountered: