@igreen/design-system 1.0.2 → 1.0.4

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 +7 -6
  2. package/postinstall.js +245 -0
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@igreen/design-system",
3
- "version": "1.0.2",
4
- "description": "iGreen Design System - Complete Package",
3
+ "version": "1.0.4",
4
+ "description": "iGreen Design System - Complete Package with Auto-Setup",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "postinstall.js"
9
10
  ],
10
11
  "scripts": {
11
12
  "build": "tsc",
12
- "dev": "tsc --watch"
13
+ "dev": "tsc --watch",
14
+ "postinstall": "node postinstall.js"
13
15
  },
14
16
  "dependencies": {
15
17
  "@igreen/themes": "^1.2.0",
@@ -18,11 +20,10 @@
18
20
  "@igreen/checkbox": "^1.0.1",
19
21
  "@igreen/input": "^1.0.1",
20
22
  "@igreen/label": "^1.0.1",
21
- "@igreen/mode-toggle": "^1.0.1",
22
23
  "@igreen/example-card": "^2.1.0"
23
24
  },
24
25
  "publishConfig": {
25
26
  "access": "public",
26
27
  "registry": "https://registry.npmjs.org"
27
28
  }
28
- }
29
+ }
package/postinstall.js ADDED
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * iGreen Design System - Postinstall Setup
5
+ *
6
+ * Configura automaticamente o projeto após npm install
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const readline = require('readline');
12
+
13
+ const rl = readline.createInterface({
14
+ input: process.stdin,
15
+ output: process.stdout
16
+ });
17
+
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;
26
+ };
27
+
28
+ 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;
35
+ };
36
+
37
+ const question = (query) => new Promise((resolve) => rl.question(query, resolve));
38
+
39
+ async function setupProject() {
40
+ console.log('\n🎨 iGreen Design System Setup\n');
41
+
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
+ }
48
+
49
+ const projectRoot = getProjectRoot();
50
+
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
+
60
+ console.log('🚀 Vamos configurar seu projeto iGreen!\n');
61
+
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
+
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');
74
+
75
+ const themeChoice = await question('Escolha o tema (1-2) [1]: ');
76
+ const theme = themeChoice === '2' ? 'solarorange' : 'igreen';
77
+
78
+ // 3. Criar estrutura de pastas
79
+ console.log('\n📁 Criando estrutura de pastas...');
80
+
81
+ const appDir = path.join(projectRoot, 'app');
82
+ const componentsDir = path.join(projectRoot, 'components');
83
+ const libDir = path.join(projectRoot, 'lib');
84
+
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
+ });
91
+
92
+ // 4. Criar globals.css
93
+ console.log('\n🎨 Configurando globals.css...');
94
+ const globalsCss = `@import 'tailwindcss';
95
+
96
+ /* iGreen Design System está configurado! */
97
+ /* O tema ${theme} será carregado automaticamente no layout */
98
+ `;
99
+
100
+ fs.writeFileSync(path.join(appDir, 'globals.css'), globalsCss);
101
+ console.log(' ✅ app/globals.css');
102
+
103
+ // 5. Criar layout.tsx
104
+ console.log(' Configurando layout.tsx...');
105
+ const layoutContent = `import '@igreen/themes/${theme}'
106
+ import './globals.css'
107
+ import type { Metadata } from 'next'
108
+
109
+ export const metadata: Metadata = {
110
+ title: 'iGreen App',
111
+ description: 'Created with iGreen Design System',
112
+ }
113
+
114
+ export default function RootLayout({
115
+ children,
116
+ }: {
117
+ children: React.Node
118
+ }) {
119
+ return (
120
+ <html lang="pt-BR">
121
+ <body>{children}</body>
122
+ </html>
123
+ )
124
+ }
125
+ `;
126
+
127
+ fs.writeFileSync(path.join(appDir, 'layout.tsx'), layoutContent);
128
+ console.log(' ✅ app/layout.tsx');
129
+
130
+ // 6. Criar page.tsx exemplo
131
+ console.log(' Criando página de exemplo...');
132
+ const pageContent = `import { Button } from '@igreen/button'
133
+ import { Input } from '@igreen/input'
134
+ import { Label } from '@igreen/label'
135
+
136
+ export default function Home() {
137
+ return (
138
+ <main className="min-h-screen p-8">
139
+ <h1 className="text-3xl font-bold mb-8">
140
+ 🎨 iGreen Design System
141
+ </h1>
142
+
143
+ <div className="space-y-6 max-w-md">
144
+ <div>
145
+ <Label>Nome</Label>
146
+ <Input placeholder="Digite seu nome" />
147
+ </div>
148
+
149
+ <div>
150
+ <Label>Email</Label>
151
+ <Input type="email" placeholder="seu@email.com" />
152
+ </div>
153
+
154
+ <Button>Enviar</Button>
155
+ </div>
156
+ </main>
157
+ )
158
+ }
159
+ `;
160
+
161
+ fs.writeFileSync(path.join(appDir, 'page.tsx'), pageContent);
162
+ console.log(' ✅ app/page.tsx');
163
+
164
+ // 7. Criar lib/utils.ts
165
+ console.log(' Configurando utilitários...');
166
+ const utilsContent = `export { cn } from '@igreen/utils'
167
+ `;
168
+
169
+ fs.writeFileSync(path.join(libDir, 'utils.ts'), utilsContent);
170
+ console.log(' ✅ lib/utils.ts');
171
+
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 {
177
+ plugins: {
178
+ '@tailwindcss/postcss': {},
179
+ },
180
+ }
181
+ `;
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
+ }
210
+ }
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();
237
+ }
238
+
239
+ // Executar setup
240
+ 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
245
+ });