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

Feature Request: Generate a new module without a component #3365

Closed
johnpapa opened this issue Dec 3, 2016 · 9 comments
Closed

Feature Request: Generate a new module without a component #3365

johnpapa opened this issue Dec 3, 2016 · 9 comments
Assignees

Comments

@johnpapa
Copy link
Contributor

johnpapa commented Dec 3, 2016

OS?

Mac OSX Sierra

Versions.

angular-cli: 1.0.0-beta.21
node: 6.9.1
os: darwin x64

Option 1

ng g m foo --no-component
This would generate the module without the component ts, css, spec, html

Option 2

ng g m foo

Or ideally the default would be to not generate a component at all. It can easily be created after by doing ng g c bar.

Why?

  1. It is easy to add a component when needed.

  2. It is distracting to generate a module and have 4 extra files created when you do not want them.

  3. Avoids having to delete 4 files with rm bar.component.*

Details

use case ...
https://github.com/johnpapa/event-view/blob/master/src/app/core/core.module.ts

Notice this one … common use case for a module that contains mostly reusable services and only one component. And in this case, the component is not named the same as the module (and shouldnt be).

Option 2 above is my preference.

@baruchvlz
Copy link
Contributor

baruchvlz commented Dec 4, 2016

I agree that the default behavior of ng g m <name> should be to create an empty module file and pass a component flag, maybe something like ng g m foo --component=true.

I have added this option to my local copy of the cli, { name: 'component', type: Boolean, default: false }, and added a conditional in the afterInstall method to create a component if the flag is true, seems simple enough. I'm not entirely sure if this needs further discussion, if not I can make the PR.

My file

@Brocco
Copy link
Contributor

Brocco commented Dec 7, 2016

After having a few conversations about this and thinking about it some more, I think we should have the modules just generate modules with one exception... routing modules. Routing modules can be created at two times: new app creation and module creation.

So what I'm suggesting on your PR, @baruchvlz, is to completely remove the --component option and only generate the module.

Thoughts?

@deebloo
Copy link
Contributor

deebloo commented Dec 7, 2016

I personally think it makes sense. Especially with component generation adding the declaration to the closest module up the tree.

@baruchvlz
Copy link
Contributor

@Brocco : Reading what @deebloo said, it would make sense to have the command only generate the module unless the --routing flag is passed.

One questions though, should the spec file be generated by default as well just to match the other generate command of components, directives, etc... or are unit tests for modules not necessarily required?

@Brocco
Copy link
Contributor

Brocco commented Dec 7, 2016

I would leave it as is, it will pick up the default from here if it is not specified in angular-cli.json or passed in as an argument.

@baruchvlz
Copy link
Contributor

Oh, interesting thanks for pointing that out. I will make the changes to the PR.

@baruchvlz
Copy link
Contributor

PR has been updated.

@Brocco
Copy link
Contributor

Brocco commented Dec 15, 2016

PR merged, closing

@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 Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants