Angular-cli: Unnecessary prompts for ng new when using create application false (i.e. Conditional Prompts)

Created on 8 Jan 2019  路  13Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

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

Command (mark with an x)

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

Versions


CLI: 7.1.4

Repro steps


Generating workspace without application still causes questions about the app:

ng new myapp --create-application=false
? Would you like to add Angular routing? No
? Which stylesheet format would you like to use? CSS

CREATE myapp/README.md (1027 bytes)
CREATE myapp/angular.json (135 bytes)
CREATE myapp/package.json (1262 bytes)
CREATE myapp/tsconfig.json (435 bytes)
CREATE myapp/tslint.json (2824 bytes)
CREATE myapp/.editorconfig (246 bytes)
CREATE myapp/.gitignore (576 bytes)

The log given by the failure

Desired functionality


The CLI should not ask questions about application it is not going to generate anyway.

Mention any other details that might be useful

schematicangular low broken bufix

Most helpful comment

Late to the party, but I just experienced this today (I've never used a workspace before). When it prompted me to select the preferred stylesheet format, I assumed that this would be a default automatically applied or inherited by all subsequent projects. This assumption was reinforced when I called generate application and it did not prompt me ... but then the application it created used the default (css) instead of what I selected on the workspace creation (scss).

So while the obvious fix would be to remove the prompts entirely, a potentially useful alternative would be to inherit the workspace's configuration in generated child projects. (Global configuration, as far as I understand, is one of the benefits of using workspaces for multiple projects...)

Just laying this out there; I didn't want to open a new ticket since this one was already open.

All 13 comments

@alan-agius4 you can get the info via

ng new --help

--create-application 
    When true (the default), creates a new initial app project in the new workspace.

@DenysVuika, apologies, re-opened.

There are actually a range of different issues related to --create-application=false. It needs a good deal of cleanup.

For example, it's not expected that ng new --create-application=false --styles=scss --routing=false would accept the styles and routing options and then completely ignore them. They don't get added to the angular.json, so a subsequent ng g app myapp gets generated with .css files.

If these options aren't compatible with --create-application=false (which I believe is the case since there is no spot to put them in angular.json for an empty workspace), then this should be documented and there should be a warning or error message when trying to use them together.

Here's an empty workspace angular.json for reference:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {}
}

This testing was done with 7.3.6. @alan-agius4 it sure would be nice to get this cleaned up for version 8 where we add --create-application=false to the official docs.

Hello!

@FrozenPandaz and I were discussing another use case for Conditional Prompts on the Nx repo (see https://github.com/nrwl/nx/issues/1211) which could be achievable via Inquirer's when option.

However, we wanted to move that discussion here since the implementation seemed less trivial than we thought for our particular use case. Given the way the x-prompt schema is defined, if we wanted to only ask questions based on previous answers we would need to define "optional" properties on the schematic's schema (example here: https://github.com/nrwl/nx/issues/1211#issuecomment-478974495).

AFAICT using the when option could also help towards solving the issue described on this ticket without further complexity, but let me know if I should open a separate ticket to specifically address the use case described on the Nx issue :)

I think many of issues related to --create-application=false can be solved by moving some prompts from the ng new schematic to the application schematic where they truly belong.

I have started experimenting with this in this draft PR.

Should I continue working on this issue?

Late to the party, but I just experienced this today (I've never used a workspace before). When it prompted me to select the preferred stylesheet format, I assumed that this would be a default automatically applied or inherited by all subsequent projects. This assumption was reinforced when I called generate application and it did not prompt me ... but then the application it created used the default (css) instead of what I selected on the workspace creation (scss).

So while the obvious fix would be to remove the prompts entirely, a potentially useful alternative would be to inherit the workspace's configuration in generated child projects. (Global configuration, as far as I understand, is one of the benefits of using workspaces for multiple projects...)

Just laying this out there; I didn't want to open a new ticket since this one was already open.

If this issue is affecting you, please 馃憤 the first post.

The application schematic now supports --routing and --style thanks to PR https://github.com/angular/angular-cli/pull/14638.

Next we need to update the ng new schematic prompting.

Yes, I am currently working on it :)

I just made a PR #15207 to solve this issue 馃檪.

For now all unit tests are green but e2e tests are red :(

All looks good in the PR now! Thank you.

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