@danhachuel/pandanews 0.1.3 → 0.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.
@@ -0,0 +1,11 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
2
+ <rect width="100" height="100" rx="20" fill="#0b1220"/>
3
+ <circle cx="25" cy="28" r="13" fill="#e6edf3"/>
4
+ <circle cx="75" cy="28" r="13" fill="#e6edf3"/>
5
+ <circle cx="50" cy="52" r="30" fill="#e6edf3"/>
6
+ <ellipse cx="37" cy="48" rx="9" ry="11" fill="#0b1220" transform="rotate(-15 37 48)"/>
7
+ <ellipse cx="63" cy="48" rx="9" ry="11" fill="#0b1220" transform="rotate(15 63 48)"/>
8
+ <circle cx="38" cy="49" r="3" fill="#22c55e"/>
9
+ <circle cx="62" cy="49" r="3" fill="#22c55e"/>
10
+ <ellipse cx="50" cy="62" rx="5" ry="4" fill="#0b1220"/>
11
+ </svg>
@@ -0,0 +1,17 @@
1
+ <!doctype html>
2
+ <html lang="pt-BR" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>PandaNews — Automação de blogs de notícias com IA</title>
8
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
9
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
11
+ <script type="module" crossorigin src="/assets/index-D0e-vr7T.js"></script>
12
+ <link rel="stylesheet" crossorigin href="/assets/index-BaPdaYIz.css">
13
+ </head>
14
+ <body>
15
+ <div id="root"></div>
16
+ </body>
17
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/pandanews",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "SaaS local de criação e automação de múltiplos blogs de notícias com IA (FastAPI + React + Tailwind).",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/scripts/build.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Compila o frontend de desenvolvimento (frontend/ -> frontend/dist).
2
2
  // A UI React + Vite + Tailwind é inicializada na Fase 2 do plano.
3
- import { existsSync } from 'node:fs';
3
+ import { existsSync, realpathSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { spawnSync } from 'node:child_process';
6
6
  import { fileURLToPath } from 'node:url';
@@ -16,10 +16,19 @@ export async function runBuild() {
16
16
  }
17
17
  const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
18
18
  console.log('Instalando dependências do frontend...');
19
- const install = spawnSync(npmCmd, ['install'], { cwd: frontendDir, stdio: 'inherit' });
19
+ // shell: true — obrigatório para .cmd no Windows (Node >= 18)
20
+ const install = spawnSync(npmCmd, ['install'], { cwd: frontendDir, stdio: 'inherit', shell: true });
20
21
  if (install.status !== 0) throw new Error('Falha ao instalar dependências do frontend.');
21
22
  console.log('Compilando o frontend...');
22
- const build = spawnSync(npmCmd, ['run', 'build'], { cwd: frontendDir, stdio: 'inherit' });
23
+ const build = spawnSync(npmCmd, ['run', 'build'], { cwd: frontendDir, stdio: 'inherit', shell: true });
23
24
  if (build.status !== 0) throw new Error('Falha ao compilar o frontend.');
24
25
  console.log('Frontend compilado em frontend/dist.');
25
26
  }
27
+
28
+ // Entry point para execução direta: node scripts/build.js
29
+ if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {
30
+ runBuild().catch((err) => {
31
+ console.error(`pandanews build: ${err && err.message}`);
32
+ process.exitCode = 1;
33
+ });
34
+ }
package/scripts/start.js CHANGED
@@ -4,9 +4,10 @@
4
4
  // provisionado, executa o install completo (Python portátil + dependências)
5
5
  // antes de subir os servidores. A UI começa em PANDANEWS_UI_PORT (padrão 4030)
6
6
  // e, se a porta estiver ocupada, tenta automaticamente a seguinte (4031, ...).
7
+ // Requisições /api/* são proxies para o backend em 127.0.0.1:8000.
7
8
  import { existsSync, readFileSync } from 'node:fs';
8
9
  import { spawn } from 'node:child_process';
9
- import { createServer } from 'node:http';
10
+ import { createServer, request as httpRequest } from 'node:http';
10
11
  import { join, extname } from 'node:path';
11
12
  import { resolveHome, runInstall, PKG_ROOT } from './install.js';
12
13
 
@@ -14,6 +15,8 @@ const BACKEND_PORT = Number(process.env.PANDANEWS_API_PORT || 8000);
14
15
  const UI_PORT_BASE = Number(process.env.PANDANEWS_UI_PORT || 4030);
15
16
  const UI_PORT_MAX_TRIES = 20;
16
17
 
18
+ const FAVICON_URI = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect width='100' height='100' rx='20' fill='%230b1220'/%3E%3Ccircle cx='25' cy='28' r='13' fill='%23e6edf3'/%3E%3Ccircle cx='75' cy='28' r='13' fill='%23e6edf3'/%3E%3Ccircle cx='50' cy='52' r='30' fill='%23e6edf3'/%3E%3Cellipse cx='37' cy='48' rx='9' ry='11' fill='%230b1220' transform='rotate(-15 37 48)'/%3E%3Cellipse cx='63' cy='48' rx='9' ry='11' fill='%230b1220' transform='rotate(15 63 48)'/%3E%3Ccircle cx='38' cy='49' r='3' fill='%2322c55e'/%3E%3Ccircle cx='62' cy='49' r='3' fill='%2322c55e'/%3E%3Cellipse cx='50' cy='62' rx='5' ry='4' fill='%230b1220'/%3E%3C/svg%3E";
19
+
17
20
  function venvBin(home) {
18
21
  return process.platform === 'win32'
19
22
  ? join(home, '.runtime', 'venv', 'Scripts', 'python.exe')
@@ -34,27 +37,70 @@ const MIME = {
34
37
  function placeholderPage() {
35
38
  return `<!DOCTYPE html>
36
39
  <html lang="pt-BR">
37
- <head><meta charset="utf-8"><title>PandaNews</title></head>
40
+ <head>
41
+ <meta charset="utf-8">
42
+ <title>PandaNews</title>
43
+ <link rel="icon" href="${FAVICON_URI}">
44
+ </head>
38
45
  <body style="font-family: Inter, system-ui, sans-serif; background: #0b1220; color: #e6edf3; display: flex; min-height: 100vh; align-items: center; justify-content: center;">
39
46
  <div style="text-align: center;">
40
47
  <h1 style="font-size: 3rem; margin: 0;">🐼 PandaNews</h1>
41
- <p style="color: #9aa7b5;">Backend ativo em <a style="color: #22c55e;" href="http://127.0.0.1:8000/api/v1/health">127.0.0.1:8000</a></p>
42
- <p style="color: #9aa7b5;">A UI React completa chega na versão 0.2.00 (Fases 1 a 3 do plano).</p>
48
+ <p style="color: #9aa7b5;">Backend ativo em <a style="color: #22c55e;" href="/api/v1/health">/api/v1/health</a></p>
49
+ <p style="color: #9aa7b5;">A UI React completa chega na versão 0.2.00.</p>
43
50
  </div>
44
51
  </body>
45
52
  </html>`;
46
53
  }
47
54
 
55
+ // Encaminha /api/* para o backend FastAPI em 127.0.0.1:8000.
56
+ function proxyApi(req, res) {
57
+ const options = {
58
+ hostname: '127.0.0.1',
59
+ port: BACKEND_PORT,
60
+ path: req.url,
61
+ method: req.method,
62
+ headers: { ...req.headers, host: `127.0.0.1:${BACKEND_PORT}` },
63
+ };
64
+ const proxied = httpRequest(options, (upstream) => {
65
+ res.writeHead(upstream.statusCode || 502, upstream.headers);
66
+ upstream.pipe(res);
67
+ });
68
+ proxied.on('error', () => {
69
+ res.writeHead(502, { 'Content-Type': 'application/json; charset=utf-8' });
70
+ res.end(JSON.stringify({ detail: `Backend PandaNews não responde em 127.0.0.1:${BACKEND_PORT}` }));
71
+ });
72
+ req.pipe(proxied);
73
+ }
74
+
48
75
  let uiServer = null;
49
76
 
50
77
  function createUiServer() {
51
78
  const distDir = join(PKG_ROOT, 'frontend', 'dist');
52
79
  return createServer((req, res) => {
80
+ if (req.url.startsWith('/api')) {
81
+ proxyApi(req, res);
82
+ return;
83
+ }
53
84
  const url = req.url.split('?')[0];
54
85
  const filePath = join(distDir, url === '/' ? 'index.html' : url.slice(1));
55
86
  if (!existsSync(filePath)) {
56
- res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
57
- res.end(placeholderPage());
87
+ // SPA (BrowserRouter): rotas sem extensão caem no index.html quando o
88
+ // build existe; sem build, mostra o placeholder.
89
+ const indexHtml = join(distDir, 'index.html');
90
+ const hasBuild = existsSync(indexHtml);
91
+ const isAsset = extname(url) !== '';
92
+ if (hasBuild && !isAsset) {
93
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
94
+ res.end(readFileSync(indexHtml));
95
+ return;
96
+ }
97
+ if (!hasBuild) {
98
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
99
+ res.end(placeholderPage());
100
+ return;
101
+ }
102
+ res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
103
+ res.end('Not found');
58
104
  return;
59
105
  }
60
106
  res.writeHead(200, { 'Content-Type': MIME[extname(filePath)] || 'application/octet-stream' });
@@ -112,7 +158,11 @@ export async function runStart() {
112
158
  const uvicorn = spawn(
113
159
  venvBin(home),
114
160
  ['-m', 'uvicorn', 'backend.app.main:app', '--host', '127.0.0.1', '--port', String(BACKEND_PORT)],
115
- { cwd: PKG_ROOT, stdio: 'inherit' },
161
+ {
162
+ cwd: PKG_ROOT,
163
+ stdio: 'inherit',
164
+ env: { ...process.env, PANDANEWS_HOME: home },
165
+ },
116
166
  );
117
167
  uvicorn.on('exit', (code) => {
118
168
  if (code !== 0 && code !== null) {