Closed
Conversation
Contributor
Author
|
A take I like a lot. /* HygenHook = (hygenVars: HygenVars) => HygenVars */
/* HygenVars = {config: HygenConfig, params: HygenParams, generator: HygenGenerator}
/* module:
logger: initializes the logger, set logLevel
help: adds preGeneratorHook to check for globalhelp request
myModule: adds some helpers
*/
const resolveModules = moduleResolver(['logger', 'help', 'myModule'])
const hygen = async (argv: Array<string>): Promise<HygenVars> => {
/* every then function is
fn: (vars: HygenVars): Promise<HygenVars>
*/
return (
resolveConfig(mkDefaultConfig(argv))
.then(preModuleHooks) // prep for modules
.then(resolveModules) // load modules
.then(postModuleHooks) // finish modules config - often module setup
.then(preGeneratorHooks) // prior to looking for a specific generator
.then(resolveGenerator) // find the specific generator
.then(postGeneratorHooks) // manipulate generator prior to params
.then(preParamsHooks) // module step
.then(resolveParams) // find all params
.then(postParamsHooks) // twiddle prams from config
.then(preTemplatesHooks) // prior to scanning for template files
.then(resolveTemplates) // read template files
.then(postTemplatesHooks) // twiddle templates from config
// or act on what's found
.then(preRenderHooks) // final chance to tweak
.then(render) // process those templates
.then(postRenderHooks) // finish up
.catch(err => {
configBase.logger.error(err.toString())
configBase.logger.debug('======== details ========')
configBase.logger.debug(err.stack)
configBase.logger.debug('=========================')
})
)
} |
Draft
Contributor
Author
|
closing in favor of #149 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
configcontains data needed for hygen and templates to run.cwd,logger,templates,helpersargscontains data needed for templates{...config.defaultArgs, config.cliArgs}.hygen.jsfinds first in tree fromprocess.cwd()up to/and use's only that .{action,custom,index,prompt,...}.jsare found and used fromcwd/_templates/gen1/action/:subActiontocwd/_templatesthe config obj , located at
/home/rincewind/code/projectis built...process.cwd()and searching up through the parents find the first.hygen.jsfileeach directory as you descend overrides any settings from the directories above. and the project directory overrides them allthe args obj from an action at '_templates/run/away/fast'
config.defaultArgsargs = {...args, ...cliArgs}if (config.preParams) args = config.preParams(args)_templates/run/away/fast/index.jsparamsorprompt_templates/run/away/index.js,_templates/run/index.js, and_templates/index.jsif (config.postParams) args = config.postParams(args)Why?
hygen run away:fast --help, alternate logging, different prompter...edit: for parent
.hygen.jsto be used in conjunction with a project level file, you need to merge config objects in a specific manor that would not scale well with more keywords.