create-oven 0.3.1 → 0.4.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/index.js +8 -91
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -88,14 +88,14 @@ async function main() {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (args.includes('--version') || args.includes('-v')) {
|
|
91
|
-
console.log('create-oven v0.
|
|
91
|
+
console.log('create-oven v0.4.0');
|
|
92
92
|
process.exit(0);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
console.log(`
|
|
96
96
|
${c.bold}${c.cyan} ╔═══════════════════════════════════════╗
|
|
97
97
|
║ ║
|
|
98
|
-
║ 🔥 Create Oven App v0.
|
|
98
|
+
║ 🔥 Create Oven App v0.4.0 ║
|
|
99
99
|
║ ║
|
|
100
100
|
║ Next.js-style framework for Bun ║
|
|
101
101
|
║ ║
|
|
@@ -174,12 +174,14 @@ ${c.bold}${c.cyan} ╔═══════════════════
|
|
|
174
174
|
version: '0.1.0',
|
|
175
175
|
private: true,
|
|
176
176
|
scripts: {
|
|
177
|
-
dev: '
|
|
178
|
-
build: '
|
|
179
|
-
start: '
|
|
177
|
+
dev: 'oven dev',
|
|
178
|
+
build: 'oven build',
|
|
179
|
+
start: 'oven start',
|
|
180
180
|
...(useEslint && { lint: 'eslint .' }),
|
|
181
181
|
},
|
|
182
|
-
dependencies: {
|
|
182
|
+
dependencies: {
|
|
183
|
+
'oven-bun': 'latest',
|
|
184
|
+
},
|
|
183
185
|
devDependencies: {
|
|
184
186
|
...(useTypescript && { '@types/bun': 'latest', 'typescript': '^5' }),
|
|
185
187
|
...(useTailwind && { '@tailwindcss/postcss': '^4', 'tailwindcss': '^4' }),
|
|
@@ -457,91 +459,6 @@ export default function RootLayout({ children }) {
|
|
|
457
459
|
fs.writeFileSync(path.join(projectDir, 'app', `page.${ext}`), pageContent);
|
|
458
460
|
spin7.stop(`Created app/page.${ext}`);
|
|
459
461
|
|
|
460
|
-
// ============ server.tsx ============
|
|
461
|
-
const spin8 = spinner(`Creating server.${ext}...`);
|
|
462
|
-
const serverContent = `/**
|
|
463
|
-
* Oven Server
|
|
464
|
-
* Powered by Bun
|
|
465
|
-
*/
|
|
466
|
-
|
|
467
|
-
const PORT = parseInt(process.env.PORT || "3000");
|
|
468
|
-
|
|
469
|
-
// Simple router
|
|
470
|
-
const routes = new Map${useTypescript ? '<string, (req: Request) => Promise<Response>>' : ''}();
|
|
471
|
-
|
|
472
|
-
async function scanRoutes() {
|
|
473
|
-
const appDir = "./app";
|
|
474
|
-
|
|
475
|
-
// Scan for page files
|
|
476
|
-
const glob = new Bun.Glob("**/page.{tsx,jsx,ts,js}");
|
|
477
|
-
|
|
478
|
-
for await (const file of glob.scan({ cwd: appDir })) {
|
|
479
|
-
const routePath = "/" + file
|
|
480
|
-
.replace(/\\/page\\.(tsx|jsx|ts|js)$/, "")
|
|
481
|
-
.replace(/^page\\.(tsx|jsx|ts|js)$/, "")
|
|
482
|
-
.replace(/\\/$/, "") || "/";
|
|
483
|
-
|
|
484
|
-
routes.set(routePath === "" ? "/" : routePath, async (req${useTypescript ? ': Request' : ''}) => {
|
|
485
|
-
const module = await import(\`\${appDir}/\${file}\`);
|
|
486
|
-
const content = await module.default();
|
|
487
|
-
|
|
488
|
-
// Wrap with layout
|
|
489
|
-
let html = content;
|
|
490
|
-
try {
|
|
491
|
-
const layout = await import(\`\${appDir}/layout.tsx\`);
|
|
492
|
-
html = await layout.default({ children: content });
|
|
493
|
-
} catch {}
|
|
494
|
-
|
|
495
|
-
return new Response(html, {
|
|
496
|
-
headers: { "Content-Type": "text/html; charset=utf-8" },
|
|
497
|
-
});
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
async function main() {
|
|
503
|
-
await scanRoutes();
|
|
504
|
-
|
|
505
|
-
Bun.serve({
|
|
506
|
-
port: PORT,
|
|
507
|
-
async fetch(req${useTypescript ? ': Request' : ''}) {
|
|
508
|
-
const url = new URL(req.url);
|
|
509
|
-
let pathname = url.pathname;
|
|
510
|
-
|
|
511
|
-
if (pathname !== "/" && pathname.endsWith("/")) {
|
|
512
|
-
pathname = pathname.slice(0, -1);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Check routes
|
|
516
|
-
const handler = routes.get(pathname);
|
|
517
|
-
if (handler) {
|
|
518
|
-
return handler(req);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// Static files
|
|
522
|
-
const publicPath = "./public" + pathname;
|
|
523
|
-
const file = Bun.file(publicPath);
|
|
524
|
-
if (await file.exists()) {
|
|
525
|
-
return new Response(file);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return new Response("Not Found", { status: 404 });
|
|
529
|
-
},
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
console.log(\`
|
|
533
|
-
${c.green}▲${c.reset} Ready in \${Date.now() - start}ms
|
|
534
|
-
|
|
535
|
-
${c.dim}➜${c.reset} Local: ${c.cyan}http://localhost:\${PORT}${c.reset}
|
|
536
|
-
\`);
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
const start = Date.now();
|
|
540
|
-
main();
|
|
541
|
-
`;
|
|
542
|
-
fs.writeFileSync(path.join(projectDir, `server.${ext}`), serverContent);
|
|
543
|
-
spin8.stop(`Created server.${ext}`);
|
|
544
|
-
|
|
545
462
|
// ============ .gitignore ============
|
|
546
463
|
const spin9 = spinner('Creating .gitignore...');
|
|
547
464
|
fs.writeFileSync(path.join(projectDir, '.gitignore'), `# Dependencies
|