UNPKG

@elsikora/commitizen-plugin-commitlint-ai

Version:
71 lines (67 loc) 2.59 kB
'use strict'; var node_fs = require('node:fs'); var node_path = require('node:path'); var load = require('@commitlint/load'); var chalk = require('chalk'); var dotenv = require('dotenv'); var Process = require('./Process.js'); require('./services/llm/index.js'); var config = require('./services/llm/config.js'); // Load environment variables from .env file try { dotenv.config(); } catch { // Silently continue if .env file is not found or cannot be loaded } // Check what commit mode to use based on config, environment variable, and fallback file const getCommitMode = () => { try { // First check environment variable (highest priority) // Next check for manual flag file if (node_fs.existsSync(node_path.join("./.elsikora", "manual"))) { return "manual"; } // Finally check config file const config$1 = config.getLLMConfig(); if (config$1?.mode && // Validation is now done in config.ts to avoid duplicate messages (config$1.mode === "auto" || config$1.mode === "manual")) { return config$1.mode; } // Default to auto if not specified return "auto"; } catch { // In case of any errors, default to auto return "auto"; } }; /** * Entry point for commitizen * @param inquirerIns instance passed by commitizen, unused * @param commit callback to execute with complete commit message * @return {void} */ async function prompter(inquirerIns, commit) { // eslint-disable-next-line @elsikora-typescript/typedef await load().then(async ({ prompt = {}, rules }) => { // Use process (AI mode) unless manual mode is enabled const commitMode = getCommitMode(); if (commitMode === "manual") { console.log(chalk.blue("Using manual commit mode...")); // Import manualProcess dynamically to avoid loading AI deps when not needed // eslint-disable-next-line @elsikora-typescript/typedef await Promise.resolve().then(function () { return require('./ManualProcess.js'); }).then(async ({ default: manualProcess }) => { await manualProcess(rules, prompt, inquirerIns).then(commit); }); } else { console.log(chalk.blue("Using AI-powered commit mode...")); await Process.default(rules, prompt, inquirerIns).then(commit); } }); } exports.getLLMConfig = config.getLLMConfig; exports.setLLMConfig = config.setLLMConfig; exports.prompter = prompter; //# sourceMappingURL=index.js.map