@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/postinstall.js +146 -138
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igreen/design-system",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "iGreen Design System - Complete Package with Auto-Setup",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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
- input: process.stdin,
15
- output: process.stdout
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
- const cwd = process.cwd();
21
- // Se estamos em node_modules/@igreen/design-system, o projeto está 3 níveis acima
22
- if (cwd.includes('node_modules')) {
23
- return true;
24
- }
25
- return false;
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
- const cwd = process.cwd();
30
- // Voltar 3 níveis: node_modules/@igreen/design-system -> root
31
- if (cwd.includes(path.join('node_modules', '@igreen', 'design-system'))) {
32
- return path.resolve(cwd, '..', '..', '..');
33
- }
34
- return cwd;
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
- console.log('\n🎨 iGreen Design System Setup\n');
48
+ console.log('\n🎨 iGreen Design System Setup\n');
41
49
 
42
- // Verificar se está sendo instalado em um projeto
43
- if (!isInstallingInProject()) {
44
- console.log('ℹ️ Instalação detectada no próprio repositório iGreen, pulando setup automático.\n');
45
- rl.close();
46
- return;
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
- const projectRoot = getProjectRoot();
57
+ const projectRoot = getProjectRoot();
50
58
 
51
- // Verificar se já foi configurado antes
52
- const igreenConfigPath = path.join(projectRoot, '.igreen-configured');
53
- if (fs.existsSync(igreenConfigPath)) {
54
- console.log('✅ Projeto já configurado anteriormente.\n');
55
- console.log('💡 Para reconfigurar, delete o arquivo .igreen-configured e reinstale.\n');
56
- rl.close();
57
- return;
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
- console.log('🚀 Vamos configurar seu projeto iGreen!\n');
68
+ console.log('🚀 Vamos configurar seu projeto iGreen!\n');
61
69
 
62
- // 1. Perguntar se quer configuração automática
63
- const autoSetup = await question('Deseja configurar automaticamente? (S/n): ');
64
- if (autoSetup.toLowerCase() === 'n') {
65
- console.log('\n📚 Configuração manual: https://github.com/seu-repo/docs\n');
66
- rl.close();
67
- return;
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
- // 2. Escolher tema
71
- console.log('\n📦 Temas disponíveis:');
72
- console.log(' 1. igreen (padrão verde)');
73
- console.log(' 2. solarorange (laranja vibrante)\n');
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
- const themeChoice = await question('Escolha o tema (1-2) [1]: ');
76
- const theme = themeChoice === '2' ? 'solarorange' : 'igreen';
83
+ const themeChoice = await question('Escolha o tema (1-2) [1]: ');
84
+ const theme = themeChoice === '2' ? 'solarorange' : 'igreen';
77
85
 
78
- // 3. Criar estrutura de pastas
79
- console.log('\n📁 Criando estrutura de pastas...');
86
+ // 3. Criar estrutura de pastas
87
+ console.log('\n📁 Criando estrutura de pastas...');
80
88
 
81
- const appDir = path.join(projectRoot, 'app');
82
- const componentsDir = path.join(projectRoot, 'components');
83
- const libDir = path.join(projectRoot, 'lib');
89
+ const appDir = path.join(projectRoot, 'app');
90
+ const componentsDir = path.join(projectRoot, 'components');
91
+ const libDir = path.join(projectRoot, 'lib');
84
92
 
85
- [appDir, componentsDir, libDir].forEach(dir => {
86
- if (!fs.existsSync(dir)) {
87
- fs.mkdirSync(dir, { recursive: true });
88
- console.log(` ✅ ${path.relative(projectRoot, dir)}/`);
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
- // 4. Criar globals.css
93
- console.log('\n🎨 Configurando globals.css...');
94
- const globalsCss = `@import 'tailwindcss';
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
- fs.writeFileSync(path.join(appDir, 'globals.css'), globalsCss);
101
- console.log(' ✅ app/globals.css');
108
+ fs.writeFileSync(path.join(appDir, 'globals.css'), globalsCss);
109
+ console.log(' ✅ app/globals.css');
102
110
 
103
- // 5. Criar layout.tsx
104
- console.log(' Configurando layout.tsx...');
105
- const layoutContent = `import '@igreen/themes/${theme}'
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
- fs.writeFileSync(path.join(appDir, 'layout.tsx'), layoutContent);
128
- console.log(' ✅ app/layout.tsx');
135
+ fs.writeFileSync(path.join(appDir, 'layout.tsx'), layoutContent);
136
+ console.log(' ✅ app/layout.tsx');
129
137
 
130
- // 6. Criar page.tsx exemplo
131
- console.log(' Criando página de exemplo...');
132
- const pageContent = `import { Button } from '@igreen/button'
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
- fs.writeFileSync(path.join(appDir, 'page.tsx'), pageContent);
162
- console.log(' ✅ app/page.tsx');
169
+ fs.writeFileSync(path.join(appDir, 'page.tsx'), pageContent);
170
+ console.log(' ✅ app/page.tsx');
163
171
 
164
- // 7. Criar lib/utils.ts
165
- console.log(' Configurando utilitários...');
166
- const utilsContent = `export { cn } from '@igreen/utils'
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
- fs.writeFileSync(path.join(libDir, 'utils.ts'), utilsContent);
170
- console.log(' ✅ lib/utils.ts');
177
+ fs.writeFileSync(path.join(libDir, 'utils.ts'), utilsContent);
178
+ console.log(' ✅ lib/utils.ts');
171
179
 
172
- // 8. Verificar/Criar postcss.config.mjs
173
- console.log('\n⚙️ Configurando PostCSS...');
174
- const postcssConfig = path.join(projectRoot, 'postcss.config.mjs');
175
- if (!fs.existsSync(postcssConfig)) {
176
- const postcssContent = `export default {
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
- fs.writeFileSync(postcssConfig, postcssContent);
183
- console.log(' ✅ postcss.config.mjs');
184
- } else {
185
- console.log(' ⏭️ postcss.config.mjs já existe');
186
- }
187
-
188
- // 9. Atualizar package.json scripts (se possível)
189
- console.log('\n📦 Verificando scripts...');
190
- const packageJsonPath = path.join(projectRoot, 'package.json');
191
- if (fs.existsSync(packageJsonPath)) {
192
- try {
193
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
194
-
195
- if (!packageJson.scripts) {
196
- packageJson.scripts = {};
197
- }
198
-
199
- if (!packageJson.scripts.dev) {
200
- packageJson.scripts.dev = 'next dev';
201
- packageJson.scripts.build = 'next build';
202
- packageJson.scripts.start = 'next start';
203
-
204
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
205
- console.log(' ✅ Scripts adicionados ao package.json');
206
- }
207
- } catch (e) {
208
- console.log(' ⚠️ Não foi possível atualizar package.json automaticamente');
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
- // 10. Marcar como configurado
213
- fs.writeFileSync(igreenConfigPath, `Configured at: ${new Date().toISOString()}\nTheme: ${theme}\n`);
214
-
215
- // 11. Mostrar próximos passos
216
- console.log('\n' + '='.repeat(60));
217
- console.log('🎉 Projeto configurado com sucesso!');
218
- console.log('='.repeat(60));
219
- console.log(`\n📦 Tema instalado: ${theme}`);
220
- console.log('\n📝 Próximos passos:\n');
221
- console.log(' 1. Instale as dependências do Next.js:');
222
- console.log(' npm install next@latest react@latest react-dom@latest');
223
- console.log('');
224
- console.log(' 2. Instale o Tailwind CSS v4:');
225
- console.log(' npm install tailwindcss@next @tailwindcss/postcss@next');
226
- console.log('');
227
- console.log(' 3. Inicie o servidor de desenvolvimento:');
228
- console.log(' npm run dev');
229
- console.log('');
230
- console.log(' 4. Abra http://localhost:3000\n');
231
- console.log('📚 Documentação: https://github.com/seu-repo/docs');
232
- console.log('💚 Componentes disponíveis:');
233
- console.log(' - Button, Input, Label, Checkbox, ExampleCard\n');
234
- console.log('='.repeat(60) + '\n');
235
-
236
- rl.close();
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
- console.error('\n❌ Erro durante configuração:', error.message);
242
- console.log('\n📚 Para configuração manual: https://github.com/seu-repo/docs\n');
243
- rl.close();
244
- process.exit(0); // Não falhar a instalação
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
  });