UNPKG

npm-install-size

Version:

Check the install size of any NPM package before installing it.

64 lines (63 loc) 2.21 kB
import inquirer from 'inquirer'; export async function promptForOptions() { const { packages } = await inquirer.prompt([ { type: 'input', name: 'packages', message: 'Enter package names (comma separated):', filter: input => input.split(',').map(s => s.trim()).filter(Boolean) } ]); const { flags } = await inquirer.prompt([ { type: 'checkbox', name: 'flags', message: 'Select options:', choices: [ { name: 'JSON output (--json)', value: 'json' }, { name: 'Summarize (--summarize)', value: 'summarize' }, { name: 'CSV output (--csv)', value: 'csv' }, { name: 'Markdown output (--md)', value: 'md' }, { name: 'Dependency tree (--deps)', value: 'deps' }, { name: 'Minified size (--minified)', value: 'minified' }, { name: 'Gzipped size (--gzipped)', value: 'gzipped' }, { name: 'File type breakdown (--types)', value: 'types' }, { name: 'Compare mode (--compare)', value: 'compare' }, { name: 'Badge (--badge)', value: 'badge' } ] } ]); const { topN } = await inquirer.prompt([ { type: 'input', name: 'topN', message: 'Show top N largest files (--top N):', validate: v => !v || (!isNaN(parseInt(v, 10)) && parseInt(v, 10) > 0) || 'Enter a positive number', filter: v => v ? parseInt(v, 10) : null } ]); const { historyN } = await inquirer.prompt([ { type: 'input', name: 'historyN', message: 'Show history for last N versions (--history N):', validate: v => !v || (!isNaN(parseInt(v, 10)) && parseInt(v, 10) > 0) || 'Enter a positive number', filter: v => v ? parseInt(v, 10) : null } ]); return { packages, json: flags.includes('json'), summarize: flags.includes('summarize'), csv: flags.includes('csv'), md: flags.includes('md'), deps: flags.includes('deps'), minified: flags.includes('minified'), gzipped: flags.includes('gzipped'), types: flags.includes('types'), compare: flags.includes('compare'), badge: flags.includes('badge'), topN, historyN }; }