Angular-cli: Have ng g c [name] generate inline-template and inline-style automatically from config

Created on 3 Jun 2017  路  10Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [X] feature request

Versions.


master

Repro steps.


ng new delete-me-quickly
cd delete-me-quickly/src/app
ng g c hello
cd hello && ls
Contains html and css files, instead of them being inline.

The log given by the failure.

Desired functionality.

If the functionality is specified in ng new using -is or -it, a respective setting should be saved in .angular-cli.json and stick in generation of new Components and/or Directives.

Mention any other details that might be useful.

I came up with it during research I'm doing for #6480, where I'm updating the documentation for ng new.

I would like to further contribute by adding this feature myself and PRing it. Would that be acceptable? Is this feature even discussed? I would very much like to contribute in the cli, especially something that is more code than docs.

EDIT

After additional research, I did find that .angular-cli.json has such configuration, as specified here:
```
/* blueprints/component/index.ts */
options.inlineStyle = options.inlineStyle !== undefined ?
options.inlineStyle : CliConfig.getValue('defaults.component.inlineStyle');

options.inlineTemplate = options.inlineTemplate !== undefined ?
  options.inlineTemplate : CliConfig.getValue('defaults.component.inlineTemplate');

````

But it is not set during ng new.

feature

Most helpful comment

@Brocco I like the suggestion. Also I think that the existing flags documentation should be updated to explain they only cause AppComponent to be inline.

All 10 comments

@Brocco WDYT?

@filipesilva @Brocco It's good option to have on the other side I think it should be on the component also as when creating small components which only are containers or have few lines would like to have those inline.

@sumitarora what you're talking about exists. My thought process behind this change is that if someone specifies in lines on new, I believe they want it for the entire app. If someone wants a particular component with inlines, the g c command accepts inlines already, and they are given priority over defaults, as you can see in the snippet above

To understand, you wish to make the change that when a user creates an app using --inline-template or --inline-style that the setting be persisted to .angular-cli.json for future generations for that app?

Current state, just the app component will get inlined, no setting saved to .angular-cli.json

Proposed: set the inline flag(s) when used during ng new

Issue: What if the dev wants to only inline their app component as it typically is very light but not all subsequent components?

Suggestion: Add new flags to clearly state the desire to have all components inlined...

--inline-style-all (-isa)
--inline-template-all (-ita)

The result of using these flags would be to set it for the current run and set the value in angular-cli.json

Thoughts?

@Brocco I like the suggestion. Also I think that the existing flags documentation should be updated to explain they only cause AppComponent to be inline.

@filipesilva @sumitarora @Brocco So it's agreed that -all is the right way to go? Can I go on and implement? Implementation would be an update to my existing PR #6571

@Brocco, @gioragutt I just gave some thoughts and in my opinion a good "logic" soluton would be:

1- When creating a new project, a setting wiil be saved to .angular-cli.jsony
2- This setting can be changed anytime by the dev in ng set defaults.inline="true/false"
3- when the dev generates a component, pipe, etc.. the cli will generate according to the defaults inline unless he specifies otherwisse with the current "-is" flag or with one new flag to be created "-nis" no inline.
4- If the dev specifies the "-is" or "-nis" this configuration will override the defaults but only for this component/pipe, etc.

What do you think?

@ampgular this is how it works today. Except that it just doesn't save it in .angular-cli.json, which is what my PR changes. You can see in the generate command, that it checks both the setting in .angular-cli.json, and the setting from the command line arguments given in the command, giving priority to the command line argument setting.

+1

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._

Was this page helpful?
0 / 5 - 0 ratings