Last active
June 6, 2019 12:35
-
-
Save sky172839465/a4b16de76f83b3338b7411df70130f87 to your computer and use it in GitHub Desktop.
Generate complex file
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
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