web-architect-cli 1.0.0

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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # web-architect-cli
2
+
package/bin/index.js ADDED
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { execSync } = require('child_process');
6
+ const readline = require('readline');
7
+
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
+ const rl = readline.createInterface({
19
+ input: process.stdin,
20
+ output: process.stdout
21
+ });
22
+
23
+ // --- TEMPLATES (CONTEÚDO DOS ARQUIVOS) ---
24
+
25
+ const CONTEUDO_BUILD_JS = `const fs = require('fs');
26
+ const archiver = require('archiver');
27
+ const path = require('path');
28
+
29
+ const CONFIG = {
30
+ MODO_AUTOMATICO: true,
31
+ NOME_ZIP: 'release-pacote.zip',
32
+ ITENS: [
33
+ { type: 'file', path: 'index.jsp', name: 'index.jsp' },
34
+ { type: 'file', path: 'index.html', name: 'index.html' },
35
+ { type: 'directory', path: 'src/', name: 'src' }
36
+ ]
37
+ };
38
+
39
+ let isBuilding = false;
40
+
41
+ function gerarZip() {
42
+ if (isBuilding) return;
43
+ isBuilding = true;
44
+ console.log('[Build] 📦 Compactando arquivos...');
45
+
46
+ const output = fs.createWriteStream(path.join(__dirname, CONFIG.NOME_ZIP));
47
+ const archive = archiver('zip', { zlib: { level: 9 } });
48
+
49
+ output.on('close', function() {
50
+ console.log(\`[Build] ✅ Sucesso! '\${CONFIG.NOME_ZIP}' (\${(archive.pointer() / 1024).toFixed(2)} KB)\`);
51
+ isBuilding = false;
52
+ });
53
+
54
+ archive.on('error', function(err) {
55
+ console.error('[Build] ❌ Erro:', err);
56
+ isBuilding = false;
57
+ });
58
+
59
+ archive.pipe(output);
60
+
61
+ CONFIG.ITENS.forEach(item => {
62
+ if (item.type === 'file') {
63
+ if (fs.existsSync(item.path)) archive.file(item.path, { name: item.name });
64
+ } else if (item.type === 'directory') {
65
+ if (fs.existsSync(item.path)) archive.directory(item.path, item.name);
66
+ }
67
+ });
68
+
69
+ archive.finalize();
70
+ }
71
+
72
+ gerarZip();
73
+
74
+ if (CONFIG.MODO_AUTOMATICO) {
75
+ console.log('[Build] 👀 Monitorando alterações...');
76
+ let debounceTimeout;
77
+ const pathsToWatch = CONFIG.ITENS.map(i => i.path).filter(p => fs.existsSync(p));
78
+
79
+ pathsToWatch.forEach(targetPath => {
80
+ fs.watch(targetPath, { recursive: true }, (eventType, filename) => {
81
+ if (filename && !filename.includes(CONFIG.NOME_ZIP)) {
82
+ clearTimeout(debounceTimeout);
83
+ debounceTimeout = setTimeout(() => {
84
+ console.log(\`[Build] 📝 Alteração: \${filename}\`);
85
+ gerarZip();
86
+ }, 500);
87
+ }
88
+ });
89
+ });
90
+ }
91
+ `;
92
+
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>`;
95
+
96
+ // --- FUNÇÕES UTILITÁRIAS ---
97
+
98
+ function criarPasta(caminho) {
99
+ if (!fs.existsSync(caminho)) fs.mkdirSync(caminho, { recursive: true });
100
+ }
101
+
102
+ function criarArquivo(caminho, conteudo) {
103
+ fs.writeFileSync(caminho, conteudo);
104
+ }
105
+
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
+ }
122
+
123
+ if (!nomeProjeto) {
124
+ console.log(`${CORES.red}❌ Nome inválido. Encerrando.${CORES.reset}`);
125
+ rl.close();
126
+ return;
127
+ }
128
+
129
+ const raiz = path.join(process.cwd(), nomeProjeto);
130
+
131
+ if (fs.existsSync(raiz)) {
132
+ console.log(`${CORES.red}❌ Erro: A pasta '${nomeProjeto}' já existe.${CORES.reset}`);
133
+ rl.close();
134
+ return;
135
+ }
136
+
137
+ console.log(`\n${CORES.yellow}📂 Criando estrutura em: ${raiz}...${CORES.reset}`);
138
+
139
+ // 1. Cria a Pasta Raiz
140
+ criarPasta(raiz);
141
+
142
+ // 2. Estrutura de Pastas baseada nas suas imagens
143
+ 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' //
152
+ ];
153
+
154
+ pastas.forEach(p => criarPasta(path.join(raiz, p)));
155
+
156
+ // 3. Arquivos Principais
157
+ criarArquivo(path.join(raiz, 'build.js'), CONTEUDO_BUILD_JS);
158
+ 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');
164
+
165
+ // 4. Package.json do projeto gerado
166
+ const packageJson = {
167
+ name: nomeProjeto,
168
+ version: "1.0.0",
169
+ main: "src/main.js",
170
+ scripts: {
171
+ "start": "node build.js",
172
+ "build": "node build.js"
173
+ },
174
+ license: "ISC"
175
+ };
176
+ criarArquivo(path.join(raiz, 'package.json'), JSON.stringify(packageJson, null, 2));
177
+
178
+ // 5. Instalação e Git
179
+ 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' });
184
+
185
+ console.log(`\n${CORES.green}✅ PROJETO ${nomeProjeto} CRIADO COM SUCESSO!${CORES.reset}`);
186
+ console.log(`\n👉 Próximos passos:`);
187
+ console.log(` cd ${nomeProjeto}`);
188
+ console.log(` npm start`);
189
+ } catch (error) {
190
+ console.error(`${CORES.red}❌ Erro na configuração: ${error.message}${CORES.reset}`);
191
+ }
192
+
193
+ rl.close();
194
+ }
195
+
196
+ iniciar();
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "web-architect-cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "web-arch": "bin/index.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/jtandrelevicius2/web-architect-cli.git"
15
+ },
16
+ "author": "Jeferson Tiago Alves Andrelevicius",
17
+ "license": "ISC",
18
+ "bugs": {
19
+ "url": "https://github.com/jtandrelevicius2/web-architect-cli/issues"
20
+ },
21
+ "homepage": "https://github.com/jtandrelevicius2/web-architect-cli#readme"
22
+ }