web-architect-cli 1.0.0 → 1.0.2

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