import newTool, { print, prompt, sleep, spinner, waitFor } from 'new-tool'
import fs from 'mz/fs'
newTool(cli())
function *cli () {
yield spinner('Idling a little')
yield sleep(1000) // just some timeout so you can see the spinner in action
const name = yield prompt('What is your name?')
yield print(`Hi ${name}!`)
yield spinner('Reading package.json')
// Can wait for promises to resolve:
const packageContents = yield waitFor(fs.readFile('package.json', { encoding: 'utf-8' }))
const packageMeta = JSON.parse(packageContents)
yield print(`Welcome to ${packageMeta.name}.`)
}
Making it beautiful using https://github.com/sindresorhus/ora: