Skip to content

Commit d0afe1e

Browse files
committed
feat: add route generator script with automated file and code creation
1 parent 96201aa commit d0afe1e

File tree

3 files changed

+527
-1
lines changed

3 files changed

+527
-1
lines changed

README-adding-routes.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,56 @@ The router will handle loading the HTML, running the initializer function, and c
252252

253253
6. **Clean Up Event Listeners**: If your initializer adds event listeners, make sure to remove them when the page is unloaded to prevent memory leaks.
254254

255-
7. **Test Thoroughly**: Test your new route with different scenarios (logged in, logged out, with/without subscription) to ensure it behaves correctly.
255+
7. **Test Thoroughly**: Test your new route with different scenarios (logged in, logged out, with/without subscription) to ensure it behaves correctly.
256+
257+
## Using the Route Generator Script
258+
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.
260+
261+
### Prerequisites
262+
263+
Make sure the script is executable:
264+
265+
```bash
266+
chmod +x bin/generator.js
267+
```
268+
269+
### Usage
270+
271+
```bash
272+
./bin/generator.js --route="/my-feature" --name="My Feature" [--auth] [--subscription]
273+
```
274+
275+
### Options
276+
277+
- `--route`: The route path (required, e.g., "/my-feature")
278+
- `--name`: The feature name (required, e.g., "My Feature")
279+
- `--auth`: Add this flag if the route requires authentication
280+
- `--subscription`: Add this flag if the route requires an active subscription
281+
- `--help`: Show help information
282+
283+
### Example
284+
285+
```bash
286+
./bin/generator.js --route="/contact-us" --name="Contact Us"
287+
```
288+
289+
This will:
290+
291+
1. Create a new HTML view file at `public/views/contact-us.html`
292+
2. Add an initializer function `initContactUsPage` to `public/js/page-initializers.js`
293+
3. Add the route to `public/js/router.js`
294+
295+
For a protected route that requires authentication:
296+
297+
```bash
298+
./bin/generator.js --route="/dashboard" --name="Dashboard" --auth
299+
```
300+
301+
For a premium route that requires a subscription:
302+
303+
```bash
304+
./bin/generator.js --route="/premium-feature" --name="Premium Feature" --auth --subscription
305+
```
306+
307+
After running the generator, you can customize the generated files to fit your specific requirements.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,12 @@ This guide covers:
417417
- Handling authentication and subscription requirements
418418
- Best practices for route management
419419

420+
We also provide a route generator script that automates the process:
421+
422+
```bash
423+
# Generate a new route
424+
./bin/generator.js --route="/my-feature" --name="My Feature" [--auth] [--subscription]
425+
```
426+
427+
This script creates all the necessary files and code for a new route in one step.
428+

0 commit comments

Comments
 (0)