rxcc
Version:
A tool to pack repository contents to single file for AI consumption
57 lines • 3 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { logger } from '../../../shared/logger.js';
import { parseFile } from '../../treeSitter/parseFile.js';
import { getFileManipulator } from '../fileManipulate.js';
export default (_a) => __awaiter(void 0, [_a], void 0, function* ({ rawFile, config }) {
const processedContent = yield processContent(rawFile, config);
return {
path: rawFile.path,
content: processedContent,
};
});
export const processContent = (rawFile, config) => __awaiter(void 0, void 0, void 0, function* () {
const processStartAt = process.hrtime.bigint();
let processedContent = rawFile.content;
const manipulator = getFileManipulator(rawFile.path);
logger.trace(`Processing file: ${rawFile.path}`);
if (manipulator && config.output.removeComments) {
processedContent = manipulator.removeComments(processedContent);
}
if (config.output.removeEmptyLines && manipulator) {
processedContent = manipulator.removeEmptyLines(processedContent);
}
processedContent = processedContent.trim();
if (config.output.compress) {
try {
const parsedContent = yield parseFile(processedContent, rawFile.path, config);
if (parsedContent === undefined) {
logger.trace(`Failed to parse ${rawFile.path} in compressed mode. Using original content.`);
}
processedContent = parsedContent !== null && parsedContent !== void 0 ? parsedContent : processedContent;
}
catch (error) {
const message = error instanceof Error ? error.message : String(error);
logger.error(`Error parsing ${rawFile.path} in compressed mode: ${message}`);
//re-throw error
throw error;
}
}
else if (config.output.showLineNumbers) {
const lines = processedContent.split('\n');
const padding = lines.length.toString().length;
const numberedLines = lines.map((line, i) => `${(i + 1).toString().padStart(padding)}: ${line}`);
processedContent = numberedLines.join('\n');
}
const processEndAt = process.hrtime.bigint();
logger.trace(`Processed file: ${rawFile.path}. Took: ${(Number(processEndAt - processStartAt) / 1e6).toFixed(2)}ms`);
return processedContent;
});
//# sourceMappingURL=fileProcessWorker.js.map