@lenne.tech/cli
Version:
lenne.Tech CLI: lt
91 lines (90 loc) • 3.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CLAUDE_MARKETPLACES_DIR = void 0;
exports.checkCommandExists = checkCommandExists;
exports.checkMarketplaceExists = checkMarketplaceExists;
exports.findClaudeCli = findClaudeCli;
exports.runClaudeCommand = runClaudeCommand;
/**
* Claude CLI utilities
* Handles detection and execution of Claude CLI commands
*/
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const os_1 = require("os");
const path_1 = require("path");
/**
* Path to Claude plugins marketplaces directory
*/
exports.CLAUDE_MARKETPLACES_DIR = (0, path_1.join)((0, os_1.homedir)(), '.claude', 'plugins', 'marketplaces');
/**
* Check if a shell command exists and succeeds
* @param command - Command to check (e.g., 'which typescript-language-server')
* @returns true if command exits with code 0
*/
function checkCommandExists(command) {
try {
const [cmd, ...args] = command.trim().split(/\s+/);
const result = (0, child_process_1.spawnSync)(cmd, args, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
return result.status === 0;
}
catch (_a) {
return false;
}
}
/**
* Check if a marketplace is already installed
* @param marketplaceName - Name of the marketplace to check
* @returns true if marketplace directory exists
*/
function checkMarketplaceExists(marketplaceName) {
return (0, fs_1.existsSync)((0, path_1.join)(exports.CLAUDE_MARKETPLACES_DIR, marketplaceName));
}
/**
* Find the Claude CLI executable path
* Checks common installation locations and falls back to 'which'
* @returns Path to Claude CLI or null if not found
*/
function findClaudeCli() {
const possiblePaths = [(0, path_1.join)((0, os_1.homedir)(), '.claude', 'local', 'claude'), '/usr/local/bin/claude', '/usr/bin/claude'];
for (const p of possiblePaths) {
if ((0, fs_1.existsSync)(p)) {
return p;
}
}
try {
const result = (0, child_process_1.spawnSync)('which', ['claude'], { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
const path = (result.stdout || '').trim();
if (result.status === 0 && path && (0, fs_1.existsSync)(path)) {
return path;
}
}
catch (_a) {
// Claude CLI not found in PATH
}
return null;
}
/**
* Execute a Claude CLI command
* @param cli - Path to Claude CLI executable
* @param args - Command arguments as string (e.g., 'plugin install foo')
* @returns Command result with output and success status
*/
function runClaudeCommand(cli, args) {
try {
const result = (0, child_process_1.spawnSync)(cli, args.split(' '), {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
});
return {
output: result.stdout + result.stderr,
success: result.status === 0,
};
}
catch (err) {
return {
output: err.message,
success: false,
};
}
}