-
Notifications
You must be signed in to change notification settings - Fork 279
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
Generator "templates" / "base generators" / mixins #105
Comments
There is a better approach that does not need to introduce a new type:
So taking the example from above, it would look like this:
This could be implemented like this:
|
ok i played around with it and I realized that the cleanest way is probably introducing a new entity "Generator mixin", which is similar to the approach above with the "baseGenerator". Here is an example (taken from the unit test):
|
hey @macrozone, somehow I didn't see this until now... not sure how I missed it example: I think that adding this as a new entity would introduce unneeded cognitive load for others using plop. I'll give this some more thought, but I would lean toward distributing something like this as a standard npm module that exports a function or a class. I'll leave this open for now for more discussion. |
A:
B:
A fits more to how plop handles generators, actions and entities. |
I believe B is easier to understand because I know that setGenerator takes a I guess the real question here is... how often do people want to create generators that inherit some of their behavior from somewhere else? My assumption is that this is a bit of an edge case. Plop is currently designed to have generators whose behavior is primarily owned by a single codebase. |
"I believe B is easier to understand because I know that setGenerator takes a name and a config object. " --> that makes no sense. This is the case in A, not B (mixins is just a config property). "My assumption is that this is a bit of an edge case." Propably, probably not. I am missing this feature. You could also providing mixins like linting or pretty every file that has been generated. I think there are a lot more use case But yeah, it can probably also be solved by saying the user to import some config generator functions manually and using them. Less elegant, but also less complex |
"that makes no sense. This is the case in A, not B (mixins is just a config property)" --> What I'm trying to say here is that the concept of a "mixin" is extra. A constructor function is a standard way to create objects in JavaScript, so I already know what is happening here. The constructor function will generate an object and the setGenerator method takes an object. I would think that linting and prettier should be handled by build process instead of generators, but I don't doubt that other use cases could be found. I'll take a look at the PR, maybe seeing your implementation will shed more light on this for me. |
I tried to revisit that and tried to remove the mixins from my ploppack as this not seems to get merged. But its hard to do. I need the plopfileconfig in my mixins and without a first-citizen api, this will get nasty:
|
is the part that "gets nasty" the fact that you have to pass the config in at 2 places? just want to be sure I understand your concern. |
@amwmedia yes, exactly! Sorry for the bad wording.
I think the underlying problem is because node-plop's architecture does not allow customizing it in a more advance way, you are stuck with the existing api (setGenerator, setAction, etc.), otherwise you have to monkeypatch it My proposal does not improve the architecture and so does not solve this underlying problem, but it adds an additional api which is similar to the existing api and solves certain use cases. Could we give it a chance as it is already implemented with tests? |
Update del to the latest version 🚀
I want to allow my users to create generators that all follow a certain convention.
E.g. the generator will place every generated element in a certain module-folder (which has a modulename) and which will create that folder if it does not exist.
What i did now is create a helper function that wraps
plop.setGenerator
and mutates the prompts and actions:and you can use it like this:
While this works, you can't use this helper function out of the box in a plopfile.
Imaging you want to load this helper functions in a plop-pack from npm. Usually, you can load this with
plop.load("plop-pack-name")
which will add generators, actions, helpers, etc.But there is no way to provide such a helper function without any changes. You would need to import it additionally through npm.
An approach would be to provide a new
generatorTemplate
.This could look like this (same example as above in
makeModuleGenerator
)So its basically a function that will mutate the config of a generator.
And you could use this like this (same example as above):
Apart from managing an additional entity "generatorTemplate", it would be easy to implement:
(I don't like the name "generatorTemplate", as "template" is already overloaded in plop, maybe we find a better name for that?
The text was updated successfully, but these errors were encountered: