import evaluate from 'ts-expression-evaluator'; import * as commander from 'commander'; import * as fs from 'fs'; import { CacheManager } from '../lib/cache'; const files: string[] = []; (async () => { const command = new commander.Command(); command .option('-o, --org-slug ', 'Org slug') .option('--all', 'Delete all orgs all cache') .option('-nd, --no-dry-run', 'Don\'t run in dry run mode') .option('-f, --files-file ', 'A file containing the files that need to be removed one per line') .option('-z, --single-file ', 'The url of the file you want to remove from cache') .option('-s, --chunk-size ', 'Size of chunk for scan. (Default: 10000)') .option('-j, --deletion-parallelism ', 'Deletion parallelism') .option('-g, --segment-options ', 'Segment options filter') .parse(process.argv); if (!command.orgSlug && !command.all) { console.log('You need to specify the org slug for which you want to evict or specify all'); return; } const filterOptions = command.segmentOptions ? command.segmentOptions.split(',') : null; const orgSlug = command.orgSlug; if (command.filesFile) { const newFiles = fs.readFileSync(command.filesFile).toString() .split('\n') .map(x => x.trim()) .filter(x => !!x); Array.prototype.push.apply(files, newFiles); } if (command.singleFile) { files.push(command.singleFile.trim()); } const chunkSize = command.chunkSize || '10000'; let parallelism = 10; if (command.deletionParallelism) { parallelism = parseInt(command.deletionParallelism, 10) || 10; } if (command.dryRun) { console.log('Running in dry run mode.'); } await CacheManager.getInstance().clearCache( orgSlug, files, chunkSize, parallelism, (segment) => { if (filterOptions) { return filterOptions.reduce((acc: boolean, curr: string) => acc && evaluate(curr, segment), true); } return true; }, command.dryRun, ); process.exit(0); })();