Skip to content

Cannot generate a component on a dir path other than the default "app/" #12141

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

Closed
alexeagle opened this issue Sep 4, 2018 · 5 comments
Closed
Labels
area: @schematics/angular feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature Issue that requests a new feature
Milestone

Comments

@alexeagle
Copy link
Contributor

From @shairez on March 2, 2018 9:41

Bug Report or Feature Request (mark with an x)

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

Area

- [ ] devkit
- [x] schematics

Versions

Node v8.9.0
Npm 5.6.0
Windows 10

Repro steps

Let's say I have the following structure -

app/
  app.module.ts

custom-app/
  app.module.ts

And I want to create a new component under custom-app

From the root of the project, trying to run any of these :

ng g c my-comp -m="../custom-app/app.module.ts"
or
ng g c custom-app/my-comp -m="../custom-app/app.module.ts"
or even
ng g c /src/custom-app/my-comp -m="../custom-app/app.module.ts"

results in a component being created under the /app folder and not /custom-app.

The log given by the failure

  create src/app/custom-app/my-comp/my-comp.component.html (26 bytes)
  create src/app/custom-app/my-comp/my-comp.component.spec.ts (629 bytes)
  create src/app/custom-app/my-comp/my-comp.component.ts (271 bytes)
  create src/app/custom-app/my-comp/my-comp.component.css (0 bytes)
  update src/custom-app/app.module.ts (419 bytes)

Desired functionality

I would expect that -

  1. Specifying a module would create the component underneath that specific module's folder

  2. If not, at least specifying a different path (starting from the src folder) will generate that component under that custom path

Mention any other details that might be useful

none

Copied from original issue: angular/devkit#476

@pascallaprade-beslogic
Copy link

We also have this issue, and have the same definition for required functionality.

Here is the output of npx ng --version:

λ npx ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.0.3
Node: 11.0.0
OS: win32 x64
Angular: 7.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.3
@angular-devkit/build-angular     0.10.3
@angular-devkit/build-optimizer   0.10.3
@angular-devkit/build-webpack     0.10.3
@angular-devkit/core              7.0.3
@angular-devkit/schematics        7.0.3
@angular/cli                      7.0.3
@ngtools/webpack                  7.0.3
@schematics/angular               7.0.3
@schematics/update                0.10.3
rxjs                              6.3.3
typescript                        3.1.3
webpack                           4.19.1

Details

If we try to create a new component, for example ng generate component Test, it will be created in src/app/test. If we specify a subfolder, it will also be relative to app. For example, ng generate component shared/Test will be created in src/app/shared/test.

However, we do not want all our code to be located in app, as we think that src is a sufficient root for our code to live in.

The only way we can avoid this problem is by either execute the generate command from the target folder, or to start our paths with ...

I will open a separate issue for that (if there is none already existing), but when generating components with a relative .. path, our styleext configuration is ignored and the stylesheet generated is plain CSS, so this is not an option for us.

Moving around in the folders could work, but since we have many components to generate, it will become tedious to constantly navigate to the proper folder before generating said new components.

As such, I would expect that the generate command should generate entities relative to the sourceRoot path defined in the angular.json config file. For us, the sourceRoot is the default value, src.

Desired functionality

If sourceRoot means something else than "the root folder where the source code lives", then a new configuration option should be added, such as generateRoot, so that we can specify ourselves the directory in which generate targets should be generated. Otherwise, generate should generate entities relatively to the sourceRoot path specified in the angular.json configuration file, as suggested by the author of the issue. If there is a reason why this cannot or should not be done, said reason should be clearly documented so that we can refer to that documentation when taking code structure decisions.

@clydin clydin added the feature Issue that requests a new feature label May 30, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog May 30, 2020
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Feb 1, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 1, 2022

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@ngbot ngbot bot modified the milestones: Backlog, needsTriage Feb 1, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 21, 2022

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: votes required Feature request which is currently still in the voting phase labels Feb 21, 2022
@alan-agius4
Copy link
Collaborator

Duplicate of #9370

@alan-agius4 alan-agius4 marked this as a duplicate of #9370 Apr 27, 2023
@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 May 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @schematics/angular feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

4 participants