hightjs 0.5.2 → 0.5.3

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.
Files changed (48) hide show
  1. package/package.json +1 -1
  2. package/src/builder.js +8 -8
  3. package/src/hotReload.ts +4 -7
  4. package/src/router.ts +14 -26
  5. package/dist/adapters/express.d.ts +0 -7
  6. package/dist/adapters/express.js +0 -63
  7. package/dist/adapters/factory.d.ts +0 -23
  8. package/dist/adapters/factory.js +0 -122
  9. package/dist/adapters/fastify.d.ts +0 -25
  10. package/dist/adapters/fastify.js +0 -61
  11. package/dist/adapters/native.d.ts +0 -8
  12. package/dist/adapters/native.js +0 -198
  13. package/dist/api/console.d.ts +0 -94
  14. package/dist/api/console.js +0 -294
  15. package/dist/api/http.d.ts +0 -180
  16. package/dist/api/http.js +0 -469
  17. package/dist/bin/hightjs.d.ts +0 -2
  18. package/dist/bin/hightjs.js +0 -214
  19. package/dist/builder.d.ts +0 -32
  20. package/dist/builder.js +0 -581
  21. package/dist/client/DefaultNotFound.d.ts +0 -1
  22. package/dist/client/DefaultNotFound.js +0 -79
  23. package/dist/client/client.d.ts +0 -3
  24. package/dist/client/client.js +0 -24
  25. package/dist/client/clientRouter.d.ts +0 -58
  26. package/dist/client/clientRouter.js +0 -132
  27. package/dist/client/entry.client.d.ts +0 -1
  28. package/dist/client/entry.client.js +0 -455
  29. package/dist/components/Link.d.ts +0 -7
  30. package/dist/components/Link.js +0 -13
  31. package/dist/global/global.d.ts +0 -117
  32. package/dist/global/global.js +0 -17
  33. package/dist/helpers.d.ts +0 -20
  34. package/dist/helpers.js +0 -583
  35. package/dist/hotReload.d.ts +0 -32
  36. package/dist/hotReload.js +0 -548
  37. package/dist/index.d.ts +0 -18
  38. package/dist/index.js +0 -494
  39. package/dist/loaders.d.ts +0 -1
  40. package/dist/loaders.js +0 -46
  41. package/dist/renderer.d.ts +0 -14
  42. package/dist/renderer.js +0 -380
  43. package/dist/router.d.ts +0 -101
  44. package/dist/router.js +0 -667
  45. package/dist/types/framework.d.ts +0 -37
  46. package/dist/types/framework.js +0 -2
  47. package/dist/types.d.ts +0 -192
  48. package/dist/types.js +0 -2
@@ -1,214 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- /*
4
- * This file is part of the HightJS Project.
5
- * Copyright (c) 2025 itsmuzin
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- // Registra o ts-node para que o Node.js entenda TypeScript/TSX
20
- require('ts-node').register();
21
- // Registra loaders customizados para arquivos markdown, imagens, etc.
22
- const { registerLoaders } = require('../loaders');
23
- registerLoaders();
24
- const { program } = require('commander');
25
- program
26
- .version('1.0.0')
27
- .description('CLI to manage the application.');
28
- // --- Comando DEV ---
29
- const fs = require('fs');
30
- const path = require('path');
31
- // 'program' já deve estar definido no seu arquivo
32
- // const { program } = require('commander');
33
- /**
34
- * Função centralizada para iniciar a aplicação
35
- * @param {object} options - Opções vindas do commander
36
- * @param {boolean} isDev - Define se é modo de desenvolvimento
37
- */
38
- function initializeApp(options, isDev) {
39
- const appOptions = {
40
- dev: isDev,
41
- port: options.port,
42
- hostname: options.hostname,
43
- framework: 'native',
44
- ssl: null, // Default
45
- };
46
- // 1. Verifica se a flag --ssl foi ativada
47
- if (options.ssl) {
48
- const C = require("../api/console");
49
- const { Levels } = C;
50
- const Console = C.default;
51
- const sslDir = path.resolve(process.cwd(), 'certs');
52
- const keyPath = path.join(sslDir, 'key.pem'); // Padrão 1: key.pem
53
- const certPath = path.join(sslDir, 'cert.pem'); // Padrão 2: cert.pem
54
- // (Você pode mudar para 'cert.key' se preferir, apenas ajuste os nomes aqui)
55
- // 2. Verifica se os arquivos existem
56
- if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
57
- appOptions.ssl = {
58
- key: keyPath,
59
- cert: certPath
60
- };
61
- // 3. Adiciona a porta de redirecionamento (útil para o initNativeServer)
62
- appOptions.ssl.redirectPort = options.httpRedirectPort || 80;
63
- }
64
- else {
65
- Console.logWithout(Levels.ERROR, null, `Ensure that './certs/key.pem' and './certs/cert.pem' exist.`, `--ssl flag was used, but the files were not found.`);
66
- process.exit(1); // Encerra o processo com erro
67
- }
68
- }
69
- // 4. Inicia o helper com as opções
70
- const teste = require("../helpers");
71
- const t = teste.default(appOptions);
72
- t.init();
73
- }
74
- // --- Comando DEV ---
75
- program
76
- .command('dev')
77
- .description('Starts the application in development mode.')
78
- .option('-p, --port <number>', 'Specifies the port to run on', '3000')
79
- .option('-H, --hostname <string>', 'Specifies the hostname to run on', '0.0.0.0')
80
- .option('--ssl', 'Activates HTTPS/SSL mode (requires ./ssl/key.pem and ./ssl/cert.pem)')
81
- .option('--http-redirect-port <number>', 'Port for HTTP->HTTPS redirection', '80')
82
- .action((options) => {
83
- initializeApp(options, true); // Chama a função com dev: true
84
- });
85
- // --- Comando START (Produção) ---
86
- program
87
- .command('start')
88
- .description('Starts the application in production mode.')
89
- .option('-p, --port <number>', 'Specifies the port to run on', '3000')
90
- .option('-H, --hostname <string>', 'Specifies the hostname to run on', '0.0.0.0')
91
- .option('--ssl', 'Activates HTTPS/SSL mode (requires ./ssl/key.pem and ./ssl/cert.pem)')
92
- .option('--http-redirect-port <number>', 'Port for HTTP->HTTPS redirection', '80')
93
- .action((options) => {
94
- initializeApp(options, false); // Chama a função com dev: false
95
- });
96
- /**
97
- * Função corrigida para copiar diretórios recursivamente.
98
- * Ela agora verifica se um item é um arquivo ou um diretório.
99
- */
100
- function copyDirRecursive(src, dest) {
101
- try {
102
- // Garante que o diretório de destino exista
103
- fs.mkdirSync(dest, { recursive: true });
104
- // Usamos { withFileTypes: true } para evitar uma chamada extra de fs.statSync
105
- const entries = fs.readdirSync(src, { withFileTypes: true });
106
- for (let entry of entries) {
107
- const srcPath = path.join(src, entry.name);
108
- const destPath = path.join(dest, entry.name);
109
- if (entry.isDirectory()) {
110
- // Se for um diretório, chama a si mesma (recursão)
111
- copyDirRecursive(srcPath, destPath);
112
- }
113
- else {
114
- // Se for um arquivo, apenas copia
115
- fs.copyFileSync(srcPath, destPath);
116
- }
117
- }
118
- }
119
- catch (error) {
120
- console.error(`❌ Erro ao copiar ${src} para ${dest}:`, error);
121
- // Lança o erro para parar o processo de exportação se a cópia falhar
122
- throw error;
123
- }
124
- }
125
- // --- INÍCIO DO SEU CÓDIGO (AGORA CORRIGIDO) ---
126
- program
127
- .command('export')
128
- .description('Exports the application as static HTML to the "exported" folder.')
129
- .option('-o, --output <path>', 'Specifies the output directory', 'exported')
130
- .action(async (options) => {
131
- const projectDir = process.cwd();
132
- // Usar path.resolve é mais seguro para garantir um caminho absoluto
133
- const exportDir = path.resolve(projectDir, options.output);
134
- console.log('🚀 Starting export...\n');
135
- try {
136
- // 1. Cria a pasta exported (limpa se já existir)
137
- if (fs.existsSync(exportDir)) {
138
- console.log('🗑️ Cleaning existing export folder...');
139
- fs.rmSync(exportDir, { recursive: true, force: true });
140
- }
141
- fs.mkdirSync(exportDir, { recursive: true });
142
- console.log('✅ Export folder created\n');
143
- // 2. Inicializa e prepara o build
144
- console.log('🔨 Building application...');
145
- // ATENÇÃO: Ajuste o caminho deste 'require' conforme a estrutura do seu projeto!
146
- const teste = require("../helpers");
147
- const app = teste.default({ dev: false, port: 3000, hostname: '0.0.0.0', framework: 'native' });
148
- await app.prepare();
149
- console.log('✅ Build complete\n');
150
- // 3. Copia a pasta .hight para exported (*** CORRIGIDO ***)
151
- const distDir = path.join(projectDir, '.hight');
152
- if (fs.existsSync(distDir)) {
153
- console.log('📦 Copying JavaScript files...');
154
- const exportDistDir = path.join(exportDir, '.hight');
155
- // --- Lógica de cópia substituída ---
156
- // A função copyDirRecursive agora lida com tudo (arquivos e subpastas)
157
- copyDirRecursive(distDir, exportDistDir);
158
- // --- Fim da substituição ---
159
- console.log('✅ JavaScript files copied\n');
160
- }
161
- // 4. Copia a pasta public se existir (*** CORRIGIDO ***)
162
- const publicDir = path.join(projectDir, 'public');
163
- if (fs.existsSync(publicDir)) {
164
- console.log('📁 Copying public files...');
165
- const exportPublicDir = path.join(exportDir, 'public');
166
- // --- Lógica de cópia substituída ---
167
- // Reutilizamos a mesma função corrigida
168
- copyDirRecursive(publicDir, exportPublicDir);
169
- // --- Fim da substituição ---
170
- console.log('✅ Public files copied\n');
171
- }
172
- // 5. Gera o index.html
173
- console.log('📝 Generating index.html...');
174
- // ATENÇÃO: Ajuste os caminhos destes 'requires' conforme a estrutura do seu projeto!
175
- const { render } = require('../renderer');
176
- const { loadRoutes, loadLayout, loadNotFound } = require('../router');
177
- // Carrega as rotas para gerar o HTML
178
- const userWebDir = path.join(projectDir, 'src', 'web');
179
- const userWebRoutesDir = path.join(userWebDir, 'routes');
180
- const routes = loadRoutes(userWebRoutesDir);
181
- loadLayout(userWebDir);
182
- loadNotFound(userWebDir);
183
- // Gera HTML para a rota raiz
184
- const rootRoute = routes.find(r => r.pattern === '/') || routes[0];
185
- if (rootRoute) {
186
- const mockReq = {
187
- url: '/',
188
- method: 'GET',
189
- headers: { host: 'localhost' },
190
- hwebDev: false,
191
- hotReloadManager: null
192
- };
193
- const html = await render({
194
- req: mockReq,
195
- route: rootRoute,
196
- params: {},
197
- allRoutes: routes
198
- });
199
- const scriptReplaced = html.replace('/_hight/', './.hight/');
200
- const indexPath = path.join(exportDir, 'index.html');
201
- fs.writeFileSync(indexPath, scriptReplaced, 'utf8');
202
- console.log('✅ index.html generated\n');
203
- }
204
- console.log('🎉 Export completed successfully!');
205
- console.log(`📂 Files exported to: ${exportDir}\n`);
206
- }
207
- catch (error) {
208
- // Logar o erro completo (com stack trace) é mais útil
209
- console.error('❌ Error during export:', error);
210
- process.exit(1);
211
- }
212
- });
213
- // Faz o "parse" dos argumentos passados na linha de comando
214
- program.parse(process.argv);
package/dist/builder.d.ts DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * Builds a single entry point into a single output file.
3
- * @param {string} entryPoint - The path to the entry file.
4
- * @param {string} outfile - The full path to the output file.
5
- * @param {boolean} isProduction - Se está em modo produção ou não.
6
- * @returns {Promise<void>}
7
- */
8
- export function build(entryPoint: string, outfile: string, isProduction?: boolean): Promise<void>;
9
- /**
10
- * Watches an entry point and its dependencies, rebuilding to a single output file.
11
- * @param {string} entryPoint - The path to the entry file.
12
- * @param {string} outfile - The full path to the output file.
13
- * @param {Object} hotReloadManager - Manager de hot reload (opcional).
14
- * @returns {Promise<void>}
15
- */
16
- export function watch(entryPoint: string, outfile: string, hotReloadManager?: Object): Promise<void>;
17
- /**
18
- * Builds with code splitting into multiple chunks based on module types.
19
- * @param {string} entryPoint - The path to the entry file.
20
- * @param {string} outdir - The directory for output files.
21
- * @param {boolean} isProduction - Se está em modo produção ou não.
22
- * @returns {Promise<void>}
23
- */
24
- export function buildWithChunks(entryPoint: string, outdir: string, isProduction?: boolean): Promise<void>;
25
- /**
26
- * Watches with code splitting enabled
27
- * @param {string} entryPoint - The path to the entry file.
28
- * @param {string} outdir - The directory for output files.
29
- * @param {Object} hotReloadManager - Manager de hot reload (opcional).
30
- * @returns {Promise<void>}
31
- */
32
- export function watchWithChunks(entryPoint: string, outdir: string, hotReloadManager?: Object): Promise<void>;