hightjs 0.3.3 → 0.3.4
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/factory.js +8 -8
- package/dist/adapters/native.js +3 -3
- package/dist/auth/client.js +5 -5
- package/dist/auth/components.js +2 -2
- package/dist/auth/core.js +2 -2
- package/dist/auth/react.js +4 -4
- package/dist/auth/routes.js +1 -1
- package/dist/bin/hightjs.js +29 -328
- package/dist/builder.js +7 -19
- package/dist/client/DefaultNotFound.js +1 -1
- package/dist/client/entry.client.js +3 -3
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +90 -28
- package/dist/hotReload.js +12 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -30
- package/dist/router.js +133 -62
- package/dist/types.d.ts +42 -0
- package/docs/config.md +201 -0
- package/example/hightjs.config.ts +81 -0
- package/example/package-lock.json +633 -3054
- package/example/package.json +1 -1
- package/package.json +1 -1
- package/src/adapters/factory.ts +8 -8
- package/src/adapters/native.ts +3 -3
- package/src/auth/client.ts +5 -5
- package/src/auth/components.tsx +2 -2
- package/src/auth/core.ts +2 -2
- package/src/auth/react.tsx +4 -4
- package/src/auth/routes.ts +1 -1
- package/src/bin/hightjs.js +30 -391
- package/src/builder.js +7 -20
- package/src/client/DefaultNotFound.tsx +1 -1
- package/src/client/entry.client.tsx +3 -3
- package/src/helpers.ts +105 -29
- package/src/hotReload.ts +12 -12
- package/src/index.ts +20 -33
- package/src/router.ts +140 -63
- package/src/types.ts +52 -0
- package/example/.hweb/entry.client.js +0 -24
- package/example/hweb-dist/main-5KKAYNUU.js +0 -1137
package/src/bin/hightjs.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* you may not use this file except in compliance with the License.
|
|
9
9
|
* You may obtain a copy of the License at
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
12
|
*
|
|
13
13
|
* Unless required by applicable law or agreed to in writing, software
|
|
14
14
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
@@ -26,7 +26,7 @@ const { program } = require('commander');
|
|
|
26
26
|
|
|
27
27
|
program
|
|
28
28
|
.version('1.0.0')
|
|
29
|
-
.description('CLI
|
|
29
|
+
.description('CLI to manage the application.');
|
|
30
30
|
|
|
31
31
|
// --- Comando DEV ---
|
|
32
32
|
const fs = require('fs');
|
|
@@ -69,7 +69,7 @@ function initializeApp(options, isDev) {
|
|
|
69
69
|
appOptions.ssl.redirectPort = options.httpRedirectPort || 80;
|
|
70
70
|
|
|
71
71
|
} else {
|
|
72
|
-
Console.logWithout(Levels.ERROR, null, `
|
|
72
|
+
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.`)
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
process.exit(1); // Encerra o processo com erro
|
|
@@ -85,11 +85,11 @@ function initializeApp(options, isDev) {
|
|
|
85
85
|
// --- Comando DEV ---
|
|
86
86
|
program
|
|
87
87
|
.command('dev')
|
|
88
|
-
.description('
|
|
89
|
-
.option('-p, --port <number>', '
|
|
90
|
-
.option('-H, --hostname <string>', '
|
|
91
|
-
.option('--ssl', '
|
|
92
|
-
.option('--http-redirect-port <number>', '
|
|
88
|
+
.description('Starts the application in development 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
93
|
.action((options) => {
|
|
94
94
|
initializeApp(options, true); // Chama a função com dev: true
|
|
95
95
|
});
|
|
@@ -97,11 +97,11 @@ program
|
|
|
97
97
|
// --- Comando START (Produção) ---
|
|
98
98
|
program
|
|
99
99
|
.command('start')
|
|
100
|
-
.description('
|
|
101
|
-
.option('-p, --port <number>', '
|
|
102
|
-
.option('-H, --hostname <string>', '
|
|
103
|
-
.option('--ssl', '
|
|
104
|
-
.option('--http-redirect-port <number>', '
|
|
100
|
+
.description('Starts the application in production mode.')
|
|
101
|
+
.option('-p, --port <number>', 'Specifies the port to run on', '3000')
|
|
102
|
+
.option('-H, --hostname <string>', 'Specifies the hostname to run on', '0.0.0.0')
|
|
103
|
+
.option('--ssl', 'Activates HTTPS/SSL mode (requires ./ssl/key.pem and ./ssl/cert.pem)')
|
|
104
|
+
.option('--http-redirect-port <number>', 'Port for HTTP->HTTPS redirection', '80')
|
|
105
105
|
.action((options) => {
|
|
106
106
|
initializeApp(options, false); // Chama a função com dev: false
|
|
107
107
|
});
|
|
@@ -109,34 +109,34 @@ program
|
|
|
109
109
|
// --- Comando EXPORT ---
|
|
110
110
|
program
|
|
111
111
|
.command('export')
|
|
112
|
-
.description('
|
|
113
|
-
.option('-o, --output <path>', '
|
|
112
|
+
.description('Exports the application as static HTML to the "exported" folder.')
|
|
113
|
+
.option('-o, --output <path>', 'Specifies the output directory', 'exported')
|
|
114
114
|
.action(async (options) => {
|
|
115
115
|
const projectDir = process.cwd();
|
|
116
116
|
const exportDir = path.join(projectDir, options.output);
|
|
117
117
|
|
|
118
|
-
console.log('🚀
|
|
118
|
+
console.log('🚀 Starting export...\n');
|
|
119
119
|
|
|
120
120
|
try {
|
|
121
121
|
// 1. Cria a pasta exported (limpa se já existir)
|
|
122
122
|
if (fs.existsSync(exportDir)) {
|
|
123
|
-
console.log('🗑️
|
|
123
|
+
console.log('🗑️ Cleaning existing export folder...');
|
|
124
124
|
fs.rmSync(exportDir, { recursive: true, force: true });
|
|
125
125
|
}
|
|
126
126
|
fs.mkdirSync(exportDir, { recursive: true });
|
|
127
|
-
console.log('✅
|
|
127
|
+
console.log('✅ Export folder created\n');
|
|
128
128
|
|
|
129
129
|
// 2. Inicializa e prepara o build
|
|
130
|
-
console.log('🔨
|
|
130
|
+
console.log('🔨 Building application...');
|
|
131
131
|
const teste = require("../helpers");
|
|
132
132
|
const app = teste.default({ dev: false, port: 3000, hostname: '0.0.0.0', framework: 'native' });
|
|
133
133
|
await app.prepare();
|
|
134
|
-
console.log('✅ Build
|
|
134
|
+
console.log('✅ Build complete\n');
|
|
135
135
|
|
|
136
136
|
// 3. Copia a pasta hweb-dist para exported
|
|
137
137
|
const distDir = path.join(projectDir, 'hweb-dist');
|
|
138
138
|
if (fs.existsSync(distDir)) {
|
|
139
|
-
console.log('📦
|
|
139
|
+
console.log('📦 Copying JavaScript files...');
|
|
140
140
|
const exportDistDir = path.join(exportDir, 'hweb-dist');
|
|
141
141
|
fs.mkdirSync(exportDistDir, { recursive: true });
|
|
142
142
|
|
|
@@ -147,13 +147,13 @@ program
|
|
|
147
147
|
path.join(exportDistDir, file)
|
|
148
148
|
);
|
|
149
149
|
});
|
|
150
|
-
console.log('✅
|
|
150
|
+
console.log('✅ JavaScript files copied\n');
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
// 4. Copia a pasta public se existir
|
|
154
154
|
const publicDir = path.join(projectDir, 'public');
|
|
155
155
|
if (fs.existsSync(publicDir)) {
|
|
156
|
-
console.log('📁
|
|
156
|
+
console.log('📁 Copying public files...');
|
|
157
157
|
const exportPublicDir = path.join(exportDir, 'public');
|
|
158
158
|
|
|
159
159
|
function copyRecursive(src, dest) {
|
|
@@ -168,11 +168,11 @@ program
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
copyRecursive(publicDir, exportPublicDir);
|
|
171
|
-
console.log('✅
|
|
171
|
+
console.log('✅ Public files copied\n');
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
// 5. Gera o index.html
|
|
175
|
-
console.log('📝
|
|
175
|
+
console.log('📝 Generating index.html...');
|
|
176
176
|
const { render } = require('../renderer');
|
|
177
177
|
const { loadRoutes, loadLayout, loadNotFound } = require('../router');
|
|
178
178
|
|
|
@@ -205,379 +205,18 @@ program
|
|
|
205
205
|
|
|
206
206
|
const indexPath = path.join(exportDir, 'index.html');
|
|
207
207
|
fs.writeFileSync(indexPath, html, 'utf8');
|
|
208
|
-
console.log('✅ index.html
|
|
208
|
+
console.log('✅ index.html generated\n');
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
console.log('🎉
|
|
212
|
-
console.log(`📂
|
|
211
|
+
console.log('🎉 Export completed successfully!');
|
|
212
|
+
console.log(`📂 Files exported to: ${exportDir}\n`);
|
|
213
213
|
|
|
214
214
|
} catch (error) {
|
|
215
|
-
console.error('❌
|
|
215
|
+
console.error('❌ Error during export:', error.message);
|
|
216
216
|
process.exit(1);
|
|
217
217
|
}
|
|
218
218
|
});
|
|
219
219
|
|
|
220
|
-
// --- Comando MIGRATE FROM NEXTJS ---
|
|
221
|
-
program
|
|
222
|
-
.command('migrate-from-nextjs')
|
|
223
|
-
.description('Migra um projeto Next.js para HightJS.')
|
|
224
|
-
.option('-s, --source <path>', 'Caminho do projeto Next.js', process.cwd())
|
|
225
|
-
.option('-o, --output <path>', 'Diretório de saída para o projeto HightJS', './hightjs-project')
|
|
226
|
-
.action(async (options) => {
|
|
227
|
-
const sourcePath = path.resolve(options.source);
|
|
228
|
-
const outputPath = path.resolve(options.output);
|
|
229
|
-
|
|
230
|
-
console.log('🚀 Iniciando migração de Next.js para HightJS...\n');
|
|
231
|
-
console.log(`📂 Origem: ${sourcePath}`);
|
|
232
|
-
console.log(`📂 Destino: ${outputPath}\n`);
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
// Verifica se o diretório de origem existe
|
|
236
|
-
if (!fs.existsSync(sourcePath)) {
|
|
237
|
-
throw new Error(`Diretório de origem não encontrado: ${sourcePath}`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Verifica se é um projeto Next.js
|
|
241
|
-
const nextConfigPath = path.join(sourcePath, 'next.config.js');
|
|
242
|
-
const nextConfigMjsPath = path.join(sourcePath, 'next.config.mjs');
|
|
243
|
-
const packageJsonPath = path.join(sourcePath, 'package.json');
|
|
244
|
-
|
|
245
|
-
if (!fs.existsSync(nextConfigPath) && !fs.existsSync(nextConfigMjsPath) && !fs.existsSync(packageJsonPath)) {
|
|
246
|
-
throw new Error('Não foi encontrado um projeto Next.js válido no diretório especificado.');
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Cria o diretório de saída
|
|
250
|
-
if (fs.existsSync(outputPath)) {
|
|
251
|
-
console.log('⚠️ Diretório de destino já existe. Limpando...');
|
|
252
|
-
fs.rmSync(outputPath, { recursive: true, force: true });
|
|
253
|
-
}
|
|
254
|
-
fs.mkdirSync(outputPath, { recursive: true });
|
|
255
|
-
|
|
256
|
-
// 1. Cria estrutura básica do HightJS
|
|
257
|
-
console.log('📁 Criando estrutura de diretórios...');
|
|
258
|
-
const srcDir = path.join(outputPath, 'src');
|
|
259
|
-
const webDir = path.join(srcDir, 'web');
|
|
260
|
-
const routesDir = path.join(webDir, 'routes');
|
|
261
|
-
const publicDir = path.join(outputPath, 'public');
|
|
262
|
-
|
|
263
|
-
fs.mkdirSync(srcDir, { recursive: true });
|
|
264
|
-
fs.mkdirSync(webDir, { recursive: true });
|
|
265
|
-
fs.mkdirSync(routesDir, { recursive: true });
|
|
266
|
-
fs.mkdirSync(publicDir, { recursive: true });
|
|
267
|
-
|
|
268
|
-
// 2. Copia arquivos públicos
|
|
269
|
-
console.log('📦 Copiando arquivos públicos...');
|
|
270
|
-
const nextPublicDir = path.join(sourcePath, 'public');
|
|
271
|
-
if (fs.existsSync(nextPublicDir)) {
|
|
272
|
-
copyDirectory(nextPublicDir, publicDir);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// 3. Migra páginas do Next.js para rotas do HightJS
|
|
276
|
-
console.log('🔄 Migrando páginas para rotas...');
|
|
277
|
-
const nextPagesDir = path.join(sourcePath, 'pages');
|
|
278
|
-
const nextAppDir = path.join(sourcePath, 'app');
|
|
279
|
-
const nextSrcPagesDir = path.join(sourcePath, 'src', 'pages');
|
|
280
|
-
const nextSrcAppDir = path.join(sourcePath, 'src', 'app');
|
|
281
|
-
|
|
282
|
-
let pagesDir = null;
|
|
283
|
-
let isAppRouter = false;
|
|
284
|
-
|
|
285
|
-
if (fs.existsSync(nextAppDir)) {
|
|
286
|
-
pagesDir = nextAppDir;
|
|
287
|
-
isAppRouter = true;
|
|
288
|
-
console.log('✅ Detectado Next.js App Router');
|
|
289
|
-
} else if (fs.existsSync(nextSrcAppDir)) {
|
|
290
|
-
pagesDir = nextSrcAppDir;
|
|
291
|
-
isAppRouter = true;
|
|
292
|
-
console.log('✅ Detectado Next.js App Router (em src/)');
|
|
293
|
-
} else if (fs.existsSync(nextPagesDir)) {
|
|
294
|
-
pagesDir = nextPagesDir;
|
|
295
|
-
console.log('✅ Detectado Next.js Pages Router');
|
|
296
|
-
} else if (fs.existsSync(nextSrcPagesDir)) {
|
|
297
|
-
pagesDir = nextSrcPagesDir;
|
|
298
|
-
console.log('✅ Detectado Next.js Pages Router (em src/)');
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (pagesDir) {
|
|
302
|
-
if (isAppRouter) {
|
|
303
|
-
migrateAppRouter(pagesDir, routesDir);
|
|
304
|
-
} else {
|
|
305
|
-
migratePagesRouter(pagesDir, routesDir);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// 5. Cria package.json
|
|
311
|
-
console.log('📄 Criando package.json...');
|
|
312
|
-
let originalPackageJson = {};
|
|
313
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
314
|
-
originalPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const newPackageJson = {
|
|
318
|
-
name: originalPackageJson.name || 'hightjs-app',
|
|
319
|
-
version: '1.0.0',
|
|
320
|
-
description: originalPackageJson.description || 'HightJS application migrated from Next.js',
|
|
321
|
-
scripts: {
|
|
322
|
-
dev: 'hight dev',
|
|
323
|
-
start: 'hight start',
|
|
324
|
-
build: 'hight export',
|
|
325
|
-
...originalPackageJson.scripts
|
|
326
|
-
},
|
|
327
|
-
dependencies: {
|
|
328
|
-
hightjs: 'latest',
|
|
329
|
-
react: originalPackageJson.dependencies?.react || '^18.2.0',
|
|
330
|
-
'react-dom': originalPackageJson.dependencies?.['react-dom'] || '^18.2.0',
|
|
331
|
-
...filterDependencies(originalPackageJson.dependencies)
|
|
332
|
-
},
|
|
333
|
-
devDependencies: {
|
|
334
|
-
'@types/node': '^20.11.24',
|
|
335
|
-
'@types/react': '^18.2.0',
|
|
336
|
-
'@types/react-dom': '^18.2.0',
|
|
337
|
-
typescript: '^5.3.3',
|
|
338
|
-
...filterDependencies(originalPackageJson.devDependencies)
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
fs.writeFileSync(
|
|
343
|
-
path.join(outputPath, 'package.json'),
|
|
344
|
-
JSON.stringify(newPackageJson, null, 2),
|
|
345
|
-
'utf8'
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
// 6. Cria tsconfig.json
|
|
349
|
-
console.log('⚙️ Criando tsconfig.json...');
|
|
350
|
-
const tsConfig = {
|
|
351
|
-
compilerOptions: {
|
|
352
|
-
target: 'ES2020',
|
|
353
|
-
lib: ['ES2020', 'DOM', 'DOM.Iterable'],
|
|
354
|
-
jsx: 'react-jsx',
|
|
355
|
-
module: 'commonjs',
|
|
356
|
-
moduleResolution: 'node',
|
|
357
|
-
esModuleInterop: true,
|
|
358
|
-
strict: true,
|
|
359
|
-
skipLibCheck: true,
|
|
360
|
-
forceConsistentCasingInFileNames: true,
|
|
361
|
-
resolveJsonModule: true,
|
|
362
|
-
allowSyntheticDefaultImports: true
|
|
363
|
-
},
|
|
364
|
-
include: ['src/**/*'],
|
|
365
|
-
exclude: ['node_modules']
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
fs.writeFileSync(
|
|
369
|
-
path.join(outputPath, 'tsconfig.json'),
|
|
370
|
-
JSON.stringify(tsConfig, null, 2),
|
|
371
|
-
'utf8'
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
// 7. Cria README
|
|
375
|
-
console.log('📖 Criando README...');
|
|
376
|
-
const readmeContent = `# ${originalPackageJson.name || 'HightJS App'}
|
|
377
|
-
|
|
378
|
-
Este projeto foi migrado de Next.js para HightJS.
|
|
379
|
-
|
|
380
|
-
## Comandos Disponíveis
|
|
381
|
-
|
|
382
|
-
- \`npm run dev\` - Inicia o servidor de desenvolvimento
|
|
383
|
-
- \`npm run start\` - Inicia o servidor em modo produção
|
|
384
|
-
- \`npm run build\` - Exporta a aplicação como HTML estático
|
|
385
|
-
|
|
386
|
-
## Próximos Passos
|
|
387
|
-
|
|
388
|
-
1. Instale as dependências: \`npm install\`
|
|
389
|
-
2. Revise os arquivos migrados em \`src/web/routes/\`
|
|
390
|
-
3. Ajuste manualmente qualquer código que precise de adaptação
|
|
391
|
-
4. Execute \`npm run dev\` para testar
|
|
392
|
-
|
|
393
|
-
## Notas de Migração
|
|
394
|
-
|
|
395
|
-
- Rotas dinâmicas do Next.js foram convertidas para o formato HightJS
|
|
396
|
-
- API Routes precisam ser migradas manualmente para HightJS API routes
|
|
397
|
-
- Server Components foram convertidos para componentes React padrão
|
|
398
|
-
- Revise imports e configurações específicas do Next.js
|
|
399
|
-
|
|
400
|
-
Para mais informações sobre HightJS, visite a documentação.
|
|
401
|
-
`;
|
|
402
|
-
|
|
403
|
-
fs.writeFileSync(path.join(outputPath, 'README.md'), readmeContent, 'utf8');
|
|
404
|
-
|
|
405
|
-
console.log('\n✅ Migração concluída com sucesso!');
|
|
406
|
-
console.log(`\n📂 Projeto criado em: ${outputPath}`);
|
|
407
|
-
console.log('\n📋 Próximos passos:');
|
|
408
|
-
console.log(` 1. cd ${path.relative(process.cwd(), outputPath)}`);
|
|
409
|
-
console.log(' 2. npm install');
|
|
410
|
-
console.log(' 3. npm run dev');
|
|
411
|
-
console.log('\n⚠️ IMPORTANTE: Revise os arquivos migrados e ajuste conforme necessário.\n');
|
|
412
|
-
|
|
413
|
-
} catch (error) {
|
|
414
|
-
console.error('❌ Erro durante a migração:', error.message);
|
|
415
|
-
console.error(error.stack);
|
|
416
|
-
process.exit(1);
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
// Funções auxiliares para migração
|
|
421
|
-
function copyDirectory(src, dest) {
|
|
422
|
-
if (!fs.existsSync(src)) return;
|
|
423
|
-
|
|
424
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
425
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
426
|
-
|
|
427
|
-
for (const entry of entries) {
|
|
428
|
-
const srcPath = path.join(src, entry.name);
|
|
429
|
-
const destPath = path.join(dest, entry.name);
|
|
430
|
-
|
|
431
|
-
if (entry.isDirectory()) {
|
|
432
|
-
copyDirectory(srcPath, destPath);
|
|
433
|
-
} else {
|
|
434
|
-
fs.copyFileSync(srcPath, destPath);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
function migratePagesRouter(pagesDir, routesDir) {
|
|
440
|
-
function processDirectory(dir, baseRoute = '') {
|
|
441
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
442
|
-
|
|
443
|
-
for (const entry of entries) {
|
|
444
|
-
const fullPath = path.join(dir, entry.name);
|
|
445
|
-
|
|
446
|
-
if (entry.isDirectory()) {
|
|
447
|
-
// Processa subdiretórios (rotas aninhadas)
|
|
448
|
-
const newBaseRoute = path.join(baseRoute, entry.name);
|
|
449
|
-
processDirectory(fullPath, newBaseRoute);
|
|
450
|
-
} else if (entry.name.match(/\.(tsx?|jsx?)$/)) {
|
|
451
|
-
// Ignora arquivos especiais do Next.js
|
|
452
|
-
if (['_app', '_document', '_error', 'api'].some(special => entry.name.startsWith(special))) {
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// Converte nome do arquivo para rota HightJS
|
|
457
|
-
let fileName = entry.name.replace(/\.(tsx?|jsx?)$/, '');
|
|
458
|
-
let routePath = baseRoute;
|
|
459
|
-
|
|
460
|
-
if (fileName === 'index') {
|
|
461
|
-
// index.tsx -> route vazia ou baseRoute
|
|
462
|
-
routePath = baseRoute || '/';
|
|
463
|
-
} else {
|
|
464
|
-
// [id].tsx -> $id.tsx
|
|
465
|
-
fileName = fileName.replace(/\[([^\]]+)\]/g, '$$$1');
|
|
466
|
-
routePath = path.join(baseRoute, fileName);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// Lê o conteúdo original
|
|
470
|
-
const originalContent = fs.readFileSync(fullPath, 'utf8');
|
|
471
|
-
|
|
472
|
-
// Transforma o conteúdo
|
|
473
|
-
const transformedContent = transformNextJsPage(originalContent);
|
|
474
|
-
|
|
475
|
-
// Cria estrutura de diretórios se necessário
|
|
476
|
-
const targetDir = path.join(routesDir, baseRoute);
|
|
477
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
478
|
-
|
|
479
|
-
// Salva o arquivo transformado
|
|
480
|
-
const targetFileName = fileName === 'index' ? 'route.tsx' : `${fileName}.route.tsx`;
|
|
481
|
-
const targetPath = path.join(targetDir, targetFileName);
|
|
482
|
-
fs.writeFileSync(targetPath, transformedContent, 'utf8');
|
|
483
|
-
|
|
484
|
-
console.log(` ✓ ${path.relative(pagesDir, fullPath)} -> ${path.relative(routesDir, targetPath)}`);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
processDirectory(pagesDir);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
function migrateAppRouter(appDir, routesDir) {
|
|
493
|
-
function processDirectory(dir, baseRoute = '') {
|
|
494
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
495
|
-
let hasPage = false;
|
|
496
|
-
|
|
497
|
-
for (const entry of entries) {
|
|
498
|
-
const fullPath = path.join(dir, entry.name);
|
|
499
|
-
|
|
500
|
-
if (entry.isDirectory()) {
|
|
501
|
-
// Suporta rotas dinâmicas como [id]
|
|
502
|
-
let dirName = entry.name;
|
|
503
|
-
if (dirName.startsWith('[') && dirName.endsWith(']')) {
|
|
504
|
-
dirName = '$' + dirName.slice(1, -1);
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
const newBaseRoute = path.join(baseRoute, dirName);
|
|
508
|
-
processDirectory(fullPath, newBaseRoute);
|
|
509
|
-
} else if (entry.name === 'page.tsx' || entry.name === 'page.jsx' || entry.name === 'page.ts' || entry.name === 'page.js') {
|
|
510
|
-
hasPage = true;
|
|
511
|
-
|
|
512
|
-
// Lê o conteúdo original
|
|
513
|
-
const originalContent = fs.readFileSync(fullPath, 'utf8');
|
|
514
|
-
|
|
515
|
-
// Transforma o conteúdo
|
|
516
|
-
const transformedContent = transformNextJsPage(originalContent);
|
|
517
|
-
|
|
518
|
-
// Cria estrutura de diretórios
|
|
519
|
-
const targetDir = path.join(routesDir, baseRoute);
|
|
520
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
521
|
-
|
|
522
|
-
// Salva como route.tsx
|
|
523
|
-
const targetPath = path.join(targetDir, 'route.tsx');
|
|
524
|
-
fs.writeFileSync(targetPath, transformedContent, 'utf8');
|
|
525
|
-
|
|
526
|
-
console.log(` ✓ ${path.relative(appDir, fullPath)} -> ${path.relative(routesDir, targetPath)}`);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
processDirectory(appDir);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
function transformNextJsPage(content) {
|
|
535
|
-
// Remove 'use client' e 'use server'
|
|
536
|
-
content = content.replace(/['"]use (client|server)['"]\s*;\s*/g, '');
|
|
537
|
-
|
|
538
|
-
// Remove imports específicos do Next.js
|
|
539
|
-
content = content.replace(/import\s+.*?from\s+['"]next\/.*?['"];?\s*/g, '');
|
|
540
|
-
|
|
541
|
-
// Substitui Link do Next.js por Link do HightJS
|
|
542
|
-
if (content.includes('Link')) {
|
|
543
|
-
content = `import { Link } from 'hightjs/client';\n` + content;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// Substitui useRouter do Next.js
|
|
547
|
-
content = content.replace(
|
|
548
|
-
/import\s*\{\s*useRouter\s*\}\s*from\s*['"]next\/router['"]/g,
|
|
549
|
-
"import { useRouter } from 'hightjs/client'"
|
|
550
|
-
);
|
|
551
|
-
|
|
552
|
-
// Substitui Image do Next.js por img normal (com comentário para revisão)
|
|
553
|
-
content = content.replace(
|
|
554
|
-
/<Image\s+/g,
|
|
555
|
-
'<img /* TODO: Migrado de Next.js Image - revisar otimizações */ '
|
|
556
|
-
);
|
|
557
|
-
|
|
558
|
-
// Remove getServerSideProps, getStaticProps, getStaticPaths
|
|
559
|
-
content = content.replace(/export\s+(async\s+)?function\s+get(ServerSideProps|StaticProps|StaticPaths)\s*\([^)]*\)\s*\{[\s\S]*?\n\}/g, '');
|
|
560
|
-
|
|
561
|
-
// Adiciona comentário sobre metadata se houver
|
|
562
|
-
if (content.includes('export const metadata')) {
|
|
563
|
-
content = '// TODO: Migrar metadata do Next.js para HightJS\n' + content;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
return content.trim();
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function filterDependencies(deps) {
|
|
570
|
-
if (!deps) return {};
|
|
571
|
-
|
|
572
|
-
const filtered = { ...deps };
|
|
573
|
-
|
|
574
|
-
// Remove dependências específicas do Next.js
|
|
575
|
-
delete filtered.next;
|
|
576
|
-
delete filtered['@next/font'];
|
|
577
|
-
delete filtered['next-auth'];
|
|
578
|
-
|
|
579
|
-
return filtered;
|
|
580
|
-
}
|
|
581
220
|
|
|
582
221
|
// Faz o "parse" dos argumentos passados na linha de comando
|
|
583
|
-
program.parse(process.argv);
|
|
222
|
+
program.parse(process.argv);
|
package/src/builder.js
CHANGED
|
@@ -86,7 +86,7 @@ const postcssPlugin = {
|
|
|
86
86
|
const pluginModule = require(resolvedPath);
|
|
87
87
|
plugins.push(pluginModule(pluginOptions || {}));
|
|
88
88
|
} catch (error) {
|
|
89
|
-
Console.warn(`
|
|
89
|
+
Console.warn(`Unable to load plugin ${pluginName}:`, error.message);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -102,8 +102,8 @@ const postcssPlugin = {
|
|
|
102
102
|
processedCss = result.css;
|
|
103
103
|
|
|
104
104
|
} catch (postcssError) {
|
|
105
|
-
Console.warn(`
|
|
106
|
-
Console.warn(`
|
|
105
|
+
Console.warn(`Error processing CSS with PostCSS:`, postcssError.message);
|
|
106
|
+
Console.warn(`Using raw CSS without processing.`);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -200,10 +200,6 @@ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
|
200
200
|
// limpar diretorio
|
|
201
201
|
fs.rmSync(outdir, { recursive: true, force: true });
|
|
202
202
|
|
|
203
|
-
if (!isProduction) {
|
|
204
|
-
console.log(`Iniciando o build com chunks de \"${entryPoint}\"...`);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
203
|
try {
|
|
208
204
|
await esbuild.build({
|
|
209
205
|
entryPoints: [entryPoint],
|
|
@@ -231,11 +227,8 @@ async function buildWithChunks(entryPoint, outdir, isProduction = false) {
|
|
|
231
227
|
treeShaking: true,
|
|
232
228
|
});
|
|
233
229
|
|
|
234
|
-
if (!isProduction) {
|
|
235
|
-
console.log(`Build com chunks finalizado! Saída: \"${outdir}\".`);
|
|
236
|
-
}
|
|
237
230
|
} catch (error) {
|
|
238
|
-
console.error('
|
|
231
|
+
console.error('An error occurred while building:', error);
|
|
239
232
|
process.exit(1);
|
|
240
233
|
}
|
|
241
234
|
}
|
|
@@ -298,7 +291,7 @@ async function watchWithChunks(entryPoint, outdir, hotReloadManager = null) {
|
|
|
298
291
|
await context.watch();
|
|
299
292
|
} catch (error) {
|
|
300
293
|
console.error(error)
|
|
301
|
-
Console.error('
|
|
294
|
+
Console.error('Error starting watch mode with chunks:', error);
|
|
302
295
|
throw error;
|
|
303
296
|
}
|
|
304
297
|
}
|
|
@@ -314,9 +307,6 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
314
307
|
// limpar diretorio do outfile
|
|
315
308
|
const outdir = path.dirname(outfile);
|
|
316
309
|
fs.rmSync(outdir, { recursive: true, force: true });
|
|
317
|
-
if (!isProduction) {
|
|
318
|
-
console.log(`Iniciando o build de \"${entryPoint}\"...`);
|
|
319
|
-
}
|
|
320
310
|
|
|
321
311
|
try {
|
|
322
312
|
await esbuild.build({
|
|
@@ -348,11 +338,8 @@ async function build(entryPoint, outfile, isProduction = false) {
|
|
|
348
338
|
drop: [], // Não remove nada automaticamente
|
|
349
339
|
});
|
|
350
340
|
|
|
351
|
-
if (!isProduction) {
|
|
352
|
-
console.log(`Build finalizado com sucesso! Saída: \"${outfile}\".`);
|
|
353
|
-
}
|
|
354
341
|
} catch (error) {
|
|
355
|
-
console.error('
|
|
342
|
+
console.error('An error occurred during build:', error);
|
|
356
343
|
process.exit(1);
|
|
357
344
|
}
|
|
358
345
|
}
|
|
@@ -416,7 +403,7 @@ async function watch(entryPoint, outfile, hotReloadManager = null) {
|
|
|
416
403
|
// Configura o watcher do esbuild
|
|
417
404
|
await context.watch();
|
|
418
405
|
} catch (error) {
|
|
419
|
-
Console.error('
|
|
406
|
+
Console.error('Error starting watch mode:', error);
|
|
420
407
|
throw error;
|
|
421
408
|
}
|
|
422
409
|
}
|
|
@@ -284,7 +284,7 @@ function initializeClient() {
|
|
|
284
284
|
const initialData = (window as any).__HWEB_INITIAL_DATA__;
|
|
285
285
|
|
|
286
286
|
if (!initialData) {
|
|
287
|
-
console.error('[hweb]
|
|
287
|
+
console.error('[hweb] Initial data not found on page.');
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
290
|
|
|
@@ -298,7 +298,7 @@ function initializeClient() {
|
|
|
298
298
|
|
|
299
299
|
const container = document.getElementById('root');
|
|
300
300
|
if (!container) {
|
|
301
|
-
console.error('[hweb] Container #root
|
|
301
|
+
console.error('[hweb] Container #root not found.');
|
|
302
302
|
return;
|
|
303
303
|
}
|
|
304
304
|
|
|
@@ -316,7 +316,7 @@ function initializeClient() {
|
|
|
316
316
|
/>
|
|
317
317
|
);
|
|
318
318
|
} catch (error) {
|
|
319
|
-
console.error('[hweb]
|
|
319
|
+
console.error('[hweb] Error rendering application:', error);
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
|