-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
146 lines (120 loc) · 3.4 KB
/
build.js
File metadata and controls
146 lines (120 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* Script de build simples
* Agrupa módulos ES6 em um único arquivo para compatibilidade
*
* NOTA: Em produção, considere usar um bundler como Rollup ou Webpack
*/
const fs = require("fs");
const path = require("path");
const SRC_DIR = path.join(__dirname, "src");
const OUTPUT_FILE = path.join(__dirname, "script.js");
/**
* Lê arquivo e retorna conteúdo
*/
function readFile(filePath) {
try {
return fs.readFileSync(filePath, "utf8");
} catch (error) {
console.error(`Erro ao ler arquivo ${filePath}:`, error.message);
return null;
}
}
/**
* Processa imports e substitui por conteúdo
*/
function processImports(content, filePath, processed = new Set()) {
const importRegex =
/import\s+(?:(?:\{[^}]*\}|\*\s+as\s+\w+|\w+)(?:\s*,\s*(?:\{[^}]*\}|\*\s+as\s+\w+|\w+))*\s+from\s+)?['"]([^'"]+)['"];?/g;
let processedContent = content;
const dir = path.dirname(filePath);
processedContent = processedContent.replace(importRegex, (match, importPath) => {
const resolvedPath = path.resolve(dir, importPath);
const fullPath = resolvedPath.endsWith(".js") ? resolvedPath : `${resolvedPath}.js`;
if (processed.has(fullPath)) {
return `// Import já processado: ${importPath}`;
}
processed.add(fullPath);
const importedContent = readFile(fullPath);
if (!importedContent) {
return `// Erro ao importar: ${importPath}`;
}
// Remove exports e processa imports recursivamente
const withoutExports = importedContent
.replace(/export\s+/g, "")
.replace(/export\s+default\s+/g, "const ")
.replace(/export\s*\{[^}]*\}\s*;?/g, "");
return processImports(withoutExports, fullPath, processed);
});
return processedContent;
}
/**
* Build principal
*/
function build() {
console.log("Iniciando build...");
const mainFile = path.join(SRC_DIR, "main.js");
const mainContent = readFile(mainFile);
if (!mainContent) {
console.error("Erro: Não foi possível ler main.js");
process.exit(1);
}
// Processa imports recursivamente
const bundled = processImports(mainContent, mainFile);
// Adiciona header
const header = `/*
* MARCELO MACEDO - PORTFOLIO 2025
* Modern Professional Portfolio
*
* Este arquivo foi gerado automaticamente a partir dos módulos em src/
* Para editar, modifique os arquivos em src/ e execute: npm run build
*/
`;
// Adiciona estilos inline (mantém compatibilidade)
const styles = `
const style = document.createElement("style");
style.textContent = \`
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(400px);
opacity: 0;
}
}
@keyframes float {
0%, 100% {
transform: translateY(0) translateX(0);
}
50% {
transform: translateY(-20px) translateX(10px);
}
}
.nav-list a.active {
color: var(--accent);
}
.nav-list a.active::before {
transform: translateX(-50%) scaleX(1);
}
\`;
document.head.appendChild(style);
`;
const finalContent = header + bundled + styles;
// Escreve arquivo
fs.writeFileSync(OUTPUT_FILE, finalContent, "utf8");
console.log(`Build concluído: ${OUTPUT_FILE}`);
console.log(`Tamanho: ${(finalContent.length / 1024).toFixed(2)} KB`);
}
// Executa build
build();