UNPKG

sinotron

Version:

Simple framework for Typescript Electron projects

67 lines (66 loc) 2.14 kB
// noinspection ES6RedundantAwait import inquirer from 'inquirer'; // import * as f from 'inquirer-fuzzy-path'; import ifp from 'inquirer-fuzzy-path'; import fileSelector from 'inquirer-file-selector'; import Path from 'node:path'; inquirer.registerPrompt('fuzzypath', ifp); export const ask = { async input(id, message) { return await inquirer.prompt({ type: 'input', name: id, message }); }, async singleChoice(id, message, options) { return await inquirer.prompt({ type: 'list', name: id, message, choices: options }); }, async multipleChoice(id, message, options) { return await inquirer.prompt({ name: id, type: 'checkbox', message, choices: options }); }, async selectFile() { return await fileSelector({ message: 'Select a directory', basePath: process.cwd(), match(file) { return file.isDir; }, allowCancel: true }); }, async selectPath(name, opts) { const { refDir, depth, targetType, message = 'Select a target directory for your component:' } = opts; return await inquirer.prompt({ name: name, // @ts-ignore type: 'fuzzypath', message, itemType: targetType, rootPath: refDir, depthLimit: depth, excludePath: (nodePath) => { // console.log({ nodePath, refDir }); const nodeModulesDir = Path.join(refDir, 'node_modules'); const gitDir = Path.join(refDir, '.git'); const ideaDir = Path.join(refDir, '.idea'); // console.log({ nodeModulesDir, gitDir, ideaDir }); // return [nodeModulesDir, gitDir, ideaDir].some((a) => nodePath.startsWith(a)); }, excludeFilter: (nodePath) => nodePath == '.', // default: 'src/', suggestOnly: false }); } };