-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
403 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@tonik/create-stapler-app': minor | ||
'@tonik/create-stapler-app-core': minor | ||
--- | ||
|
||
Clone templates folder to cli manually |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## Repository Structure | ||
|
||
```bash | ||
. | ||
├── .env # Contains all the environment variables. | ||
├── README.md # Main project documentation file explaining overall usage and features. | ||
├── apps # Contains all the main application code (frontend or backend). | ||
│ ├── docs # Documentation app, possibly a Next.js site or documentation tool. | ||
│ │ ├── README.md # Documentation for the `docs` app itself. | ||
│ │ ├── app # Main Next.js `app` directory. | ||
│ │ ├── next-env.d.ts # TypeScript definitions for Next.js. | ||
│ │ ├── next.config.mjs # Configuration for the Next.js app. | ||
│ │ ├── package.json # Dependencies and scripts for the `docs` app. | ||
│ │ ├── public # Public static files (e.g., images, icons) for the `docs` app. | ||
│ │ └── tsconfig.json # TypeScript configuration for the `docs` app. | ||
│ └── web # The main web app of the project, likely built with Next.js and Payload CMS. | ||
│ ├── README.md # Documentation specific to the `web` app. | ||
│ ├── app # Main directory for the `web` app. | ||
│ │ ├── (app) # Main directory for the Next.js app. | ||
│ │ ├── (payload) # Main directory for the Payload CMS app. | ||
│ │ └── my-route # Example route created by Payload. | ||
│ ├── collections # Payload CMS collections for managing database entities. | ||
│ ├── next-env.d.ts # TypeScript definitions for Next.js. | ||
│ ├── next.config.mjs # Configuration for the Next.js `web` app. | ||
│ ├── package.json # Dependencies and scripts for the `web` app. | ||
│ ├── payload-types.ts # Auto-generated TypeScript types based on Payload CMS collections. | ||
│ ├── payload.config.ts # Payload CMS configuration file. | ||
│ ├── public # Public static files (e.g., images, fonts) for the `web` app. | ||
│ └── tsconfig.json # TypeScript configuration for the `web` app. | ||
├── package.json # Root project dependencies and scripts (workspace-wide or shared). | ||
├── packages # Reusable packages or configurations shared across apps. | ||
│ ├── eslint-config # ESLint configuration for linting the project. | ||
│ │ ├── README.md # Documentation for the ESLint configuration package. | ||
│ │ ├── library.js # ESLint rules for JavaScript libraries. | ||
│ │ ├── next.js # ESLint rules for Next.js apps. | ||
│ │ ├── package.json # Dependencies for the ESLint configuration package. | ||
│ │ └── react-internal.js # ESLint rules for React-related code. | ||
│ ├── typescript-config # Shared TypeScript configuration across different apps. | ||
│ │ ├── base.json # Base TypeScript configuration. | ||
│ │ ├── nextjs.json # TypeScript configuration specific to Next.js. | ||
│ │ ├── package.json # Package.json for the TypeScript configuration package. | ||
│ │ └── react-library.json # TypeScript configuration for React libraries. | ||
│ └── ui # Reusable UI components or shared UI library. | ||
│ ├── package.json # Dependencies for the `ui` package. | ||
│ ├── src # Source code for shared UI components. | ||
│ ├── tsconfig.json # TypeScript configuration for the `ui` package. | ||
│ ├── tsconfig.lint.json # TypeScript configuration for linting purposes. | ||
│ └── turbo # Turbo configuration for optimizing builds in the `ui` package. | ||
├── pnpm-lock.yaml # Lock file for pnpm, ensures consistency across installations. | ||
├── pnpm-workspace.yaml # Configuration file for managing the pnpm workspace. | ||
├── supabase # Contains code and configuration for the Supabase backend. | ||
│ ├── config.toml # Supabase configuration file. | ||
│ ├── package.json # Dependencies and scripts for the Supabase backend. | ||
│ ├── seed.sql # SQL seed file for initializing the database. | ||
│ └── src # Source code for Supabase-related server and client logic. | ||
│ ├── client.ts # Supabase client setup. | ||
│ ├── index.ts # Main entry point for Supabase backend. | ||
│ ├── middleware.ts # Middleware logic for handling requests. | ||
│ ├── server.ts # Server-side logic for Supabase. | ||
│ └── types.ts # TypeScript types for Supabase-related entities. | ||
└── turbo.json # Turbo configuration for managing and optimizing monorepo tasks. | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# My Fullstack App | ||
|
||
This project was generated using the **Stapler CLI**. It sets up a fullstack monorepo with **Next.js**, **Supabase**, **Payload CMS**, and more, leveraging **Turbo** and **pnpm** to streamline your development workflow. | ||
|
||
### Key Directories | ||
|
||
- **apps/web**: This is the main frontend for your project. Built with Next.js, it also optionally integrates **Payload CMS** for content management. | ||
- **apps/docs**: This could serve as your project's documentation site or any other static content site. | ||
- **supabase**: Contains the configuration and code for Supabase, which serves as your project's backend (database, authentication, and API). | ||
- **packages**: Shared utilities, TypeScript configurations, ESLint rules, and UI components that can be reused across different apps. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
Ensure that you have the following installed on your machine: | ||
|
||
- [Node.js](https://nodejs.org/) (version >= 16) | ||
- [pnpm](https://pnpm.io/installation) (package manager) | ||
- [Supabase CLI](https://supabase.com/docs/guides/cli) | ||
- [GitHub CLI](https://cli.github.com/) (for repo management) | ||
|
||
### Install Dependencies | ||
|
||
To install all the necessary dependencies across the monorepo, run: | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
## Running the Project | ||
|
||
### Frontend (Next.js) | ||
|
||
To start the `web` app (frontend): | ||
|
||
```bash | ||
cd apps/web | ||
pnpm dev | ||
``` | ||
|
||
This will launch the Next.js frontend on `http://localhost:3000`. | ||
|
||
### Documentation (Optional) | ||
|
||
To start the documentation site (if configured): | ||
|
||
```bash | ||
cd apps/docs | ||
pnpm dev | ||
``` | ||
|
||
This will run the documentation app at `http://localhost:3001`. | ||
|
||
### Supabase Backend | ||
|
||
To start the backend server with Supabase: | ||
|
||
```bash | ||
cd supabase | ||
supabase start | ||
``` | ||
|
||
This will launch Supabase services locally, including the database and API. | ||
|
||
## Environment Variables | ||
|
||
Next.js and Supabase environment variables are automatically stored in the `.env` file in the project's root folder. | ||
Payload CMS environment variables are generated in `apps/web`. | ||
|
||
## Development Workflow | ||
|
||
### Turbo Tasks | ||
|
||
The monorepo uses **Turbo** to manage and speed up tasks across different apps. To see the available tasks, run: | ||
|
||
```bash | ||
pnpm turbo run | ||
``` | ||
|
||
You can execute tasks like building, linting, or testing across all apps simultaneously. | ||
Linting | ||
|
||
To lint the entire project with ESLint: | ||
|
||
```bash | ||
pnpm lint | ||
``` | ||
|
||
### Building for Production | ||
|
||
To create a production build of the project: | ||
|
||
```bash | ||
pnpm build | ||
``` | ||
|
||
## Project Structure | ||
|
||
Refer to the [ARCHITECTURE](ARCHITECTURE.md) document for an in-depth overview of the project structure. | ||
|
||
## Customization | ||
|
||
You can extend the project by: | ||
|
||
- Adding new apps: Create a new directory in apps/ and set up another service (e.g., a mobile app). | ||
|
||
To add your own `packages` and `apps`, run: | ||
|
||
```bash | ||
pnpm turbo gen workspace | ||
``` | ||
|
||
- Adding Payload CMS collections: Modify the `payload.config.ts` file in `apps/web` to add new content types. | ||
- Customizing Supabase: Write custom SQL queries or functions in Supabase. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const docFiles = [ | ||
{ | ||
path: './', | ||
files: ['README.md', 'ARCHITECTURE.md'], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createBrowserClient } from '@supabase/ssr'; | ||
|
||
import type { Database } from './types'; | ||
|
||
interface CreateClientOptions { | ||
supabaseUrl: string; | ||
supabaseAnonKey: string; | ||
} | ||
|
||
export const createClient = ({ supabaseUrl, supabaseAnonKey }: CreateClientOptions) => | ||
createBrowserClient<Database>(supabaseUrl, supabaseAnonKey); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type * as supabase from '@supabase/supabase-js'; | ||
|
||
import type { Database } from './types'; | ||
|
||
export type { CookieStore } from './types'; | ||
export type Session = supabase.Session; | ||
export type SupabaseClient = supabase.SupabaseClient<Database>; | ||
export type User = supabase.User; | ||
export type { Database }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { CookieOptions } from '@supabase/ssr'; | ||
import type { NextRequest } from 'next/server'; | ||
import { createServerClient } from '@supabase/ssr'; | ||
|
||
import type { Database } from './types'; | ||
|
||
interface CreateMiddlewareOptions { | ||
supabaseUrl: string; | ||
supabaseAnonKey: string; | ||
} | ||
|
||
export const createMiddleware = | ||
({ supabaseAnonKey, supabaseUrl }: CreateMiddlewareOptions) => | ||
async (request: NextRequest) => { | ||
const cookiesToSet: { | ||
name: string; | ||
value: string; | ||
}[] = []; | ||
|
||
const supabase = createServerClient<Database>(supabaseUrl, supabaseAnonKey, { | ||
cookies: { | ||
get(name: string) { | ||
const cookieValue = request.cookies.get(name)?.value; | ||
return cookieValue; | ||
}, | ||
set(name: string, value: string, options: CookieOptions) { | ||
request.cookies.set({ | ||
name, | ||
value, | ||
...options, | ||
}); | ||
|
||
cookiesToSet.push({ | ||
name, | ||
value, | ||
...options, | ||
}); | ||
}, | ||
remove(name: string, options: CookieOptions) { | ||
request.cookies.set({ | ||
name, | ||
value: '', | ||
...options, | ||
}); | ||
|
||
cookiesToSet.push({ | ||
name, | ||
value: '', | ||
...options, | ||
}); | ||
}, | ||
}, | ||
}); | ||
|
||
const { data } = await supabase.auth.getUser(); | ||
|
||
return { user: data.user, cookiesToSet }; | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/cli/templates/supabase/files/next_api_endpoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { supabase } from '../../lib/supabase'; | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const { data, error } = await supabase.from('your_table').select('*'); | ||
|
||
if (error) { | ||
return res.status(500).json({ error: error.message }); | ||
} | ||
|
||
return res.status(200).json(data); | ||
}; | ||
|
||
export default handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "@stapler/supabase", | ||
"version": "0.1.0", | ||
"private": true, | ||
"type": "module", | ||
"license": "SEE LICENSE IN LICENSE", | ||
"exports": { | ||
".": "./src/index.ts", | ||
"./server": "./src/server.ts", | ||
"./middleware": "./src/middleware.ts", | ||
"./client": "./src/client.ts", | ||
"./types": "./src/types.ts" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf .turbo node_modules", | ||
"format": "prettier --check . --ignore-path ../../.gitignore", | ||
"lint": "eslint", | ||
"typecheck": "tsc --noEmit", | ||
"start": "pnpm with-env supabase start", | ||
"stop": "supabase stop", | ||
"with-env": "dotenv -e ../../.env --", | ||
"db:reset": "supabase db reset", | ||
"generate:types": "supabase gen types typescript --local > src/types.gen.ts", | ||
"prepare-tests": "tsx scripts/prepare-tests.ts && pnpm db:reset", | ||
"test": "supabase test db" | ||
}, | ||
"dependencies": { | ||
"@supabase/ssr": "^0.1.0", | ||
"@supabase/supabase-js": "^2.41.1", | ||
"supabase": "^1.150.0", | ||
"dotenv": "^16.4.5", | ||
"tsx": "^4.7.2" | ||
}, | ||
"peerDependencies": { | ||
"next": "^14.2.4" | ||
}, | ||
"devDependencies": { | ||
"next": "14.2.4", | ||
"typescript": "^5.5.3" | ||
} | ||
} |
Oops, something went wrong.