Skip to content

Commit

Permalink
feat: introduce wait helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Aug 18, 2020
1 parent 5ac70cd commit 3ed941b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/cli-plugin-scaffold/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const pluginToChoice = plugin => ({
value: plugin.name
});

const wait = (ms = 1000) => {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};

const scaffold = async ({ context }) => {
const inquirer = require("inquirer");
const ora = require("ora");
Expand Down Expand Up @@ -42,16 +48,16 @@ const scaffold = async ({ context }) => {
const oraSpinner = ora().start(`Generating template...\n`);

try {
await scaffold.generate({ input, context, oraSpinner });
await scaffold.generate({ input, context, wait, oraSpinner });
oraSpinner.succeed("Done!");

if (typeof scaffold.onSuccess === "function") {
await scaffold.onSuccess({ input, context, oraSpinner });
await scaffold.onSuccess({ input, context, wait, oraSpinner });
}
} catch (e) {
oraSpinner.stop();
if (typeof scaffold.onError === "function") {
await scaffold.onError({ input, context, oraSpinner, error: e });
await scaffold.onError({ input, context, wait, oraSpinner, error: e });
} else {
console.log(e);
}
Expand Down

0 comments on commit 3ed941b

Please sign in to comment.