Skip to content

Instantly share code, notes, and snippets.

@sky172839465
Last active June 6, 2019 12:35
Show Gist options
  • Save sky172839465/a4b16de76f83b3338b7411df70130f87 to your computer and use it in GitHub Desktop.
Save sky172839465/a4b16de76f83b3338b7411df70130f87 to your computer and use it in GitHub Desktop.
Generate complex file
const fs = require('fs')
const inquirer = require('inquirer')
const colors = require('colors')
const NAME_QUIZ = {
type: 'input',
name: 'name',
message: 'Please enter your name',
}
const GENDER_QUIZ = {
type: 'list',
name: 'gender',
message: 'Please choose your gender',
choices: [ 'Male', 'Female', 'None']
}
const getExporterContent = ans =>
`const ans = ${JSON.stringify(ans, null, 2).replace(/"/g, '\'')}
export default ans
`
const ask = async () => {
console.log(colors.bgCyan(' Start '), 'asking question 👇')
const ans = await inquirer.prompt([NAME_QUIZ, GENDER_QUIZ])
fs.writeFileSync('./ans.js', getExporterContent(ans), 'utf8')
console.log(colors.bgCyan(' END '), 'Thanks for your replied 👆')
}
ask()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment