@igreen/design-system 1.0.4 → 1.0.5
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 +1 -1
- package/postinstall.js +146 -138
package/package.json
CHANGED
package/postinstall.js
CHANGED
|
@@ -11,98 +11,106 @@ const path = require('path');
|
|
|
11
11
|
const readline = require('readline');
|
|
12
12
|
|
|
13
13
|
const rl = readline.createInterface({
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
input: process.stdin,
|
|
15
|
+
output: process.stdout
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
// Detectar se está sendo instalado em um projeto (não no próprio igreen)
|
|
19
19
|
const isInstallingInProject = () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const cwd = process.cwd();
|
|
21
|
+
|
|
22
|
+
// Se estamos dentro de node_modules/@igreen/design-system
|
|
23
|
+
if (cwd.includes(path.join('node_modules', '@igreen', 'design-system'))) {
|
|
24
|
+
const projectRoot = path.resolve(cwd, '..', '..', '..');
|
|
25
|
+
|
|
26
|
+
// Verificar se o projeto raiz NÃO é o igreen (verificando se tem packages/)
|
|
27
|
+
const hasPackagesDir = fs.existsSync(path.join(projectRoot, 'packages', 'design-system'));
|
|
28
|
+
|
|
29
|
+
// Se NÃO tem packages/design-system, é um projeto externo
|
|
30
|
+
return !hasPackagesDir;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return false;
|
|
26
34
|
};
|
|
27
35
|
|
|
28
36
|
const getProjectRoot = () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
const cwd = process.cwd();
|
|
38
|
+
// Voltar 3 níveis: node_modules/@igreen/design-system -> root
|
|
39
|
+
if (cwd.includes(path.join('node_modules', '@igreen', 'design-system'))) {
|
|
40
|
+
return path.resolve(cwd, '..', '..', '..');
|
|
41
|
+
}
|
|
42
|
+
return cwd;
|
|
35
43
|
};
|
|
36
44
|
|
|
37
45
|
const question = (query) => new Promise((resolve) => rl.question(query, resolve));
|
|
38
46
|
|
|
39
47
|
async function setupProject() {
|
|
40
|
-
|
|
48
|
+
console.log('\n🎨 iGreen Design System Setup\n');
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
// Verificar se está sendo instalado em um projeto
|
|
51
|
+
if (!isInstallingInProject()) {
|
|
52
|
+
console.log('ℹ️ Instalação detectada no próprio repositório iGreen, pulando setup automático.\n');
|
|
53
|
+
rl.close();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
48
56
|
|
|
49
|
-
|
|
57
|
+
const projectRoot = getProjectRoot();
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
// Verificar se já foi configurado antes
|
|
60
|
+
const igreenConfigPath = path.join(projectRoot, '.igreen-configured');
|
|
61
|
+
if (fs.existsSync(igreenConfigPath)) {
|
|
62
|
+
console.log('✅ Projeto já configurado anteriormente.\n');
|
|
63
|
+
console.log('💡 Para reconfigurar, delete o arquivo .igreen-configured e reinstale.\n');
|
|
64
|
+
rl.close();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
59
67
|
|
|
60
|
-
|
|
68
|
+
console.log('🚀 Vamos configurar seu projeto iGreen!\n');
|
|
61
69
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
// 1. Perguntar se quer configuração automática
|
|
71
|
+
const autoSetup = await question('Deseja configurar automaticamente? (S/n): ');
|
|
72
|
+
if (autoSetup.toLowerCase() === 'n') {
|
|
73
|
+
console.log('\n📚 Configuração manual: https://github.com/seu-repo/docs\n');
|
|
74
|
+
rl.close();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
78
|
+
// 2. Escolher tema
|
|
79
|
+
console.log('\n📦 Temas disponíveis:');
|
|
80
|
+
console.log(' 1. igreen (padrão verde)');
|
|
81
|
+
console.log(' 2. solarorange (laranja vibrante)\n');
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
const themeChoice = await question('Escolha o tema (1-2) [1]: ');
|
|
84
|
+
const theme = themeChoice === '2' ? 'solarorange' : 'igreen';
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
// 3. Criar estrutura de pastas
|
|
87
|
+
console.log('\n📁 Criando estrutura de pastas...');
|
|
80
88
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
const appDir = path.join(projectRoot, 'app');
|
|
90
|
+
const componentsDir = path.join(projectRoot, 'components');
|
|
91
|
+
const libDir = path.join(projectRoot, 'lib');
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
[appDir, componentsDir, libDir].forEach(dir => {
|
|
94
|
+
if (!fs.existsSync(dir)) {
|
|
95
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
96
|
+
console.log(` ✅ ${path.relative(projectRoot, dir)}/`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
91
99
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
// 4. Criar globals.css
|
|
101
|
+
console.log('\n🎨 Configurando globals.css...');
|
|
102
|
+
const globalsCss = `@import 'tailwindcss';
|
|
95
103
|
|
|
96
104
|
/* iGreen Design System está configurado! */
|
|
97
105
|
/* O tema ${theme} será carregado automaticamente no layout */
|
|
98
106
|
`;
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
108
|
+
fs.writeFileSync(path.join(appDir, 'globals.css'), globalsCss);
|
|
109
|
+
console.log(' ✅ app/globals.css');
|
|
102
110
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
// 5. Criar layout.tsx
|
|
112
|
+
console.log(' Configurando layout.tsx...');
|
|
113
|
+
const layoutContent = `import '@igreen/themes/${theme}'
|
|
106
114
|
import './globals.css'
|
|
107
115
|
import type { Metadata } from 'next'
|
|
108
116
|
|
|
@@ -124,12 +132,12 @@ export default function RootLayout({
|
|
|
124
132
|
}
|
|
125
133
|
`;
|
|
126
134
|
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
fs.writeFileSync(path.join(appDir, 'layout.tsx'), layoutContent);
|
|
136
|
+
console.log(' ✅ app/layout.tsx');
|
|
129
137
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
// 6. Criar page.tsx exemplo
|
|
139
|
+
console.log(' Criando página de exemplo...');
|
|
140
|
+
const pageContent = `import { Button } from '@igreen/button'
|
|
133
141
|
import { Input } from '@igreen/input'
|
|
134
142
|
import { Label } from '@igreen/label'
|
|
135
143
|
|
|
@@ -158,88 +166,88 @@ export default function Home() {
|
|
|
158
166
|
}
|
|
159
167
|
`;
|
|
160
168
|
|
|
161
|
-
|
|
162
|
-
|
|
169
|
+
fs.writeFileSync(path.join(appDir, 'page.tsx'), pageContent);
|
|
170
|
+
console.log(' ✅ app/page.tsx');
|
|
163
171
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
172
|
+
// 7. Criar lib/utils.ts
|
|
173
|
+
console.log(' Configurando utilitários...');
|
|
174
|
+
const utilsContent = `export { cn } from '@igreen/utils'
|
|
167
175
|
`;
|
|
168
176
|
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
fs.writeFileSync(path.join(libDir, 'utils.ts'), utilsContent);
|
|
178
|
+
console.log(' ✅ lib/utils.ts');
|
|
171
179
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
// 8. Verificar/Criar postcss.config.mjs
|
|
181
|
+
console.log('\n⚙️ Configurando PostCSS...');
|
|
182
|
+
const postcssConfig = path.join(projectRoot, 'postcss.config.mjs');
|
|
183
|
+
if (!fs.existsSync(postcssConfig)) {
|
|
184
|
+
const postcssContent = `export default {
|
|
177
185
|
plugins: {
|
|
178
186
|
'@tailwindcss/postcss': {},
|
|
179
187
|
},
|
|
180
188
|
}
|
|
181
189
|
`;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
190
|
+
fs.writeFileSync(postcssConfig, postcssContent);
|
|
191
|
+
console.log(' ✅ postcss.config.mjs');
|
|
192
|
+
} else {
|
|
193
|
+
console.log(' ⏭️ postcss.config.mjs já existe');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 9. Atualizar package.json scripts (se possível)
|
|
197
|
+
console.log('\n📦 Verificando scripts...');
|
|
198
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
199
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
200
|
+
try {
|
|
201
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
202
|
+
|
|
203
|
+
if (!packageJson.scripts) {
|
|
204
|
+
packageJson.scripts = {};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (!packageJson.scripts.dev) {
|
|
208
|
+
packageJson.scripts.dev = 'next dev';
|
|
209
|
+
packageJson.scripts.build = 'next build';
|
|
210
|
+
packageJson.scripts.start = 'next start';
|
|
211
|
+
|
|
212
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
213
|
+
console.log(' ✅ Scripts adicionados ao package.json');
|
|
214
|
+
}
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.log(' ⚠️ Não foi possível atualizar package.json automaticamente');
|
|
210
217
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 10. Marcar como configurado
|
|
221
|
+
fs.writeFileSync(igreenConfigPath, `Configured at: ${new Date().toISOString()}\nTheme: ${theme}\n`);
|
|
222
|
+
|
|
223
|
+
// 11. Mostrar próximos passos
|
|
224
|
+
console.log('\n' + '='.repeat(60));
|
|
225
|
+
console.log('🎉 Projeto configurado com sucesso!');
|
|
226
|
+
console.log('='.repeat(60));
|
|
227
|
+
console.log(`\n📦 Tema instalado: ${theme}`);
|
|
228
|
+
console.log('\n📝 Próximos passos:\n');
|
|
229
|
+
console.log(' 1. Instale as dependências do Next.js:');
|
|
230
|
+
console.log(' npm install next@latest react@latest react-dom@latest');
|
|
231
|
+
console.log('');
|
|
232
|
+
console.log(' 2. Instale o Tailwind CSS v4:');
|
|
233
|
+
console.log(' npm install tailwindcss@next @tailwindcss/postcss@next');
|
|
234
|
+
console.log('');
|
|
235
|
+
console.log(' 3. Inicie o servidor de desenvolvimento:');
|
|
236
|
+
console.log(' npm run dev');
|
|
237
|
+
console.log('');
|
|
238
|
+
console.log(' 4. Abra http://localhost:3000\n');
|
|
239
|
+
console.log('📚 Documentação: https://github.com/seu-repo/docs');
|
|
240
|
+
console.log('💚 Componentes disponíveis:');
|
|
241
|
+
console.log(' - Button, Input, Label, Checkbox, ExampleCard\n');
|
|
242
|
+
console.log('='.repeat(60) + '\n');
|
|
243
|
+
|
|
244
|
+
rl.close();
|
|
237
245
|
}
|
|
238
246
|
|
|
239
247
|
// Executar setup
|
|
240
248
|
setupProject().catch(error => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
249
|
+
console.error('\n❌ Erro durante configuração:', error.message);
|
|
250
|
+
console.log('\n📚 Para configuração manual: https://github.com/seu-repo/docs\n');
|
|
251
|
+
rl.close();
|
|
252
|
+
process.exit(0); // Não falhar a instalação
|
|
245
253
|
});
|