216 lines
6.6 KiB
JavaScript
216 lines
6.6 KiB
JavaScript
#!/usr/bin/env node
|
||
|
||
/**
|
||
* 🚀 CRIADOR EXPRESS DE DOMÍNIOS - Sistema PraFrota
|
||
*
|
||
* Criação super rápida de domínios com configurações padrão via argumentos.
|
||
*
|
||
* Uso:
|
||
* npm run create:domain:express -- products Produtos 2
|
||
* npm run create:domain:express -- contracts Contratos 3 --photos --sidecard --color
|
||
*
|
||
* Argumentos:
|
||
* 1. nome-do-dominio (obrigatório)
|
||
* 2. Nome para Exibição (obrigatório)
|
||
* 3. posição-menu [1-6] (obrigatório)
|
||
*
|
||
* Flags opcionais:
|
||
* --photos Sub-aba de fotos
|
||
* --sidecard Side card lateral
|
||
* --kilometer Campo quilometragem
|
||
* --color Campo cor
|
||
* --status Campo status
|
||
* --commit Commit automático
|
||
*/
|
||
|
||
const { execSync } = require('child_process');
|
||
const { main: createDomainMain } = require('./create-domain.js');
|
||
|
||
// 🎨 Cores para console
|
||
const colors = {
|
||
reset: '\x1b[0m',
|
||
bright: '\x1b[1m',
|
||
red: '\x1b[31m',
|
||
green: '\x1b[32m',
|
||
yellow: '\x1b[33m',
|
||
blue: '\x1b[34m',
|
||
cyan: '\x1b[36m'
|
||
};
|
||
|
||
const log = {
|
||
info: (msg) => console.log(`${colors.blue}ℹ️ ${msg}${colors.reset}`),
|
||
success: (msg) => console.log(`${colors.green}✅ ${msg}${colors.reset}`),
|
||
warning: (msg) => console.log(`${colors.yellow}⚠️ ${msg}${colors.reset}`),
|
||
error: (msg) => console.log(`${colors.red}❌ ${msg}${colors.reset}`),
|
||
title: (msg) => console.log(`${colors.cyan}${colors.bright}🚀 ${msg}${colors.reset}\n`)
|
||
};
|
||
|
||
// 📝 Configurações padrão
|
||
const menuPositions = ['', 'vehicles', 'drivers', 'routes', 'finances', 'reports', 'settings'];
|
||
const menuNames = ['', 'Veículos', 'Motoristas', 'Rotas', 'Finanças', 'Relatórios', 'Configurações'];
|
||
|
||
async function main() {
|
||
try {
|
||
log.title('CRIADOR EXPRESS DE DOMÍNIOS - SISTEMA PRAFROTA');
|
||
|
||
// Processar argumentos
|
||
const args = process.argv.slice(2);
|
||
const config = parseArguments(args);
|
||
|
||
// Mostrar configuração
|
||
displayConfiguration(config);
|
||
|
||
// Criar o domínio usando a configuração
|
||
await createDomainWithConfig(config);
|
||
|
||
log.success('🎉 DOMÍNIO CRIADO EXPRESS COM SUCESSO!');
|
||
log.info(`🔗 Acesse: http://localhost:4200/app/${config.name}`);
|
||
|
||
} catch (error) {
|
||
log.error(`Erro: ${error.message}`);
|
||
showUsage();
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
function parseArguments(args) {
|
||
if (args.length < 3) {
|
||
throw new Error('Argumentos insuficientes');
|
||
}
|
||
|
||
const [name, displayName, menuPos] = args;
|
||
|
||
// Validações
|
||
if (!name || !name.match(/^[a-z]+$/)) {
|
||
throw new Error('Nome deve ser singular, minúsculo, sem espaços');
|
||
}
|
||
|
||
if (!displayName) {
|
||
throw new Error('Nome para exibição é obrigatório');
|
||
}
|
||
|
||
const menuPosition = parseInt(menuPos);
|
||
if (!menuPosition || menuPosition < 1 || menuPosition > 6) {
|
||
throw new Error('Posição do menu deve ser 1-6');
|
||
}
|
||
|
||
// Processar flags
|
||
const flags = args.slice(3);
|
||
|
||
return {
|
||
name,
|
||
displayName,
|
||
menuPosition: menuPositions[menuPosition],
|
||
menuPositionName: menuNames[menuPosition],
|
||
hasPhotos: flags.includes('--photos'),
|
||
hasSideCard: flags.includes('--sidecard'),
|
||
hasKilometer: flags.includes('--kilometer'),
|
||
hasColor: flags.includes('--color'),
|
||
hasStatus: flags.includes('--status'),
|
||
autoCommit: flags.includes('--commit'),
|
||
remoteSelects: []
|
||
};
|
||
}
|
||
|
||
function displayConfiguration(config) {
|
||
log.info('📋 CONFIGURAÇÃO EXPRESS:');
|
||
console.log(`📝 Nome: ${config.name}`);
|
||
console.log(`📋 Exibição: ${config.displayName}`);
|
||
console.log(`🧭 Menu: após ${config.menuPositionName} (${config.menuPosition})`);
|
||
console.log(`📸 Fotos: ${config.hasPhotos ? 'Sim' : 'Não'}`);
|
||
console.log(`🃏 Side Card: ${config.hasSideCard ? 'Sim' : 'Não'}`);
|
||
console.log(`🛣️ Quilometragem: ${config.hasKilometer ? 'Sim' : 'Não'}`);
|
||
console.log(`🎨 Cor: ${config.hasColor ? 'Sim' : 'Não'}`);
|
||
console.log(`📊 Status: ${config.hasStatus ? 'Sim' : 'Não'}`);
|
||
console.log(`🚀 Commit: ${config.autoCommit ? 'Automático' : 'Manual'}`);
|
||
console.log('');
|
||
}
|
||
|
||
async function createDomainWithConfig(config) {
|
||
// Simular entrada do usuário para o script principal
|
||
const originalArgv = process.argv;
|
||
const originalStdin = process.stdin;
|
||
|
||
try {
|
||
// Mock das respostas do usuário
|
||
const responses = [
|
||
config.name,
|
||
config.displayName,
|
||
config.menuPosition.toString(),
|
||
config.hasPhotos ? 's' : 'n',
|
||
config.hasSideCard ? 's' : 'n',
|
||
config.hasKilometer ? 's' : 'n',
|
||
config.hasColor ? 's' : 'n',
|
||
config.hasStatus ? 's' : 'n',
|
||
'n', // remote selects
|
||
's' // confirmação
|
||
];
|
||
|
||
let responseIndex = 0;
|
||
|
||
// Mock readline
|
||
const originalCreateInterface = require('readline').createInterface;
|
||
require('readline').createInterface = () => ({
|
||
question: (prompt, callback) => {
|
||
const response = responses[responseIndex++];
|
||
console.log(`${prompt}${response}`);
|
||
callback(response);
|
||
},
|
||
close: () => {}
|
||
});
|
||
|
||
// Executar o script principal de forma programática
|
||
await createDomainMain();
|
||
|
||
// Restaurar readline
|
||
require('readline').createInterface = originalCreateInterface;
|
||
|
||
} catch (error) {
|
||
throw new Error(`Erro na criação: ${error.message}`);
|
||
}
|
||
}
|
||
|
||
function showUsage() {
|
||
console.log(`
|
||
${colors.cyan}🚀 USO DO CRIADOR EXPRESS:${colors.reset}
|
||
|
||
${colors.bright}npm run create:domain:express -- <nome> <exibição> <posição> [flags]${colors.reset}
|
||
|
||
${colors.yellow}📝 ARGUMENTOS OBRIGATÓRIOS:${colors.reset}
|
||
nome Nome do domínio (singular, minúsculo)
|
||
exibição Nome para exibição (plural)
|
||
posição Posição no menu (1-6):
|
||
1. vehicles (após Veículos)
|
||
2. drivers (após Motoristas)
|
||
3. routes (após Rotas)
|
||
4. finances (após Finanças)
|
||
5. reports (após Relatórios)
|
||
6. settings (após Configurações)
|
||
|
||
${colors.yellow}🎛️ FLAGS OPCIONAIS:${colors.reset}
|
||
--photos Sub-aba de fotos
|
||
--sidecard Side card lateral
|
||
--kilometer Campo quilometragem
|
||
--color Campo cor
|
||
--status Campo status
|
||
--commit Commit automático
|
||
|
||
${colors.green}📋 EXEMPLOS:${colors.reset}
|
||
|
||
# Domínio básico
|
||
npm run create:domain:express -- products Produtos 2
|
||
|
||
# Domínio completo
|
||
npm run create:domain:express -- contracts Contratos 3 --photos --sidecard --color --status --commit
|
||
|
||
# Domínio com recursos específicos
|
||
npm run create:domain:express -- suppliers Fornecedores 4 --sidecard --status
|
||
`);
|
||
}
|
||
|
||
// 🚀 Executar
|
||
if (require.main === module) {
|
||
main();
|
||
}
|
||
|
||
module.exports = { main };
|