Generate command for libraries adds to app folder instead of lib folder
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.
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
This issue was moved to angular/angular-cli#12116