UNPKG

ctrlshiftleft

Version:

AI-powered toolkit for embedding QA and security testing into development workflows

69 lines 3.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.watchCommand = watchCommand; const chalk_1 = __importDefault(require("chalk")); const path_1 = __importDefault(require("path")); const watcher_1 = require("../core/watcher"); const fileUtils_1 = require("../utils/fileUtils"); function watchCommand(program) { program .command('watch') .description('Watch source files and auto-generate tests on changes') .argument('<source>', 'Source file or directory to watch') .option('-o, --output <directory>', 'Output directory for generated tests', './tests') .option('-i, --ignore <patterns>', 'Comma-separated glob patterns to ignore', 'node_modules,dist,build,*.test.*') .option('-d, --delay <ms>', 'Debounce delay in milliseconds', '1000') .option('-r, --run-tests', 'Auto-run tests after generation', true) .option('-c, --generate-checklists', 'Generate security and QA checklists', true) .option('-s, --show-diffs', 'Show file diff when files change', true) .option('-b, --browser <browser>', 'Browser to use for tests', 'chromium') .option('--headless', 'Run tests in headless mode', true) .option('-w, --workers <count>', 'Number of parallel test workers', '1') .action(async (source, options) => { try { // Validate source path if (!await (0, fileUtils_1.isValidSourcePath)(source)) { console.error(chalk_1.default.red(`Invalid source path: ${source}`)); return; } const absoluteSourcePath = path_1.default.resolve(process.cwd(), source); const outputDir = path_1.default.resolve(process.cwd(), options.output); const ignorePatterns = options.ignore.split(',').map((pattern) => pattern.trim()); // Initialize watcher const watcher = new watcher_1.Watcher({ debounceMs: parseInt(options.delay, 10), ignorePatterns, runTests: options.runTests !== false, generateChecklists: options.generateChecklists !== false, showDiffs: options.showDiffs !== false, browser: options.browser, headless: options.headless !== false, workers: parseInt(options.workers, 10) }); console.log(chalk_1.default.blue(`Watching ${chalk_1.default.bold(source)} for changes...`)); console.log(chalk_1.default.gray(`Test output directory: ${outputDir}`)); console.log(chalk_1.default.gray(`Ignored patterns: ${ignorePatterns.join(', ')}`)); // Start watching await watcher.watch(absoluteSourcePath, outputDir); // Prevent the process from exiting process.stdin.resume(); // Handle graceful shutdown const shutdown = () => { console.log(chalk_1.default.yellow('\nStopping watcher...')); watcher.stop(); process.exit(0); }; process.on('SIGINT', shutdown); process.on('SIGTERM', shutdown); } catch (error) { console.error(chalk_1.default.red(`Watch error: ${error.message}`)); console.error(chalk_1.default.red(error.stack)); process.exit(1); } }); } //# sourceMappingURL=watch.js.map