prompt-helper
Version:
A CLI tool to help you create and manage prompts for AI models.
91 lines • 3.42 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 () {
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;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.collectTodos = collectTodos;
// src/collectors/todoCollector.ts
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
// Matches lines like: "// TO DO: something" or "// FIX ME - details" - Leave spaces breaking words to avoid IDE linter trigger
const TODO_REGEX = /\/\/\s*(TODO|FIXME)\s*[:-]?\s*(.*)$/;
/**
* Recursively finds code files with .ts/.tsx/.js/.jsx extensions.
*
* @param dir - Directory to search.
* @param results - Accumulator array for matching file paths.
* @returns Array of absolute file paths.
*/
function findCodeFiles(dir, results = []) {
for (const entry of fs.readdirSync(dir)) {
const fullPath = path.join(dir, entry);
const stat = fs.statSync(fullPath);
if (stat.isDirectory()) {
findCodeFiles(fullPath, results);
}
else if (/\.(ts|tsx|js|jsx)$/.test(entry)) {
results.push(fullPath);
}
}
return results;
}
/**
* Collects TODO and FIXME comments from source files and adds them to project info.
*
* @param baseDir - Root directory to begin scanning from.
* @param projectInfo - The project info object to populate with TODO items.
*/
function collectTodos(baseDir, projectInfo) {
const todos = [];
const files = findCodeFiles(baseDir);
for (const file of files) {
// Skip node_modules or vendor-style folders
if (file.includes('node_modules')) {
continue;
}
const relPath = path.relative(baseDir, file).replace(/\\/g, '/');
const lines = fs.readFileSync(file, 'utf8').split('\n');
lines.forEach((line, idx) => {
const match = TODO_REGEX.exec(line);
if (match) {
todos.push({
file: relPath,
line: idx + 1,
text: line.trim(),
});
}
});
}
projectInfo.todos = todos;
}
//# sourceMappingURL=todoCollector.js.map