SamagraX-Stencil / stencil-cli

NestJS CLI on steroids for stencil 🍹
https://stencil.samagra.io/cli/introduction
Other
3 stars 9 forks source link

[schematics] Multiple imports from custom packages generated in separate lines #11

Closed sooraj1002 closed 2 months ago

sooraj1002 commented 6 months ago

Description

Presently the cli imports one object in a single import statements even if they are from the same package. Tweak the CLI to club imports from the same package into a single import statement.

References

Current Behaviour:

import { MonitoringModule } from "@samagra-x/stencil"
import { PrometheusController } from "@samagra-x/stencil"

Expected Behaviour

import { MonitoringModule, PrometheusController } from "@samagra-x/stencil"

LoC to refer: monitoring module schematics and monitoring generation cli

Savio629 commented 3 months ago

Current Behaviour:

import { MonitoringModule } from "@samagra-x/stencil" import { PrometheusController } from "@samagra-x/stencil"

Where could I find this and How should I test this ?

// @sooraj1002 @techsavvyash

techsavvyash commented 3 months ago

We have linked to files where the code resides in the issue ticket itself @Savio629. As for if you want to see this in action, just bootstrap a new project with stencil new and add monitoring to it, you'll see this happening. I think there are two ways to solve this:

  1. Setting up the linter to club imports together -- we would want this fix applied in the eslint config as well.
  2. Updating the schematics to generate the import statments clubbing things together. -- this is the ideal solution and needs to be a part of the PR for this issue.
Savio629 commented 2 months ago

Am I running it properly? There seems to be an error while running it through schematics itself image

sooraj1002 commented 2 months ago

could you please elaborate on how you are running it through schematics itself?

to just use schematics in a project which has been bootstrapped using @nestjs/cli, you would need to install @samagra-x/schematics and then update collection in nest-cli.json to @samagra-x/schematics as it has been done here.

once these changes have been made, commands like nest g monitormodule should work as expected

Savio629 commented 2 months ago

Yeah I had followed the same steps Is the following steps right to test it via stencil cli locally?

npm link and npm run build inside schematics npm link and npm run build inside stencil-cli

npm link @samagra/schematics and npm link @samagra/stencil-cli inside a new project ( i also tried npm link @samagra/schematics inside of stencli-cli folder)

Now local changes should work right?

sooraj1002 commented 2 months ago
  1. npm run build in schematics
  2. npm link in schematics
  3. npm link @samgra-x/schematics in cli
  4. npm run build in cli
  5. npm link in cli

be sure to remove the installed samagra-x/schematics package from the cli before building otherwise changes in schematics wont be reflected

now, stencil new project and everything else will be available globally in your system

also, could you please share a video showing the steps you followed to get that error?

Savio629 commented 2 months ago

I have made it to work but we'll have to document it to so anyone can contribute to it easily

Savio629 commented 2 months ago

Before: image

After: image

Ref: Added some more modules and controllers to test image

sooraj1002 commented 2 months ago

looks good. could you also remove hello from first being printed in the console as part of the PR for this issue?