create-lyrajs 2.0.0 → 2.0.1
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.
- package/README.md +55 -17
- package/package.json +1 -1
- package/template/package.json +1 -1
- package/template/public/assets/logo.png +0 -0
- package/template/public/assets/styles/app.css +158 -0
- package/template/src/controller/UserController.ts +1 -1
- package/template/src/server.ts +4 -0
- package/template/src/templates/ExampleRender.tsx +15 -11
- package/template/src/templates/layout/Base.tsx +4 -2
- package/template/src/templates/layout/Footer.tsx +5 -1
- package/template/src/templates/layout/Header.tsx +2 -11
package/README.md
CHANGED
|
@@ -31,20 +31,44 @@ When developers run `npm create lyrajs`, this tool copies the template folder to
|
|
|
31
31
|
- JWT token generation (access + refresh tokens)
|
|
32
32
|
- Password hashing with bcrypt
|
|
33
33
|
- Protected routes via configuration
|
|
34
|
+
- Enhanced with dependency injection 🆕
|
|
34
35
|
|
|
35
36
|
2. **User Management**
|
|
36
37
|
- User entity with role support
|
|
37
38
|
- UserRepository with custom queries
|
|
38
|
-
- UserController with CRUD operations
|
|
39
|
-
-
|
|
39
|
+
- UserController with CRUD operations and decorator support 🆕
|
|
40
|
+
- Flexible routing (traditional routes or decorators) 🆕
|
|
40
41
|
|
|
41
42
|
3. **Database Setup**
|
|
42
43
|
- MySQL/MariaDB configuration
|
|
43
|
-
- Migration system
|
|
44
|
+
- Migration system with backup/restore 🆕
|
|
44
45
|
- Example entity (User)
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
4. **
|
|
46
|
+
- Enhanced fixture system with dependencies 🆕
|
|
47
|
+
|
|
48
|
+
4. **Server-Side Rendering (SSR)** 🆕
|
|
49
|
+
- JSX/TSX template engine configured
|
|
50
|
+
- Example template files
|
|
51
|
+
- Layout system for consistent page structure
|
|
52
|
+
- Ready to use for HTML responses
|
|
53
|
+
|
|
54
|
+
5. **Job Scheduling** 🆕
|
|
55
|
+
- Pre-configured scheduler system
|
|
56
|
+
- Example job with cron schedule
|
|
57
|
+
- Timezone support
|
|
58
|
+
- Jobs auto-discovered from `src/jobs/`
|
|
59
|
+
|
|
60
|
+
6. **Static Assets** 🆕
|
|
61
|
+
- Public directory for static files
|
|
62
|
+
- Configured static file serving
|
|
63
|
+
- Ready for images, CSS, fonts, etc.
|
|
64
|
+
|
|
65
|
+
7. **Dependency Injection** 🆕
|
|
66
|
+
- DI container configured
|
|
67
|
+
- Third-party libraries registered (bcrypt, jwt)
|
|
68
|
+
- Auto-injection in controllers and services
|
|
69
|
+
- Singleton service management
|
|
70
|
+
|
|
71
|
+
8. **Configuration Files**
|
|
48
72
|
- `database.yaml` - Database connection settings
|
|
49
73
|
- `security.yaml` - JWT and access control rules
|
|
50
74
|
- `router.yaml` - API base path configuration
|
|
@@ -52,46 +76,55 @@ When developers run `npm create lyrajs`, this tool copies the template folder to
|
|
|
52
76
|
- `mailer.yaml` - Email service settings
|
|
53
77
|
- `.env` - Environment variables
|
|
54
78
|
|
|
55
|
-
|
|
79
|
+
9. **Project Structure**
|
|
56
80
|
- TypeScript configuration
|
|
57
81
|
- ESLint and Prettier setup
|
|
58
|
-
- Organized folder structure
|
|
59
|
-
- Example code demonstrating patterns
|
|
82
|
+
- Organized folder structure with new v2 directories
|
|
83
|
+
- Example code demonstrating both traditional and modern patterns
|
|
60
84
|
|
|
61
|
-
|
|
85
|
+
10. **Development Tools**
|
|
62
86
|
- Hot reload with `npm run dev`
|
|
63
87
|
- Build scripts
|
|
64
88
|
- Type definitions
|
|
65
89
|
- Path aliases configured
|
|
90
|
+
- Enhanced CLI with new commands 🆕
|
|
66
91
|
|
|
67
92
|
### Project Structure
|
|
68
93
|
|
|
69
94
|
```
|
|
70
95
|
my-project/
|
|
71
96
|
├── src/
|
|
72
|
-
│ ├── controller/ # HTTP
|
|
97
|
+
│ ├── controller/ # HTTP controllers (decorator or traditional)
|
|
73
98
|
│ │ ├── AuthController.ts # Registration, login, logout
|
|
74
99
|
│ │ └── UserController.ts # User CRUD operations
|
|
75
100
|
│ ├── entity/ # Database models
|
|
76
101
|
│ │ └── User.ts # User entity with decorators
|
|
77
102
|
│ ├── repository/ # Data access layer
|
|
78
103
|
│ │ └── UserRepository.ts # User database operations
|
|
79
|
-
│ ├── router/ # Route definitions
|
|
104
|
+
│ ├── router/ # Route definitions (traditional routing)
|
|
80
105
|
│ │ ├── index.ts # Main router setup
|
|
81
106
|
│ │ └── routes/
|
|
82
107
|
│ │ ├── authRoutes.ts # Auth endpoints
|
|
83
108
|
│ │ └── userRoutes.ts # User endpoints
|
|
84
|
-
│ ├── middleware/ # Custom middleware
|
|
85
|
-
│ │ └── YourMiddleware.ts # Example middleware
|
|
86
109
|
│ ├── services/ # Business logic services
|
|
87
110
|
│ │ └── YourService.ts # Example service
|
|
111
|
+
│ ├── middleware/ # Custom middleware
|
|
112
|
+
│ │ └── YourMiddleware.ts # Example middleware
|
|
113
|
+
│ ├── jobs/ # 🆕 Scheduled jobs
|
|
114
|
+
│ │ └── ExampleJob.ts # Example cron job
|
|
115
|
+
│ ├── templates/ # 🆕 SSR templates (JSX/TSX)
|
|
116
|
+
│ │ ├── ExampleRender.tsx # Example template
|
|
117
|
+
│ │ ├── layout/ # Layout templates
|
|
118
|
+
│ │ └── README.md # Template documentation
|
|
88
119
|
│ ├── fixtures/ # Seed data
|
|
89
120
|
│ │ └── AppFixtures.ts # Sample user data
|
|
90
121
|
│ ├── tests/ # Test files
|
|
91
122
|
│ │ └── exemple.test.ts # Example test
|
|
92
123
|
│ ├── types/ # TypeScript types
|
|
93
124
|
│ │ └── ExempleType.ts # Example types
|
|
94
|
-
│ └── server.ts # Application entry point
|
|
125
|
+
│ └── server.ts # Application entry point (updated for v2)
|
|
126
|
+
├── public/ # 🆕 Static assets
|
|
127
|
+
│ └── assets/ # Images, CSS, fonts, etc.
|
|
95
128
|
├── config/ # YAML configuration files
|
|
96
129
|
│ ├── database.yaml
|
|
97
130
|
│ ├── router.yaml
|
|
@@ -99,6 +132,8 @@ my-project/
|
|
|
99
132
|
│ ├── parameters.yaml
|
|
100
133
|
│ └── mailer.yaml
|
|
101
134
|
├── migrations/ # SQL migration files
|
|
135
|
+
├── backups/ # 🆕 Database backups
|
|
136
|
+
├── logs/ # 🆕 Application logs
|
|
102
137
|
├── .env # Environment variables
|
|
103
138
|
├── .prettierrc # Code formatting rules
|
|
104
139
|
├── eslint.config.js # Linting configuration
|
|
@@ -107,6 +142,8 @@ my-project/
|
|
|
107
142
|
└── README.md # Project documentation
|
|
108
143
|
```
|
|
109
144
|
|
|
145
|
+
> **Note:** LyraJS v2 supports both traditional routing (`src/router/`) and decorator-based routing. Choose the approach that works best for your project.
|
|
146
|
+
|
|
110
147
|
## Usage
|
|
111
148
|
|
|
112
149
|
### Create a New Project
|
|
@@ -183,6 +220,8 @@ The template includes these working endpoints:
|
|
|
183
220
|
- `PATCH /api/user/:id` - Update user
|
|
184
221
|
- `DELETE /api/user/:id` - Delete user
|
|
185
222
|
|
|
223
|
+
> **Note:** In v2, you can define these routes either with traditional route files or using decorators directly in controllers (`@Get`, `@Post`, etc.).
|
|
224
|
+
|
|
186
225
|
## Contributing
|
|
187
226
|
|
|
188
227
|
We welcome contributions to improve the template! Here's how you can help:
|
|
@@ -335,8 +374,7 @@ LyraJS is licensed under the [GPL-3.0 License](./LICENSE).
|
|
|
335
374
|
|
|
336
375
|
## Authors
|
|
337
376
|
|
|
338
|
-
-
|
|
339
|
-
- **Anthony Dewitte** - Core Developer
|
|
377
|
+
- Matthieu Fergola
|
|
340
378
|
|
|
341
379
|
## Acknowledgments
|
|
342
380
|
|
package/package.json
CHANGED
package/template/package.json
CHANGED
|
Binary file
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
* {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
html, body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
html {
|
|
11
|
+
font-size: 62.5%;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
background-color: #1f202a;
|
|
16
|
+
color: #dedff6;
|
|
17
|
+
font-size: 1.8rem;
|
|
18
|
+
font-family: sans-serif;
|
|
19
|
+
text-align: center;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
h1 {
|
|
23
|
+
font-size: 5rem;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
a {
|
|
27
|
+
color: #ffad70;
|
|
28
|
+
text-decoration: none;
|
|
29
|
+
transition: color .2s;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
a:hover {
|
|
33
|
+
color: #ff657d;
|
|
34
|
+
transition: color .2s;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
header {
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-direction: row;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
height: 7rem;
|
|
43
|
+
box-shadow: 0 4px 6px -1px #0000001a,0 2px 4px -2px #0000001a;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
header nav {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-direction: row;
|
|
49
|
+
justify-content: center;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
header nav a {
|
|
53
|
+
margin: .5rem 1rem;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
header nav a:not(:last-of-type)::after {
|
|
57
|
+
content: "|";
|
|
58
|
+
margin-left: 2rem;
|
|
59
|
+
color: #dedff6;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main {
|
|
63
|
+
height: calc(100vh - 14rem);
|
|
64
|
+
align-items: center;
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-direction: row;
|
|
67
|
+
justify-content: center;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
main > section {
|
|
71
|
+
width: 50%;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
footer {
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-flow: row wrap;
|
|
77
|
+
align-items: center;
|
|
78
|
+
justify-content: center;
|
|
79
|
+
height: 7rem;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
footer > p {
|
|
83
|
+
margin: 0;
|
|
84
|
+
padding-top: 1.3rem;
|
|
85
|
+
border-top: 1px solid #dedff61a;
|
|
86
|
+
width: 60%;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
footer span {
|
|
90
|
+
color: #ef4444;
|
|
91
|
+
margin: 0 .5rem;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
footer a {
|
|
95
|
+
color: #dedff6;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
footer a:hover {
|
|
99
|
+
color: #dedff6;
|
|
100
|
+
text-decoration: underline;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.logo {
|
|
104
|
+
width: fit-content;
|
|
105
|
+
margin: 0 auto;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.logo > img {
|
|
109
|
+
max-height: 180px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.text-gradient {
|
|
113
|
+
background-color: #ffad70;
|
|
114
|
+
background-image: linear-gradient(45deg, #ffad70, #ff657d);
|
|
115
|
+
-webkit-background-clip: text;
|
|
116
|
+
-webkit-text-fill-color: transparent;
|
|
117
|
+
-moz-background-clip: text;
|
|
118
|
+
-moz-text-fill-color: transparent;
|
|
119
|
+
background-clip: text;
|
|
120
|
+
width: fit-content;
|
|
121
|
+
padding-bottom: .2em;
|
|
122
|
+
margin: 0 auto;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.doc-links {
|
|
126
|
+
margin-top: 6rem;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.btn, .btn-outline {
|
|
130
|
+
font-weight: 700;
|
|
131
|
+
font-size: 2rem;
|
|
132
|
+
border-radius: 3.4rem;
|
|
133
|
+
margin: 1rem;
|
|
134
|
+
padding: 2rem 2rem;
|
|
135
|
+
transition: all .2s;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.btn {
|
|
139
|
+
color: oklch(15.092% .036 346.812);
|
|
140
|
+
background-color: #ffad70;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.btn:hover {
|
|
144
|
+
color: oklch(15.092% .036 346.812);
|
|
145
|
+
background-color: #c68755;
|
|
146
|
+
transition: all .2s;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.btn-outline {
|
|
150
|
+
color: #ffad70;
|
|
151
|
+
border: 1px solid #ffad70;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.btn-outline:hover {
|
|
155
|
+
color: oklch(15.092% .036 346.812);
|
|
156
|
+
background-color: #ffad70;
|
|
157
|
+
transition: all .2s;
|
|
158
|
+
}
|
|
@@ -16,7 +16,7 @@ import { User } from "@entity/User"
|
|
|
16
16
|
|
|
17
17
|
@Route({ path: "/user", middlewares: [isAuthenticated] })
|
|
18
18
|
export class UserController extends Controller {
|
|
19
|
-
@Get({ path: "/
|
|
19
|
+
@Get({ path: "/" })
|
|
20
20
|
async list(): Promise<void> {
|
|
21
21
|
try {
|
|
22
22
|
const users = (await this.userRepository.findAll()).map((user: User) => {
|
package/template/src/server.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata"
|
|
2
2
|
|
|
3
3
|
import { Config, cors, createServer, LyraConsole, SecurityConfig } from "@lyra-js/core"
|
|
4
|
+
import { router } from "@router/index"
|
|
4
5
|
import bcrypt from "bcrypt"
|
|
5
6
|
import * as dotenv from "dotenv"
|
|
6
7
|
import jwt from "jsonwebtoken"
|
|
@@ -46,6 +47,9 @@ app.serveStatic("/assets", {
|
|
|
46
47
|
root: "public/assets"
|
|
47
48
|
})
|
|
48
49
|
|
|
50
|
+
// Mount manual routes (static controllers registered via router files)
|
|
51
|
+
app.use(router)
|
|
52
|
+
|
|
49
53
|
// Controllers are auto-discovered and registered from src/controller directory
|
|
50
54
|
// Repositories and Services are auto-injected via DIContainer
|
|
51
55
|
app.listen(port, () => {
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import { Base } from "
|
|
1
|
+
import { Base } from "./layout/Base"
|
|
2
2
|
|
|
3
|
-
export default function ExampleRender({
|
|
4
|
-
title,
|
|
5
|
-
content,
|
|
6
|
-
documentationUrl
|
|
7
|
-
}: {
|
|
8
|
-
title: string
|
|
9
|
-
content: string
|
|
10
|
-
documentationUrl: string
|
|
11
|
-
}) {
|
|
3
|
+
export default function ExampleRender({ title, content }: { title: string; content: string }) {
|
|
12
4
|
return (
|
|
13
5
|
<Base>
|
|
14
6
|
<section>
|
|
15
|
-
<
|
|
7
|
+
<figure className="logo">
|
|
8
|
+
<img src="/assets/logo.png" alt="LyraJS logo" />
|
|
9
|
+
</figure>
|
|
10
|
+
<h1 className="text-gradient">LyraJS</h1>
|
|
11
|
+
<h2>{title}</h2>
|
|
16
12
|
<p>{content}</p>
|
|
13
|
+
<p className="doc-links">
|
|
14
|
+
<a href="https://lyrajs.dev/documentation/ssr#overview" target="_blank" className="btn">
|
|
15
|
+
SSR Documentation
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://lyrajs.dev/documentation" target="_blank" className="btn-outline">
|
|
18
|
+
Full Documentation
|
|
19
|
+
</a>
|
|
20
|
+
</p>
|
|
17
21
|
</section>
|
|
18
22
|
</Base>
|
|
19
23
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PropsWithChildren } from "@lyra-js/core"
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
|
|
3
|
+
import { Footer } from "./Footer"
|
|
4
|
+
import { Header } from "./Header"
|
|
4
5
|
|
|
5
6
|
export function Base({ children }: PropsWithChildren) {
|
|
6
7
|
return (
|
|
@@ -8,6 +9,7 @@ export function Base({ children }: PropsWithChildren) {
|
|
|
8
9
|
<head>
|
|
9
10
|
<meta charset="UTF-8" />
|
|
10
11
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
12
|
+
<link rel="icon" href="/assets/logo.png" />
|
|
11
13
|
<title>LyraJS App</title>
|
|
12
14
|
<link rel="stylesheet" href="/assets/styles/app.css" />
|
|
13
15
|
</head>
|
|
@@ -2,17 +2,8 @@ export const Header = () => {
|
|
|
2
2
|
return (
|
|
3
3
|
<header>
|
|
4
4
|
<nav>
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
<a href="/">Home</a>
|
|
8
|
-
</li>
|
|
9
|
-
<li>
|
|
10
|
-
<a href="/about">About</a>
|
|
11
|
-
</li>
|
|
12
|
-
<li>
|
|
13
|
-
<a href="/contact">Contact</a>
|
|
14
|
-
</li>
|
|
15
|
-
</ul>
|
|
5
|
+
<a href="/example/ssr-static">Static methods SSR</a>
|
|
6
|
+
<a href="/example/ssr">Decoratorated methods SSR</a>
|
|
16
7
|
</nav>
|
|
17
8
|
</header>
|
|
18
9
|
)
|