Skip to content

Commit 3b1067b

Browse files
committed
Fix Next.js template scaffold and preview issues
- Create complete Next.js scaffold directory with TypeScript, Tailwind CSS, and shadcn/ui - Fix scaffold path resolution using app.getAppPath() instead of manual dirname - Replace bulk fs.copy with robust item-by-item copying for better error handling - Add Next.js specific URL detection patterns for preview system - Implement Next.js server command detection (npm run dev vs npx vite) - Remove broken GitHub dependency for Next.js template - Add comprehensive scaffold files including hooks, utils, and config files - Enhance error handling and debugging for scaffold operations
1 parent 655fe42 commit 3b1067b

File tree

21 files changed

+744
-23
lines changed

21 files changed

+744
-23
lines changed

scaffold-nextjs/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

scaffold-nextjs/AI_RULES.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Tech Stack
2+
- You are building a Next.js application.
3+
- Use TypeScript.
4+
- Use Next.js App Router (app directory).
5+
- Always put source code in the appropriate directories.
6+
- Put pages into app/ directory (using App Router)
7+
- Put components into components/ directory
8+
- Put reusable UI components into components/ui/ directory
9+
- Put custom hooks into src/hooks/ directory
10+
- Put utility functions into src/utils/ or lib/ directory
11+
- The main page is app/page.tsx
12+
- UPDATE the main page to include the new components. OTHERWISE, the user can NOT see any components!
13+
- ALWAYS try to use the shadcn/ui library.
14+
- Tailwind CSS: always use Tailwind CSS for styling components. Utilize Tailwind classes extensively for layout, spacing, colors, and other design aspects.
15+
16+
## Project Structure
17+
- `app/`: Next.js App Router directory
18+
- `layout.tsx`: Root layout component
19+
- `page.tsx`: Home page component
20+
- `globals.css`: Global styles and Tailwind directives
21+
- `components/`: React components
22+
- `lib/`: Utility functions and configurations
23+
- `package.json`: Dependencies and scripts
24+
- `next.config.js`: Next.js configuration
25+
- `tailwind.config.js`: Tailwind CSS configuration
26+
- `components.json`: shadcn/ui configuration
27+
28+
## Development Guidelines
29+
- Use Next.js App Router for routing and layouts
30+
- Implement proper TypeScript types throughout the codebase
31+
- Use Server Components when possible, Client Components when needed
32+
- Follow Next.js best practices for performance and SEO
33+
- Use Tailwind CSS for styling with shadcn/ui components
34+
- Implement proper error boundaries and loading states
35+
- Use Next.js Image component for optimized images
36+
- Follow REST API conventions or GraphQL for data fetching
37+
38+
## Available packages and libraries
39+
- The lucide-react package is installed for icons
40+
- You ALREADY have ALL the shadcn/ui components and their dependencies installed. So you don't need to install them again.
41+
- You have ALL the necessary Radix UI components installed.
42+
- Use prebuilt components from the shadcn/ui library after importing them. Note that these files shouldn't be edited, so make new components if you need to change them.
43+
- @tanstack/react-query is available for data fetching and caching
44+
45+
## Next.js Specific Guidelines
46+
- Use `app/` directory for App Router (not `pages/`)
47+
- Create route groups with parentheses: `(group-name)`
48+
- Use `loading.tsx` for loading states
49+
- Use `error.tsx` for error boundaries
50+
- Use `not-found.tsx` for 404 pages
51+
- Use `layout.tsx` for shared layouts
52+
- Use Server Actions for form submissions when appropriate
53+
- Use `next/font` for optimized font loading
54+
- Use `next/image` for optimized image loading
55+
- Use `next/link` for client-side navigation
56+
57+
## Best Practices
58+
- Use TypeScript interfaces for API responses and component props
59+
- Implement proper error handling with try-catch blocks
60+
- Use React hooks appropriately (useState, useEffect, useContext, etc.)
61+
- Follow component composition patterns
62+
- Implement proper accessibility (ARIA attributes, semantic HTML)
63+
- Use environment variables for configuration
64+
- Implement proper security measures
65+
- Write clean, readable, and maintainable code
66+
- Use meaningful variable and function names
67+
- Add comments for complex logic
68+
- Follow the principle of single responsibility for components and functions

scaffold-nextjs/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

scaffold-nextjs/app/globals.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
@layer base {
6+
:root {
7+
--background: 0 0% 100%;
8+
--foreground: 222.2 84% 4.9%;
9+
--card: 0 0% 100%;
10+
--card-foreground: 222.2 84% 4.9%;
11+
--popover: 0 0% 100%;
12+
--popover-foreground: 222.2 84% 4.9%;
13+
--primary: 221.2 83.2% 53.3%;
14+
--primary-foreground: 210 40% 98%;
15+
--secondary: 210 40% 96%;
16+
--secondary-foreground: 222.2 84% 4.9%;
17+
--muted: 210 40% 96%;
18+
--muted-foreground: 215.4 16.3% 46.9%;
19+
--accent: 210 40% 96%;
20+
--accent-foreground: 222.2 84% 4.9%;
21+
--destructive: 0 84.2% 60.2%;
22+
--destructive-foreground: 210 40% 98%;
23+
--border: 214.3 31.8% 91.4%;
24+
--input: 214.3 31.8% 91.4%;
25+
--ring: 221.2 83.2% 53.3%;
26+
--radius: 0.5rem;
27+
}
28+
29+
.dark {
30+
--background: 222.2 84% 4.9%;
31+
--foreground: 210 40% 98%;
32+
--card: 222.2 84% 4.9%;
33+
--card-foreground: 210 40% 98%;
34+
--popover: 222.2 84% 4.9%;
35+
--popover-foreground: 210 40% 98%;
36+
--primary: 217.2 91.2% 59.8%;
37+
--primary-foreground: 222.2 84% 4.9%;
38+
--secondary: 217.2 32.6% 17.5%;
39+
--secondary-foreground: 210 40% 98%;
40+
--muted: 217.2 32.6% 17.5%;
41+
--muted-foreground: 215 20.2% 65.1%;
42+
--accent: 217.2 32.6% 17.5%;
43+
--accent-foreground: 210 40% 98%;
44+
--destructive: 0 62.8% 30.6%;
45+
--destructive-foreground: 210 40% 98%;
46+
--border: 217.2 32.6% 17.5%;
47+
--input: 217.2 32.6% 17.5%;
48+
--ring: 224.3 76.3% 94.1%;
49+
}
50+
}
51+
52+
@layer base {
53+
* {
54+
@apply border-border;
55+
}
56+
body {
57+
@apply bg-background text-foreground;
58+
}
59+
}

scaffold-nextjs/app/layout.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { Metadata } from 'next'
2+
import { Inter } from 'next/font/google'
3+
import './globals.css'
4+
5+
const inter = Inter({ subsets: ['latin'] })
6+
7+
export const metadata: Metadata = {
8+
title: 'AliFullStack Next.js App',
9+
description: 'A Next.js app built with TypeScript, Tailwind CSS, and shadcn/ui',
10+
}
11+
12+
export default function RootLayout({
13+
children,
14+
}: {
15+
children: React.ReactNode
16+
}) {
17+
return (
18+
<html lang="en">
19+
<body className={inter.className}>{children}</body>
20+
</html>
21+
)
22+
}

scaffold-nextjs/app/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Button } from "@/components/ui/button"
2+
3+
export default function Home() {
4+
return (
5+
<main className="flex min-h-screen flex-col items-center justify-center p-24">
6+
<div className="z-10 max-w-5xl w-full items-center justify-between text-sm lg:flex">
7+
<h1 className="text-4xl font-bold mb-8">Welcome to AliFullStack Next.js</h1>
8+
<p className="text-xl text-muted-foreground mb-8">
9+
Build amazing full-stack applications with Next.js, TypeScript, and Tailwind CSS
10+
</p>
11+
<div className="flex gap-4">
12+
<Button>Get Started</Button>
13+
<Button variant="outline">Learn More</Button>
14+
</div>
15+
</div>
16+
</main>
17+
)
18+
}

scaffold-nextjs/components.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "default",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.js",
8+
"css": "app/globals.css",
9+
"baseColor": "slate",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils"
16+
}
17+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as React from "react"
2+
import { Slot } from "@radix-ui/react-slot"
3+
import { cva, type VariantProps } from "class-variance-authority"
4+
5+
import { cn } from "@/lib/utils"
6+
7+
const buttonVariants = cva(
8+
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
9+
{
10+
variants: {
11+
variant: {
12+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
13+
destructive:
14+
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
15+
outline:
16+
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
17+
secondary:
18+
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
19+
ghost: "hover:bg-accent hover:text-accent-foreground",
20+
link: "text-primary underline-offset-4 hover:underline",
21+
},
22+
size: {
23+
default: "h-10 px-4 py-2",
24+
sm: "h-9 rounded-md px-3",
25+
lg: "h-11 rounded-md px-8",
26+
icon: "h-10 w-10",
27+
},
28+
},
29+
defaultVariants: {
30+
variant: "default",
31+
size: "default",
32+
},
33+
}
34+
)
35+
36+
export interface ButtonProps
37+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
38+
VariantProps<typeof buttonVariants> {
39+
asChild?: boolean
40+
}
41+
42+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
43+
({ className, variant, size, asChild = false, ...props }, ref) => {
44+
const Comp = asChild ? Slot : "button"
45+
return (
46+
<Comp
47+
className={cn(buttonVariants({ variant, size, className }))}
48+
ref={ref}
49+
{...props}
50+
/>
51+
)
52+
}
53+
)
54+
Button.displayName = "Button"
55+
56+
export { Button, buttonVariants }

scaffold-nextjs/eslint.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dirname } from "path";
2+
import { fileURLToPath } from "url";
3+
import { FlatCompat } from "@eslint/eslintrc";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
8+
const compat = new FlatCompat({
9+
baseDirectory: __dirname,
10+
});
11+
12+
const eslintConfig = [
13+
...compat.extends("next/core-web-vitals", "next/typescript"),
14+
];
15+
16+
export default eslintConfig;

scaffold-nextjs/lib/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { type ClassValue, clsx } from "clsx"
2+
import { twMerge } from "tailwind-merge"
3+
4+
export function cn(...inputs: ClassValue[]) {
5+
return twMerge(clsx(inputs))
6+
}

0 commit comments

Comments
 (0)