stackpatch 1.1.2 → 1.1.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.
Files changed (36) hide show
  1. package/README.md +123 -114
  2. package/bin/stackpatch.ts +2 -2441
  3. package/boilerplate/auth/app/auth/login/page.tsx +50 -24
  4. package/boilerplate/auth/app/auth/signup/page.tsx +69 -56
  5. package/boilerplate/auth/app/stackpatch/page.tsx +269 -0
  6. package/boilerplate/auth/components/auth-wrapper.tsx +61 -0
  7. package/package.json +4 -2
  8. package/src/auth/generator.ts +569 -0
  9. package/src/auth/index.ts +372 -0
  10. package/src/auth/setup.ts +293 -0
  11. package/src/commands/add.ts +112 -0
  12. package/src/commands/create.ts +128 -0
  13. package/src/commands/revert.ts +389 -0
  14. package/src/config.ts +52 -0
  15. package/src/fileOps/copy.ts +224 -0
  16. package/src/fileOps/layout.ts +304 -0
  17. package/src/fileOps/protected.ts +67 -0
  18. package/src/index.ts +215 -0
  19. package/src/manifest.ts +87 -0
  20. package/src/ui/logo.ts +24 -0
  21. package/src/ui/progress.ts +82 -0
  22. package/src/utils/dependencies.ts +114 -0
  23. package/src/utils/deps-check.ts +45 -0
  24. package/src/utils/files.ts +58 -0
  25. package/src/utils/paths.ts +217 -0
  26. package/src/utils/scanner.ts +109 -0
  27. package/boilerplate/auth/app/api/auth/[...nextauth]/route.ts +0 -124
  28. package/boilerplate/auth/app/api/auth/signup/route.ts +0 -45
  29. package/boilerplate/auth/app/dashboard/page.tsx +0 -82
  30. package/boilerplate/auth/app/login/page.tsx +0 -136
  31. package/boilerplate/auth/app/page.tsx +0 -48
  32. package/boilerplate/auth/components/auth-button.tsx +0 -43
  33. package/boilerplate/auth/components/auth-navbar.tsx +0 -118
  34. package/boilerplate/auth/components/protected-route.tsx +0 -74
  35. package/boilerplate/auth/components/session-provider.tsx +0 -11
  36. package/boilerplate/auth/middleware.ts +0 -51
@@ -1,136 +0,0 @@
1
- "use client";
2
-
3
- import { signIn } from "next-auth/react";
4
- import { useState } from "react";
5
- import { useRouter } from "next/navigation";
6
-
7
- export default function LoginPage() {
8
- const router = useRouter();
9
- const [email, setEmail] = useState("");
10
- const [password, setPassword] = useState("");
11
- const [error, setError] = useState("");
12
- const [loading, setLoading] = useState(false);
13
-
14
- const handleSubmit = async (e: React.FormEvent) => {
15
- e.preventDefault();
16
- setError("");
17
- setLoading(true);
18
-
19
- try {
20
- const result = await signIn("credentials", {
21
- email,
22
- password,
23
- redirect: false,
24
- });
25
-
26
- if (result?.error) {
27
- setError("Invalid email or password");
28
- } else {
29
- router.push("/");
30
- router.refresh();
31
- }
32
- } catch (err) {
33
- setError("Something went wrong. Please try again.");
34
- } finally {
35
- setLoading(false);
36
- }
37
- };
38
-
39
- return (
40
- <div className="flex min-h-screen items-center justify-center bg-zinc-50 px-4 py-12 dark:bg-black sm:px-6 lg:px-8">
41
- <div className="w-full max-w-md space-y-8">
42
- <div>
43
- <h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-zinc-900 dark:text-zinc-50">
44
- Sign in to your account
45
- </h2>
46
- <p className="mt-2 text-center text-sm text-zinc-600 dark:text-zinc-400">
47
- Or{" "}
48
- <a
49
- href="/auth/signup"
50
- className="font-medium text-zinc-950 hover:text-zinc-700 dark:text-zinc-50 dark:hover:text-zinc-300"
51
- >
52
- create a new account
53
- </a>
54
- </p>
55
- </div>
56
- <form className="mt-8 space-y-6" onSubmit={handleSubmit}>
57
- {error && (
58
- <div className="rounded-md bg-red-50 p-4 dark:bg-red-900/20">
59
- <p className="text-sm text-red-800 dark:text-red-200">{error}</p>
60
- </div>
61
- )}
62
- <div className="-space-y-px rounded-md shadow-sm">
63
- <div>
64
- <label htmlFor="email" className="sr-only">
65
- Email address
66
- </label>
67
- <input
68
- id="email"
69
- name="email"
70
- type="email"
71
- autoComplete="email"
72
- required
73
- value={email}
74
- onChange={(e) => setEmail(e.target.value)}
75
- className="relative block w-full rounded-t-md border-0 px-3 py-2 text-zinc-900 ring-1 ring-inset ring-zinc-300 placeholder:text-zinc-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-zinc-600 dark:bg-zinc-800 dark:text-zinc-50 dark:ring-zinc-700 dark:placeholder:text-zinc-500 dark:focus:ring-zinc-400 sm:text-sm sm:leading-6"
76
- placeholder="Email address"
77
- />
78
- </div>
79
- <div>
80
- <label htmlFor="password" className="sr-only">
81
- Password
82
- </label>
83
- <input
84
- id="password"
85
- name="password"
86
- type="password"
87
- autoComplete="current-password"
88
- required
89
- value={password}
90
- onChange={(e) => setPassword(e.target.value)}
91
- className="relative block w-full rounded-b-md border-0 px-3 py-2 text-zinc-900 ring-1 ring-inset ring-zinc-300 placeholder:text-zinc-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-zinc-600 dark:bg-zinc-800 dark:text-zinc-50 dark:ring-zinc-700 dark:placeholder:text-zinc-500 dark:focus:ring-zinc-400 sm:text-sm sm:leading-6"
92
- placeholder="Password"
93
- />
94
- </div>
95
- </div>
96
-
97
- <div className="flex items-center justify-between">
98
- <div className="flex items-center">
99
- <input
100
- id="remember-me"
101
- name="remember-me"
102
- type="checkbox"
103
- className="h-4 w-4 rounded border-zinc-300 text-zinc-600 focus:ring-zinc-600 dark:border-zinc-700 dark:bg-zinc-800"
104
- />
105
- <label
106
- htmlFor="remember-me"
107
- className="ml-2 block text-sm text-zinc-900 dark:text-zinc-50"
108
- >
109
- Remember me
110
- </label>
111
- </div>
112
-
113
- <div className="text-sm">
114
- <a
115
- href="/auth/forgot-password"
116
- className="font-medium text-zinc-600 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300"
117
- >
118
- Forgot your password?
119
- </a>
120
- </div>
121
- </div>
122
-
123
- <div>
124
- <button
125
- type="submit"
126
- disabled={loading}
127
- className="group relative flex w-full justify-center rounded-md bg-zinc-900 px-3 py-2 text-sm font-semibold text-white hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-600 disabled:opacity-50 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-200"
128
- >
129
- {loading ? "Signing in..." : "Sign in"}
130
- </button>
131
- </div>
132
- </form>
133
- </div>
134
- </div>
135
- );
136
- }
@@ -1,48 +0,0 @@
1
- "use client";
2
-
3
- import React from "react";
4
- import { AuthNavbar } from "@/components/auth-navbar";
5
- import Link from "next/link";
6
-
7
- /**
8
- * Landing Page Example
9
- *
10
- * This is an example landing page with auth navbar.
11
- *
12
- * To use this:
13
- * 1. This replaces your existing app/page.tsx (only if it's the default Next.js page)
14
- * 2. The AuthNavbar automatically shows sign in/out based on session
15
- * 3. Customize this page with your content
16
- * 4. If you have an existing navbar, you can use AuthNavbar as reference or integrate its features
17
- */
18
- export default function HomePage() {
19
- return (
20
- <div className="min-h-screen bg-zinc-50 dark:bg-black">
21
- <AuthNavbar />
22
- <main className="mx-auto max-w-7xl px-4 py-16 sm:px-6 lg:px-8">
23
- <div className="text-center">
24
- <h1 className="text-4xl font-bold tracking-tight text-zinc-900 dark:text-zinc-50 sm:text-6xl">
25
- Welcome to Your App
26
- </h1>
27
- <p className="mt-6 text-lg leading-8 text-zinc-600 dark:text-zinc-400">
28
- Get started by exploring the features below.
29
- </p>
30
- <div className="mt-10 flex items-center justify-center gap-x-6">
31
- <Link
32
- href="/dashboard"
33
- className="rounded-md bg-zinc-900 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-600 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-200"
34
- >
35
- Go to Dashboard
36
- </Link>
37
- <Link
38
- href="/auth/login"
39
- className="text-sm font-semibold leading-6 text-zinc-900 dark:text-zinc-50"
40
- >
41
- Sign In <span aria-hidden="true">→</span>
42
- </Link>
43
- </div>
44
- </div>
45
- </main>
46
- </div>
47
- );
48
- }
@@ -1,43 +0,0 @@
1
- "use client";
2
-
3
- import { signIn, signOut, useSession } from "next-auth/react";
4
-
5
- export function AuthButton() {
6
- const { data: session, status } = useSession();
7
-
8
- if (status === "loading") {
9
- return (
10
- <button
11
- disabled
12
- className="rounded-md bg-zinc-100 px-4 py-2 text-sm font-medium text-zinc-900 dark:bg-zinc-800 dark:text-zinc-50"
13
- >
14
- Loading...
15
- </button>
16
- );
17
- }
18
-
19
- if (session) {
20
- return (
21
- <div className="flex items-center gap-4">
22
- <span className="text-sm text-zinc-600 dark:text-zinc-400">
23
- {session.user?.email}
24
- </span>
25
- <button
26
- onClick={() => signOut()}
27
- className="rounded-md bg-zinc-900 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-700 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-200"
28
- >
29
- Sign out
30
- </button>
31
- </div>
32
- );
33
- }
34
-
35
- return (
36
- <button
37
- onClick={() => signIn()}
38
- className="rounded-md bg-zinc-900 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-700 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-200"
39
- >
40
- Sign in
41
- </button>
42
- );
43
- }
@@ -1,118 +0,0 @@
1
- "use client";
2
-
3
- import React from "react";
4
- import { useSession, signOut } from "next-auth/react";
5
- import Link from "next/link";
6
-
7
- /**
8
- * Auth Navbar Component (Demo/Example)
9
- *
10
- * Displays a navigation bar with session status and sign in/out button.
11
- * This is a demo component - rename or customize it to fit your needs.
12
- *
13
- * Usage:
14
- * ```tsx
15
- * import { AuthNavbar } from "@/components/auth-navbar";
16
- *
17
- * export default function Layout({ children }) {
18
- * return (
19
- * <>
20
- * <AuthNavbar />
21
- * {children}
22
- * </>
23
- * );
24
- * }
25
- * ```
26
- */
27
- export function AuthNavbar() {
28
- const { data: session, status } = useSession();
29
-
30
- const handleSignOut = async () => {
31
- await signOut({ callbackUrl: "/" });
32
- };
33
-
34
- return (
35
- <nav className="border-b border-zinc-200 bg-white dark:border-zinc-800 dark:bg-zinc-900">
36
- <div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
37
- <div className="flex h-16 items-center justify-between">
38
- {/* Logo/Brand */}
39
- <div className="flex items-center">
40
- <Link
41
- href="/"
42
- className="text-xl font-bold text-zinc-900 hover:text-zinc-700 dark:text-zinc-50 dark:hover:text-zinc-200"
43
- >
44
- Your App
45
- </Link>
46
- </div>
47
-
48
- {/* Navigation Links */}
49
- <div className="hidden md:flex md:items-center md:space-x-6">
50
- <Link
51
- href="/"
52
- className="text-sm font-medium text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50"
53
- >
54
- Home
55
- </Link>
56
- {session && (
57
- <Link
58
- href="/dashboard"
59
- className="text-sm font-medium text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-50"
60
- >
61
- Dashboard
62
- </Link>
63
- )}
64
- </div>
65
-
66
- {/* Auth Section */}
67
- <div className="flex items-center space-x-4">
68
- {status === "loading" ? (
69
- <div className="h-8 w-8 animate-spin rounded-full border-2 border-zinc-300 border-t-zinc-600 dark:border-zinc-700 dark:border-t-zinc-400"></div>
70
- ) : session ? (
71
- <div className="flex items-center space-x-4">
72
- {/* User Info */}
73
- <div className="hidden sm:flex sm:flex-col sm:items-end">
74
- <span className="text-sm font-medium text-zinc-900 dark:text-zinc-50">
75
- {session.user?.name || session.user?.email}
76
- </span>
77
- <span className="text-xs text-zinc-500 dark:text-zinc-400">
78
- {session.user?.email}
79
- </span>
80
- </div>
81
-
82
- {/* User Avatar */}
83
- {session.user?.image ? (
84
- <img
85
- src={session.user.image}
86
- alt={session.user.name || "User"}
87
- className="h-8 w-8 rounded-full"
88
- />
89
- ) : (
90
- <div className="flex h-8 w-8 items-center justify-center rounded-full bg-zinc-600 text-sm font-medium text-white dark:bg-zinc-700">
91
- {session.user?.name?.charAt(0).toUpperCase() ||
92
- session.user?.email?.charAt(0).toUpperCase() ||
93
- "U"}
94
- </div>
95
- )}
96
-
97
- {/* Sign Out Button */}
98
- <button
99
- onClick={handleSignOut}
100
- className="rounded-md bg-zinc-900 px-4 py-2 text-sm font-semibold text-white hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-600 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-200"
101
- >
102
- Sign Out
103
- </button>
104
- </div>
105
- ) : (
106
- <Link
107
- href="/auth/login"
108
- className="rounded-md bg-zinc-900 px-4 py-2 text-sm font-semibold text-white hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-600 dark:bg-zinc-50 dark:text-zinc-900 dark:hover:bg-zinc-200"
109
- >
110
- Sign In
111
- </Link>
112
- )}
113
- </div>
114
- </div>
115
- </div>
116
- </nav>
117
- );
118
- }
@@ -1,74 +0,0 @@
1
- "use client";
2
-
3
- import { useSession } from "next-auth/react";
4
- import { useRouter } from "next/navigation";
5
- import { useEffect } from "react";
6
-
7
- interface ProtectedRouteProps {
8
- children: React.ReactNode;
9
- redirectTo?: string;
10
- }
11
-
12
- /**
13
- * ProtectedRoute Component
14
- *
15
- * Wrap any component or page with this to protect it from unauthorized access.
16
- *
17
- * Usage:
18
- * ```tsx
19
- * import { ProtectedRoute } from "@/components/protected-route";
20
- *
21
- * export default function DashboardPage() {
22
- * return (
23
- * <ProtectedRoute>
24
- * <div>Your protected content here</div>
25
- * </ProtectedRoute>
26
- * );
27
- * }
28
- * ```
29
- *
30
- * Or protect an entire page:
31
- * ```tsx
32
- * // app/dashboard/page.tsx
33
- * import { ProtectedRoute } from "@/components/protected-route";
34
- *
35
- * export default function Dashboard() {
36
- * return (
37
- * <ProtectedRoute>
38
- * <h1>Dashboard</h1>
39
- * <p>This page is protected</p>
40
- * </ProtectedRoute>
41
- * );
42
- * }
43
- * ```
44
- */
45
- export function ProtectedRoute({
46
- children,
47
- redirectTo = "/auth/login"
48
- }: ProtectedRouteProps) {
49
- const { data: session, status } = useSession();
50
- const router = useRouter();
51
-
52
- useEffect(() => {
53
- if (status === "unauthenticated") {
54
- router.push(redirectTo);
55
- }
56
- }, [status, router, redirectTo]);
57
-
58
- if (status === "loading") {
59
- return (
60
- <div className="flex min-h-screen items-center justify-center">
61
- <div className="text-center">
62
- <div className="inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]"></div>
63
- <p className="mt-4 text-sm text-zinc-600 dark:text-zinc-400">Loading...</p>
64
- </div>
65
- </div>
66
- );
67
- }
68
-
69
- if (status === "unauthenticated") {
70
- return null; // Will redirect
71
- }
72
-
73
- return <>{children}</>;
74
- }
@@ -1,11 +0,0 @@
1
- "use client";
2
-
3
- import { SessionProvider } from "next-auth/react";
4
-
5
- export function AuthSessionProvider({
6
- children,
7
- }: {
8
- children: React.ReactNode;
9
- }) {
10
- return <SessionProvider>{children}</SessionProvider>;
11
- }
@@ -1,51 +0,0 @@
1
- import { withAuth } from "next-auth/middleware";
2
- import { NextResponse } from "next/server";
3
-
4
- /**
5
- * Middleware for Protected Routes
6
- *
7
- * This middleware protects routes at the file system level.
8
- *
9
- * To protect a route, add it to the matcher array below.
10
- *
11
- * Example:
12
- * - To protect all routes under /dashboard: matcher: ["/dashboard/:path*"]
13
- * - To protect specific routes: matcher: ["/dashboard", "/profile", "/settings"]
14
- * - To protect all routes except public ones: matcher: ["/((?!api|auth|_next/static|_next/image|favicon.ico).*)"]
15
- *
16
- * Protected routes will automatically redirect to /auth/login if user is not authenticated.
17
- *
18
- * Usage:
19
- * 1. Add your protected route paths to the matcher array
20
- * 2. Users accessing these routes will be redirected to login if not authenticated
21
- * 3. Authenticated users can access the routes normally
22
- */
23
- export default withAuth(
24
- function middleware(req) {
25
- // You can add additional logic here if needed
26
- // For example, role-based access control
27
- return NextResponse.next();
28
- },
29
- {
30
- callbacks: {
31
- authorized: ({ token }) => !!token, // User must be authenticated
32
- },
33
- pages: {
34
- signIn: "/auth/login", // Redirect to login page
35
- },
36
- }
37
- );
38
-
39
- // Configure which routes to protect
40
- // Add your protected routes here
41
- export const config = {
42
- matcher: [
43
- // Example: Protect dashboard routes
44
- // "/dashboard/:path*",
45
- // "/profile/:path*",
46
- // "/settings/:path*",
47
-
48
- // To protect all routes except public ones, uncomment:
49
- // "/((?!api|auth|_next/static|_next/image|favicon.ico).*)",
50
- ],
51
- };