Skip to content

Instantly share code, notes, and snippets.

@harrietty
Last active April 21, 2018 00:28
Show Gist options
  • Save harrietty/e698a28541af59299a876c27da0361b0 to your computer and use it in GitHub Desktop.
Save harrietty/e698a28541af59299a876c27da0361b0 to your computer and use it in GitHub Desktop.
const inquirer = require('inquirer');
const fs = require('fs');
const CHOICES = fs.readdirSync(`${__dirname}/templates`);
const QUESTIONS = [
{
name: 'project-choice',
type: 'list',
message: 'What project template would you like to generate?',
choices: CHOICES
},
{
name: 'project-name',
type: 'input',
message: 'Project name:',
validate: function (input) {
if (/^([A-Za-z\-\_\d])+$/.test(input)) return true;
else return 'Project name may only include letters, numbers, underscores and hashes.';
}
}
];
inquirer.prompt(QUESTIONS)
.then(answers => {
console.log(answers);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment