Skip to content

Instantly share code, notes, and snippets.

@JeremyEnglert
Last active April 22, 2020 02:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JeremyEnglert/649cea9de86c67d1ac5327f260c522fa to your computer and use it in GitHub Desktop.
Save JeremyEnglert/649cea9de86c67d1ac5327f260c522fa to your computer and use it in GitHub Desktop.
JavaScript Async/Await with Inquirer
async function startTheme() {
try {
const answers = await inquirer.prompt(questions);
const themeSetup = await Promise.all ([
downloadFramework(answers.framework), // This task takes some time to run
installFramework(answers.framework),
changeThemeName(answers.themeName),
changeNamespace(answers.themeNamespace),
changeLocalUrl(answers.themeLocalUrl)
])
console.log("Install successful! Run 'npm build' to get started."); // Only want this to happen after all of the above functions have finishjed
} catch(error) {
console.log("Error");
}
};
async function downloadFramework(frameworkChoice) {
exec(`npm install ${frameworkName} --save-dev`, (error, stdout, stderr) => { // Download file from npm with cli
if (error) {
console.error(`${error}`);
return;
}
console.log(`${frameworkDisplayName} successfully downloaded.`); // This runs after the npm download is complete
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment