@yakuzaa/jade 0.1.7 → 0.1.8
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/cli.js +10 -0
- package/commands/formatar.js +123 -0
- package/package.json +3 -3
package/cli.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Comandos disponíveis:
|
|
6
6
|
* jade init <nome> → cria estrutura de projeto
|
|
7
7
|
* jade compilar <arquivo.jd> → compila + gera index.html + runtime.js
|
|
8
|
+
* jade formatar [arquivo.jd] → formata arquivo(s) .jd (sem arg = todos)
|
|
8
9
|
* jade servir [pasta] [porta] → servidor estático para testar no browser
|
|
9
10
|
* jade --version → exibe versão
|
|
10
11
|
* jade --help → exibe ajuda
|
|
@@ -31,6 +32,7 @@ jade ${versao()} — JADE DSL em português
|
|
|
31
32
|
Comandos:
|
|
32
33
|
jade init <nome> Cria projeto JADE com estrutura completa
|
|
33
34
|
jade compilar <arquivo.jd> [-o] Compila e gera artefatos para o browser
|
|
35
|
+
jade formatar [arquivo.jd] Formata arquivos .jd (sem arg = todo o projeto)
|
|
34
36
|
jade servir [pasta] [porta] Inicia servidor local para testar no browser
|
|
35
37
|
|
|
36
38
|
Opções do compilar:
|
|
@@ -41,6 +43,8 @@ Exemplos:
|
|
|
41
43
|
jade init meu-projeto
|
|
42
44
|
jade compilar src/app.jd
|
|
43
45
|
jade compilar src/app.jd -o dist/app
|
|
46
|
+
jade formatar src/estoque.jd
|
|
47
|
+
jade formatar
|
|
44
48
|
jade servir dist
|
|
45
49
|
jade servir dist 8080
|
|
46
50
|
|
|
@@ -74,6 +78,12 @@ async function main() {
|
|
|
74
78
|
return;
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
if (comando === 'formatar') {
|
|
82
|
+
const { formatar } = await import('./commands/formatar.js');
|
|
83
|
+
await formatar(args.slice(1));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
if (comando === 'servir') {
|
|
78
88
|
const { servir } = await import('./commands/servir.js');
|
|
79
89
|
const pasta = args[1] ?? 'dist';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* commands/formatar.js — Formata arquivos .jd usando o formatter do compilador
|
|
3
|
+
*
|
|
4
|
+
* Uso:
|
|
5
|
+
* jade formatar <arquivo.jd> → formata e sobrescreve um arquivo
|
|
6
|
+
* jade formatar → formata todos os .jd do projeto recursivamente
|
|
7
|
+
*
|
|
8
|
+
* Delega para: jadec --format-write
|
|
9
|
+
* Chamado por: jade/cli.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { spawn } from 'child_process';
|
|
13
|
+
import { resolve, join, relative } from 'path';
|
|
14
|
+
import { existsSync, readdirSync, statSync } from 'fs';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
16
|
+
|
|
17
|
+
const verde = (s) => `\x1b[1;32m${s}\x1b[0m`;
|
|
18
|
+
const dim = (s) => `\x1b[2m${s}\x1b[0m`;
|
|
19
|
+
const vermelho = (s) => `\x1b[1;31m${s}\x1b[0m`;
|
|
20
|
+
const azul = (s) => `\x1b[34m${s}\x1b[0m`;
|
|
21
|
+
|
|
22
|
+
// ── Localiza jadec ────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
function localizarJadec() {
|
|
25
|
+
const candidatos = [
|
|
26
|
+
join(process.cwd(), 'node_modules', '.bin', 'jadec'),
|
|
27
|
+
resolve(fileURLToPath(import.meta.url), '..', '..', '..', 'jade-compiler', 'dist', 'cli.js'),
|
|
28
|
+
];
|
|
29
|
+
for (const c of candidatos) {
|
|
30
|
+
if (existsSync(c)) return c;
|
|
31
|
+
}
|
|
32
|
+
return 'jadec';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ── Coleta todos os .jd recursivamente ───────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
function coletarArquivos(dir, arquivos = []) {
|
|
38
|
+
const IGNORAR = ['node_modules', 'dist', '.git', '.cache'];
|
|
39
|
+
for (const entry of readdirSync(dir)) {
|
|
40
|
+
if (IGNORAR.includes(entry)) continue;
|
|
41
|
+
const caminho = join(dir, entry);
|
|
42
|
+
const stat = statSync(caminho);
|
|
43
|
+
if (stat.isDirectory()) {
|
|
44
|
+
coletarArquivos(caminho, arquivos);
|
|
45
|
+
} else if (entry.endsWith('.jd')) {
|
|
46
|
+
arquivos.push(caminho);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return arquivos;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── Roda jadec --format-write em um arquivo ──────────────────────────────────
|
|
53
|
+
|
|
54
|
+
function formatarArquivo(arquivo) {
|
|
55
|
+
return new Promise((res, rej) => {
|
|
56
|
+
const jadec = localizarJadec();
|
|
57
|
+
const cmd = jadec.endsWith('.js') ? 'node' : jadec;
|
|
58
|
+
const argv = jadec.endsWith('.js') ? [jadec, arquivo, '--format-write'] : [arquivo, '--format-write'];
|
|
59
|
+
|
|
60
|
+
const proc = spawn(cmd, argv, { stdio: ['inherit', 'pipe', 'pipe'] });
|
|
61
|
+
|
|
62
|
+
let stdout = '';
|
|
63
|
+
let stderr = '';
|
|
64
|
+
proc.stdout?.on('data', d => stdout += d);
|
|
65
|
+
proc.stderr?.on('data', d => stderr += d);
|
|
66
|
+
|
|
67
|
+
proc.on('close', code => {
|
|
68
|
+
if (code === 0) res({ ok: true, stdout, stderr });
|
|
69
|
+
else rej(new Error(stderr || `jadec saiu com código ${code}`));
|
|
70
|
+
});
|
|
71
|
+
proc.on('error', rej);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── Comando principal ─────────────────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
export async function formatar(args) {
|
|
78
|
+
const arquivoArg = args?.find(a => !a.startsWith('-'));
|
|
79
|
+
|
|
80
|
+
let arquivos;
|
|
81
|
+
|
|
82
|
+
if (arquivoArg) {
|
|
83
|
+
// Arquivo específico
|
|
84
|
+
const caminho = resolve(arquivoArg);
|
|
85
|
+
if (!existsSync(caminho)) {
|
|
86
|
+
console.error(`\n${vermelho('erro')}: arquivo '${arquivoArg}' não encontrado.\n`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
arquivos = [caminho];
|
|
90
|
+
} else {
|
|
91
|
+
// Todos os .jd do projeto
|
|
92
|
+
arquivos = coletarArquivos(process.cwd());
|
|
93
|
+
if (arquivos.length === 0) {
|
|
94
|
+
console.log(dim('nenhum arquivo .jd encontrado.'));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log(dim(`\nformatando ${arquivos.length} arquivo${arquivos.length > 1 ? 's' : ''}...\n`));
|
|
100
|
+
|
|
101
|
+
let ok = 0;
|
|
102
|
+
let erros = 0;
|
|
103
|
+
|
|
104
|
+
for (const arquivo of arquivos) {
|
|
105
|
+
const rel = relative(process.cwd(), arquivo);
|
|
106
|
+
try {
|
|
107
|
+
await formatarArquivo(arquivo);
|
|
108
|
+
console.log(` ${verde('ok')} ${azul(rel)}`);
|
|
109
|
+
ok++;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error(` ${vermelho('erro')} ${azul(rel)}: ${e.message}`);
|
|
112
|
+
erros++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log('');
|
|
117
|
+
if (erros === 0) {
|
|
118
|
+
console.log(`${verde('formatação concluída')} — ${ok} arquivo${ok > 1 ? 's' : ''} formatado${ok > 1 ? 's' : ''}.`);
|
|
119
|
+
} else {
|
|
120
|
+
console.log(`${ok} ok, ${vermelho(`${erros} com erro${erros > 1 ? 's' : ''}`)}.`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yakuzaa/jade",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Jade DSL — linguagem empresarial em português compilada para WebAssembly. Instala compilador + runtime + CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"postinstall": "node postinstall.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@yakuzaa/jade-compiler": "^0.1.
|
|
21
|
-
"@yakuzaa/jade-runtime": "^0.1.
|
|
20
|
+
"@yakuzaa/jade-compiler": "^0.1.11",
|
|
21
|
+
"@yakuzaa/jade-runtime": "^0.1.8"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
24
|
"jade",
|