hightjs 0.2.52 → 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/dist/adapters/express.js +1 -1
- package/dist/api/console.d.ts +6 -4
- package/dist/api/console.js +27 -9
- package/dist/auth/components.js +16 -0
- package/dist/auth/core.js +16 -0
- package/dist/auth/index.js +16 -0
- package/dist/auth/jwt.js +16 -0
- package/dist/auth/providers/index.js +16 -0
- package/dist/auth/providers.js +16 -0
- package/dist/auth/react/index.js +16 -0
- package/dist/auth/react.js +16 -0
- package/dist/auth/routes.js +16 -0
- package/dist/auth/types.js +16 -0
- package/dist/bin/hightjs.js +68 -11
- package/dist/builder.js +16 -0
- package/dist/client/clientRouter.js +16 -0
- package/dist/client/entry.client.js +16 -0
- package/dist/client.js +16 -0
- package/dist/helpers.d.ts +7 -6
- package/dist/helpers.js +284 -198
- package/dist/hotReload.js +23 -7
- package/dist/index.js +49 -25
- package/dist/router.js +16 -0
- package/dist/types.d.ts +6 -0
- package/docs/cli.md +4 -5
- package/package.json +1 -1
- package/src/adapters/express.ts +18 -1
- package/src/adapters/factory.ts +16 -0
- package/src/adapters/fastify.ts +16 -0
- package/src/adapters/native.ts +16 -0
- package/src/api/console.ts +28 -10
- package/src/api/http.ts +16 -0
- package/src/auth/client.ts +16 -0
- package/src/auth/components.tsx +16 -0
- package/src/auth/core.ts +16 -0
- package/src/auth/index.ts +16 -0
- package/src/auth/jwt.ts +16 -0
- package/src/auth/providers/credentials.ts +16 -0
- package/src/auth/providers/discord.ts +16 -0
- package/src/auth/providers/google.ts +16 -0
- package/src/auth/providers/index.ts +16 -0
- package/src/auth/providers.ts +16 -0
- package/src/auth/react/index.ts +16 -0
- package/src/auth/react.tsx +16 -0
- package/src/auth/routes.ts +17 -0
- package/src/auth/types.ts +17 -0
- package/src/bin/hightjs.js +79 -11
- package/src/builder.js +16 -0
- package/src/client/DefaultNotFound.tsx +16 -0
- package/src/client/clientRouter.ts +16 -0
- package/src/client/entry.client.tsx +16 -0
- package/src/client.ts +16 -0
- package/src/components/Link.tsx +16 -0
- package/src/helpers.ts +327 -215
- package/src/hotReload.ts +24 -8
- package/src/index.ts +54 -25
- package/src/renderer.tsx +16 -0
- package/src/router.ts +16 -0
- package/src/types/framework.ts +16 -0
- package/src/types.ts +22 -0
package/src/hotReload.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the HightJS Project.
|
|
3
|
+
* Copyright (c) 2025 itsmuzin
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
1
17
|
import { WebSocket, WebSocketServer } from 'ws';
|
|
2
18
|
import * as chokidar from 'chokidar';
|
|
3
19
|
import * as path from 'path';
|
|
@@ -5,7 +21,7 @@ import * as fs from 'fs';
|
|
|
5
21
|
import { IncomingMessage } from 'http';
|
|
6
22
|
import * as url from 'url';
|
|
7
23
|
import { clearFileCache } from './router';
|
|
8
|
-
import Console, {Levels} from "./api/console"
|
|
24
|
+
import Console, {Colors, Levels} from "./api/console"
|
|
9
25
|
|
|
10
26
|
interface ClientConnection {
|
|
11
27
|
ws: WebSocket;
|
|
@@ -95,11 +111,11 @@ export class HotReloadManager {
|
|
|
95
111
|
});
|
|
96
112
|
|
|
97
113
|
ws.on('error', (error) => {
|
|
98
|
-
Console.logWithout(Levels.ERROR,
|
|
114
|
+
Console.logWithout(Levels.ERROR, Colors.BgRed,`WebSocket error: ${error.message}`);
|
|
99
115
|
this.cleanupClient(ws);
|
|
100
116
|
});
|
|
101
117
|
|
|
102
|
-
Console.logWithout(Levels.INFO, '🔌 Hot-reload cliente conectado');
|
|
118
|
+
Console.logWithout(Levels.INFO, Colors.BgRed,'🔌 Hot-reload cliente conectado');
|
|
103
119
|
});
|
|
104
120
|
}
|
|
105
121
|
|
|
@@ -168,7 +184,7 @@ export class HotReloadManager {
|
|
|
168
184
|
}
|
|
169
185
|
|
|
170
186
|
private async handleAnySrcChange(filePath: string) {
|
|
171
|
-
Console.logWithout(Levels.INFO,
|
|
187
|
+
Console.logWithout(Levels.INFO, Colors.BgRed,`🔄 Arquivo alterado: ${path.basename(filePath)}`);
|
|
172
188
|
|
|
173
189
|
// Detecta se é arquivo de frontend ou backend
|
|
174
190
|
const isFrontendFile = filePath.includes(path.join('src', 'web', 'routes')) ||
|
|
@@ -197,21 +213,21 @@ export class HotReloadManager {
|
|
|
197
213
|
|
|
198
214
|
// Se for arquivo de frontend, notifica o cliente para recarregar a página
|
|
199
215
|
if (isFrontendFile) {
|
|
200
|
-
Console.logWithout(Levels.INFO,
|
|
216
|
+
Console.logWithout(Levels.INFO, Colors.BgRed,`📄 Recarregando frontend...`);
|
|
201
217
|
this.frontendChangeCallback?.();
|
|
202
218
|
this.notifyClients('frontend-reload', { file: filePath, event: 'change' });
|
|
203
219
|
}
|
|
204
220
|
|
|
205
221
|
// Se for arquivo de backend, recarrega o módulo e notifica
|
|
206
222
|
if (isBackendFile) {
|
|
207
|
-
Console.logWithout(Levels.INFO,
|
|
223
|
+
Console.logWithout(Levels.INFO, Colors.BgRed,`⚙️ Recarregando backend...`);
|
|
208
224
|
this.backendApiChangeCallback?.();
|
|
209
225
|
this.notifyClients('backend-api-reload', { file: filePath, event: 'change' });
|
|
210
226
|
}
|
|
211
227
|
|
|
212
228
|
// Fallback: se não for nem frontend nem backend detectado, recarrega tudo
|
|
213
229
|
if (!isFrontendFile && !isBackendFile) {
|
|
214
|
-
Console.logWithout(Levels.INFO,
|
|
230
|
+
Console.logWithout(Levels.INFO, Colors.BgRed,`🔄 Recarregando aplicação...`);
|
|
215
231
|
this.frontendChangeCallback?.();
|
|
216
232
|
this.backendApiChangeCallback?.();
|
|
217
233
|
this.notifyClients('src-reload', { file: filePath, event: 'change' });
|
|
@@ -241,7 +257,7 @@ export class HotReloadManager {
|
|
|
241
257
|
try {
|
|
242
258
|
ws.send(message);
|
|
243
259
|
} catch (error) {
|
|
244
|
-
Console.logWithout(Levels.ERROR, `Erro ao enviar mensagem WebSocket: ${error}`);
|
|
260
|
+
Console.logWithout(Levels.ERROR, Colors.BgRed, `Erro ao enviar mensagem WebSocket: ${error}`);
|
|
245
261
|
deadClients.push(ws);
|
|
246
262
|
}
|
|
247
263
|
} else {
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the HightJS Project.
|
|
3
|
+
* Copyright (c) 2025 itsmuzin
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
1
17
|
import path from 'path';
|
|
2
18
|
import fs from 'fs';
|
|
3
19
|
import {ExpressAdapter} from './adapters/express';
|
|
@@ -167,6 +183,8 @@ import '${relativeEntryPath}';
|
|
|
167
183
|
|
|
168
184
|
export default function hweb(options: HightJSOptions) {
|
|
169
185
|
const { dev = true, dir = process.cwd(), port = 3000 } = options;
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
process.hight = options;
|
|
170
188
|
const userWebDir = path.join(dir, 'src', 'web');
|
|
171
189
|
const userWebRoutesDir = path.join(userWebDir, 'routes');
|
|
172
190
|
const userBackendRoutesDir = path.join(userWebDir, 'backend', 'routes');
|
|
@@ -185,8 +203,6 @@ export default function hweb(options: HightJSOptions) {
|
|
|
185
203
|
request: HightJSRequest,
|
|
186
204
|
params: { [key: string]: string }
|
|
187
205
|
): Promise<HightJSResponse> {
|
|
188
|
-
// @ts-ignore
|
|
189
|
-
process.hight = options;
|
|
190
206
|
if (!middlewares || middlewares.length === 0) {
|
|
191
207
|
// Não há middlewares, executa diretamente o handler final
|
|
192
208
|
return await finalHandler(request, params);
|
|
@@ -250,7 +266,16 @@ export default function hweb(options: HightJSOptions) {
|
|
|
250
266
|
regenerateEntryFile();
|
|
251
267
|
});
|
|
252
268
|
}
|
|
253
|
-
|
|
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
|
|
254
279
|
// ORDEM IMPORTANTE: Carrega TUDO antes de criar o arquivo de entrada
|
|
255
280
|
frontendRoutes = loadRoutes(userWebRoutesDir);
|
|
256
281
|
loadBackendRoutes(userBackendRoutesDir);
|
|
@@ -267,32 +292,36 @@ export default function hweb(options: HightJSOptions) {
|
|
|
267
292
|
fs.mkdirSync(outDir, {recursive: true});
|
|
268
293
|
|
|
269
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`);
|
|
270
297
|
|
|
271
|
-
// Usa chunks quando há muitas rotas ou o projeto é grande
|
|
272
|
-
const shouldUseChunks = frontendRoutes.length > 5 || isLargeProject(dir);
|
|
273
298
|
|
|
274
|
-
if (
|
|
275
|
-
const
|
|
299
|
+
if (isProduction) {
|
|
300
|
+
const time = Console.dynamicLine(` ${Colors.BgYellow} build ${Colors.Reset} Iniciando build do cliente para produção`);
|
|
276
301
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
} else {
|
|
281
|
-
watchWithChunks(entryPoint, outDir, hotReloadManager!).catch(err => {
|
|
282
|
-
Console.error(`Erro ao iniciar o watch com chunks`, err);
|
|
283
|
-
});
|
|
284
|
-
Console.info(`🚀 Modo watch com chunks ativo para ${frontendRoutes.length} rotas.`);
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
outfile = path.join(dir, 'hweb-dist', 'main.js');
|
|
302
|
+
// Spinner
|
|
303
|
+
const spinnerFrames = ['|', '/', '-', '\\'];
|
|
304
|
+
let frameIndex = 0;
|
|
288
305
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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`);
|
|
296
325
|
}
|
|
297
326
|
|
|
298
327
|
},
|
package/src/renderer.tsx
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the HightJS Project.
|
|
3
|
+
* Copyright (c) 2025 itsmuzin
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
1
17
|
import React from 'react';
|
|
2
18
|
import { RouteConfig, Metadata } from './types';
|
|
3
19
|
import { getLayout } from './router';
|
package/src/router.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the HightJS Project.
|
|
3
|
+
* Copyright (c) 2025 itsmuzin
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
1
17
|
import fs from 'fs';
|
|
2
18
|
import path from 'path';
|
|
3
19
|
import { RouteConfig, BackendRouteConfig, HightMiddleware, WebSocketHandler, WebSocketContext } from './types';
|
package/src/types/framework.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the HightJS Project.
|
|
3
|
+
* Copyright (c) 2025 itsmuzin
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
1
17
|
// Tipos genéricos para abstrair diferentes frameworks web
|
|
2
18
|
export interface GenericRequest {
|
|
3
19
|
method: string;
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the HightJS Project.
|
|
3
|
+
* Copyright (c) 2025 itsmuzin
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
1
17
|
import type { ComponentType } from 'react';
|
|
2
18
|
import type { GenericRequest } from './types/framework';
|
|
3
19
|
import {HightJSRequest, HightJSResponse} from "./api/http";
|
|
@@ -24,6 +40,12 @@ export interface HightJSOptions {
|
|
|
24
40
|
port?: number;
|
|
25
41
|
dir?: string;
|
|
26
42
|
framework?: 'express' | 'fastify' | 'native';
|
|
43
|
+
ssl?: {
|
|
44
|
+
redirectPort: number;
|
|
45
|
+
key: string;
|
|
46
|
+
cert: string;
|
|
47
|
+
ca?: string;
|
|
48
|
+
};
|
|
27
49
|
}
|
|
28
50
|
export interface Metadata {
|
|
29
51
|
title?: string;
|