default.js 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const inquirer = require('inquirer')
  2. const inquirerFileTreeSelection = require('../dist')
  3. const path = require('path');
  4. const chalk = require('chalk');
  5. inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)
  6. inquirer
  7. .prompt([
  8. {
  9. type: 'file-tree-selection',
  10. name: 'file',
  11. default: __filename,
  12. message: 'choose a file',
  13. transformer: (input) => {
  14. const name = input.split(path.sep).pop();
  15. if (name[0] == ".") {
  16. return chalk.grey(name);
  17. }
  18. return name;
  19. }
  20. },
  21. {
  22. type: 'file-tree-selection',
  23. name: 'files',
  24. default: [__dirname],
  25. multiple: true,
  26. message: 'choose mutiple file',
  27. transformer: (input) => {
  28. const name = input.split(path.sep).pop();
  29. if (name[0] == ".") {
  30. return chalk.grey(name);
  31. }
  32. return name;
  33. }
  34. }
  35. ])
  36. .then(answers => {
  37. console.log(JSON.stringify(answers))
  38. });