Closed Danimal03 closed 3 months ago
Hey! The changes in recent versions of Nx have moved away from specifying directory options directly and instead just running the generator from that directory.
You should be able to access the cwd in your generator by using
import { cwd } from 'process';
Alternatively, you can always do any kind of custom prefilling you want with a (tbh hidden) feature: Nx Console Plugins.
I think just using the cwd
is your best bet but if that's not an option for you I can tell you more about how to configure Nx Console plugins :)
I'll close this as completed for now because I don't think there's anything actionable for me to do in Nx Console
Hi Max,
thanks for your quick answer. The solution with cwd
is working perfectly!
Since I am building generators around our new architecture I am very interested in knowing about configuring Nx Console. There are many more things to come since we just started. Maybe you can tell me how to configure Nx Console plugins ? :)
Description
By right-clicking on a folder and choosing 'Nx generate' in VS Code the working directory is specified below the search bar of the nx generate UI.
I would like to have access to the new 'working directory' in my custom generator without filling out the directory option manually. Did I miss the functionallity to access the working directory composed by Nx Console in my custom generators ?
The prefilling function is gone with the latest update, because the experimental UI setting got removed.
Motivation
We have a custom generator which generates files with the
generateFiles()
method. For some files we need the directory as part of the substitutions. The directory is identical to the working directory, if nx generate is clicked after right clicking a folder - in our case.Now with the new design it is not possible to access the working directory in our custom generator. This way we cant use it as part of our substitutions. It is necessary to fill out the directory option manually.
Suggested Implementation
In my opinion there are two solutions which could solve this.
Tree
which is passed into the generator. -> e.g.: tree.workingDirectory = libs/foo/barAlternate Implementations