@jasondark/proompt
Version:
CLI tool for running AI prompts with structure and repeatability
99 lines • 4.18 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.getCommandModule = exports.getCommandModules = exports.discoverCommandModules = void 0;
const fs_1 = require("fs");
const path = __importStar(require("path"));
/**
* Automatically discover and load all command modules
*/
const discoverCommandModules = () => {
const commands = new Map();
const commandsDir = __dirname;
try {
// Get all directories in the commands folder
const entries = (0, fs_1.readdirSync)(commandsDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory() && entry.name !== 'node_modules') {
const commandPath = path.join(commandsDir, entry.name);
try {
// Try to load the command module
const indexPath = path.join(commandPath, 'index.js');
// Check if index.js exists
if ((0, fs_1.statSync)(indexPath).isFile()) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const moduleExports = require(indexPath);
// Look for command export (convention: {commandName}Command)
const commandKey = Object.keys(moduleExports).find((key) => key.endsWith('Command'));
if (commandKey) {
const commandModule = moduleExports[commandKey];
// Basic validation - we trust that our command modules are properly typed
if (commandModule &&
commandModule.config &&
commandModule.config.name) {
commands.set(commandModule.config.name, commandModule);
}
}
}
}
catch (error) {
console.warn(`Warning: Could not load command module ${entry.name}: ${error.message}`);
}
}
}
}
catch (error) {
console.warn(`Warning: Could not scan commands directory: ${error.message}`);
}
return commands;
};
exports.discoverCommandModules = discoverCommandModules;
/**
* Get all available command modules
*/
const getCommandModules = () => {
const commandMap = (0, exports.discoverCommandModules)();
return Array.from(commandMap.values());
};
exports.getCommandModules = getCommandModules;
/**
* Get a specific command module by name
*/
const getCommandModule = (name) => {
const commandMap = (0, exports.discoverCommandModules)();
return commandMap.get(name) || null;
};
exports.getCommandModule = getCommandModule;
//# sourceMappingURL=index.js.map