Last active
April 22, 2020 02:58
-
-
Save JeremyEnglert/649cea9de86c67d1ac5327f260c522fa to your computer and use it in GitHub Desktop.
JavaScript Async/Await with Inquirer
This file contains 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
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