@paulohenriquevn/m2js
Version:
Transform TypeScript/JavaScript code into LLM-friendly Markdown summaries + Smart Dead Code Detection + Graph-Deep Diff Analysis. Extract exported functions, classes, and JSDoc comments for better AI context with 60%+ token reduction. Intelligent dead cod
116 lines • 4.69 kB
JavaScript
;
/* eslint-disable max-lines-per-function */
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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__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.processBatch = processBatch;
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const parser_1 = require("./parser");
const generator_1 = require("./generator");
async function processBatch(options) {
const result = {
totalFiles: 0,
successCount: 0,
failureCount: 0,
processedFiles: [],
};
// Import scanDirectory here to avoid circular dependencies
const { scanDirectory } = await Promise.resolve().then(() => __importStar(require('./file-scanner')));
// Discover files in directory
const scanResult = await scanDirectory(options.sourceDirectory);
if (scanResult.errors.length > 0) {
throw new Error(`Directory scan failed: ${scanResult.errors.join(', ')}`);
}
if (scanResult.files.length === 0) {
throw new Error(`No TypeScript/JavaScript files found in directory: ${options.sourceDirectory}`);
}
result.totalFiles = scanResult.files.length;
// Process each file sequentially
for (let i = 0; i < scanResult.files.length; i++) {
const filePath = scanResult.files[i];
const fileName = path_1.default.basename(filePath);
// Call progress callback if provided
if (options.onProgress) {
options.onProgress(i + 1, result.totalFiles, fileName);
}
try {
await processIndividualFile(filePath, options.includeComments || false);
const outputPath = (0, generator_1.getOutputPath)(filePath);
result.processedFiles.push({
filePath,
success: true,
outputPath,
});
result.successCount++;
// Call file processed callback if provided
if (options.onFileProcessed) {
options.onFileProcessed(filePath, true);
}
}
catch (error) {
const errorMessage = error.message;
result.processedFiles.push({
filePath,
success: false,
error: errorMessage,
});
result.failureCount++;
// Call file processed callback if provided
if (options.onFileProcessed) {
options.onFileProcessed(filePath, false, errorMessage);
}
// Continue processing other files (don't fail the entire batch)
continue;
}
}
return result;
}
async function processIndividualFile(filePath, includeComments) {
// Read file content
const content = await fs_1.promises.readFile(filePath, 'utf-8');
// Parse with existing pipeline
const parsedFile = (0, parser_1.parseFile)(filePath, content);
// Generate markdown with existing generator
const markdown = (0, generator_1.generateMarkdown)(parsedFile, {
includeComments,
});
// Write output file co-located with source
const outputPath = (0, generator_1.getOutputPath)(filePath);
await fs_1.promises.writeFile(outputPath, markdown, 'utf-8');
}
//# sourceMappingURL=batch-processor.js.map