JavaScript Python PHP
async function executar(values) {
function generateInfraGitignore(v) {
const language = infraChoice(v.language, ['JavaScript', 'TypeScript', 'Python', 'PHP', 'Go', 'Rust', 'Java']), framework = infraChoice(v.framework, ['Nenhum', 'Next.js', 'Vite', 'Django', 'Laravel']);
const editor = infraChoice(v.editor, ['Nenhum', 'VS Code', 'JetBrains']), os = infraChoice(v.os, ['Linux', 'macOS', 'Windows']);
if ((['Next.js', 'Vite'].includes(framework) && !['JavaScript', 'TypeScript'].includes(language)) || (framework === 'Django' && language !== 'Python') || (framework === 'Laravel' && language !== 'PHP'))
throw new Error('O framework selecionado não corresponde à linguagem.');
const languages = { JavaScript: ['node_modules/', 'coverage/', '*.log'], TypeScript: ['node_modules/', 'coverage/', '*.log', '*.tsbuildinfo'], Python: ['__pycache__/', '*.py[cod]', '.venv/', '.pytest_cache/', '.ruff_cache/', 'build/', 'dist/', '*.egg-info/'], PHP: ['vendor/', '.phpunit.cache/', '.phpunit.result.cache'], Go: ['bin/', 'coverage.out'], Rust: ['target/'], Java: ['target/', 'build/', '.gradle/', '*.class'] };
const frameworks = { Nenhum: [], 'Next.js': ['.next/', 'out/'], Vite: ['dist/', '.vite/'], Django: ['*.sqlite3', 'media/', 'staticfiles/'], Laravel: ['node_modules/', 'public/hot', 'public/storage', 'storage/*.key', 'storage/framework/cache/', 'storage/framework/sessions/', 'storage/framework/views/', 'storage/logs/'] };
const editors = { Nenhum: [], 'VS Code': ['.vscode/*', '!.vscode/extensions.json'], JetBrains: ['.idea/', '*.iml'] };
const systems = { Linux: ['*~', '.directory'], macOS: ['.DS_Store', '._*', '.Spotlight-V100/', '.Trashes/'], Windows: ['Thumbs.db', 'Desktop.ini', '$RECYCLE.BIN/'] };
const rules = [...languages[language], ...frameworks[framework], ...editors[editor], ...systems[os], '.env', '.env.*', '!.env.example', ...infraText(v.input).split(/\r\n|\r|\n/)];
const seen = new Set(), output = [];
for (let i = rules.length - 1; i >= 0; i--) {
const rule = rules[i];
if (!rule || rule.startsWith('#')) {
if (rule)
output.unshift(rule);
continue;
}
if (!seen.has(rule)) {
seen.add(rule);
output.unshift(rule);
}
}
const text = `# Modelo local: ${language} / ${framework} / ${editor} / ${os}\n# Revise regras; .gitignore não remove arquivos já rastreados.\n` + output.join('\n') + '\n';
return { text, files: [{ name: '.gitignore', content: text }] };
}
function infraText(value, limit = 100000) {
if (typeof value !== 'string' || value.length > limit)
throw new Error(`Use texto com até ${limit} caracteres.`);
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ufffe\uffff]/u.test(value) || /[\uD800-\uDFFF]/u.test(value))
throw new Error('Há caracteres de controle ou Unicode inválidos na entrada.');
return value;
}
function infraChoice(value, options) {
if (!options.includes(value))
throw new Error('Opção não suportada: ' + value);
return value;
}
for (const value of Object.values(values)) infraText(value);
const output = await generateInfraGitignore(values);
if (output.text.length > 1000000) throw new Error("Resultado excede 1 milhão de caracteres.");
return output;
}
import re
def executar(values):
def text(value, limit=100000):
if not isinstance(value, str) or len(value.encode('utf-16-le')) // 2 > limit or re.search(r'[\x00-\x08\x0b\x0c\x0e-\x1f\ufffe\uffff\ud800-\udfff]', value):
raise ValueError('Texto excede o limite ou contém caracteres inválidos.')
return value
def choice(value, options):
if value not in options:
raise ValueError('Opção não suportada.')
return value
for value in values.values(): text(value)
language = choice(values['language'], ['JavaScript', 'TypeScript', 'Python', 'PHP', 'Go', 'Rust', 'Java'])
framework = choice(values['framework'], ['Nenhum', 'Next.js', 'Vite', 'Django', 'Laravel'])
editor, system = choice(values['editor'], ['Nenhum', 'VS Code', 'JetBrains']), choice(values['os'], ['Linux', 'macOS', 'Windows'])
if (framework in ['Next.js', 'Vite'] and language not in ['JavaScript', 'TypeScript']) or (framework == 'Django' and language != 'Python') or (framework == 'Laravel' and language != 'PHP'): raise ValueError('Framework incompatível com a linguagem.')
languages = {'JavaScript': ['node_modules/', 'coverage/', '*.log'], 'TypeScript': ['node_modules/', 'coverage/', '*.log', '*.tsbuildinfo'], 'Python': ['__pycache__/', '*.py[cod]', '.venv/', '.pytest_cache/', '.ruff_cache/', 'build/', 'dist/', '*.egg-info/'], 'PHP': ['vendor/', '.phpunit.cache/', '.phpunit.result.cache'], 'Go': ['bin/', 'coverage.out'], 'Rust': ['target/'], 'Java': ['target/', 'build/', '.gradle/', '*.class']}
frameworks = {'Nenhum': [], 'Next.js': ['.next/', 'out/'], 'Vite': ['dist/', '.vite/'], 'Django': ['*.sqlite3', 'media/', 'staticfiles/'], 'Laravel': ['node_modules/', 'public/hot', 'public/storage', 'storage/*.key', 'storage/framework/cache/', 'storage/framework/sessions/', 'storage/framework/views/', 'storage/logs/']}
editors, systems = {'Nenhum': [], 'VS Code': ['.vscode/*', '!.vscode/extensions.json'], 'JetBrains': ['.idea/', '*.iml']}, {'Linux': ['*~', '.directory'], 'macOS': ['.DS_Store', '._*', '.Spotlight-V100/', '.Trashes/'], 'Windows': ['Thumbs.db', 'Desktop.ini', '$RECYCLE.BIN/']}
rules = languages[language] + frameworks[framework] + editors[editor] + systems[system] + ['.env', '.env.*', '!.env.example'] + re.split(r'\r\n|\r|\n', values['input'])
output, seen = [], set()
for rule in reversed(rules):
if not rule or rule.startswith('#'):
if rule: output.insert(0, rule)
elif rule not in seen:
seen.add(rule)
output.insert(0, rule)
result = f'# Modelo local: {language} / {framework} / {editor} / {system}\n# Revise regras; .gitignore não remove arquivos já rastreados.\n' + '\n'.join(output) + '\n'
return {'text': result, 'files': [{'name': '.gitignore', 'content': result}]}
<?php
function executar(array $values): array {
$text = static function ($value, $limit = 100000) { if (!is_string($value) || !preg_match('//u', $value) || strlen(iconv('UTF-8', 'UTF-16LE', $value)) / 2 > $limit || preg_match('/[\x00-\x08\x0b\x0c\x0e-\x1f\x{fffe}\x{ffff}]/u', $value)) throw new InvalidArgumentException('Texto excede o limite ou contém caracteres inválidos.'); return $value; };
$choice = static function ($value, $options) { if (!in_array($value, $options, true)) throw new InvalidArgumentException('Opção não suportada.'); return $value; };
foreach ($values as $value) $text($value);
$language = $choice($values['language'], ['JavaScript', 'TypeScript', 'Python', 'PHP', 'Go', 'Rust', 'Java']); $framework = $choice($values['framework'], ['Nenhum', 'Next.js', 'Vite', 'Django', 'Laravel']); $editor = $choice($values['editor'], ['Nenhum', 'VS Code', 'JetBrains']); $os = $choice($values['os'], ['Linux', 'macOS', 'Windows']);
if ((in_array($framework, ['Next.js', 'Vite'], true) && !in_array($language, ['JavaScript', 'TypeScript'], true)) || ($framework === 'Django' && $language !== 'Python') || ($framework === 'Laravel' && $language !== 'PHP')) throw new InvalidArgumentException('Framework incompatível com a linguagem.');
$languages = ['JavaScript' => ['node_modules/', 'coverage/', '*.log'], 'TypeScript' => ['node_modules/', 'coverage/', '*.log', '*.tsbuildinfo'], 'Python' => ['__pycache__/', '*.py[cod]', '.venv/', '.pytest_cache/', '.ruff_cache/', 'build/', 'dist/', '*.egg-info/'], 'PHP' => ['vendor/', '.phpunit.cache/', '.phpunit.result.cache'], 'Go' => ['bin/', 'coverage.out'], 'Rust' => ['target/'], 'Java' => ['target/', 'build/', '.gradle/', '*.class']];
$frameworks = ['Nenhum' => [], 'Next.js' => ['.next/', 'out/'], 'Vite' => ['dist/', '.vite/'], 'Django' => ['*.sqlite3', 'media/', 'staticfiles/'], 'Laravel' => ['node_modules/', 'public/hot', 'public/storage', 'storage/*.key', 'storage/framework/cache/', 'storage/framework/sessions/', 'storage/framework/views/', 'storage/logs/']];
$editors = ['Nenhum' => [], 'VS Code' => ['.vscode/*', '!.vscode/extensions.json'], 'JetBrains' => ['.idea/', '*.iml']]; $systems = ['Linux' => ['*~', '.directory'], 'macOS' => ['.DS_Store', '._*', '.Spotlight-V100/', '.Trashes/'], 'Windows' => ['Thumbs.db', 'Desktop.ini', '$RECYCLE.BIN/']];
$rules = array_merge($languages[$language], $frameworks[$framework], $editors[$editor], $systems[$os], ['.env', '.env.*', '!.env.example'], preg_split('/\r\n|\r|\n/', $values['input'])); $out = []; $seen = [];
for ($i = count($rules) - 1; $i >= 0; $i--) { $rule = $rules[$i]; if ($rule === '' || str_starts_with($rule, '#')) { if ($rule !== '') array_unshift($out, $rule); } elseif (!array_key_exists($rule, $seen)) { $seen[$rule] = true; array_unshift($out, $rule); } }
$output = "# Modelo local: $language / $framework / $editor / $os\n# Revise regras; .gitignore não remove arquivos já rastreados.\n" . implode("\n", $out) . "\n";
return ['text' => $output, 'files' => [['name' => '.gitignore', 'content' => $output]]];
}