Don't know what to title the question but I will try my best to convey in the rest of the question.
I am developing a CLI which first prompt user for a few questions and clone a repository based on the answers.
Example:
Frontend Framework:
[x] Vue
[ ] React
⠋ Cloning Vue repository...
I am using Ora to display the spinner.
The problem is spinner freezes before it starts. Other packages I am using is Inquirer, Shelljs, Chalk and Commander.js for CLI.
CLI
.command("Frontend")
.alias("F")
.description("Frontend Framework")
.action(() => {
inquirer.prompt(Questions).then((Answers) => {
const Spinner = new Ora({
text: `${chalk.bold(chalk.blue('Cloning Git Repository...'))}`,
discardStdin: false
}).start()
if (Answers.Framework === 'Vue') {
cloneRepo(Answers.Dir, "git@github.com:Vue/Vuejs.git")
} else if (Answers.Framework === 'React') {
cloneRepo(Answers.Dir, "git@github.com:facebook/reactjs.git")
}
Spinner.stopAndPersist({
symbol: "✨",
text: `${chalk.bold(chalk.green('Git repository cloned'))}`
})
})
})
Questions array
const Questions = [
{
type: "list",
name: "Framework",
message: "Which frontend framework would you like to use?",
default: "Vue",
choices: [
'Vue',
'React',
]
},
]
Clone function:
const cloneRepo = (Dir, Repo) => {
if (shell.exec(`cd ${Dir} && git clone ${Repo} -q .`).code !== 0) {
shell.echo('Error: Git clone failed')
shell.exit(1)
}
}
I tried Spinnies but the problem is same, it freezes and once the process completes, it shows the success message. I have tried a few possibilities but don't know how to workaround with Async.
Other packages: - Inquirer.js - Commander.js - Shelljs
Any help would be highly appreciated.