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

Set dest dynamically within a monorepo (workspace) environment #395

Open
moltar opened this issue Sep 4, 2023 · 6 comments
Open

Set dest dynamically within a monorepo (workspace) environment #395

moltar opened this issue Sep 4, 2023 · 6 comments

Comments

@moltar
Copy link

moltar commented Sep 4, 2023

I have a monorepo (workspace), with multiple packages.

The same layout as plop repo:

package/a/package.json
package/b/package.json

When running plop from the root of the workspace (./), I'd like the present a choice (list) of packages to target, as the base destination.

? [PLOP] Please choose a package. (Use arrow keys)
❯ a
  b

Once the user selects a package, this selection becomes the dest for the rest of the plop run.

Then each action would only need to define path relative to the package root.


I think the solution should/can be split up in two problems:

  1. Ability to have a global prompt, that is always asked, regardless of the generator being invoked.
  2. Ability to set the dest value programmatically. There's already a getDestBasePath, so a matching pair setDestBasePath would suffice, I am guessing.
@amwmedia
Copy link
Member

If you have a plopfile at the root of the project, couldn't you just prompt for the destination package and then use that value in your add actions? I'm not sure why this would require a code change. It seems like it's already supported.

@moltar
Copy link
Author

moltar commented Sep 15, 2023

If you have a plopfile at the root of the project, couldn't you just prompt for the destination package and then use that value in your add actions? I'm not sure why this would require a code change. It seems like it's already supported.

Plop also has a concept of loading external plop files. Those won't have the dest defined, especially if you do not control them, e.g. coming from a third-party npm package.

@amwmedia
Copy link
Member

A generator that is imported from a source you don't control is not likely to respect your project structure. You could import actions from an external plopfile and configure them to work within your project structure. That's what I would expect most people to do when it comes to external imports that they don't control (import helpers, actions, etc).

@moltar
Copy link
Author

moltar commented Sep 15, 2023

A generator that is imported from a source you don't control is not likely to respect your project structure.

Yes, and that's precisely why I think setting dest is of value.

I can point any generator at any directory, as long as the generator is not too opinionated.

@amwmedia
Copy link
Member

I think this would require a shift in thinking when it comes to generators. When you're writing a generator for plop currently, you are thinking about project structure and where this file belongs. What I think you're proposing is that a generator would no longer expect to control the full path, but a subpath. So in a project with a structure that puts components into a common folder like src/components, the generator would no longer care about src/components, ideally it would be given src/components as a basepath by something upstream and the generator would just be responsible for the paths that exist within its own subfolder (i.e. src/components/myNewButton). Am I understanding you correctly? What would determine the base path and how would it be configured (normally under the generator's control)?

@moltar
Copy link
Author

moltar commented Sep 15, 2023

When you're writing a generator for plop currently, you are thinking about project structure and where this file belongs.

Not necessarily. This is one way to do this. But it is certainly not the only way.

Plop already has the --dest flag, which becomes the base dir for the output. That is even exposed thru the official API via getDestBasePath.

So the only difference I am proposing is that dest can be promptable (optionally), rather than always specified by a flag or a default process.cwd().

It could be solved by some API that precedes any generator, e.g.:

    plop.setGlobalPrompts({
            type: 'input',
            name: 'dest',
            message: 'Dest?'
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants