Call me lazy but I really expected to be able to type ng g function foo and have the CLI generate a file foo.ts that contains an empty function ready for me to modify.
export function foo(): any {
}
From an abstract point of view it's very easy to do that manually. But on the other hand we already offer generators for classes, enums and interfaces. I'd say a function is more common than an enum, for instance.
So my opinion is that it should be there for the sake of completion, if nothing else. Basic file creation with classes etc is usually the responsibility of IDEs, but if the CLI can offer a complete-ish experience then users won't need to go do it in the IDE.
I think there's value in that.
@Brocco @johnpapa what do you think?
I lean towards not including this. It's a function ... very simple to do on your own. There is no additional hidden value by helping with the syntax. In fact, most editor have a built in function snippet that at least get you something like ... function foo() { ... }
I also believe this is scope creep.
I vote no.
It seems weird to me to so tightly equate a file and a function. And seeing such an option in the documentation would make me wonder what Angular-CLI was doing with functions which necessitated such a "higher level" step. I feel Angular-CLI should stick to making it easy to assemble the somewhat-tricky-for-the-uninitiated combinations required by Angular; more than that seems like feature creep to me. (*coughgithubdeploycough*)
I tend to agree with @johnpapa here, even though I submitted a PR for this generation. But just because I won't use this feature does not mean that others won't find value in it.
There is no additional hidden value by helping with the syntax
For me it is mostly about helping with the file's creation. In Windows it's not that easy to create an empty file using the command prompt. (see https://stackoverflow.com/questions/1702762/how-to-create-an-empty-file-at-the-command-line-in-windows)
For me one of the reasons to include it would be to let the developer know that this is one of the options you have to structure your code.
I never used functions in separate files but I can see the benefit, having this option in the cli invites to explore it.
I vote for adding it.
I think the level of granularity drops dramatically by introducing a generator for functions. I see this being followed by a generation for a file with a constant, variable, or an empty file.
I agree with @johnpapa that this looks like a scope creep and vote no as well.
This is a line we need to draw, and function could be useful in the case of creating unit tests for example. That being said, I don't think that in the particular case of Angular a function makes sense. There are really rare cases where you want a function instead of, say, a service for your code, but those cases are not particularly hard to work through.
I think adding function only adds clutter to our API surface and vote no as well.
Based upon feedback provided I think this is something that will not get included in the CLI, when custom blueprints are added this can be added as a plugin/addon.
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._
Most helpful comment
I lean towards not including this. It's a function ... very simple to do on your own. There is no additional hidden value by helping with the syntax. In fact, most editor have a built in function snippet that at least get you something like ...
function foo() { ... }I also believe this is scope creep.
I vote no.