codesnap-analyzer
Version:
Create comprehensive snapshots of your codebase with token counting for LLMs
38 lines (37 loc) • 1.57 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CodeSnap = void 0;
// src/services/codesnap.ts
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const analyzer_1 = require("../core/analyzer");
const formatter_1 = require("../services/formatter");
const file_1 = require("../utils/file");
class CodeSnap {
static async analyze(directory, options = {}) {
const absolutePath = path_1.default.resolve(directory);
if (!(await fs_extra_1.default.pathExists(absolutePath))) {
throw new Error(`Directory not found: ${directory}`);
}
const analyzer = new analyzer_1.DirectoryAnalyzer(absolutePath, options);
const { files, stats, tokenCounts } = await analyzer.analyze();
const summary = formatter_1.OutputFormatter.createSummary(absolutePath, stats, tokenCounts);
const tree = formatter_1.OutputFormatter.createTree(files);
if (options.output) {
// Write the complete analysis to the output file
const content = formatter_1.OutputFormatter.createContent(files);
await file_1.FileUtils.writeOutput(options.output, `${summary}\n\n${tree}\n\n${content}`);
}
return {
files,
stats,
tokenCounts,
summary,
tree,
};
}
}
exports.CodeSnap = CodeSnap;