-
Notifications
You must be signed in to change notification settings - Fork 22
Description
This is related to the data bullet in #35.
For the first time in all of my node.js projects, globals are looking like the most appropriate solution. Given that generators are run via command line to scaffold out a new project, versus running a server for a live application or something. In a single session, generate can chain generators and, ideally (and optionally), prevent the same prompt from being presented multiple times by:
- caching answers/data throughout the session, and
- making this "answer cache" available to all generators, allowing implementors to choose whether or not they want to make use of it. This should be a choice. Implementors can listen (or not) to feedback from users to decide whether or not this makes sense for their generator.
We've tried a few solutions to make sure the data from prompts is always available to all generators, but it hasn't been easy - especially since the code is written to ensure that generators have their own instance (and do not share state). The need for a session answer-cache that is available to all generators consistently seems like as good of a use case for globals as we're likely ever going to have.
Assuming others don't find this completely distasteful, here is how I propose we do it:
- store the data on a unique namespace on
global, likeSOME_LONG_ANSWER_CACHE_NAME - provide methods for getting and setting, like
app.global.set(),app.global.get()etc. These would of course also support object paths, likeapp.global.get('foo.bar.baz'). We could also have a.merge()method or something, so that data from generators could be stored separately until it's needed, at which time it would be cloned and merged.
I'm open to any alternatives, opinions, suggestions or pushback...
Any thoughts @doowb @stefanwalther @tunnckoCore @dawsonbotsford or others?