-
-
Notifications
You must be signed in to change notification settings - Fork 305
feat: add getArgument #1011
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
feat: add getArgument #1011
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want this changed?
lib/index.js
Outdated
@@ -373,6 +374,18 @@ class Generator extends EventEmitter { | |||
this._running = true; | |||
this.emit('run'); | |||
|
|||
const restArgs = Object.keys(Object.assign({}, this)).filter(orginalArg => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this?
In general, I'm fine with this approach and want to ensure the generators API is flexible enough to support Webpack CLI's needs here. I would say that once we've had a look from @SBoudrias @sindresorhus or @silvenon it would be good to get some tests added for this addition. Update: On second read through, it looks like the way we're exposing this feature might limit the ability to work with anything other than the last generator that came through. |
Perhaps a bit more consistent way, is to check if Edit: Do you want me to rewrite the object names to something more indicative? |
(orginalArg.substring(0, 1) !== '_') && (orginalArg !== 'orginalArgs'); | ||
}); | ||
|
||
this.env.getArgument = function (name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line here is problematic as this environment object is shared between all generator instances. With this code, only the last ran generator will be available through getArguments
.
Maybe a way to access a generator instance would be more flexible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be a good match. Any ideas on how to achieve that on the programming end?
Maybe you'd want to explore instantiating the generator on your own and reading from the instance; kind of like var generator = env.create('webpack', { args, options });
generator.run(() => {
console.log(generator.configuration);
}); |
Would be great, but we're dependant on |
In hindsight, I think the best option here, is to make us get |
@ev1stensberg Hey, went over the webpack-cli code yesterday. There's not much to see yet, but I'm really unclear about what you guys are trying to achieve. It looks to me like you're only using Yeoman for the prompt system. I think you told me that was a temporary step in your timeline, but it's hard to see what's the vision and the end goal here. Let me know if some concept of Yeoman seems foreign to you. Maybe a better theoretical overview would help you put the pieces together? From a technical perspective, Yeoman does not read/write each time someone edit the config. Instead, we save all the file system state into an in-memory file system (backed by That solution does seems a bit complicated to me. I wonder if you should rather create a base generator-webpack. To extend the behavior, other generators would just have to compose with the base one and pass the options it wishes to overwrite. |
@SBoudrias Hey! Thanks for having a look. Indeed, this is a temp hack. Might be alright to run from a fork after all. Shortly after we've released, we're going to go with what you mentioned. Think I've got a good overview of Yeoman, so there's no real need of that. Here's the source code with the solution implemented, but we have to go to I really want to make use of
Is there any way to discard the file save and read from an variable instead for this? |
@SBoudrias Asking if you could make a change to Going to close this, as we're going to transition into using yeoman generators explicitly pretty soon. For now, running against a local fork is fine, but I'm a bit nervous about how the |
Adds a
env.getArgument
function to env, as there's no way of getting anthis
object inside a generator. If you want to run a feature based on an internal object of the generator, this opens up the opportunity for that.I found no "real" effective way to get calls from the child class, so I've made a copy of the
this
object at initialization, where we later compare the initial state of thethis
object to the updatedthis
after it has been initialized. This way we can get the addedthis
objects from an generator.Examples:
Generator
Yeoman Env