From bf353082c585234d3d6c4ad12a0b04456a22e4a4 Mon Sep 17 00:00:00 2001 From: StrangeDrVN <172238701+StrangeDrVN@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:09:35 +0530 Subject: [PATCH] add validate script --- scripts/commands/workers/validate.ts | 67 ++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 scripts/commands/workers/validate.ts diff --git a/scripts/commands/workers/validate.ts b/scripts/commands/workers/validate.ts new file mode 100644 index 000000000..10b6cc7bc --- /dev/null +++ b/scripts/commands/workers/validate.ts @@ -0,0 +1,67 @@ +import { Storage } from '@freearhey/storage-js' +import { ROOT_DIR } from '../../constants' +import { program } from 'commander' +import chalk from 'chalk' + +program.parse(process.argv) + +interface ValidationError { + line: number + type: 'missing_crlf' | 'contains_spaces' + content: string +} + +async function main() { + const rootStorage = new Storage(ROOT_DIR) + + if (!await rootStorage.exists('workers.txt')) { + console.log(chalk.red('workers.txt file not found!')) + process.exit(1) + } + + const workersTxt = await rootStorage.load('workers.txt') + const lines = workersTxt.split('\n') + + let totalFiles = 0 + let totalErrors = 0 + let totalWarnings = 0 + + const errors: ValidationError[] = [] + + lines.forEach((line, index) => { + const lineNum = index + 1 + + if (lineNum === lines.length && line.trim() === '') return + + if (!line.endsWith('\r')) { + errors.push({ line: lineNum, type: 'missing_crlf', content: line.replace('\r', '') }) + totalErrors++ + } + + if (line.includes(' ')) { + errors.push({ line: lineNum, type: 'contains_spaces', content: line.replace('\r', '') }) + totalErrors++ + } + }) + + if (errors.length) { + console.log(chalk.underline('workers.txt')) + console.table(errors, ['line', 'type', 'content']) + console.log() + totalFiles++ + } + + const totalProblems = totalWarnings + totalErrors + if (totalProblems > 0) { + console.log( + chalk.red( + `${totalProblems} problems (${totalErrors} errors, ${totalWarnings} warnings) in ${totalFiles} file(s)` + ) + ) + if (totalErrors > 0) { + process.exit(1) + } + } +} + +main()