@endgame-build/claude-workflows
Version:
Claude Code workflow system with commands, agents, and templates for AI-native development
153 lines (129 loc) ⢠5.34 kB
JavaScript
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import fs from 'fs-extra';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { program } from 'commander';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const packageRoot = join(__dirname, '..');
const targetDir = process.cwd();
async function checkExistingInstallation() {
const claudeDir = join(targetDir, '.claude');
const egCommandsDir = join(claudeDir, 'commands', 'eg');
return await fs.pathExists(egCommandsDir);
}
async function copyWorkflowFiles(force = false) {
console.log(chalk.blue('š¦ Installing Endgame Claude Workflows...'));
// Copy specific subdirectories within .claude, not the entire directory
const filesToCopy = [
{ src: '.claude/commands/eg', dest: '.claude/commands/eg' },
{ src: '.claude/agents/eg', dest: '.claude/agents/eg' },
{ src: '.claude/templates', dest: '.claude/templates' },
{ src: '.eg', dest: '.eg' },
{ src: 'CLAUDE.workflows.md', dest: 'CLAUDE.workflows.md' }
];
let copiedFiles = [];
for (const file of filesToCopy) {
const srcPath = join(packageRoot, file.src);
const destPath = join(targetDir, file.dest);
try {
if (await fs.pathExists(srcPath)) {
if (await fs.pathExists(destPath) && !force) {
const { overwrite } = await inquirer.prompt([{
type: 'confirm',
name: 'overwrite',
message: `${file.dest} already exists. Overwrite?`,
default: false
}]);
if (!overwrite) {
console.log(chalk.yellow(`āļø Skipped ${file.dest}`));
continue;
}
}
// Ensure parent directory exists
await fs.ensureDir(dirname(destPath));
await fs.copy(srcPath, destPath, { overwrite: true });
copiedFiles.push(file.dest);
console.log(chalk.green(`ā Copied ${file.dest}`));
}
} catch (error) {
console.error(chalk.red(`ā Failed to copy ${file.dest}: ${error.message}`));
}
}
return copiedFiles;
}
async function showPostInstallMessage(copiedFiles) {
console.log('\n' + chalk.green.bold('⨠Endgame Claude Workflows installed successfully!'));
if (copiedFiles.length > 0) {
console.log(chalk.white('\nFiles created:'));
if (copiedFiles.some(f => f.includes('.claude/commands/eg'))) {
console.log(chalk.gray(' ⢠.claude/commands/eg/ - Workflow commands'));
}
if (copiedFiles.some(f => f.includes('.claude/agents/eg'))) {
console.log(chalk.gray(' ⢠.claude/agents/eg/ - AI agents'));
}
if (copiedFiles.some(f => f.includes('.claude/templates'))) {
console.log(chalk.gray(' ⢠.claude/templates/ - Output templates'));
}
if (copiedFiles.includes('.eg')) {
console.log(chalk.gray(' ⢠.eg/ - Workflow state directory'));
}
if (copiedFiles.includes('CLAUDE.workflows.md')) {
console.log(chalk.gray(' ⢠CLAUDE.workflows.md - Documentation'));
}
}
console.log(chalk.white('\nTo get started:'));
console.log(chalk.cyan(' 1. Read CLAUDE.workflows.md for workflow documentation'));
console.log(chalk.cyan(' 2. Try: /eg:define my-feature "User authentication"'));
console.log(chalk.cyan(' 3. View all commands in .claude/commands/eg/'));
console.log('');
}
async function main() {
program
.name('endgame-claude-workflows')
.description('Install Endgame Claude Workflows into your project')
.version('1.0.0')
.option('-f, --force', 'overwrite existing files without prompting')
.option('--dry-run', 'preview what will be installed')
.parse();
const options = program.opts();
console.log(chalk.bold('\nš Endgame Claude Workflows Installer\n'));
if (targetDir === packageRoot) {
console.error(chalk.red('ā Cannot install in the source directory!'));
console.log(chalk.yellow('Please run this command from your target project directory.'));
process.exit(1);
}
if (options.dryRun) {
console.log(chalk.yellow('š Dry run mode - no files will be modified\n'));
console.log('Would install:');
console.log(' ⢠.claude/commands/eg/ - Workflow commands');
console.log(' ⢠.claude/agents/eg/ - AI agents');
console.log(' ⢠.claude/templates/ - Output templates');
console.log(' ⢠.eg/ - Workflow state directory');
console.log(' ⢠CLAUDE.workflows.md - Documentation');
return;
}
const alreadyInstalled = await checkExistingInstallation();
if (alreadyInstalled && !options.force) {
const { proceed } = await inquirer.prompt([{
type: 'confirm',
name: 'proceed',
message: 'Endgame workflows appear to be already installed. Continue anyway?',
default: false
}]);
if (!proceed) {
console.log(chalk.yellow('Installation cancelled.'));
return;
}
}
try {
const copiedFiles = await copyWorkflowFiles(options.force);
await showPostInstallMessage(copiedFiles);
} catch (error) {
console.error(chalk.red(`\nā Installation failed: ${error.message}`));
process.exit(1);
}
}
main().catch(console.error);