This commit is contained in:
Luiz Silva 2025-08-10 11:36:10 -03:00
parent 0dc2d7a0df
commit 24561a6199
6 changed files with 157 additions and 4 deletions

57
src/instalarAmbiente.ts Normal file
View file

@ -0,0 +1,57 @@
import fs from "node:fs"
import path from "node:path"
/**
* Mescla objetos recursivamente.
* - Adiciona chaves novas
* - Sobrescreve valores primitivos
* - Mescla objetos aninhados
*/
const mesclar = (entrada: any, novo: any): any => {
const saida = { ...(entrada || {}) }
for (const [k, v] of Object.entries(novo)) {
if (v && typeof v === "object" && !Array.isArray(v)) {
saida[k] = mesclar(saida[k], v)
} else {
saida[k] = v
}
}
return saida
}
/** Lê JSON ou retorna objeto vazio */
const abrirJson = (caminho: string) => {
try {
return JSON.parse(fs.readFileSync(caminho, "utf-8"))
} catch {
return {}
}
}
const settings_json = {
"editor.defaultFormatter": "biomejs.biome",
"[javascript]": { "editor.defaultFormatter": "biomejs.biome" },
"[javascriptreact]": { "editor.defaultFormatter": "biomejs.biome" },
"[typescript]": { "editor.defaultFormatter": "biomejs.biome" },
"[typescriptreact]": { "editor.defaultFormatter": "biomejs.biome" },
"[json]": { "editor.defaultFormatter": "biomejs.biome" },
"[jsonc]": { "editor.defaultFormatter": "biomejs.biome" },
"[vue]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "always",
"source.fixAll.biome": "always",
},
}
const caminhoSeting = path.join(process.cwd(), ".vscode/settings.json")
// Garante a pasta .vscode
fs.mkdirSync(path.dirname(caminhoSeting), { recursive: true })
// Mescla e grava
const atual = abrirJson(caminhoSeting)
const final = mesclar(atual, settings_json)
fs.writeFileSync(caminhoSeting, JSON.stringify(final, null, 2), "utf8")
console.log(`✅ Configurações salvas em ${caminhoSeting}`)