Skip to content
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

Generate minimal component in app, with defaultProject lib #20666

Closed
1 of 15 tasks
krbaio3 opened this issue Apr 30, 2021 · 6 comments · Fixed by #20690
Closed
1 of 15 tasks

Generate minimal component in app, with defaultProject lib #20666

krbaio3 opened this issue Apr 30, 2021 · 6 comments · Fixed by #20690
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@krbaio3
Copy link

krbaio3 commented Apr 30, 2021

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Description

When I generate a component, with --minimal ( inlineTemplate, inlineStyle, skipTests => true, style: scss), it is generated with test, template and css.

🔬 Minimal Reproduction

I created a NG app with ng new bug-ng-cli --create-application false --strict false.
I run ng add @angular-eslint/schematics
I run ng g application demo --minimal --minimal --routing --style scss
I run ng g @angular-eslint/schematics:convert-tslint-to-eslint --remove-tslint-if-no-more-tslint-targets --ignore-existing-tslint-config demo
I run ng g library foo

If i run:

▶ ng g c components/authComponent --project=demo -d
CREATE projects/demo/src/app/components/auth-component/auth-component.component.ts (288 bytes)
UPDATE projects/demo/src/app/app.module.ts (516 bytes)

It is Ok.

But, If I change my defaultProject from demo to foo (library)

▶ ng g c components/authComponent --project=demo -d
CREATE projects/demo/src/app/components/auth-component/auth-component.component.css (0 bytes)
CREATE projects/demo/src/app/components/auth-component/auth-component.component.html (29 bytes)
CREATE projects/demo/src/app/components/auth-component/auth-component.component.spec.ts (676 bytes)
CREATE projects/demo/src/app/components/auth-component/auth-component.component.ts (306 bytes)
UPDATE projects/demo/src/app/app.module.ts (516 bytes)

The repository example is: https://github.com/krbaio3/bug-ng-cli.git

Thanks!

@alan-agius4
Copy link
Collaborator

Hi @krbaio3, \this is because minimal only effects application projects. It is important to mention that minimal projects only meant to be used for testing / prototyping and are to be considered as throw away projects.

What is the user-case here to have minimal respected in a library project?

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label Apr 30, 2021
@krbaio3
Copy link
Author

krbaio3 commented Apr 30, 2021

Hi @alan-agius4,,

My intention is to make a library and then, a minimal project with a small example (demo) of how to use it. This way, I avoid having in the demo everything related to testing, linter, etc., since it is just that, a small example.

I understand that I may be wrong, but I like to have inside the projects folder the library, and separately, in another folder, the demo of using the library.

Thank you very much!

@alan-agius4
Copy link
Collaborator

Hi @krbaio3,

Thanks for getting back, however the above doesn't answer my question to why you need a library project to support the minimal option, ie doesn't generate inlined templates and inlined styles.

That said, you can use disable these either by passing the following CLI arguments --no-inline-style --skip-tests --no-inline-template to ng generate component or by setting these in angular.json, so that everything you create a component you don't need to provide the previously mentioned flags.

This can be done by using ng config as shown below;

 ng config projects.auth.schematics.@schematics/angular:component '{inlineTemplate: true, inlineStyle: true, skipTests: true}'

More information about these options can be found https://angular.io/cli/generate#component-command

@alan-agius4 alan-agius4 changed the title Generate minimal component in app, with defaultProyect lib Generate minimal component in app, with defaultProject lib May 3, 2021
@krbaio3
Copy link
Author

krbaio3 commented May 4, 2021

Hi!,

My demo project has this config:

▶ ng config projects.demo.schematics
{
  "@schematics/angular:component": {
    "inlineTemplate": true,
    "inlineStyle": true,
    "style": "scss",
    "skipTests": true
  },
  "@schematics/angular:class": {
    "skipTests": true
  },
  "@schematics/angular:directive": {
    "skipTests": true
  },
  "@schematics/angular:guard": {
    "skipTests": true
  },
  "@schematics/angular:interceptor": {
    "skipTests": true
  },
  "@schematics/angular:module": {
    "skipTests": true
  },
  "@schematics/angular:pipe": {
    "skipTests": true
  },
  "@schematics/angular:service": {
    "skipTests": true
  }
}

and my library has this config:

▶ ng config projects.auth
{
  "projectType": "library",
  "schematics": {
    "@schematics/angular:component": {
      "inlineTemplate": true,
      "inlineStyle": true,
      "style": "scss",
      "skipTests": true
    }
  },
  "root": "projects/auth",
  "sourceRoot": "projects/auth/src",
  "prefix": "lib",
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:ng-packagr",
      "options": {
        "tsConfig": "projects/auth/tsconfig.lib.json",
        "project": "projects/auth/ng-package.json"
      },
      "configurations": {
        "production": {
          "tsConfig": "projects/auth/tsconfig.lib.prod.json"
        }
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "projects/auth/src/test.ts",
        "tsConfig": "projects/auth/tsconfig.spec.json",
        "karmaConfig": "projects/auth/karma.conf.js"
      }
    },
    "lint": {
      "builder": "@angular-eslint/builder:lint",
      "options": {
        "lintFilePatterns": [
          "projects/auth/**/*.ts",
          "projects/auth/**/*.html"
        ]
      }
    }
  }
}

My minimal project is "demo". That is, I build my library with my logic, and I want to use it in my demo project. The demo project is an example of using the library.

The --minimal flag is in the demo project, not the library.

My main project is the library, so I change the defaultProject from demo to auth.

When I generate the components like this: ng g c components/authComponent --project=demo, it generates the components with the "normal configuration", but I want the minimal configuration, because I have indicated. It is ignoring the angular.json configuration by the demo project (above).

@alan-agius4
Copy link
Collaborator

@krbaio3, thanks for the above explanation. Managed to find the issue.

@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely type: bug/fix area: @angular/cli and removed needs: more info Reporter must clarify the issue labels May 4, 2021
@ngbot ngbot bot added this to the needsTriage milestone May 4, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog May 4, 2021
clydin pushed a commit that referenced this issue May 5, 2021
…roject`

Previously, the `--project` flag was ignored when gathering and merging the schematics defaults from the angular workspace configuration file.

Closes #20666
clydin pushed a commit that referenced this issue May 5, 2021
…roject`

Previously, the `--project` flag was ignored when gathering and merging the schematics defaults from the angular workspace configuration file.

Closes #20666

(cherry picked from commit 586226a)
@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 Jun 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants