UNPKG

depxbox

Version:

Test npm packages super quick and easy.

53 lines (52 loc) 1.59 kB
import inquirer from 'inquirer'; import Logger from './utils/logger.js'; import { DEFAULT_PATH, MODES } from './constants.js'; import { ModeFactory } from './modes/Factory.js'; async function promptUser(prompt) { switch (prompt) { case 'mode': const { mode } = await inquirer.prompt({ type: 'list', name: 'mode', message: 'Select the execution mode:', choices: Object.values(MODES), default: MODES.REPL, }); return mode; case 'path': const { path } = await inquirer.prompt({ type: 'input', name: 'path', message: 'Enter the path:', default: DEFAULT_PATH, }); return path; default: return ''; } } async function executeStrategy(packages, config) { const sandbox = ModeFactory.createMode(config); Logger.blue(`Starting ${config.mode} mode...`); sandbox.run(packages); } export const action = async (packages, options) => { const config = { mode: options.mode, path: options.path, }; if (options.default) { Logger.info('Using default values...'); config.mode = MODES.REPL; config.path = DEFAULT_PATH; } if (!config.mode) { const answer = await promptUser('mode'); config.mode = answer; } if (!config.path) { const answer = await promptUser('path'); config.path = answer; } executeStrategy(packages, config); };