raizcode-ofc 1.2.0 → 1.3.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 -22
- package/package.json +1 -1
package/compilador.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const os = require('os');
|
|
6
|
-
const { execSync } = require('child_process');
|
|
6
|
+
const { execSync, exec } = require('child_process');
|
|
7
7
|
|
|
8
8
|
const args = process.argv.slice(2);
|
|
9
9
|
const arquivoOuCmd = args[0];
|
|
@@ -29,6 +29,34 @@ if (arquivoOuCmd === '--setup') {
|
|
|
29
29
|
// Variável para controle se é um site
|
|
30
30
|
let ehSite = false;
|
|
31
31
|
|
|
32
|
+
// --- NOVAS FUNÇÕES DE ACRÉSCIMO PARA INDEPENDÊNCIA ---
|
|
33
|
+
|
|
34
|
+
function traduzirEstrutura(conteudo) {
|
|
35
|
+
return conteudo.split('\n').map(linha => {
|
|
36
|
+
let t = linha.trim();
|
|
37
|
+
if (t.startsWith('titulo ')) return `<h1>\${${t.replace('titulo ', '')}}</h1>`;
|
|
38
|
+
if (t.startsWith('texto ')) return `<p>\${${t.replace('texto ', '')}}</p>`;
|
|
39
|
+
if (t.startsWith('botao ')) {
|
|
40
|
+
let p = t.replace('botao ', '').split(' id ');
|
|
41
|
+
return `<button id="\${${p[1] || 'btn' }}">\${${p[0]}}</button>`;
|
|
42
|
+
}
|
|
43
|
+
if (t.startsWith('caixa ')) return `<div class="\${${t.replace('caixa ', '')}}">`;
|
|
44
|
+
if (t === 'fim') return `</div>`;
|
|
45
|
+
return "";
|
|
46
|
+
}).join('');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function traduzirEstilo(conteudo) {
|
|
50
|
+
let css = conteudo
|
|
51
|
+
.replace(/fundo:/g, 'background:')
|
|
52
|
+
.replace(/cor-texto:/g, 'color:')
|
|
53
|
+
.replace(/verde-neon/g, '#00ff88')
|
|
54
|
+
.replace(/ao-passar-mouse:/g, '&:hover')
|
|
55
|
+
.replace(/estilo /g, '.')
|
|
56
|
+
.replace(/fim/g, '}');
|
|
57
|
+
return css;
|
|
58
|
+
}
|
|
59
|
+
|
|
32
60
|
// 2. TRADUTOR (Com novos comandos de Site)
|
|
33
61
|
function traduzir(linha) {
|
|
34
62
|
let t = linha.trim();
|
|
@@ -40,22 +68,14 @@ function traduzir(linha) {
|
|
|
40
68
|
let titulo = t.replace('pagina ', '');
|
|
41
69
|
return `
|
|
42
70
|
document.title = ${titulo};
|
|
43
|
-
document.
|
|
44
|
-
|
|
45
|
-
|
|
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');
|
|
71
|
+
if(!document.getElementById('raiz-app')){
|
|
72
|
+
document.body.innerHTML = '<div id="raiz-app"></div>';
|
|
73
|
+
}
|
|
54
74
|
`;
|
|
55
75
|
}
|
|
56
76
|
|
|
57
77
|
if (t.startsWith('titulo ')) {
|
|
58
|
-
return `raiz.innerHTML += "<h1>" + ${t.replace('titulo ', '')} + "</h1>";`;
|
|
78
|
+
return `document.getElementById('raiz-app').innerHTML += "<h1>" + ${t.replace('titulo ', '')} + "</h1>";`;
|
|
59
79
|
}
|
|
60
80
|
|
|
61
81
|
if (t.startsWith('botao ')) {
|
|
@@ -66,7 +86,7 @@ function traduzir(linha) {
|
|
|
66
86
|
const btn = document.createElement('button');
|
|
67
87
|
btn.innerText = ${texto};
|
|
68
88
|
btn.onclick = () => { ${traduzir(acao)} };
|
|
69
|
-
raiz.appendChild(btn);
|
|
89
|
+
document.getElementById('raiz-app').appendChild(btn);
|
|
70
90
|
`;
|
|
71
91
|
}
|
|
72
92
|
|
|
@@ -91,37 +111,62 @@ if (!arquivoOuCmd) {
|
|
|
91
111
|
}
|
|
92
112
|
|
|
93
113
|
const caminho = path.resolve(arquivoOuCmd);
|
|
114
|
+
const nomeBase = caminho.substring(0, caminho.lastIndexOf('.'));
|
|
115
|
+
|
|
94
116
|
if (!fs.existsSync(caminho)) {
|
|
95
117
|
console.log("❌ Arquivo não existe.");
|
|
96
118
|
process.exit(1);
|
|
97
119
|
}
|
|
98
120
|
|
|
99
121
|
try {
|
|
122
|
+
// Busca arquivos companheiros (.rcx e .estilo)
|
|
123
|
+
const arqRcx = nomeBase + '.rcx';
|
|
124
|
+
const arqEstilo = nomeBase + '.estilo';
|
|
125
|
+
|
|
126
|
+
let htmlExtra = "";
|
|
127
|
+
let cssExtra = "";
|
|
128
|
+
|
|
129
|
+
if (fs.existsSync(arqRcx)) {
|
|
130
|
+
htmlExtra = traduzirEstrutura(fs.readFileSync(arqRcx, 'utf-8'));
|
|
131
|
+
ehSite = true;
|
|
132
|
+
}
|
|
133
|
+
if (fs.existsSync(arqEstilo)) {
|
|
134
|
+
cssExtra = traduzirEstilo(fs.readFileSync(arqEstilo, 'utf-8'));
|
|
135
|
+
ehSite = true;
|
|
136
|
+
}
|
|
137
|
+
|
|
100
138
|
const codigo = fs.readFileSync(caminho, 'utf-8');
|
|
101
139
|
const js = codigo.split('\n').map(traduzir).join('\n');
|
|
102
|
-
const saidaJS =
|
|
140
|
+
const saidaJS = nomeBase + '.js';
|
|
103
141
|
|
|
104
142
|
fs.writeFileSync(saidaJS, js);
|
|
105
143
|
|
|
106
|
-
// MÁGICA: Se o compilador detectou o comando 'pagina', ele cria o HTML sozinho
|
|
107
144
|
if (ehSite) {
|
|
108
|
-
const saidaHTML =
|
|
109
|
-
const nomeJS = path.basename(saidaJS);
|
|
145
|
+
const saidaHTML = nomeBase + '.html';
|
|
110
146
|
const estruturaHTML = `
|
|
111
147
|
<!DOCTYPE html>
|
|
112
148
|
<html lang="pt-br">
|
|
113
149
|
<head>
|
|
114
150
|
<meta charset="UTF-8">
|
|
115
|
-
<
|
|
151
|
+
<style>
|
|
152
|
+
body { background: #0a0a0a; color: #fff; font-family: sans-serif; }
|
|
153
|
+
${cssExtra}
|
|
154
|
+
</style>
|
|
116
155
|
</head>
|
|
117
156
|
<body>
|
|
118
|
-
<
|
|
157
|
+
<div id="raiz-app">${htmlExtra}</div>
|
|
158
|
+
<script>${js}</script>
|
|
119
159
|
</body>
|
|
120
160
|
</html>`;
|
|
121
161
|
fs.writeFileSync(saidaHTML, estruturaHTML);
|
|
122
|
-
console.log(`🌐 [Raizcode Site]
|
|
162
|
+
console.log(`🌐 [Raizcode Site] Independente gerado com sucesso!`);
|
|
163
|
+
|
|
164
|
+
// Abre o navegador sozinho
|
|
165
|
+
const url = `file://${saidaHTML}`;
|
|
166
|
+
const cmd = os.platform() === 'win32' ? `start ${url}` : (os.platform() === 'darwin' ? `open ${url}` : `termux-open ${url} || xdg-open ${url}`);
|
|
167
|
+
exec(cmd);
|
|
168
|
+
|
|
123
169
|
} else {
|
|
124
|
-
// Se não for site, roda no terminal como antes
|
|
125
170
|
execSync(`node "${saidaJS}"`, { stdio: 'inherit' });
|
|
126
171
|
}
|
|
127
172
|
} catch (err) {
|