raizcode-ofc 1.1.0 → 1.2.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/compilador.js +67 -7
- package/package.json +1 -1
package/compilador.js
CHANGED
|
@@ -26,12 +26,53 @@ if (arquivoOuCmd === '--setup') {
|
|
|
26
26
|
process.exit();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
//
|
|
29
|
+
// Variável para controle se é um site
|
|
30
|
+
let ehSite = false;
|
|
31
|
+
|
|
32
|
+
// 2. TRADUTOR (Com novos comandos de Site)
|
|
30
33
|
function traduzir(linha) {
|
|
31
34
|
let t = linha.trim();
|
|
32
35
|
if (!t || t.startsWith("//")) return t;
|
|
33
36
|
|
|
34
|
-
//
|
|
37
|
+
// --- NOVOS COMANDOS DE SITE ---
|
|
38
|
+
if (t.startsWith('pagina ')) {
|
|
39
|
+
ehSite = true;
|
|
40
|
+
let titulo = t.replace('pagina ', '');
|
|
41
|
+
return `
|
|
42
|
+
document.title = ${titulo};
|
|
43
|
+
document.body.innerHTML = '<div id="raiz-app"></div>';
|
|
44
|
+
const style = document.createElement('style');
|
|
45
|
+
style.textContent = \`
|
|
46
|
+
body { background: #0a0a0a; color: #00ff88; font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
|
|
47
|
+
#raiz-app { text-align: center; border: 2px solid #00ff88; padding: 50px; border-radius: 20px; box-shadow: 0 0 30px rgba(0,255,136,0.3); }
|
|
48
|
+
button { background: #00ff88; color: #000; border: none; padding: 12px 25px; border-radius: 8px; font-weight: bold; cursor: pointer; transition: 0.3s; margin: 10px; }
|
|
49
|
+
button:hover { transform: scale(1.1); box-shadow: 0 0 20px #00ff88; }
|
|
50
|
+
h1 { font-size: 3rem; text-shadow: 0 0 10px #00ff88; }
|
|
51
|
+
\`;
|
|
52
|
+
document.head.appendChild(style);
|
|
53
|
+
const raiz = document.getElementById('raiz-app');
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (t.startsWith('titulo ')) {
|
|
58
|
+
return `raiz.innerHTML += "<h1>" + ${t.replace('titulo ', '')} + "</h1>";`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (t.startsWith('botao ')) {
|
|
62
|
+
let partes = t.replace('botao ', '').split(' acao ');
|
|
63
|
+
let texto = partes[0];
|
|
64
|
+
let acao = partes[1];
|
|
65
|
+
return `
|
|
66
|
+
const btn = document.createElement('button');
|
|
67
|
+
btn.innerText = ${texto};
|
|
68
|
+
btn.onclick = () => { ${traduzir(acao)} };
|
|
69
|
+
raiz.appendChild(btn);
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (t.startsWith('alerta ')) return `alert(${t.replace('alerta ', '')});`;
|
|
74
|
+
|
|
75
|
+
// --- COMANDOS ORIGINAIS ---
|
|
35
76
|
if (t.startsWith('mostrar ')) return t.replace('mostrar ', 'console.log(') + ');';
|
|
36
77
|
if (t.startsWith('variavel ')) {
|
|
37
78
|
let p = t.split(' ');
|
|
@@ -58,12 +99,31 @@ if (!fs.existsSync(caminho)) {
|
|
|
58
99
|
try {
|
|
59
100
|
const codigo = fs.readFileSync(caminho, 'utf-8');
|
|
60
101
|
const js = codigo.split('\n').map(traduzir).join('\n');
|
|
61
|
-
const
|
|
102
|
+
const saidaJS = caminho.replace('.rc', '.js');
|
|
62
103
|
|
|
63
|
-
fs.writeFileSync(
|
|
104
|
+
fs.writeFileSync(saidaJS, js);
|
|
64
105
|
|
|
65
|
-
//
|
|
66
|
-
|
|
106
|
+
// MÁGICA: Se o compilador detectou o comando 'pagina', ele cria o HTML sozinho
|
|
107
|
+
if (ehSite) {
|
|
108
|
+
const saidaHTML = caminho.replace('.rc', '.html');
|
|
109
|
+
const nomeJS = path.basename(saidaJS);
|
|
110
|
+
const estruturaHTML = `
|
|
111
|
+
<!DOCTYPE html>
|
|
112
|
+
<html lang="pt-br">
|
|
113
|
+
<head>
|
|
114
|
+
<meta charset="UTF-8">
|
|
115
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
116
|
+
</head>
|
|
117
|
+
<body>
|
|
118
|
+
<script src="${nomeJS}"></script>
|
|
119
|
+
</body>
|
|
120
|
+
</html>`;
|
|
121
|
+
fs.writeFileSync(saidaHTML, estruturaHTML);
|
|
122
|
+
console.log(`🌐 [Raizcode Site] HTML gerado: ${path.basename(saidaHTML)}`);
|
|
123
|
+
} else {
|
|
124
|
+
// Se não for site, roda no terminal como antes
|
|
125
|
+
execSync(`node "${saidaJS}"`, { stdio: 'inherit' });
|
|
126
|
+
}
|
|
67
127
|
} catch (err) {
|
|
68
|
-
//
|
|
128
|
+
// Erro silencioso
|
|
69
129
|
}
|