UNPKG

@claude-powers/slash-commands

Version:

πŸš€ Claude Powers - Essential slash commands for Claude Code

173 lines (145 loc) β€’ 4.83 kB
#!/usr/bin/env node /** * Claude Powers - Build Script * Validates and prepares the project for publishing */ const fs = require('fs'); const path = require('path'); console.log('πŸš€ Claude Powers - Building project...\n'); // Verificar estructura del proyecto function validateProjectStructure() { console.log('πŸ“ Validating project structure...'); const requiredFiles = [ 'package.json', 'index.js', 'README.md', 'LICENSE', 'scripts/install.js' ]; const requiredDirs = [ '.claude', 'scripts' ]; let isValid = true; // Verificar archivos requeridos for (const file of requiredFiles) { if (!fs.existsSync(file)) { console.error(`❌ Missing required file: ${file}`); isValid = false; } else { console.log(`βœ… Found: ${file}`); } } // Verificar directorios requeridos for (const dir of requiredDirs) { if (!fs.existsSync(dir)) { console.error(`❌ Missing required directory: ${dir}`); isValid = false; } else { console.log(`βœ… Found: ${dir}/`); } } return isValid; } // Verificar comandos slash function validateSlashCommands() { console.log('\n⚑ Validating slash commands...'); const claudeDir = '.claude'; const expectedCommands = [ 'generate-tests-config.json', 'fix-bugs-config.json', 'performance-turbo-config.json', 'security-fortress-config.json', 'explain-code-config.json', 'find-bugs-config.json', 'find-unused-code-config.json', 'auto-commit-config.json', 'create-pr-config.json', 'code-review-config.json' ]; let commandsValid = true; for (const command of expectedCommands) { const commandPath = path.join(claudeDir, command); if (!fs.existsSync(commandPath)) { console.error(`❌ Missing command config: ${command}`); commandsValid = false; } else { // Verificar que sea JSON vΓ‘lido try { const content = fs.readFileSync(commandPath, 'utf8'); JSON.parse(content); console.log(`βœ… Valid command: ${command}`); } catch (error) { console.error(`❌ Invalid JSON in: ${command}`); commandsValid = false; } } } return commandsValid; } // Verificar package.json function validatePackageJson() { console.log('\nπŸ“¦ Validating package.json...'); try { const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); const requiredFields = ['name', 'version', 'description', 'main', 'bin', 'author', 'license']; let packageValid = true; for (const field of requiredFields) { if (!packageJson[field]) { console.error(`❌ Missing package.json field: ${field}`); packageValid = false; } else { console.log(`βœ… Package field: ${field} = ${packageJson[field]}`); } } // Verificar que el archivo main existe if (packageJson.main && !fs.existsSync(packageJson.main)) { console.error(`❌ Main file not found: ${packageJson.main}`); packageValid = false; } // Verificar que el archivo bin existe if (packageJson.bin && packageJson.bin['claude-powers']) { const binFile = packageJson.bin['claude-powers']; if (!fs.existsSync(binFile)) { console.error(`❌ Bin file not found: ${binFile}`); packageValid = false; } else { // Verificar que el archivo bin es ejecutable const stats = fs.statSync(binFile); if (!(stats.mode & parseInt('111', 8))) { console.log(`⚠️ Making bin file executable: ${binFile}`); fs.chmodSync(binFile, '755'); } console.log(`βœ… Bin file: ${binFile}`); } } return packageValid; } catch (error) { console.error(`❌ Error reading package.json: ${error.message}`); return false; } } // FunciΓ³n principal de build function build() { console.log('πŸ”¨ Starting build process...\n'); const structureValid = validateProjectStructure(); const commandsValid = validateSlashCommands(); const packageValid = validatePackageJson(); console.log('\nπŸ“Š Build Summary:'); console.log(`Project Structure: ${structureValid ? 'βœ… Valid' : '❌ Invalid'}`); console.log(`Slash Commands: ${commandsValid ? 'βœ… Valid' : '❌ Invalid'}`); console.log(`Package.json: ${packageValid ? 'βœ… Valid' : '❌ Invalid'}`); if (structureValid && commandsValid && packageValid) { console.log('\nπŸŽ‰ Build completed successfully!'); console.log('πŸ“¦ Project is ready for publishing.'); process.exit(0); } else { console.log('\nπŸ’₯ Build failed! Please fix the errors above.'); process.exit(1); } } // Ejecutar build si se llama directamente if (require.main === module) { build(); } module.exports = { build };