UNPKG

@aquaori/deplens

Version:

A precise dependency analysis tool for npm and pnpm projects

109 lines (106 loc) 2.41 kB
#!/usr/bin/env node import yargs, { ArgumentsCamelCase } from 'yargs'; import { hideBin } from 'yargs/helpers'; import { showBanner, logInfo, logFatal, } from './utils/cli-utils'; import { analyzeProject } from './index'; yargs(hideBin(process.argv)) .scriptName('deplens') .usage('Usage: $0 <command> [options]') .command('check', 'Check project dependencies', (yargs) => { return yargs .option('path', { alias: 'p', type: 'string', description: 'Path to check (defaults to current directory)', default: process.cwd() }) .option('verbose', { alias: 'V', type: 'boolean', description: 'Enable verbose output', default: false }) .option('pnpm', { alias: 'pn', type: 'boolean', description: 'Enable pnpm support', default: false }) .option('ignoreDep', { alias: 'id', type: 'string', description: 'Ignore dependencies', default: '' }) .option('ignorePath', { alias: 'ip', type: 'string', description: 'Ignore paths', default: '' }) .option('ignoreFile', { alias: 'if', type: 'string', description: 'Ignore files', default: '' }) .option('config', { alias: 'c', type: 'string', description: 'Path of config file', default: '' }) .option('silence', { alias: 's', type: 'boolean', description: 'Silence output', default: false }) .option('html', { alias: 'H', type: 'boolean', description: 'Generate HTML report', default: false }) .option('output', { alias: 'o', type: 'string', description: 'Output path for HTML report', default: '' }); }, async (argv) => { if (!argv.silence) { showBanner(); logInfo(` Starting dependency analysis for: ${argv.path}`); } try { await analyzeProject(argv as ArgumentsCamelCase<{ path: string; verbose: boolean; pnpm: boolean; silence: boolean; ignoreDep: string; ignorePath: string; ignoreFile: string; config: string; html: boolean; output: string; }>); } catch (error) { console.log("\n") logFatal(` Analysis failed: ${error instanceof Error ? error.message : String(error)}`); process.exit(1); } }) .help() .alias('help', 'h') .version() .alias('version', 'v') .demandCommand(1, 'You need at least one command before moving on') .recommendCommands() .strict() .argv;