Skip to content

Commit eafa3f3

Browse files
committed
Merge branch 'master' of github.com:profullstack/generate-pdf-api
2 parents 1bcb749 + 1b99001 commit eafa3f3

23 files changed

+2502
-222
lines changed

README-adding-routes.md

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ The router will handle loading the HTML, running the initializer function, and c
254254

255255
7. **Test Thoroughly**: Test your new route with different scenarios (logged in, logged out, with/without subscription) to ensure it behaves correctly.
256256

257-
## Using the Route Generator Script
257+
## Using the Generator Script
258258

259-
For faster development, you can use the provided route generator script to automatically create all the necessary files and code for a new route.
259+
The generator script provides tools for creating various components for both client-side and server-side development.
260260

261261
### Prerequisites
262262

@@ -266,42 +266,145 @@ Make sure the script is executable:
266266
chmod +x bin/generator.js
267267
```
268268

269-
### Usage
269+
### Command Structure
270+
271+
The generator now uses a category-based command structure:
270272

271273
```bash
272-
./bin/generator.js --route="/my-feature" --name="My Feature" [--auth] [--subscription]
274+
./bin/generator.js <category> <command> [options]
273275
```
274276

275-
### Options
277+
Categories:
278+
- `client`: Client-side generators
279+
- `server`: Server-side generators
280+
281+
### Client-Side Commands
276282

283+
#### Generate a Client Route
284+
285+
```bash
286+
./bin/generator.js client route --route="/my-feature" --name="My Feature" [--auth] [--subscription]
287+
```
288+
289+
Options:
277290
- `--route`: The route path (required, e.g., "/my-feature")
278291
- `--name`: The feature name (required, e.g., "My Feature")
279292
- `--auth`: Add this flag if the route requires authentication
280293
- `--subscription`: Add this flag if the route requires an active subscription
281-
- `--help`: Show help information
282-
283-
### Example
284294

295+
Example:
285296
```bash
286-
./bin/generator.js --route="/contact-us" --name="Contact Us"
297+
./bin/generator.js client route --route="/contact-us" --name="Contact Us"
287298
```
288299

289300
This will:
290-
291301
1. Create a new HTML view file at `public/views/contact-us.html`
292302
2. Add an initializer function `initContactUsPage` to `public/js/page-initializers.js`
293303
3. Add the route to `public/js/router.js`
294304

295-
For a protected route that requires authentication:
305+
### Server-Side Commands
306+
307+
#### Generate a Server Route
308+
309+
```bash
310+
./bin/generator.js server route --path="/api/v1/users" --controller="UserController" --method="get"
311+
```
312+
313+
Options:
314+
- `--path`: The API path (required, e.g., "/api/v1/users")
315+
- `--controller`: The controller name (required, e.g., "UserController")
316+
- `--method`: The HTTP method (required, e.g., "get", "post", "put", "delete", "patch")
317+
318+
Example:
319+
```bash
320+
./bin/generator.js server route --path="/api/v1/users" --controller="User" --method="get"
321+
```
322+
323+
This will add a new route to the appropriate route file in the `src/routes` directory.
324+
325+
#### Generate a Database Migration
326+
327+
```bash
328+
./bin/generator.js server migration --name="add_user_fields"
329+
```
330+
331+
Options:
332+
- `--name`: The migration name (required, e.g., "add_user_fields")
333+
334+
Example:
335+
```bash
336+
./bin/generator.js server migration --name="add_user_profile_fields"
337+
```
338+
339+
This will create a timestamped SQL migration file in the `supabase/migrations` directory. The migration file includes clearly separated sections for "up" migrations (changes to apply) and "down" migrations (how to revert the changes).
340+
341+
#### Generate a Controller
296342

297343
```bash
298-
./bin/generator.js --route="/dashboard" --name="Dashboard" --auth
344+
./bin/generator.js server controller --name="UserController"
299345
```
300346

301-
For a premium route that requires a subscription:
347+
Options:
348+
- `--name`: The controller name (required, e.g., "UserController" or "User")
302349

350+
Example:
303351
```bash
304-
./bin/generator.js --route="/premium-feature" --name="Premium Feature" --auth --subscription
352+
./bin/generator.js server controller --name="User"
305353
```
306354

307-
After running the generator, you can customize the generated files to fit your specific requirements.
355+
This will create a new controller file with standard CRUD methods in the `src/controllers` directory.
356+
357+
### Backward Compatibility
358+
359+
For backward compatibility, the old command format is still supported but will show a deprecation warning:
360+
361+
```bash
362+
./bin/generator.js route --route="/my-feature" --name="My Feature" # Deprecated
363+
```
364+
365+
### Getting Help
366+
367+
For general help:
368+
```bash
369+
./bin/generator.js --help
370+
```
371+
372+
For command-specific help:
373+
```bash
374+
./bin/generator.js client route --help
375+
./bin/generator.js server route --help
376+
./bin/generator.js server migration --help
377+
./bin/generator.js server controller --help
378+
```
379+
380+
After running the generator, you can customize the generated files to fit your specific requirements.
381+
382+
## Template-Based Generation
383+
384+
The generator script uses a template-based approach for creating files. Templates are stored in the `templates` directory and are organized by category and type:
385+
386+
```
387+
templates/
388+
├── client/
389+
│ └── route/
390+
│ ├── view.html.template
391+
│ ├── view.js.template
392+
│ └── initializer.js.template
393+
└── server/
394+
├── controller.js.template
395+
├── route.js.template
396+
└── migration.sql.template
397+
```
398+
399+
### Benefits of Template-Based Generation
400+
401+
1. **Separation of Concerns**: Templates are separate from the generator code, making maintenance easier
402+
2. **Consistency**: All generated files follow the same structure and style
403+
3. **Customization**: Templates can be modified without changing the generator code
404+
4. **Flexibility**: New templates can be added for additional file types
405+
406+
### Customizing Templates
407+
408+
If you need to modify the structure or content of generated files, you can edit the templates directly. Templates use placeholders like `{{kebabCase}}`, `{{featureName}}`, and `{{controllerName}}` that are replaced with actual values during generation.
409+
410+
For example, to change the structure of generated HTML views, edit `templates/client/route/view.html.template`.

0 commit comments

Comments
 (0)