agentic-qe
Version:
Agentic Quality Engineering Fleet System - AI-driven quality management platform
122 lines • 5.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCleanCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
function createCleanCommand() {
const command = new commander_1.Command('clean');
command
.description('Clean test artifacts and temporary files')
.option('--coverage', 'Clean coverage reports only', false)
.option('--snapshots', 'Clean snapshot files only', false)
.option('--cache', 'Clean test cache only', false)
.option('--dry-run', 'Show what would be cleaned without deleting', false)
.option('--show-size', 'Show size of files to be cleaned', false)
.action(async (options) => {
console.log(chalk_1.default.bold('Cleaning test artifacts...\n'));
const artifacts = getArtifactPaths(options);
let totalSize = 0;
for (const artifact of artifacts) {
const exists = fs.existsSync(artifact.path);
const size = exists ? getDirectorySize(artifact.path) : 0;
if (exists) {
totalSize += size;
if (options.dryRun) {
console.log(chalk_1.default.yellow(`Would clean: ${artifact.name}`));
}
else {
fs.rmSync(artifact.path, { recursive: true, force: true });
console.log(chalk_1.default.green(`✓ Cleaned: ${artifact.name}`));
}
if (options.showSize) {
console.log(chalk_1.default.gray(` Size: ${formatSize(size)}`));
}
}
else {
console.log(chalk_1.default.gray(`⊘ Not found: ${artifact.name}`));
}
}
console.log(chalk_1.default.bold(`\nTotal ${options.dryRun ? 'would clean' : 'cleaned'}: ${formatSize(totalSize)}`));
});
return command;
}
exports.createCleanCommand = createCleanCommand;
function getArtifactPaths(options) {
const artifacts = [];
if (!options.coverage && !options.snapshots && !options.cache) {
// Clean all if no specific option
artifacts.push({ name: 'Coverage reports', path: path.join(process.cwd(), 'coverage') }, { name: 'Snapshots', path: path.join(process.cwd(), '__snapshots__') }, { name: 'Test cache', path: path.join(process.cwd(), '.vitest') }, { name: 'Test results', path: path.join(process.cwd(), 'test-results') }, { name: 'Temp files', path: path.join(process.cwd(), '.tmp-test') });
}
else {
if (options.coverage) {
artifacts.push({ name: 'Coverage reports', path: path.join(process.cwd(), 'coverage') });
}
if (options.snapshots) {
artifacts.push({ name: 'Snapshots', path: path.join(process.cwd(), '__snapshots__') });
}
if (options.cache) {
artifacts.push({ name: 'Test cache', path: path.join(process.cwd(), '.vitest') });
}
}
return artifacts;
}
function getDirectorySize(dirPath) {
let size = 0;
try {
if (fs.existsSync(dirPath)) {
const stats = fs.statSync(dirPath);
if (stats.isFile()) {
size = stats.size;
}
else if (stats.isDirectory()) {
const files = fs.readdirSync(dirPath);
for (const file of files) {
size += getDirectorySize(path.join(dirPath, file));
}
}
}
}
catch (error) {
// Ignore errors
}
return size;
}
function formatSize(bytes) {
const units = ['B', 'KB', 'MB', 'GB'];
let size = bytes;
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(2)} ${units[unitIndex]}`;
}
//# sourceMappingURL=clean.js.map