web-architect-cli 1.0.0 → 1.0.1

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/bin/index.js CHANGED
@@ -1,26 +1,75 @@
1
- #!/usr/bin/env node
2
-
3
1
  const fs = require('fs');
4
2
  const path = require('path');
5
3
  const { execSync } = require('child_process');
6
4
  const readline = require('readline');
7
5
 
8
- // --- CONFIGURAÇÕES VISUAIS ---
9
- const CORES = {
10
- reset: "\x1b[0m",
11
- bright: "\x1b[1m",
12
- green: "\x1b[32m",
13
- yellow: "\x1b[33m",
14
- cyan: "\x1b[36m",
15
- red: "\x1b[31m"
16
- };
17
-
18
6
  const rl = readline.createInterface({
19
7
  input: process.stdin,
20
8
  output: process.stdout
21
9
  });
22
10
 
23
- // --- TEMPLATES (CONTEÚDO DOS ARQUIVOS) ---
11
+ // --- 1. DEFINIÇÃO DOS CONTEÚDOS DOS ARQUIVOS ---
12
+
13
+ const CONTEUDO_INDEX_JSP = `<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored ="false"%>
14
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
15
+ <%@ page import="java.util.*" %>
16
+ <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
17
+ <%@ taglib prefix="snk" uri="/WEB-INF/tld/sankhyaUtil.tld" %>
18
+ <html>
19
+ <head>
20
+ <meta charset="UTF-8">
21
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
22
+ <title>Meu modelo</title>
23
+ <script src="\${BASE_FOLDER}/src/assets/js/tailwindcss.js"></script>
24
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
25
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
26
+ <link rel="stylesheet" href="\${BASE_FOLDER}/src/assets/css/style.css">
27
+
28
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@jtandrelevicius/utils-js-library@latest/index.js"></script>
29
+ <snk:load/>
30
+ </head>
31
+ <body>
32
+
33
+ <header class="header">
34
+
35
+ </header>
36
+
37
+ <main class="main">
38
+
39
+ </main>
40
+
41
+ <script type="module" src="\${BASE_FOLDER}/src/main.js"></script>
42
+ </body>
43
+ </html>`;
44
+
45
+ const CONTEUDO_INDEX_HTML = `<!DOCTYPE html>
46
+ <html lang="pt-PT">
47
+ <head>
48
+ <meta charset="UTF-8">
49
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
50
+ <title>Meu modelo</title>
51
+
52
+ <script src="src/assets/js/tailwindcss.js"></script>
53
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
54
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
55
+ <link rel="stylesheet" href="./src/assets/css/style.css">
56
+
57
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@jtandrelevicius/utils-js-library@latest/index.js"></script>
58
+ <body>
59
+
60
+ <header class="header">
61
+
62
+ </header>
63
+
64
+ <main class="main">
65
+
66
+ </main>
67
+
68
+
69
+ <script type="module" src="src/main.js"></script>
70
+
71
+ </body>
72
+ </html>`;
24
73
 
25
74
  const CONTEUDO_BUILD_JS = `const fs = require('fs');
26
75
  const archiver = require('archiver');
@@ -28,7 +77,7 @@ const path = require('path');
28
77
 
29
78
  const CONFIG = {
30
79
  MODO_AUTOMATICO: true,
31
- NOME_ZIP: 'release-pacote.zip',
80
+ NOME_ZIP: 'projeto.zip',
32
81
  ITENS: [
33
82
  { type: 'file', path: 'index.jsp', name: 'index.jsp' },
34
83
  { type: 'file', path: 'index.html', name: 'index.html' },
@@ -41,18 +90,18 @@ let isBuilding = false;
41
90
  function gerarZip() {
42
91
  if (isBuilding) return;
43
92
  isBuilding = true;
44
- console.log('[Build] 📦 Compactando arquivos...');
93
+ console.log('📦 [Build] Compactando arquivos...');
45
94
 
46
95
  const output = fs.createWriteStream(path.join(__dirname, CONFIG.NOME_ZIP));
47
96
  const archive = archiver('zip', { zlib: { level: 9 } });
48
97
 
49
98
  output.on('close', function() {
50
- console.log(\`[Build] Sucesso! '\${CONFIG.NOME_ZIP}' (\${(archive.pointer() / 1024).toFixed(2)} KB)\`);
99
+ console.log(\`✅ [Build] Sucesso! '\${CONFIG.NOME_ZIP}' criado (\${(archive.pointer() / 1024).toFixed(2)} KB)\`);
51
100
  isBuilding = false;
52
101
  });
53
102
 
54
103
  archive.on('error', function(err) {
55
- console.error('[Build] Erro:', err);
104
+ console.error('[Build] Erro:', err);
56
105
  isBuilding = false;
57
106
  });
58
107
 
@@ -72,7 +121,7 @@ function gerarZip() {
72
121
  gerarZip();
73
122
 
74
123
  if (CONFIG.MODO_AUTOMATICO) {
75
- console.log('[Build] 👀 Monitorando alterações...');
124
+ console.log('👀 [Build] Monitorando alterações...');
76
125
  let debounceTimeout;
77
126
  const pathsToWatch = CONFIG.ITENS.map(i => i.path).filter(p => fs.existsSync(p));
78
127
 
@@ -81,7 +130,7 @@ if (CONFIG.MODO_AUTOMATICO) {
81
130
  if (filename && !filename.includes(CONFIG.NOME_ZIP)) {
82
131
  clearTimeout(debounceTimeout);
83
132
  debounceTimeout = setTimeout(() => {
84
- console.log(\`[Build] 📝 Alteração: \${filename}\`);
133
+ console.log(\`📝 Alteração detectada: \${filename}\`);
85
134
  gerarZip();
86
135
  }, 500);
87
136
  }
@@ -90,107 +139,134 @@ if (CONFIG.MODO_AUTOMATICO) {
90
139
  }
91
140
  `;
92
141
 
93
- const CONTEUDO_GITIGNORE = `node_modules/\n*.zip\n.DS_Store`;
94
- const CONTEUDO_INDEX_JSP = `<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>\n<!DOCTYPE html>\n<html>\n<head><title>App</title></head>\n<body>\n<h1>App Iniciado</h1>\n<script src="src/main.js"></script>\n</body>\n</html>`;
142
+ const CONTEUDO_GITIGNORE = `node_modules/
143
+ *.zip
144
+ .DS_Store
145
+ `;
146
+
147
+ const CONTEUDO_GITATTRIBUTES = `* text=auto`;
95
148
 
96
- // --- FUNÇÕES UTILITÁRIAS ---
149
+ // --- 2. FUNÇÕES DO SISTEMA ---
150
+
151
+ const logPasso = (emoji, msg) => console.log(`${emoji} ${msg}`);
97
152
 
98
153
  function criarPasta(caminho) {
99
- if (!fs.existsSync(caminho)) fs.mkdirSync(caminho, { recursive: true });
154
+ if (!fs.existsSync(caminho)) {
155
+ fs.mkdirSync(caminho, { recursive: true });
156
+ logPasso('📂', `Pasta criada: ${caminho}`);
157
+ } else {
158
+ logPasso('⚠️', `Pasta já existe: ${caminho}`);
159
+ }
100
160
  }
101
161
 
102
162
  function criarArquivo(caminho, conteudo) {
103
163
  fs.writeFileSync(caminho, conteudo);
164
+ logPasso('📄', `Arquivo criado: ${caminho}`);
104
165
  }
105
166
 
106
- const pergunta = (texto) => new Promise(resolve => rl.question(`${CORES.cyan}${texto}${CORES.reset}`, resolve));
107
-
108
- // --- LÓGICA PRINCIPAL ---
109
-
110
- async function iniciar() {
111
- console.clear();
112
- console.log(`${CORES.bright}${CORES.green}=========================================${CORES.reset}`);
113
- console.log(`${CORES.bright}${CORES.green} 🏗️ WEB ARCHITECT CLI - Novo Projeto ${CORES.reset}`);
114
- console.log(`${CORES.bright}${CORES.green}=========================================${CORES.reset}\n`);
115
-
116
- // Pega o nome do argumento (ex: web-arch meu-projeto) ou pergunta
117
- let nomeProjeto = process.argv[2];
118
-
119
- if (!nomeProjeto) {
120
- nomeProjeto = await pergunta("? Nome do projeto (sem espaços): ");
121
- }
167
+ // --- 3. EXECUÇÃO PRINCIPAL ---
122
168
 
169
+ rl.question('🚀 Digite o nome do projeto: ', (nomeProjeto) => {
123
170
  if (!nomeProjeto) {
124
- console.log(`${CORES.red}❌ Nome inválido. Encerrando.${CORES.reset}`);
171
+ console.log('❌ Nome inválido.');
125
172
  rl.close();
126
173
  return;
127
174
  }
128
175
 
129
176
  const raiz = path.join(process.cwd(), nomeProjeto);
130
177
 
178
+ console.log(`\n---------------------------------------------------`);
179
+ console.log(`🔨 INICIANDO CRIAÇÃO DO PROJETO: ${nomeProjeto}`);
180
+ console.log(`---------------------------------------------------\n`);
181
+
182
+ // 1. Criar Pasta Raiz
131
183
  if (fs.existsSync(raiz)) {
132
- console.log(`${CORES.red}❌ Erro: A pasta '${nomeProjeto}' já existe.${CORES.reset}`);
184
+ console.log(`❌ A pasta '${nomeProjeto}' já existe.`);
133
185
  rl.close();
134
186
  return;
135
187
  }
136
-
137
- console.log(`\n${CORES.yellow}📂 Criando estrutura em: ${raiz}...${CORES.reset}`);
138
-
139
- // 1. Cria a Pasta Raiz
140
188
  criarPasta(raiz);
141
189
 
142
- // 2. Estrutura de Pastas baseada nas suas imagens
190
+ // 2. Criar Estrutura de Pastas
143
191
  const pastas = [
144
- 'src/assets/css', //
145
- 'src/assets/img', //
146
- 'src/assets/js', //
147
- 'src/components', //
148
- 'src/controllers', //
149
- 'src/models', //
150
- 'src/utils', //
151
- 'src/views' //
192
+ 'src/assets/css',
193
+ 'src/assets/img',
194
+ 'src/assets/js',
195
+ 'src/components',
196
+ 'src/controllers',
197
+ 'src/models',
198
+ 'src/utils',
199
+ 'src/views'
152
200
  ];
153
201
 
154
202
  pastas.forEach(p => criarPasta(path.join(raiz, p)));
155
203
 
156
- // 3. Arquivos Principais
204
+ // 3. Criar Arquivos de Configuração e Raiz
205
+ criarArquivo(path.join(raiz, 'index.jsp'), CONTEUDO_INDEX_JSP);
206
+ criarArquivo(path.join(raiz, 'index.html'), CONTEUDO_INDEX_HTML);
157
207
  criarArquivo(path.join(raiz, 'build.js'), CONTEUDO_BUILD_JS);
158
208
  criarArquivo(path.join(raiz, '.gitignore'), CONTEUDO_GITIGNORE);
159
- criarArquivo(path.join(raiz, 'index.jsp'), CONTEUDO_INDEX_JSP); //
160
- criarArquivo(path.join(raiz, 'index.html'), '');
161
- criarArquivo(path.join(raiz, 'README.md'), `# ${nomeProjeto}`);
162
- criarArquivo(path.join(raiz, 'src/main.js'), `console.log('App ready');`);
163
- criarArquivo(path.join(raiz, '.gitattributes'), '* text=auto');
209
+ criarArquivo(path.join(raiz, '.gitattributes'), CONTEUDO_GITATTRIBUTES);
210
+ criarArquivo(path.join(raiz, 'README.md'), `# ${nomeProjeto}\n\nProjeto gerado automaticamente.`);
164
211
 
165
- // 4. Package.json do projeto gerado
212
+ // 4. Criar Package.json
166
213
  const packageJson = {
167
214
  name: nomeProjeto,
168
215
  version: "1.0.0",
216
+ description: "",
169
217
  main: "src/main.js",
170
218
  scripts: {
171
- "start": "node build.js",
172
- "build": "node build.js"
219
+ "build": "node build.js",
220
+ "start": "node build.js"
173
221
  },
222
+ author: "",
174
223
  license: "ISC"
175
224
  };
176
225
  criarArquivo(path.join(raiz, 'package.json'), JSON.stringify(packageJson, null, 2));
177
226
 
178
- // 5. Instalação e Git
227
+ // 5. Criar Arquivos dentro de SRC
228
+ criarArquivo(path.join(raiz, 'src/main.js'), `console.log('Aplicação iniciada');`);
229
+
230
+ // 6. Criar Arquivos dentro de ASSETS (CSS)
231
+ criarArquivo(path.join(raiz, 'src/assets/css/style.css'), `/* Estilos Globais */\nbody { font-family: 'Inter', sans-serif; }`);
232
+
233
+ // --- LÓGICA DE CÓPIA DO TAILWIND ---
234
+ const origemTailwind = path.join(__dirname, 'tailwindcss.js');
235
+ const destinoTailwind = path.join(raiz, 'src/assets/js/tailwindcss.js');
236
+
237
+ if (fs.existsSync(origemTailwind)) {
238
+ try {
239
+ fs.copyFileSync(origemTailwind, destinoTailwind);
240
+ logPasso('📄', `Arquivo copiado: ${destinoTailwind}`);
241
+ } catch (err) {
242
+ console.error('❌ Erro ao copiar tailwindcss.js:', err.message);
243
+ }
244
+ } else {
245
+ console.log('⚠️ AVISO: O arquivo "tailwindcss.js" não foi encontrado na mesma pasta deste script.');
246
+ console.log(' Ele não foi copiado para o novo projeto.');
247
+ }
248
+
249
+ console.log(`\n---------------------------------------------------`);
250
+ console.log(`⚙️ EXECUTANDO CONFIGURAÇÕES DE AMBIENTE`);
251
+ console.log(`---------------------------------------------------\n`);
252
+
179
253
  try {
180
- console.log(`${CORES.cyan}📦 Inicializando Git e Instalando Dependências...${CORES.reset}`);
181
-
182
- execSync('git init', { cwd: raiz, stdio: 'ignore' });
183
- execSync('npm install archiver', { cwd: raiz, stdio: 'ignore' });
254
+ // 7. Inicializar GIT
255
+ logPasso('GitHub', '📦 Inicializando repositório Git...');
256
+ execSync('git init', { cwd: raiz, stdio: 'inherit' });
257
+
258
+ // 8. Instalar Dependências (Archiver)
259
+ logPasso('NPM', ' 📦 Instalando dependência: archiver...');
260
+ execSync('npm install archiver', { cwd: raiz, stdio: 'inherit' });
184
261
 
185
- console.log(`\n${CORES.green}✅ PROJETO ${nomeProjeto} CRIADO COM SUCESSO!${CORES.reset}`);
186
- console.log(`\n👉 Próximos passos:`);
262
+ console.log(`\n✅ PROJETO CRIADO COM SUCESSO!\n`);
263
+ console.log(`👉 Próximos passos:`);
187
264
  console.log(` cd ${nomeProjeto}`);
188
- console.log(` npm start`);
265
+ console.log(` npm start (Para rodar o build automático)`);
266
+
189
267
  } catch (error) {
190
- console.error(`${CORES.red}❌ Erro na configuração: ${error.message}${CORES.reset}`);
268
+ console.error("❌ Erro ao executar comandos do sistema:", error.message);
191
269
  }
192
270
 
193
271
  rl.close();
194
- }
195
-
196
- iniciar();
272
+ });