testes/Modulos Angular/scripts/git-commit.js

71 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
const readline = require('readline');
const { execSync } = require('child_process');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const types = {
'feat': 'Nova funcionalidade',
'fix': 'Correção de bug',
'docs': 'Documentação',
'style': 'Formatação/estilo',
'refactor': 'Refatoração',
'test': 'Testes',
'chore': 'Manutenção',
'perf': 'Performance',
'ci': 'CI/CD',
'build': 'Build',
'revert': 'Reverter'
};
console.log('🚀 Assistente de Commit\n');
console.log('📋 Tipos disponíveis:');
Object.entries(types).forEach(([key, desc], index) => {
console.log(`${index + 1}. ${key.padEnd(8)} - ${desc}`);
});
rl.question('\n🏷 Escolha o tipo (1-11): ', (typeChoice) => {
const typeKeys = Object.keys(types);
const type = typeKeys[parseInt(typeChoice) - 1];
if (!type) {
console.log('❌ Tipo inválido');
process.exit(1);
}
rl.question('📦 Escopo (opcional): ', (scope) => {
rl.question('📝 Descrição: ', (description) => {
rl.question('📄 Corpo da mensagem (opcional): ', (body) => {
const scopePart = scope ? `(${scope})` : '';
const firstLine = `${type}${scopePart}: ${description}`;
const fullMessage = body ? `${firstLine}\n\n${body}` : firstLine;
console.log('\n📋 Mensagem de commit:');
console.log('─'.repeat(50));
console.log(fullMessage);
console.log('─'.repeat(50));
rl.question('\n✅ Confirmar commit? (y/N): ', (confirm) => {
if (confirm.toLowerCase() === 'y') {
try {
execSync(`git commit -m "${fullMessage}"`, { stdio: 'inherit' });
console.log('✅ Commit realizado com sucesso!');
} catch (error) {
console.log('❌ Erro no commit:', error.message);
}
} else {
console.log('❌ Commit cancelado');
}
rl.close();
});
});
});
});
});