hightjs 0.2.53 → 0.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/src/hotReload.ts CHANGED
@@ -21,7 +21,7 @@ import * as fs from 'fs';
21
21
  import { IncomingMessage } from 'http';
22
22
  import * as url from 'url';
23
23
  import { clearFileCache } from './router';
24
- import Console, {Levels} from "./api/console"
24
+ import Console, {Colors, Levels} from "./api/console"
25
25
 
26
26
  interface ClientConnection {
27
27
  ws: WebSocket;
@@ -111,11 +111,11 @@ export class HotReloadManager {
111
111
  });
112
112
 
113
113
  ws.on('error', (error) => {
114
- Console.logWithout(Levels.ERROR, `WebSocket error: ${error.message}`);
114
+ Console.logWithout(Levels.ERROR, Colors.BgRed,`WebSocket error: ${error.message}`);
115
115
  this.cleanupClient(ws);
116
116
  });
117
117
 
118
- Console.logWithout(Levels.INFO, '🔌 Hot-reload cliente conectado');
118
+ Console.logWithout(Levels.INFO, Colors.BgRed,'🔌 Hot-reload cliente conectado');
119
119
  });
120
120
  }
121
121
 
@@ -184,7 +184,7 @@ export class HotReloadManager {
184
184
  }
185
185
 
186
186
  private async handleAnySrcChange(filePath: string) {
187
- Console.logWithout(Levels.INFO, `🔄 Arquivo alterado: ${path.basename(filePath)}`);
187
+ Console.logWithout(Levels.INFO, Colors.BgRed,`🔄 Arquivo alterado: ${path.basename(filePath)}`);
188
188
 
189
189
  // Detecta se é arquivo de frontend ou backend
190
190
  const isFrontendFile = filePath.includes(path.join('src', 'web', 'routes')) ||
@@ -213,21 +213,21 @@ export class HotReloadManager {
213
213
 
214
214
  // Se for arquivo de frontend, notifica o cliente para recarregar a página
215
215
  if (isFrontendFile) {
216
- Console.logWithout(Levels.INFO, `📄 Recarregando frontend...`);
216
+ Console.logWithout(Levels.INFO, Colors.BgRed,`📄 Recarregando frontend...`);
217
217
  this.frontendChangeCallback?.();
218
218
  this.notifyClients('frontend-reload', { file: filePath, event: 'change' });
219
219
  }
220
220
 
221
221
  // Se for arquivo de backend, recarrega o módulo e notifica
222
222
  if (isBackendFile) {
223
- Console.logWithout(Levels.INFO, `⚙️ Recarregando backend...`);
223
+ Console.logWithout(Levels.INFO, Colors.BgRed,`⚙️ Recarregando backend...`);
224
224
  this.backendApiChangeCallback?.();
225
225
  this.notifyClients('backend-api-reload', { file: filePath, event: 'change' });
226
226
  }
227
227
 
228
228
  // Fallback: se não for nem frontend nem backend detectado, recarrega tudo
229
229
  if (!isFrontendFile && !isBackendFile) {
230
- Console.logWithout(Levels.INFO, `🔄 Recarregando aplicação...`);
230
+ Console.logWithout(Levels.INFO, Colors.BgRed,`🔄 Recarregando aplicação...`);
231
231
  this.frontendChangeCallback?.();
232
232
  this.backendApiChangeCallback?.();
233
233
  this.notifyClients('src-reload', { file: filePath, event: 'change' });
@@ -257,7 +257,7 @@ export class HotReloadManager {
257
257
  try {
258
258
  ws.send(message);
259
259
  } catch (error) {
260
- Console.logWithout(Levels.ERROR, `Erro ao enviar mensagem WebSocket: ${error}`);
260
+ Console.logWithout(Levels.ERROR, Colors.BgRed, `Erro ao enviar mensagem WebSocket: ${error}`);
261
261
  deadClients.push(ws);
262
262
  }
263
263
  } else {
package/src/index.ts CHANGED
@@ -183,6 +183,8 @@ import '${relativeEntryPath}';
183
183
 
184
184
  export default function hweb(options: HightJSOptions) {
185
185
  const { dev = true, dir = process.cwd(), port = 3000 } = options;
186
+ // @ts-ignore
187
+ process.hight = options;
186
188
  const userWebDir = path.join(dir, 'src', 'web');
187
189
  const userWebRoutesDir = path.join(userWebDir, 'routes');
188
190
  const userBackendRoutesDir = path.join(userWebDir, 'backend', 'routes');
@@ -201,8 +203,6 @@ export default function hweb(options: HightJSOptions) {
201
203
  request: HightJSRequest,
202
204
  params: { [key: string]: string }
203
205
  ): Promise<HightJSResponse> {
204
- // @ts-ignore
205
- process.hight = options;
206
206
  if (!middlewares || middlewares.length === 0) {
207
207
  // Não há middlewares, executa diretamente o handler final
208
208
  return await finalHandler(request, params);
@@ -266,7 +266,16 @@ export default function hweb(options: HightJSOptions) {
266
266
  regenerateEntryFile();
267
267
  });
268
268
  }
269
-
269
+ const now = Date.now();
270
+ const timee = Console.dynamicLine(` ${Colors.BgYellow} router ${Colors.Reset} Carregando rotas e componentes do frontend e backend`);
271
+ const spinnerFrames1 = ['|', '/', '-', '\\'];
272
+ let frameIndex1 = 0;
273
+
274
+ const spinner1 = setInterval(() => {
275
+ Console.info('aaaa')
276
+ timee.update(` ${Colors.FgYellow}${spinnerFrames1[frameIndex1]}${Colors.Reset} Carregando rotas e componentes...`);
277
+ frameIndex1 = (frameIndex1 + 1) % spinnerFrames1.length;
278
+ }, 100); // muda a cada 100ms
270
279
  // ORDEM IMPORTANTE: Carrega TUDO antes de criar o arquivo de entrada
271
280
  frontendRoutes = loadRoutes(userWebRoutesDir);
272
281
  loadBackendRoutes(userBackendRoutesDir);
@@ -283,32 +292,36 @@ export default function hweb(options: HightJSOptions) {
283
292
  fs.mkdirSync(outDir, {recursive: true});
284
293
 
285
294
  entryPoint = createEntryFile(dir, frontendRoutes);
295
+ clearInterval(spinner1)
296
+ timee.end(` ${Colors.BgGreen} router ${Colors.Reset} Rotas e componentes carregados em ${Date.now() - now}ms`);
286
297
 
287
- // Usa chunks quando há muitas rotas ou o projeto é grande
288
- const shouldUseChunks = frontendRoutes.length > 5 || isLargeProject(dir);
289
298
 
290
- if (shouldUseChunks) {
291
- const outDir = path.join(dir, 'hweb-dist');
299
+ if (isProduction) {
300
+ const time = Console.dynamicLine(` ${Colors.BgYellow} build ${Colors.Reset} Iniciando build do cliente para produção`);
292
301
 
293
- if (isProduction) {
294
- await buildWithChunks(entryPoint, outDir, isProduction);
295
- Console.info(`✅ Build com chunks finalizado! ${frontendRoutes.length} rotas processadas.`);
296
- } else {
297
- watchWithChunks(entryPoint, outDir, hotReloadManager!).catch(err => {
298
- Console.error(`Erro ao iniciar o watch com chunks`, err);
299
- });
300
- Console.info(`🚀 Modo watch com chunks ativo para ${frontendRoutes.length} rotas.`);
301
- }
302
- } else {
303
- outfile = path.join(dir, 'hweb-dist', 'main.js');
302
+ // Spinner
303
+ const spinnerFrames = ['|', '/', '-', '\\'];
304
+ let frameIndex = 0;
304
305
 
305
- if (isProduction) {
306
- await build(entryPoint, outfile, isProduction);
307
- } else {
308
- watch(entryPoint, outfile, hotReloadManager!).catch(err => {
309
- Console.error(`Erro ao iniciar o watch`, err);
310
- });
311
- }
306
+ const spinner = setInterval(() => {
307
+ time.update(` ${Colors.FgYellow}${spinnerFrames[frameIndex]}${Colors.Reset} Buildando para produção...`);
308
+ frameIndex = (frameIndex + 1) % spinnerFrames.length;
309
+ }, 100); // muda a cada 100ms
310
+
311
+ const now = Date.now();
312
+ await buildWithChunks(entryPoint, outDir, isProduction);
313
+ const elapsed = Date.now() - now;
314
+
315
+ clearInterval(spinner); // para o spinner
316
+ time.update(""); // limpa a linha
317
+ time.end(` ${Colors.BgGreen} build ${Colors.Reset} Build do cliente concluído em ${elapsed}ms`);
318
+
319
+ } else {
320
+ const time = Console.dynamicLine(` ${Colors.BgYellow} watcher ${Colors.Reset} Iniciando watch do cliente`);
321
+ watchWithChunks(entryPoint, outDir, hotReloadManager!).catch(err => {
322
+ Console.error(`Erro ao iniciar o watch`, err);
323
+ });
324
+ time.end(` ${Colors.BgGreen} watcher ${Colors.Reset} Watch do cliente iniciado`);
312
325
  }
313
326
 
314
327
  },
package/src/types.ts CHANGED
@@ -40,6 +40,12 @@ export interface HightJSOptions {
40
40
  port?: number;
41
41
  dir?: string;
42
42
  framework?: 'express' | 'fastify' | 'native';
43
+ ssl?: {
44
+ redirectPort: number;
45
+ key: string;
46
+ cert: string;
47
+ ca?: string;
48
+ };
43
49
  }
44
50
  export interface Metadata {
45
51
  title?: string;