angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Ng generate always assumes an `app` folder

Open mikehallishere opened this issue 7 years ago • 15 comments

Our project setup doesn't have an immediate sub-folder of app, however, it appears that running ng generate always assume that you have an app folder under the app root folder you specified in .angular-cli.json

Versions

Angular CLI: 1.6.0
Node: 7.0.0
OS: darwin x64
Angular:
...

Repro steps

  • Setup a simple .angular-cli.json with:
{
  "apps": [
    {
      "name": "client",
      "root": "projects/client"
    }
  ]
}
  • Run:
ng g c form-inputs/mike --skip-import --dry-run --app=client

Observed behavior

You'll see the output path always assumes an app folder:

  create projects/client/app/form-inputs/mike/mike.component.css (0 bytes)
  create projects/client/app/form-inputs/mike/mike.component.html (23 bytes)
  create projects/client/app/form-inputs/mike/mike.component.spec.ts (614 bytes)
  create projects/client/app/form-inputs/mike/mike.component.ts (261 bytes)

Desired behavior

I'd like an option to be able to configure whether your project has the app folder or not. Or maybe an option to configure the whole path the component gets created in.

mikehallishere avatar Jan 24 '18 20:01 mikehallishere

Actually, there is an undocumented option in .angular-cli.json called appRoot which is probably you're looking for.

PoiScript avatar Feb 01 '18 15:02 PoiScript

@PoiScript is right, there's appRoot options for this, see https://github.com/angular/angular-cli/pull/7775.

martinsik avatar Feb 13 '18 16:02 martinsik

Using appRoot leads to an error "Workspace needs to be loaded before it is used." and is not included in the json-schema for angular.json.

leonadler avatar Jun 19 '18 09:06 leonadler

@leonadler appRoot is used for angular cli 1.x project. angular cli 6 introduces a new configuration schema. Each projects now has individual root and sourceRoot options, see https://github.com/angular/angular-cli/wiki/angular-workspace

PoiScript avatar Jun 19 '18 13:06 PoiScript

ng generate is adding app to the path by default. How to remove 'app' ? "root": "", "sourceRoot": "ui-lib/src", "projectType": "library",

ng g module dashboard/widget -d CREATE src/app/dashboard/widget/widget.module.spec.ts (275 bytes) CREATE src/app/dashboard/widget/widget.module.ts (190 bytes)

jacobjojan avatar Jul 10 '18 15:07 jacobjojan

I'm having the same issue as @jacobjojan, every time I run ng generate it generates by default in app folder, I want to generate out of app folder, how to do that?

wasif-digitalnet avatar Aug 01 '18 09:08 wasif-digitalnet

@wasif-digitalnet what about

ng generate module ../my-module

CREATE src/my-module/my-module.module.spec.ts (292 bytes)
CREATE src/my-module/my-module.module.ts (192 bytes)

giolf avatar Aug 22 '18 16:08 giolf

@giolf I have tried it, I guess there was some issues while generating the project, I made a new project and it's working fine now,

wasif-digitalnet avatar Aug 28 '18 11:08 wasif-digitalnet

@wasif-digitalnet probably you run that command in a nested folder of your project ?

Anyway I’m glad to hear that you could solve it

giolf avatar Aug 28 '18 17:08 giolf

@giolf Your solution worked... Cheers!

ilivestrong avatar Oct 08 '18 05:10 ilivestrong

@ilivestrong Cool

giolf avatar Oct 08 '18 11:10 giolf

This problem is still unresolved.

We have a code-base similar to Angular Material, where the library modules folders are directly beneath the main library folder.

We have recently replaced our custom build systems in favor of the Angular CLI, but when using the ng generate commands, they automatically add either app or lib depending on the project type (application or library).

Why can't this be configurable? Why isn't "sourceRoot" the literal root?

Paitum avatar Jul 31 '19 19:07 Paitum

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.

angular-robot[bot] avatar Feb 01 '22 17:02 angular-robot[bot]

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[bot] avatar Feb 21 '22 13:02 angular-robot[bot]

This style guide https://angular.dev/style-guide#organize-your-project-by-feature-areas recommends using /src as the root to put feature folders inside.

This conflicts with Angular CLI schematics path adding app between src and the name of the component.

umagon avatar Aug 06 '25 00:08 umagon