@caioms/pre-git-auto-format 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +29 -28
- package/postinstall.js +50 -11
package/package.json
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
2
|
+
"name": "@caioms/pre-git-auto-format",
|
3
|
+
"version": "1.2.3",
|
4
|
+
"description": "Automatic pre-commit formatting with BiomeJS and lint-staged",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"postinstall": "node postinstall.js",
|
8
|
+
"prepare": "husky"
|
9
|
+
},
|
10
|
+
"files": [
|
11
|
+
".lintstagedrc.json",
|
12
|
+
"postinstall.js"
|
13
|
+
],
|
14
|
+
"keywords": [
|
15
|
+
"lint-staged",
|
16
|
+
"husky",
|
17
|
+
"biome",
|
18
|
+
"pre-commit",
|
19
|
+
"formatting",
|
20
|
+
"git-hooks"
|
21
|
+
],
|
22
|
+
"author": "Caio Marques Silva",
|
23
|
+
"license": "MIT",
|
24
|
+
"dependencies": {
|
25
|
+
"@caioms/biomejs-config": "^1.1.1"
|
26
|
+
},
|
27
|
+
"peerDependencies": {
|
28
|
+
"husky": "^9.0.0",
|
29
|
+
"lint-staged": "^15.0.0"
|
30
|
+
}
|
30
31
|
}
|
package/postinstall.js
CHANGED
@@ -6,6 +6,17 @@ const YOUR_PACKAGE_NAME = '@caioms/pre-git-auto-format';
|
|
6
6
|
|
7
7
|
console.log('🚀 Configurando formatação automática pré-commit...\n');
|
8
8
|
|
9
|
+
// Função para atualizar o pacote biome para a versão mais recente
|
10
|
+
function updateBiomeConfig() {
|
11
|
+
console.log('⚡ Verificando atualizações do @caioms/biomejs-config...');
|
12
|
+
try {
|
13
|
+
execSync('npm install @caioms/biomejs-config@latest', { stdio: 'inherit' });
|
14
|
+
console.log('✅ @caioms/biomejs-config atualizado para a versão mais recente');
|
15
|
+
} catch (error) {
|
16
|
+
console.log('ℹ️ Usando versão atual do @caioms/biomejs-config');
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
9
20
|
// Função para verificar se um pacote está instalado
|
10
21
|
function isPackageInstalled(packageName) {
|
11
22
|
try {
|
@@ -77,6 +88,9 @@ function copyConfigFile(fileName, description) {
|
|
77
88
|
}
|
78
89
|
|
79
90
|
try {
|
91
|
+
// 0. Atualizar pacote do biome para versão mais recente
|
92
|
+
updateBiomeConfig();
|
93
|
+
|
80
94
|
// 1. Verificar e instalar lint-staged
|
81
95
|
if (!isPackageInstalled('lint-staged')) {
|
82
96
|
installPackage('lint-staged');
|
@@ -104,11 +118,31 @@ try {
|
|
104
118
|
// 5. Verificar se existe repositório git
|
105
119
|
if (!fs.existsSync('.git')) {
|
106
120
|
console.log('⚠️ Repositório git não encontrado. Execute "git init" primeiro.');
|
121
|
+
console.log('ℹ️ Pulando configuração dos git hooks...');
|
122
|
+
|
123
|
+
// Ainda configura lint-staged para uso manual
|
124
|
+
console.log('✅ lint-staged configurado (use "npx lint-staged" manualmente)');
|
125
|
+
|
126
|
+
// Pula configuração do husky e git hooks
|
127
|
+
console.log('\n🎉 Configuração parcial concluída!');
|
128
|
+
console.log('\n📋 O que foi configurado:');
|
129
|
+
console.log(' • BiomeJS (via @caioms/biomejs-config)');
|
130
|
+
console.log(' • lint-staged (para uso manual)');
|
131
|
+
console.log('\n⚡ Para ativar os git hooks:');
|
132
|
+
console.log(' 1. Execute "git init" no seu projeto');
|
133
|
+
console.log(' 2. Execute "npx husky init"');
|
134
|
+
console.log(' 3. Execute "echo \'npx lint-staged\' > .husky/pre-commit"');
|
135
|
+
console.log('\n🔧 Scripts disponíveis:');
|
136
|
+
console.log(' • npm run lint - Verificar código');
|
137
|
+
console.log(' • npm run format - Formatar código');
|
138
|
+
console.log(' • npx lint-staged - Formatar arquivos staged');
|
139
|
+
return;
|
107
140
|
}
|
108
141
|
|
109
142
|
// 6. Configurar pre-commit hook
|
110
143
|
const preCommitPath = path.join('.husky', 'pre-commit');
|
111
|
-
const preCommitContent = '#!/usr/bin/env sh\n. "$(dirname -- "$0")/_/husky.sh"\n\nnpx lint-staged\n';
|
144
|
+
// const preCommitContent = '#!/usr/bin/env sh\n. "$(dirname -- "$0")/_/husky.sh"\n\nnpx lint-staged\n';
|
145
|
+
const preCommitContent = 'npx lint-staged';
|
112
146
|
|
113
147
|
if (!fs.existsSync(preCommitPath)) {
|
114
148
|
createOrUpdateFile(preCommitPath, preCommitContent, 'Hook pre-commit');
|
@@ -118,17 +152,22 @@ try {
|
|
118
152
|
} catch (error) {
|
119
153
|
// Ignora erro de chmod no Windows
|
120
154
|
}
|
121
|
-
} else {
|
122
|
-
// Verificar se já contém o comando lint-staged
|
123
|
-
const existingContent = fs.readFileSync(preCommitPath, 'utf8');
|
124
|
-
if (!existingContent.includes('npx lint-staged')) {
|
125
|
-
// Adicionar ao final do arquivo existente
|
126
|
-
const updatedContent = existingContent.trim() + '\n\nnpx lint-staged\n';
|
127
|
-
createOrUpdateFile(preCommitPath, updatedContent, 'Hook pre-commit (atualizado)');
|
128
|
-
} else {
|
129
|
-
console.log('ℹ️ Hook pre-commit já contém lint-staged - nenhuma alteração necessária');
|
130
|
-
}
|
131
155
|
}
|
156
|
+
// else {
|
157
|
+
// // Verificar se já contém o comando lint-staged
|
158
|
+
// const existingContent = fs.readFileSync(preCommitPath, 'utf8');
|
159
|
+
// if (!existingContent.includes('npx lint-staged')) {
|
160
|
+
// // Adicionar ao final do arquivo existente
|
161
|
+
// const updatedContent = existingContent.trim() + '\n\nnpx lint-staged\n';
|
162
|
+
// createOrUpdateFile(preCommitPath, updatedContent, 'Hook pre-commit (atualizado)');
|
163
|
+
// } else {
|
164
|
+
// console.log('ℹ️ Hook pre-commit já contém lint-staged - nenhuma alteração necessária');
|
165
|
+
// }
|
166
|
+
// }
|
167
|
+
else {
|
168
|
+
// Always overwrite the content
|
169
|
+
createOrUpdateFile(preCommitPath, preCommitContent, 'Hook pre-commit (updated)');
|
170
|
+
}
|
132
171
|
|
133
172
|
// 7. Verificar package.json para adicionar scripts úteis (opcional)
|
134
173
|
const packageJsonPath = path.join(process.cwd(), 'package.json');
|