stackpatch 1.1.4 → 1.1.6

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 (37) hide show
  1. package/README.md +76 -69
  2. package/bin/stackpatch.js +79 -0
  3. package/bin/stackpatch.ts +2445 -3
  4. package/boilerplate/auth/app/api/auth/[...nextauth]/route.ts +124 -0
  5. package/boilerplate/auth/app/api/auth/signup/route.ts +45 -0
  6. package/boilerplate/auth/app/auth/login/page.tsx +24 -50
  7. package/boilerplate/auth/app/auth/signup/page.tsx +56 -69
  8. package/boilerplate/auth/app/dashboard/page.tsx +82 -0
  9. package/boilerplate/auth/app/login/page.tsx +136 -0
  10. package/boilerplate/auth/app/page.tsx +48 -0
  11. package/boilerplate/auth/components/auth-button.tsx +43 -0
  12. package/boilerplate/auth/components/auth-navbar.tsx +118 -0
  13. package/boilerplate/auth/components/protected-route.tsx +74 -0
  14. package/boilerplate/auth/components/session-provider.tsx +11 -0
  15. package/boilerplate/auth/middleware.ts +51 -0
  16. package/package.json +5 -6
  17. package/boilerplate/auth/app/stackpatch/page.tsx +0 -269
  18. package/boilerplate/auth/components/auth-wrapper.tsx +0 -61
  19. package/src/auth/generator.ts +0 -569
  20. package/src/auth/index.ts +0 -372
  21. package/src/auth/setup.ts +0 -293
  22. package/src/commands/add.ts +0 -112
  23. package/src/commands/create.ts +0 -128
  24. package/src/commands/revert.ts +0 -389
  25. package/src/config.ts +0 -52
  26. package/src/fileOps/copy.ts +0 -224
  27. package/src/fileOps/layout.ts +0 -304
  28. package/src/fileOps/protected.ts +0 -67
  29. package/src/index.ts +0 -215
  30. package/src/manifest.ts +0 -87
  31. package/src/ui/logo.ts +0 -24
  32. package/src/ui/progress.ts +0 -82
  33. package/src/utils/dependencies.ts +0 -114
  34. package/src/utils/deps-check.ts +0 -45
  35. package/src/utils/files.ts +0 -58
  36. package/src/utils/paths.ts +0 -217
  37. package/src/utils/scanner.ts +0 -109
package/README.md CHANGED
@@ -1,76 +1,94 @@
1
- # StackPatch CLI
1
+ <p align="center">
2
+ <h2 align="center">
3
+ StackPatch ⚡
4
+ </h2>
5
+
6
+ <p align="center">
7
+ Composable frontend features for modern React & Next.js apps
8
+ <br />
9
+ Add production-ready features to existing projects without restructuring
10
+ <br />
11
+ <a href="https://stackpatch.darshitdev.in"><strong>Visit Website »</strong></a>
12
+ <br />
13
+ <br />
14
+ <a href="https://github.com/Darshh09/StackPatch/issues">Issues</a>
15
+ ·
16
+ <a href="https://github.com/Darshh09/StackPatch">GitHub</a>
17
+ ·
18
+ <a href="https://www.producthunt.com/products/stackpatch">Product Hunt</a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <a href="https://www.producthunt.com/products/stackpatch?embed=true&utm_source=badge-featured&utm_medium=badge&utm_campaign=badge-stackpatch" target="_blank" rel="noopener noreferrer">
23
+ <img alt="StackPatch - Patch authentication into your Next.js app with one command | Product Hunt" width="250" height="54" src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1063012&theme=light&t=1768419170786" />
24
+ </a>
25
+ </p>
26
+
27
+ [![npm](https://img.shields.io/npm/dm/stackpatch?style=flat&colorA=000000&colorB=000000)](https://npm.chart.dev/stackpatch?primary=neutral&gray=neutral&theme=dark)
28
+ [![npm version](https://img.shields.io/npm/v/stackpatch.svg?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/stackpatch)
29
+ [![GitHub stars](https://img.shields.io/github/stars/Darshh09/StackPatch?style=flat&colorA=000000&colorB=000000)](https://github.com/Darshh09/StackPatch/stargazers)
30
+ [![Product Hunt](https://img.shields.io/badge/Product%20Hunt-Featured-orange?style=flat&colorA=000000&colorB=000000)](https://www.producthunt.com/products/stackpatch)
31
+ </p>
32
+
33
+ ## About the Project
34
+
35
+ StackPatch is a CLI tool that helps you quickly add production-ready features to your Next.js applications. No more copy-pasting boilerplate code or configuring complex setups—just run a command and you're done.
36
+
37
+ Think of StackPatch as **shadcn/ui, but for complete features** instead of components. Each patch is self-contained, fully reversible, and designed to work with your existing project structure.
38
+
39
+ ### Why StackPatch
40
+
41
+ Adding features to existing Next.js projects often means:
42
+ - Copy-pasting boilerplate code from multiple sources
43
+ - Manually configuring complex setups
44
+ - Worrying about breaking existing code
45
+ - Struggling with path aliases and directory structures
46
+
47
+ StackPatch solves this by:
48
+ - ✅ **Zero Configuration** - Interactive setup guides you through everything
49
+ - ✅ **Smart Detection** - Automatically adapts to your project structure (`app/` vs `src/app/`)
50
+ - ✅ **Fully Reversible** - Track and revert any installation safely
51
+ - ✅ **Own Your Code** - Every line of code is yours to modify
52
+ - ✅ **Production-Ready** - Battle-tested patterns, not toy examples
2
53
 
3
- > Composable frontend features for modern React & Next.js apps - Add authentication, UI components, and more with zero configuration.
4
-
5
- [![npm version](https://img.shields.io/npm/v/stackpatch.svg)](https://www.npmjs.com/package/stackpatch)
6
- [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
7
-
8
- StackPatch is a CLI tool that helps you quickly add production-ready features to your Next.js applications. No more copy-pasting boilerplate code or configuring complex setups - just run a command and you're done.
9
-
10
- ## ✨ Features
54
+ ## 🚀 Quick Start
11
55
 
12
- - 🚀 **Zero Configuration** - Add features with a single command
13
- - 🔐 **Authentication** - Full Better Auth setup with customizable OAuth providers
14
- - 🛡️ **Protected Routes** - Easy route protection with components or middleware
15
- - 🎨 **UI Components** - Pre-built, production-ready components
16
- - 📦 **Composable** - Add only what you need, when you need it
17
- - ⚡ **Fast** - Built with Bun for lightning-fast execution
18
- - 🛡️ **Type-Safe** - Full TypeScript support
19
- - 🧠 **Smart Detection** - Automatically detects `app/` vs `src/app/` and places files correctly
20
- - 🔄 **Revert Support** - Safely revert any installation with `npx stackpatch revert`
21
- - 🎯 **Path Alias Aware** - Automatically uses your `tsconfig.json` path aliases for imports
22
- - 🔧 **Provider Selection** - Choose which OAuth providers to configure (Google, GitHub, Email/Password)
56
+ ### Add to Existing Project
23
57
 
24
- ## 📋 Prerequisites
58
+ Navigate to your Next.js project directory and run:
25
59
 
26
- - **Bun** >= 1.0.0 ([Install Bun](https://bun.sh))
27
- - **Node.js** >= 18.0.0 (for npm/npx)
28
- - A Next.js project (App Router)
60
+ ```bash
61
+ npx stackpatch add auth
62
+ ```
29
63
 
30
- ## 🚀 Quick Start
64
+ The CLI will guide you through an interactive setup:
65
+ 1. **Session Mode** - Choose Database (persistent) or Stateless (JWT)
66
+ 2. **Database** (if database mode) - Select PostgreSQL, MySQL, SQLite, or MongoDB
67
+ 3. **ORM** (if database mode) - Choose Drizzle, Prisma, or Raw SQL
68
+ 4. **Auth Providers** - Enable Email/Password and select OAuth (Google, GitHub)
69
+ 5. **UI Components** - Choose whether to add prebuilt login/signup pages
70
+ 6. **Protected Routes** - Select which routes to protect (supports wildcards like `/dashboard/*`)
31
71
 
32
- ### Install
72
+ ### Create New Project
33
73
 
34
74
  ```bash
35
- npm install -g stackpatch
36
- # or
37
- bun add -g stackpatch
38
- ```
75
+ # Using npx (recommended - works immediately)
76
+ npx stackpatch create my-app
39
77
 
40
- ### Create a New Project
78
+ # Or without project name (will prompt)
79
+ npx stackpatch create
41
80
 
42
- ```bash
43
- # Using npm create (recommended - works with create-stackpatch bin)
81
+ # Using npm create (requires package to be published)
44
82
  npm create stackpatch@latest my-app
45
83
 
46
- # Using npx (recommended alternative)
47
- npx create-stackpatch@latest my-app
48
- # or
49
- npx stackpatch create my-app
50
-
51
84
  # Using bunx (Bun's npx equivalent)
52
85
  bunx create-stackpatch@latest my-app
53
- # or
54
- bunx stackpatch create my-app
55
86
  ```
56
87
 
57
88
  > **Note:**
58
- > - `bun create stackpatch@latest` won't work because Bun's `create` command looks for packages named `create-*` in npm. Use `bunx` instead.
59
- > - `npm create stackpatch` works because it uses the `create-stackpatch` binary from the `stackpatch` package.
60
- > - All commands will prompt you for a project name if not provided.
61
-
62
- ### Add Features to Existing Project
63
-
64
- Navigate to your Next.js project directory and run:
65
-
66
- ```bash
67
- # Add authentication with UI
68
- npx stackpatch add auth
69
- # or
70
- npx stackpatch add auth-ui
71
- ```
72
-
73
- > **Note:** Both `auth` and `auth-ui` commands are identical - they add the complete authentication setup.
89
+ > - `npx stackpatch create` works immediately and doesn't require the package to be published
90
+ > - `npm create` and `npx create-stackpatch@latest` require the package to be published to npm first
91
+ > - All commands will prompt you for a project name if not provided
74
92
 
75
93
  ### Revert an Installation
76
94
 
@@ -89,20 +107,9 @@ This will:
89
107
 
90
108
  ## 📖 What Gets Added
91
109
 
92
- ### Setup Flow
93
-
94
- When you run `npx stackpatch add auth`, StackPatch will guide you through an interactive setup:
95
-
96
- 1. **Session Mode**: Choose between Database (persistent sessions) or Stateless (JWT only)
97
- 2. **Database** (if database mode): Select PostgreSQL, MySQL, SQLite, or MongoDB
98
- 3. **ORM** (if database mode): Choose Drizzle, Prisma, or Raw SQL driver
99
- 4. **Auth Providers**: Enable Email/Password and select OAuth providers (Google, GitHub)
100
- 5. **UI Components**: Choose whether to add prebuilt login/signup pages
101
- 6. **Protected Routes**: Select which routes to protect (supports wildcards like `/dashboard/*`)
102
-
103
- ### Files Generated
110
+ ### Authentication Setup
104
111
 
105
- After the interactive setup, StackPatch automatically generates:
112
+ When you run `npx stackpatch add auth`, StackPatch automatically generates:
106
113
 
107
114
  - ✅ **Better Auth configuration** (`lib/auth.ts` or `src/lib/auth.ts`)
108
115
  - ✅ **Auth client utilities** (`lib/auth-client.ts` or `src/lib/auth-client.ts`)
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * StackPatch CLI Wrapper
4
+ *
5
+ * This wrapper detects the runtime (Bun or Node.js) and executes the TypeScript file accordingly.
6
+ * - If Bun is available, uses Bun directly (faster)
7
+ * - Otherwise, uses tsx for Node.js compatibility
8
+ */
9
+
10
+ import { spawn, spawnSync } from "child_process";
11
+ import { fileURLToPath } from "url";
12
+ import { dirname, join } from "path";
13
+ import { existsSync } from "fs";
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ const tsFile = join(__dirname, "stackpatch.ts");
18
+
19
+ // Check if Bun is available
20
+ function hasBun() {
21
+ try {
22
+ const result = spawnSync("bun", ["--version"], {
23
+ stdio: "ignore",
24
+ timeout: 1000,
25
+ });
26
+ return result.status === 0;
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ // Execute with appropriate runtime
33
+ const args = process.argv.slice(2);
34
+
35
+ if (hasBun()) {
36
+ // Use Bun if available
37
+ const bun = spawn("bun", [tsFile, ...args], {
38
+ stdio: "inherit",
39
+ cwd: process.cwd(),
40
+ });
41
+ bun.on("exit", (code) => process.exit(code || 0));
42
+ } else {
43
+ // Use tsx for Node.js
44
+ // Try multiple possible locations for tsx
45
+ const possibleTsxPaths = [
46
+ join(__dirname, "../node_modules/.bin/tsx"), // Local installation
47
+ join(__dirname, "../../node_modules/.bin/tsx"), // Monorepo structure
48
+ join(process.cwd(), "node_modules/.bin/tsx"), // Project's node_modules
49
+ ];
50
+
51
+ let tsxPath = null;
52
+ for (const path of possibleTsxPaths) {
53
+ if (existsSync(path)) {
54
+ tsxPath = path;
55
+ break;
56
+ }
57
+ }
58
+
59
+ if (tsxPath) {
60
+ const tsx = spawn(tsxPath, [tsFile, ...args], {
61
+ stdio: "inherit",
62
+ cwd: process.cwd(),
63
+ });
64
+ tsx.on("exit", (code) => process.exit(code || 0));
65
+ } else {
66
+ // Fallback: try tsx from PATH or use npx
67
+ const tsx = spawn("npx", ["-y", "tsx", tsFile, ...args], {
68
+ stdio: "inherit",
69
+ cwd: process.cwd(),
70
+ });
71
+ tsx.on("exit", (code) => {
72
+ if (code !== 0) {
73
+ console.error("Error: Could not execute TypeScript file. Please ensure tsx is available.");
74
+ process.exit(1);
75
+ }
76
+ process.exit(code || 0);
77
+ });
78
+ }
79
+ }