raizcode-ofc 1.2.0 → 1.4.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.
Files changed (2) hide show
  1. package/compilador.js +131 -42
  2. 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,39 @@ 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
+ if(!conteudo) return "";
36
+ return conteudo.split('\n').map(linha => {
37
+ let t = linha.trim();
38
+ if(!t) return "";
39
+ if (t.startsWith('titulo ')) return `<h1>${t.replace('titulo ', '').replace(/"/g, '')}</h1>`;
40
+ if (t.startsWith('texto ')) return `<p>${t.replace('texto ', '').replace(/"/g, '')}</p>`;
41
+ if (t.startsWith('botao ')) {
42
+ let p = t.replace('botao ', '').split(' id ');
43
+ let texto = p[0].replace(/"/g, '');
44
+ let id = p[1] ? p[1].replace(/"/g, '') : 'btn-' + Math.floor(Math.random()*1000);
45
+ return `<button id="${id}">${texto}</button>`;
46
+ }
47
+ if (t.startsWith('caixa ')) return `<div class="${t.replace('caixa ', '').replace(/"/g, '')}">`;
48
+ if (t === 'fim') return `</div>`;
49
+ return "";
50
+ }).join('');
51
+ }
52
+
53
+ function traduzirEstilo(conteudo) {
54
+ if(!conteudo) return "";
55
+ let css = conteudo
56
+ .replace(/fundo:/g, 'background:')
57
+ .replace(/cor-texto:/g, 'color:')
58
+ .replace(/verde-neon/g, '#00ff88')
59
+ .replace(/ao-passar-mouse:/g, '&:hover')
60
+ .replace(/estilo /g, '.')
61
+ .replace(/fim/g, '}');
62
+ return css;
63
+ }
64
+
32
65
  // 2. TRADUTOR (Com novos comandos de Site)
33
66
  function traduzir(linha) {
34
67
  let t = linha.trim();
@@ -38,36 +71,7 @@ function traduzir(linha) {
38
71
  if (t.startsWith('pagina ')) {
39
72
  ehSite = true;
40
73
  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
- `;
74
+ return `document.title = ${titulo};`;
71
75
  }
72
76
 
73
77
  if (t.startsWith('alerta ')) return `alert(${t.replace('alerta ', '')});`;
@@ -91,39 +95,124 @@ if (!arquivoOuCmd) {
91
95
  }
92
96
 
93
97
  const caminho = path.resolve(arquivoOuCmd);
98
+ const nomeBase = caminho.substring(0, caminho.lastIndexOf('.'));
99
+
94
100
  if (!fs.existsSync(caminho)) {
95
101
  console.log("❌ Arquivo não existe.");
96
102
  process.exit(1);
97
103
  }
98
104
 
99
105
  try {
106
+ // Busca arquivos companheiros (.rcx e .estilo)
107
+ const arqRcx = nomeBase + '.rcx';
108
+ const arqEstilo = nomeBase + '.estilo';
109
+
110
+ let htmlExtra = "";
111
+ let cssExtra = "";
112
+
113
+ if (fs.existsSync(arqRcx)) {
114
+ htmlExtra = traduzirEstrutura(fs.readFileSync(arqRcx, 'utf-8'));
115
+ ehSite = true;
116
+ }
117
+ if (fs.existsSync(arqEstilo)) {
118
+ cssExtra = traduzirEstilo(fs.readFileSync(arqEstilo, 'utf-8'));
119
+ ehSite = true;
120
+ }
121
+
100
122
  const codigo = fs.readFileSync(caminho, 'utf-8');
101
123
  const js = codigo.split('\n').map(traduzir).join('\n');
102
- const saidaJS = caminho.replace('.rc', '.js');
103
-
104
- fs.writeFileSync(saidaJS, js);
105
124
 
106
- // MÁGICA: Se o compilador detectou o comando 'pagina', ele cria o HTML sozinho
107
125
  if (ehSite) {
108
- const saidaHTML = caminho.replace('.rc', '.html');
109
- const nomeJS = path.basename(saidaJS);
126
+ // --- SISTEMA DE ARQUIVO TEMPORÁRIO (INVISÍVEL) ---
127
+ const tmpDir = os.tmpdir();
128
+ const nomeTemporario = 'raiz-' + Date.now() + '.html';
129
+ const caminhoHTMLTemporario = path.join(tmpDir, nomeTemporario);
130
+
110
131
  const estruturaHTML = `
111
132
  <!DOCTYPE html>
112
133
  <html lang="pt-br">
113
134
  <head>
114
135
  <meta charset="UTF-8">
115
136
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
137
+ <style>
138
+ /* DNA Raiz - Design System Padrão (Top) */
139
+ body {
140
+ background: #0d0d0d;
141
+ color: #f0f0f0;
142
+ font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
143
+ display: flex;
144
+ justify-content: center;
145
+ align-items: center;
146
+ height: 100vh;
147
+ margin: 0;
148
+ overflow: hidden;
149
+ }
150
+ #raiz-app {
151
+ text-align: center;
152
+ border: 1px solid rgba(0,255,136,0.3);
153
+ padding: 50px;
154
+ border-radius: 20px;
155
+ background: #1a1a1a;
156
+ box-shadow: 0 10px 40px rgba(0,0,0,0.5);
157
+ transition: 0.3s;
158
+ }
159
+ h1 { font-size: 3.5rem; color: #00ff88; text-shadow: 0 0 15px #00ff88; margin-bottom: 10px; }
160
+ p { font-size: 1.2rem; color: #a0a0a0; margin-bottom: 30px; }
161
+ button {
162
+ background: linear-gradient(135deg, #00ff88, #00cc6a);
163
+ color: #000;
164
+ border: none;
165
+ padding: 15px 30px;
166
+ border-radius: 10px;
167
+ font-weight: bold;
168
+ font-size: 1rem;
169
+ cursor: pointer;
170
+ transition: 0.3s;
171
+ margin: 10px;
172
+ box-shadow: 0 5px 15px rgba(0,255,136,0.2);
173
+ }
174
+ button:hover {
175
+ transform: translateY(-3px) scale(1.05);
176
+ box-shadow: 0 10px 25px rgba(0,255,136,0.4);
177
+ }
178
+
179
+ /* Estilos personalizados do usuário */
180
+ ${cssExtra}
181
+ </style>
116
182
  </head>
117
183
  <body>
118
- <script src="${nomeJS}"></script>
184
+ <div id="raiz-app">${htmlExtra}</div>
185
+ <script>${js}</script>
119
186
  </body>
120
187
  </html>`;
121
- fs.writeFileSync(saidaHTML, estruturaHTML);
122
- console.log(`🌐 [Raizcode Site] HTML gerado: ${path.basename(saidaHTML)}`);
188
+
189
+ // Gravamos o arquivo temporário
190
+ fs.writeFileSync(caminhoHTMLTemporario, estruturaHTML);
191
+ console.log(`🌐 [Raizcode Site] Gerando pré-visualização profissional...`);
192
+
193
+ // Abre o navegador sozinho no arquivo temporário
194
+ const cmd = os.platform() === 'win32' ? `start file://${caminhoHTMLTemporario}` :
195
+ (os.platform() === 'darwin' ? `open file://${caminhoHTMLTemporario}` :
196
+ `termux-open ${caminhoHTMLTemporario} || xdg-open ${caminhoHTMLTemporario}`);
197
+
198
+ exec(cmd, (error) => {
199
+ // Após 2 segundos (tempo pro navegador ler o arquivo), deletamos ele
200
+ setTimeout(() => {
201
+ if (fs.existsSync(caminhoHTMLTemporario)) {
202
+ fs.unlinkSync(caminhoHTMLTemporario);
203
+ }
204
+ }, 2000);
205
+ });
206
+
123
207
  } else {
124
- // Se não for site, roda no terminal como antes
208
+ const saidaJS = nomeBase + '.js';
209
+ fs.writeFileSync(saidaJS, js);
125
210
  execSync(`node "${saidaJS}"`, { stdio: 'inherit' });
211
+ // Ocultamos o JS gerado deletando ele logo após a execução
212
+ if (fs.existsSync(saidaJS)) {
213
+ fs.unlinkSync(saidaJS);
214
+ }
126
215
  }
127
216
  } catch (err) {
128
- // Erro silencioso
217
+ console.error("❌ Erro na compilação invisível.");
129
218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raizcode-ofc",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Linguagem de programação Brasileira focada em simplicidade e performance.",
5
5
  "main": "compilador.js",
6
6
  "bin": {