UNPKG

@caioms/biomejs-config

Version:

Configuração compartilhada do BiomeJS para meus projetos

51 lines (43 loc) 1.84 kB
const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); try { require.resolve('@biomejs/biome'); console.log('✅ @biomejs/biome já está instalado'); } catch { console.log('⚡ Instalando @biomejs/biome...'); execSync('npm install @biomejs/biome --save-dev', { stdio: 'inherit' }); } const CONFIG_FILE = 'biome.json'; const YOUR_PACKAGE_NAME = '@caioms/biomejs-config'; try { const processPath = process.env.INIT_CWD || process.cwd(); const targetPath = path.join(processPath, CONFIG_FILE); // Se o arquivo não existe, cria com extends if (!fs.existsSync(targetPath)) { fs.writeFileSync(targetPath, JSON.stringify({ "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", "extends": [`node_modules/${YOUR_PACKAGE_NAME}/${CONFIG_FILE}`] }, null, 2)); console.log('✅ Configuração do BiomeJS criada (estendendo seu pacote)'); return; } // Se o arquivo existe, verifica se já extende seu pacote const existingConfig = JSON.parse(fs.readFileSync(targetPath, 'utf8')); if (!existingConfig.extends?.includes(`node_modules/${YOUR_PACKAGE_NAME}/${CONFIG_FILE}`)) { // Adiciona o extends mantendo as configurações existentes const updatedConfig = { ...existingConfig, extends: [ ...(existingConfig.extends ? [].concat(existingConfig.extends) : []), `node_modules/${YOUR_PACKAGE_NAME}/${CONFIG_FILE}` ] }; fs.writeFileSync(targetPath, JSON.stringify(updatedConfig, null, 2)); console.log('✅ Seu pacote foi adicionado ao "extends" do biome.json existente'); } else { console.log('ℹ️ O projeto já estende sua configuração - nenhuma alteração necessária'); } } catch (error) { console.error('❌ Erro ao configurar BiomeJS:', error.message); }