@incidental/project-templates
Version:
Claude Code template library for JavaScript projects with framework auto-detection
111 lines (96 loc) • 3.19 kB
JavaScript
import inquirer from 'inquirer';
import ora from 'ora';
import { logger } from '../utils/logger.js';
import { claudeDirectoryExists } from '../utils/file-ops.js';
import { detectFramework } from '../detectors/framework-detector.js';
import TemplateInstaller from '../installers/template-installer.js';
export async function initCommand(options) {
logger.header('🚀 Claude Code Template Installer');
// Check for existing .claude directory
const hasClaudeDir = await claudeDirectoryExists();
if (hasClaudeDir) {
logger.info('Found existing .claude directory');
}
// Detect framework
const spinner = ora('Detecting project framework...').start();
let framework = options.framework;
if (!framework) {
const detected = await detectFramework();
if (detected) {
spinner.succeed(`Detected framework: ${detected}`);
framework = detected;
} else {
spinner.fail('Could not detect framework');
framework = 'vanilla';
}
} else {
spinner.succeed(`Using specified framework: ${framework}`);
}
// Interactive prompts (unless --yes flag)
let selections = {
installCommands: true,
installAgents: true,
installSkills: true,
installSteering: true
};
if (!options.yes) {
const answers = await inquirer.prompt([
{
type: 'confirm',
name: 'installCommands',
message: `Install command templates for ${framework}?`,
default: true
},
{
type: 'confirm',
name: 'installAgents',
message: `Install agent templates for ${framework}?`,
default: true
},
{
type: 'confirm',
name: 'installSkills',
message: 'Install skill templates?',
default: true
},
{
type: 'confirm',
name: 'installSteering',
message: 'Install steering documents?',
default: true
}
]);
selections = answers;
}
// Install selected templates
const installer = new TemplateInstaller();
try {
if (selections.installSteering) {
await installer.installSteering();
}
if (selections.installCommands) {
logger.section('Installing Commands...');
// TODO: This will install all available commands for the framework
// For now, just show a placeholder
logger.info('Command installation will be available once templates are created');
}
if (selections.installAgents) {
logger.section('Installing Agents...');
logger.info('Agent installation will be available once templates are created');
}
if (selections.installSkills) {
logger.section('Installing Skills...');
logger.info('Skill installation will be available once templates are created');
}
// Success message
logger.header('✨ Installation Complete!');
logger.info('Next steps:');
logger.dim(' 1. Run Claude Code in your project: claude');
logger.dim(' 2. Try a custom command: /your-command');
logger.dim(' 3. List available templates: npx @incidental/project-templates list');
} catch (error) {
logger.error('Installation failed');
throw error;
}
}
export default initCommand;