devkit icon indicating copy to clipboard operation
devkit copied to clipboard

Generate command for libraries adds to app folder instead of lib folder

Open tonyholt opened this issue 8 years ago • 2 comments

Bug Report or Feature Request (mark with an x)

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

Area

- [ ] devkit
- [x] schematics

Versions

node: v8.9.1 npm: 5.8.0

Repro steps

ng generate library foo
ng g c foo-component --project=foo -d 

The log given by the failure

None. Notice that the command will attempt to add the foo component like this:

CREATE projects/foo/src/app/foo-component/foo-component.component.html (32 bytes) CREATE projects/foo/src/app/foo-component/foo-component.component.spec.ts (671 bytes) CREATE projects/foo/src/app/foo-component/foo-component.component.ts (296 bytes) CREATE projects/foo/src/app/foo-component/foo-component.component.css (0 bytes)

NOTE: Run with "dry run" no changes were made.

Desired functionality

Instead of the app folder, it would be nice if the schematics recognizes the project as a library and instead adds functionality to the lib folder. If the projectType from the angular.json can be queried, then the schematics could determine whether the project is an application or a library

I can get around this in the meantime by adding a --path flag like this:

ng g c foo-component -d --project=foo --path=projects/foo/src/lib
CREATE projects/foo/src/lib/foo-component/foo-component.component.html (32 bytes)
CREATE projects/foo/src/lib/foo-component/foo-component.component.spec.ts (671 bytes)
CREATE projects/foo/src/lib/foo-component/foo-component.component.ts (296 bytes)
CREATE projects/foo/src/lib/foo-component/foo-component.component.css (0 bytes)
UPDATE projects/foo/src/lib/foo.module.ts (313 bytes)

Mention any other details that might be useful

It would be beneficial if I didn't have to use the path flag when trying to introduce functionality with the generate command.

tonyholt avatar Apr 20 '18 11:04 tonyholt

This appears to be a problem for any item that can be generated as "/src/app/" is hard coded when the path flag isn't provided.

Code causing the issue is here: https://github.com/angular/devkit/blob/421d5a05944ee7797544b19a6f37c0ad8e4bbe9e/packages/schematics/angular/component/index.ts#L115-L117

JR33D avatar Apr 20 '18 13:04 JR33D

This issue was moved to angular/angular-cli#12116

alexeagle avatar Sep 04 '18 23:09 alexeagle