validate.js 606 B

12345678910111213141516171819202122232425
  1. const inquirer = require('inquirer')
  2. const inquirerFileTreeSelection = require('../dist/index')
  3. const path = require('path');
  4. inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)
  5. inquirer
  6. .prompt([
  7. {
  8. type: 'file-tree-selection',
  9. name: 'file',
  10. message: 'choose a file',
  11. pageSize: 5,
  12. validate: (item) => {
  13. const name = item.split(path.sep).pop();
  14. if (name[0] != ".") {
  15. return "please select another file"
  16. }
  17. return true;
  18. },
  19. }
  20. ])
  21. .then(answers => {
  22. console.log(JSON.stringify(answers))
  23. });