diff --git a/.vscode/settings.json b/.vscode/settings.json index f341cd0..74bd76d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,27 @@ "editor.codeActionsOnSave": { "source.organizeImports.biome": "always", "source.fixAll.biome": "always" + }, + "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" } -} +} \ No newline at end of file diff --git a/Documentos/biome.json b/Documentos/biome.json index 9928072..6f60a26 100644 --- a/Documentos/biome.json +++ b/Documentos/biome.json @@ -1,6 +1,7 @@ { "$schema": "../node_modules/@biomejs/biome/configuration_schema.json", "root": false, + "linter": { "enabled": true, "rules": { @@ -38,7 +39,7 @@ "noUselessFragments":"off" }, "performance": { - "noAccumulatingSpread": "warn" + "noAccumulatingSpread": "off" }, "a11y": { "useSemanticElements": "off" diff --git a/README.md b/README.md index 9062059..14fc5b3 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Este guia mostra como configurar o [BiomeJS](https://biomejs.dev) para formatar Certifique-se de que o pacote `p-comuns` (ou outro com a configuração compartilhada) esteja disponível no seu projeto. Ele deve conter o arquivo `Documentos/biome.json`. +pnpm up p-comuns + --- ### 2. Instalar o Biome com `pnpm` @@ -45,7 +47,7 @@ Inclua o comando abaixo em `"scripts"`: ```json { "scripts": { - "biome": "pnpm exec biome check --write" + "biome": "pnpm exec biome check --write", } } ``` @@ -73,6 +75,14 @@ Se quiser aplicar o Biome a todo o projeto (não só `src/`), altere o include: adicionar em .vscode/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": "octref.vetur"}, "editor.codeActionsOnSave": { "source.organizeImports.biome": "always", "source.fixAll.biome": "always" diff --git a/dist-back/instalarAmbiente.js b/dist-back/instalarAmbiente.js new file mode 100644 index 0000000..d31e0a5 --- /dev/null +++ b/dist-back/instalarAmbiente.js @@ -0,0 +1,63 @@ +"use strict"; +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var import_node_fs = __toESM(require("node:fs")); +var import_node_path = __toESM(require("node:path")); +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; +}; +const abrirJson = (caminho) => { + try { + return JSON.parse(import_node_fs.default.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 = import_node_path.default.join(process.cwd(), ".vscode/settings.json"); +import_node_fs.default.mkdirSync(import_node_path.default.dirname(caminhoSeting), { recursive: true }); +const atual = abrirJson(caminhoSeting); +const final = mesclar(atual, settings_json); +import_node_fs.default.writeFileSync(caminhoSeting, JSON.stringify(final, null, 2), "utf8"); +console.log(`\u2705 Configura\xE7\xF5es salvas em ${caminhoSeting}`); diff --git a/package.json b/package.json index 2db4bfe..d261c0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "p-comuns", - "version": "0.211.0", + "version": "0.212.0", "description": "", "main": "./dist-back/index.js", "module": "./dist-front/index.mjs", diff --git a/src/instalarAmbiente.ts b/src/instalarAmbiente.ts new file mode 100644 index 0000000..4e08809 --- /dev/null +++ b/src/instalarAmbiente.ts @@ -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}`)