web-architect-cli 1.1.0 → 1.1.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/README.md +0 -2
- package/bin/build.js +137 -0
- package/bin/index.js +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/bin/build.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
|
|
8
|
+
const currentDirName = path.basename(path.resolve(__dirname));
|
|
9
|
+
|
|
10
|
+
const CONFIG = {
|
|
11
|
+
MODO_AUTOMATICO: true,
|
|
12
|
+
NOME_ZIP: `${currentDirName}.zip`,
|
|
13
|
+
ENTRY_FILE: 'index.jsp',
|
|
14
|
+
SOURCE_DIR: 'src',
|
|
15
|
+
ITENS: [
|
|
16
|
+
{ type: 'file', path: 'index.jsp' },
|
|
17
|
+
{ type: 'directory', path: 'src/' }
|
|
18
|
+
]
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let isBuilding = false;
|
|
22
|
+
|
|
23
|
+
function gerarZip() {
|
|
24
|
+
if (isBuilding) return;
|
|
25
|
+
isBuilding = true;
|
|
26
|
+
|
|
27
|
+
console.clear();
|
|
28
|
+
console.log(`🖥️ Sistema detectado: ${IS_WINDOWS ? 'WINDOWS' : 'LINUX/MAC'}`);
|
|
29
|
+
console.log('🚀 [Build] Iniciando processo...');
|
|
30
|
+
|
|
31
|
+
if (fs.existsSync('verify.js')) {
|
|
32
|
+
try {
|
|
33
|
+
execSync('node verify.js', { stdio: 'inherit' });
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.log('❌ Build cancelado: Erro na verificação.');
|
|
36
|
+
isBuilding = false;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
if (fs.existsSync(CONFIG.NOME_ZIP)) {
|
|
43
|
+
fs.unlinkSync(CONFIG.NOME_ZIP);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (IS_WINDOWS) {
|
|
47
|
+
buildWindows();
|
|
48
|
+
} else {
|
|
49
|
+
buildLinux();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('❌ Erro Fatal:', error);
|
|
54
|
+
isBuilding = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function buildLinux() {
|
|
59
|
+
console.log('🐧 [Linux] Ajustando permissões...');
|
|
60
|
+
|
|
61
|
+
if (fs.existsSync(CONFIG.SOURCE_DIR)) {
|
|
62
|
+
execSync(`chmod -R 777 "${CONFIG.SOURCE_DIR}"`);
|
|
63
|
+
}
|
|
64
|
+
if (fs.existsSync(CONFIG.ENTRY_FILE)) {
|
|
65
|
+
execSync(`chmod 777 "${CONFIG.ENTRY_FILE}"`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log('📦 [Linux] Compactando com ZIP nativo...');
|
|
69
|
+
|
|
70
|
+
const cmd = `zip -r "${CONFIG.NOME_ZIP}" "${CONFIG.ENTRY_FILE}" "${CONFIG.SOURCE_DIR}"`;
|
|
71
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
72
|
+
|
|
73
|
+
console.log(`✅ [Sucesso] Arquivo '${CONFIG.NOME_ZIP}' criado com permissões!`);
|
|
74
|
+
isBuilding = false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
function buildWindows() {
|
|
79
|
+
console.log('🪟 [Windows] Compactando com Archiver...');
|
|
80
|
+
|
|
81
|
+
const output = fs.createWriteStream(path.join(__dirname, CONFIG.NOME_ZIP));
|
|
82
|
+
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
83
|
+
|
|
84
|
+
output.on('close', function() {
|
|
85
|
+
const size = (archive.pointer() / 1024).toFixed(2);
|
|
86
|
+
console.log(`✅ [Sucesso] '${CONFIG.NOME_ZIP}' criado (${size} KB)`);
|
|
87
|
+
isBuilding = false;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
archive.on('error', function(err) {
|
|
91
|
+
throw err;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
archive.pipe(output);
|
|
95
|
+
|
|
96
|
+
if (fs.existsSync(CONFIG.ENTRY_FILE)) {
|
|
97
|
+
archive.file(CONFIG.ENTRY_FILE, {
|
|
98
|
+
name: CONFIG.ENTRY_FILE,
|
|
99
|
+
mode: 0o777,
|
|
100
|
+
date: new Date()
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (fs.existsSync(CONFIG.SOURCE_DIR)) {
|
|
105
|
+
archive.glob('**/*', {
|
|
106
|
+
cwd: CONFIG.SOURCE_DIR,
|
|
107
|
+
ignore: ['.DS_Store', 'Thumbs.db']
|
|
108
|
+
}, {
|
|
109
|
+
prefix: CONFIG.SOURCE_DIR,
|
|
110
|
+
mode: 0o777,
|
|
111
|
+
date: new Date()
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
archive.finalize();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
gerarZip();
|
|
119
|
+
|
|
120
|
+
if (CONFIG.MODO_AUTOMATICO) {
|
|
121
|
+
console.log('\n👀 Monitorando alterações...');
|
|
122
|
+
let debounce;
|
|
123
|
+
|
|
124
|
+
const paths = CONFIG.ITENS.map(i => i.path).filter(p => fs.existsSync(p));
|
|
125
|
+
|
|
126
|
+
paths.forEach(p => {
|
|
127
|
+
fs.watch(p, { recursive: true }, (evt, filename) => {
|
|
128
|
+
if (filename && !filename.includes('.zip') && !filename.includes('.tmp')) {
|
|
129
|
+
clearTimeout(debounce);
|
|
130
|
+
debounce = setTimeout(() => {
|
|
131
|
+
console.log(`📝 Alteração: ${filename}`);
|
|
132
|
+
gerarZip();
|
|
133
|
+
}, 500);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
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...');
|