raizcode-ofc 1.0.1 → 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 +93 -109
- package/package.json +1 -1
package/compilador.js
CHANGED
|
@@ -3,143 +3,127 @@
|
|
|
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
7
|
|
|
7
8
|
const args = process.argv.slice(2);
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
// ---------------------------------------------------------
|
|
11
|
-
// 🛠 SEÇÃO 1: CONFIGURAÇÃO DE AMBIENTE (--setup)
|
|
12
|
-
// ---------------------------------------------------------
|
|
13
|
-
if (comandoOuArquivo === '--setup') {
|
|
14
|
-
const vscodeExtDir = path.join(os.homedir(), '.vscode', 'extensions', 'raizcode-extension');
|
|
15
|
-
const sourceDir = __dirname;
|
|
16
|
-
|
|
17
|
-
console.log("🌱 [Raizcode] Iniciando configuração de ambiente...");
|
|
9
|
+
const arquivoOuCmd = args[0];
|
|
18
10
|
|
|
11
|
+
// 1. SETUP DO VSCODE (Ícones e Cores)
|
|
12
|
+
if (arquivoOuCmd === '--setup') {
|
|
13
|
+
const extDir = path.join(os.homedir(), '.vscode', 'extensions', 'raizcode-extension');
|
|
19
14
|
try {
|
|
20
|
-
if (!fs.existsSync(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// Arquivos necessários para a identidade visual no VS Code
|
|
25
|
-
const assets = ['package.json', 'syntaxes', 'icons'];
|
|
26
|
-
|
|
27
|
-
assets.forEach(item => {
|
|
28
|
-
const src = path.join(sourceDir, item);
|
|
29
|
-
const dest = path.join(vscodeExtDir, item);
|
|
30
|
-
|
|
15
|
+
if (!fs.existsSync(extDir)) fs.mkdirSync(extDir, { recursive: true });
|
|
16
|
+
['package.json', 'syntaxes', 'icons'].forEach(f => {
|
|
17
|
+
const src = path.join(__dirname, f);
|
|
18
|
+
const dest = path.join(extDir, f);
|
|
31
19
|
if (fs.existsSync(src)) {
|
|
32
|
-
if (fs.lstatSync(src).isDirectory()) {
|
|
33
|
-
|
|
34
|
-
} else {
|
|
35
|
-
fs.copyFileSync(src, dest);
|
|
36
|
-
}
|
|
20
|
+
if (fs.lstatSync(src).isDirectory()) fs.cpSync(src, dest, { recursive: true });
|
|
21
|
+
else fs.copyFileSync(src, dest);
|
|
37
22
|
}
|
|
38
23
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.log("🔄 Reinicie o seu editor para ativar o ícone RC e as cores.");
|
|
42
|
-
} catch (err) {
|
|
43
|
-
console.error("❌ Erro no setup:", err.message);
|
|
44
|
-
}
|
|
24
|
+
console.log("✅ Ambiente configurado! Reinicie o VS Code.");
|
|
25
|
+
} catch (e) { console.log("❌ Erro no setup local."); }
|
|
45
26
|
process.exit();
|
|
46
27
|
}
|
|
47
28
|
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
// ---------------------------------------------------------
|
|
51
|
-
function traduzirLinha(linha) {
|
|
52
|
-
let t = linha.trim();
|
|
53
|
-
if (!t || t.startsWith("//")) return t; // Ignora vazios e comentários
|
|
54
|
-
|
|
55
|
-
// Mapeamento de Comandos Simples
|
|
56
|
-
const mapa = {
|
|
57
|
-
'mostrar': 'console.log',
|
|
58
|
-
'imprimir': 'console.log',
|
|
59
|
-
'alerta': 'alert',
|
|
60
|
-
'retornar': 'return',
|
|
61
|
-
'fim': '}',
|
|
62
|
-
'senao': '} else {'
|
|
63
|
-
};
|
|
29
|
+
// Variável para controle se é um site
|
|
30
|
+
let ehSite = false;
|
|
64
31
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
32
|
+
// 2. TRADUTOR (Com novos comandos de Site)
|
|
33
|
+
function traduzir(linha) {
|
|
34
|
+
let t = linha.trim();
|
|
35
|
+
if (!t || t.startsWith("//")) return t;
|
|
36
|
+
|
|
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
|
+
`;
|
|
71
55
|
}
|
|
72
56
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let condicao = t.replace('se ', '').trim();
|
|
76
|
-
return `if (${condicao}) {`;
|
|
57
|
+
if (t.startsWith('titulo ')) {
|
|
58
|
+
return `raiz.innerHTML += "<h1>" + ${t.replace('titulo ', '')} + "</h1>";`;
|
|
77
59
|
}
|
|
78
60
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
let
|
|
82
|
-
let
|
|
83
|
-
return `
|
|
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
|
+
`;
|
|
84
71
|
}
|
|
85
72
|
|
|
86
|
-
|
|
87
|
-
if (t.startsWith('funcao ')) {
|
|
88
|
-
let partes = t.split(' ');
|
|
89
|
-
let nome = partes[1];
|
|
90
|
-
let params = partes.slice(2).join(', ');
|
|
91
|
-
return `function ${nome}(${params}) {`;
|
|
92
|
-
}
|
|
73
|
+
if (t.startsWith('alerta ')) return `alert(${t.replace('alerta ', '')});`;
|
|
93
74
|
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
if (t === chave) return mapa[chave];
|
|
75
|
+
// --- COMANDOS ORIGINAIS ---
|
|
76
|
+
if (t.startsWith('mostrar ')) return t.replace('mostrar ', 'console.log(') + ');';
|
|
77
|
+
if (t.startsWith('variavel ')) {
|
|
78
|
+
let p = t.split(' ');
|
|
79
|
+
return `let ${p[1]} = ${p.slice(2).join(' ')};`;
|
|
101
80
|
}
|
|
102
|
-
|
|
103
|
-
|
|
81
|
+
if (t.startsWith('se ')) return `if (${t.replace('se ', '').trim()}) {`;
|
|
82
|
+
if (t === 'fim') return '}';
|
|
83
|
+
|
|
84
|
+
return t;
|
|
104
85
|
}
|
|
105
86
|
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (!comandoOuArquivo) {
|
|
110
|
-
console.log("🌱 Raizcode v1.0.0");
|
|
111
|
-
console.log("Uso: raizcode <arquivo.rc> ou raizcode --setup");
|
|
87
|
+
// 3. EXECUÇÃO
|
|
88
|
+
if (!arquivoOuCmd) {
|
|
89
|
+
console.log("🌱 Raizcode - Use: raizcode <arquivo.rc>");
|
|
112
90
|
process.exit();
|
|
113
91
|
}
|
|
114
92
|
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
console.error(`❌ Erro: Arquivo '${comandoOuArquivo}' não encontrado.`);
|
|
93
|
+
const caminho = path.resolve(arquivoOuCmd);
|
|
94
|
+
if (!fs.existsSync(caminho)) {
|
|
95
|
+
console.log("❌ Arquivo não existe.");
|
|
119
96
|
process.exit(1);
|
|
120
97
|
}
|
|
98
|
+
|
|
121
99
|
try {
|
|
122
|
-
const
|
|
123
|
-
const
|
|
100
|
+
const codigo = fs.readFileSync(caminho, 'utf-8');
|
|
101
|
+
const js = codigo.split('\n').map(traduzir).join('\n');
|
|
102
|
+
const saidaJS = caminho.replace('.rc', '.js');
|
|
124
103
|
|
|
125
|
-
|
|
104
|
+
fs.writeFileSync(saidaJS, js);
|
|
126
105
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}
|
|
143
127
|
} catch (err) {
|
|
144
|
-
|
|
128
|
+
// Erro silencioso
|
|
145
129
|
}
|