I am new to Javascript, and for what i see, i may have a async code problem here:
I have a function to call composewith in my main generator. Before calling composeWith in that function, I use yosay() if needed.
My problem is that all yoSay function are called before any composeWith.
here's my code: writing and _composeWith functions
async writing() {
this.log('Before subGenerator 1 ======================================');
if (this.answers.licence) {
await this._ComposeWith(constants.license);
}
this.log('After subGenerator 1 ======================================');
this.log('Before subGenerator 2 ======================================');
if (this.answers.dockerized) {
await this._ComposeWith(constants.docker, {
options: {
packageManager: this.answers.packageManager,
destinationRoot: this._generateRoot()
}
});
}
this.log('After subGenerator 2 ======================================');
}
async _ComposeWith(configObject, args = undefined) {
if (configObject.displayYeoman) {
this.log('YEOMAN ======================================');
//Have Yeoman asking the user some more questions
this.log(
yosay(
`I will now ask you some questions about ${chalk.red(
configObject.context
)} !`
)
);
}
this.log('Calling composeWith ======================================');
this.composeWith(require.resolve(configObject.generator), args);
}
Everithing works as expected, except the printing of yosay in _ComposeWith.
Output example:
Before subGenerator 1 ====================================== YEOMAN ====================================== _-----_ ╭──────────────────────────╮ | | │ I will now ask you some │ |--(o)--| │ questions about the │ `---------´ │ license ! │ ( _´U`_ ) ╰──────────────────────────╯ /___A___\ / | ~ | __'.___.'__ ´ ` |° ´ Y ` Calling composeWith ====================================== After subGenerator 1 ====================================== Before subGenerator 2 ====================================== YEOMAN ====================================== _-----_ | | ╭──────────────────────────╮ |--(o)--| │ I will now ask you some │ `---------´ │ questions about docker ! │ ( _´U`_ ) ╰──────────────────────────╯ /___A___\ / | ~ | __'.___.'__ ´ ` |° ´ Y ` Calling composeWith ====================================== After subGenerator 2 ====================================== ? What's your name: John Doe ? Your email (optional): john.doe@example.com ? Your website (optional): ? Which license do you want to use? Apache 2.0 ? Which version of node will you run in the container? 8 ? Whick package manager will you use? npm create LICENSE create Dockerfile create .dockerignore
Any help/explaination of my mistake(s) would be much appreciated ! :)