import program from 'commander'; import path from 'path'; import fs from 'fs-extra'; import { files, todos, } from './handler'; const run = program.command('run [script]'); run.option('-d, --dir [dir]', 'Path to run the script on', process.cwd()); run.option('--dry-run', 'Do not write changes to files'); run.option('--hide-output', 'Do not show changes'); run.option('-p --pattern [pattern]', 'Search pattern'); run.option('--max-size [maxSize]', 'do not scan larger documents', parseInt); run.action(async (script = 'line-processor.js', { dir, dryRun, maxSize = 10000000, pattern }) => { try { const scriptPath = path.join(process.cwd(), script); const scriptStats = await fs.stat(scriptPath); if (!scriptStats.isFile()) { throw new Error(`Script ${script} not found`) } const scriptModule = require(scriptPath); files(dir, scriptModule({ handlers: { todos, }, }), { dryRun: !!dryRun, maxSize: maxSize, showChanges: true, pattern, }); } catch (err) { console.error(err); } }); program.parse(process.argv);