51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
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, novo) => {
|
|
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) => {
|
|
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}`);
|