@igreen/design-system 1.0.4 → 1.0.6

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