web-architect-cli 1.1.0 → 1.1.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/README.md +0 -2
- package/bin/build.js +164 -0
- package/bin/index.js +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/bin/build.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const archiver = require('archiver');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
|
|
6
|
+
const IS_WINDOWS = process.platform === 'win32';
|
|
7
|
+
const currentDirName = path.basename(path.resolve(__dirname));
|
|
8
|
+
|
|
9
|
+
const CONFIG = {
|
|
10
|
+
MODO_AUTOMATICO: true,
|
|
11
|
+
NOME_ZIP: `${currentDirName}.zip`,
|
|
12
|
+
ENTRY_FILE: 'index.jsp',
|
|
13
|
+
SOURCE_DIR: 'src',
|
|
14
|
+
ITENS: [
|
|
15
|
+
{ type: 'file', path: 'index.jsp' },
|
|
16
|
+
{ type: 'directory', path: 'src/' }
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
let isBuilding = false;
|
|
21
|
+
let blockWatchEvents = false;
|
|
22
|
+
|
|
23
|
+
function gerarZip() {
|
|
24
|
+
if (isBuilding || blockWatchEvents) return;
|
|
25
|
+
|
|
26
|
+
isBuilding = true;
|
|
27
|
+
blockWatchEvents = true;
|
|
28
|
+
|
|
29
|
+
console.log(`\n🖥️ Sistema detectado: ${IS_WINDOWS ? 'WINDOWS' : 'LINUX/MAC'}`);
|
|
30
|
+
console.log('🚀 [Build] Iniciando processo...');
|
|
31
|
+
|
|
32
|
+
if (fs.existsSync('verify.js')) {
|
|
33
|
+
try {
|
|
34
|
+
execSync('node verify.js', { stdio: 'inherit' });
|
|
35
|
+
} catch (e) {
|
|
36
|
+
console.log('❌ Build cancelado: Erro na verificação.');
|
|
37
|
+
finalizarProcesso();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
if (fs.existsSync(CONFIG.NOME_ZIP)) {
|
|
44
|
+
fs.unlinkSync(CONFIG.NOME_ZIP);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (IS_WINDOWS) {
|
|
48
|
+
buildWindows();
|
|
49
|
+
} else {
|
|
50
|
+
buildLinux();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error('❌ Erro Fatal:', error);
|
|
55
|
+
finalizarProcesso();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function finalizarProcesso() {
|
|
60
|
+
isBuilding = false;
|
|
61
|
+
|
|
62
|
+
console.log('🛡️ Ignorando eventos pós-build por 3s...');
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
blockWatchEvents = false;
|
|
65
|
+
console.log('👀 Monitoramento reativado.');
|
|
66
|
+
}, 3000);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function buildLinux() {
|
|
70
|
+
console.log('🐧 [Linux] Ajustando permissões...');
|
|
71
|
+
|
|
72
|
+
if (fs.existsSync(CONFIG.SOURCE_DIR)) {
|
|
73
|
+
execSync(`chmod -R 777 "${CONFIG.SOURCE_DIR}"`);
|
|
74
|
+
}
|
|
75
|
+
if (fs.existsSync(CONFIG.ENTRY_FILE)) {
|
|
76
|
+
execSync(`chmod 777 "${CONFIG.ENTRY_FILE}"`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log('📦 [Linux] Compactando com ZIP nativo...');
|
|
80
|
+
|
|
81
|
+
const cmd = `zip -r "${CONFIG.NOME_ZIP}" "${CONFIG.ENTRY_FILE}" "${CONFIG.SOURCE_DIR}"`;
|
|
82
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
83
|
+
|
|
84
|
+
console.log(`✅ [Sucesso] Arquivo '${CONFIG.NOME_ZIP}' criado!`);
|
|
85
|
+
finalizarProcesso();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function buildWindows() {
|
|
89
|
+
console.log('🪟 [Windows] Compactando com Archiver...');
|
|
90
|
+
|
|
91
|
+
const output = fs.createWriteStream(path.join(__dirname, CONFIG.NOME_ZIP));
|
|
92
|
+
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
93
|
+
|
|
94
|
+
output.on('close', function() {
|
|
95
|
+
const size = (archive.pointer() / 1024).toFixed(2);
|
|
96
|
+
console.log(`✅ [Sucesso] '${CONFIG.NOME_ZIP}' criado (${size} KB)`);
|
|
97
|
+
finalizarProcesso();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
archive.on('error', function(err) {
|
|
101
|
+
throw err;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
archive.pipe(output);
|
|
105
|
+
|
|
106
|
+
if (fs.existsSync(CONFIG.ENTRY_FILE)) {
|
|
107
|
+
archive.file(CONFIG.ENTRY_FILE, { name: CONFIG.ENTRY_FILE, mode: 0o777, date: new Date() });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (fs.existsSync(CONFIG.SOURCE_DIR)) {
|
|
111
|
+
archive.glob('**/*', {
|
|
112
|
+
cwd: CONFIG.SOURCE_DIR,
|
|
113
|
+
ignore: ['.DS_Store', 'Thumbs.db']
|
|
114
|
+
}, {
|
|
115
|
+
prefix: CONFIG.SOURCE_DIR,
|
|
116
|
+
mode: 0o777,
|
|
117
|
+
date: new Date()
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
archive.finalize();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
gerarZip();
|
|
125
|
+
|
|
126
|
+
if (CONFIG.MODO_AUTOMATICO) {
|
|
127
|
+
console.log('\n👀 Monitorando alterações...');
|
|
128
|
+
|
|
129
|
+
let debounceTimer;
|
|
130
|
+
let pendingChanges = new Set();
|
|
131
|
+
|
|
132
|
+
const paths = CONFIG.ITENS.map(i => i.path).filter(p => fs.existsSync(p));
|
|
133
|
+
|
|
134
|
+
paths.forEach(p => {
|
|
135
|
+
fs.watch(p, { recursive: true }, (evt, filename) => {
|
|
136
|
+
|
|
137
|
+
if (blockWatchEvents || isBuilding) return;
|
|
138
|
+
|
|
139
|
+
if (filename && !filename.includes('.zip') && !filename.includes('.tmp')) {
|
|
140
|
+
|
|
141
|
+
pendingChanges.add(filename);
|
|
142
|
+
clearTimeout(debounceTimer);
|
|
143
|
+
|
|
144
|
+
debounceTimer = setTimeout(() => {
|
|
145
|
+
if (blockWatchEvents || isBuilding) return;
|
|
146
|
+
|
|
147
|
+
console.clear();
|
|
148
|
+
console.log('━'.repeat(50));
|
|
149
|
+
console.log(`📝 DETECTADAS ${pendingChanges.size} ALTERAÇÕES (Usuário):`);
|
|
150
|
+
console.log('━'.repeat(50));
|
|
151
|
+
|
|
152
|
+
pendingChanges.forEach(file => {
|
|
153
|
+
console.log(` • ${file}`);
|
|
154
|
+
});
|
|
155
|
+
console.log('━'.repeat(50));
|
|
156
|
+
|
|
157
|
+
pendingChanges.clear();
|
|
158
|
+
gerarZip();
|
|
159
|
+
|
|
160
|
+
}, 1500);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
package/bin/index.js
CHANGED
|
@@ -404,7 +404,7 @@ function criarProjetoHTML5(raiz, nomeProjeto) {
|
|
|
404
404
|
|
|
405
405
|
criarArquivo(path.join(raiz, 'index.jsp'), CONTEUDO_INDEX_JSP);
|
|
406
406
|
criarArquivo(path.join(raiz, 'index.html'), CONTEUDO_INDEX_HTML);
|
|
407
|
-
criarArquivo(path.join(raiz, 'build.js'), CONTEUDO_BUILD_JS);
|
|
407
|
+
//criarArquivo(path.join(raiz, 'build.js'), CONTEUDO_BUILD_JS);
|
|
408
408
|
criarArquivo(path.join(raiz, 'commit.js'), CONTEUDO_COMMIT_JS);
|
|
409
409
|
criarArquivo(path.join(raiz, 'verify.js'), CONTEUDO_VERIFY_JS);
|
|
410
410
|
criarArquivo(path.join(raiz, 'eslint.config.js'), CONTEUDO_ESLINT);
|
|
@@ -437,6 +437,17 @@ function criarProjetoHTML5(raiz, nomeProjeto) {
|
|
|
437
437
|
logPasso('📄', `Tailwind copiado.`);
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
const origemBuild = path.join(__dirname, 'build.js');
|
|
441
|
+
const destinoBuild = path.join(raiz, 'build.js');
|
|
442
|
+
|
|
443
|
+
if (fs.existsSync(origemBuild)) {
|
|
444
|
+
fs.copyFileSync(origemBuild, destinoBuild);
|
|
445
|
+
console.log('📄 Arquivo build.js (Híbrido) copiado com sucesso.');
|
|
446
|
+
} else {
|
|
447
|
+
console.error('❌ ERRO: O arquivo build.js não foi encontrado na pasta do gerador!');
|
|
448
|
+
criarArquivo(path.join(raiz, 'build.js'), '// ERRO: modelo-build.js não encontrado.');
|
|
449
|
+
}
|
|
450
|
+
|
|
440
451
|
console.log(`\n⚙️ CONFIGURANDO AMBIENTE WEB...`);
|
|
441
452
|
try {
|
|
442
453
|
logPasso('Git', 'Inicializando repositório...');
|