Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

inquirer-file-tree-selection-prompt

anc9579.6kISC2.0.5TypeScript support: included

inquerer file tree selection prompt

inquirer, filetree

readme

Inquirer File Tree Selection Prompt

Node.js Package

QuickDemo

QuickDemo

Install

npm install inquirer-file-tree-selection-prompt

If you are still using CJS, please install inquirer-file-tree-selection-prompt@^1

Usage

inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)

inquirer.prompt({
  type: 'file-tree-selection',
  ...
})

Options

Takes type, name, message, [filter, validate, transformer, default, pageSize, onlyShowDir, onlyShowValid, hideChildrenOfValid, root, hideRoot, multiple, enableGoUpperDirector] properties.

The extra options that this plugin provides are:

  • onlyShowDir: (Boolean) if true, will only show directory. Default: false.
  • root: (String) it is the root of file tree. Default: process.cwd().
  • onlyShowValid: (Boolean) if true, will only show valid files (if validate is provided). Default: false.
  • hideChildrenOfValid: (Boolean) if true, will hide children of valid directories (if validate is provided). Default: false.
  • transformer: (Function) a hook function to transform the display of directory or file name.
  • multiple: (Boolean) if true, will enable to select multiple files. Default: false.
  • enableGoUpperDirectory: (Boolean) Show .. in inside root dir, and the user can press space on it to go upper directory. Default: false.

When multiple is enabled, default should be string[] type, otherwise it's string type.

Typescript Support

version >= 1.0.16

  1. Install @types/inquirer

  2. Ensure you have registered with file-tree-selection

inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)
  1. And you will get type support when you code in IDE

ts

Example

ESM (version ^2)

import inquirer from 'inquirer'
import inquirerFileTreeSelection from 'inquirer-file-tree-selection-prompt'

inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)

inquirer
  .prompt([
    {
      type: 'file-tree-selection',
      name: 'file'
    }
  ])
  .then(answers => {
    console.log(JSON.stringify(answers))
  });

CJS (version ^1 and <2)

const inquirer = require('inquirer')
const inquirerFileTreeSelection = require('inquirer-file-tree-selection-prompt')

inquirer.registerPrompt('file-tree-selection', inquirerFileTreeSelection)

inquirer
  .prompt([
    {
      type: 'file-tree-selection',
      name: 'file'
    }
  ])
  .then(answers => {
    console.log(JSON.stringify(answers))
  });

More examples

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

1.0.8

28 June 2021

  • Remove unused dependency 'directory-tree' #26
  • Fix keyword typo #27
  • chore(deps): bump lodash from 4.17.19 to 4.17.21 #24
  • feat: use left and right keys to navigate folders #22
  • fix: arrow display & validate the filtered value #28 #29 7320a94
  • ci: changelog ad975c7
  • Remove directory-tree 5f93d58

v1.0.7

10 October 2020

  • Optimize #19
  • fix: Windows error #17
  • chore(deps): bump lodash from 4.17.13 to 4.17.19 #15
  • feat: lazy load the children of dir #18 31e8acc
  • chore: changelog 651894f
  • chore: add postpublish hook ca71886

v1.0.6

3 May 2020

  • adds two options: onlyShowValid and hideChildrenOfValid #10
  • adds support for transformer property #8
  • makes root a more accurate parent of file tree #6
  • adds support for tab key to open/close folders #4
  • chore(deps): bump lodash from 4.17.11 to 4.17.13 #2
  • feat: init f68f6ac
  • feat: file show ac83feb
  • feat: add multiple option 3aa4abf