vasuzex 2.0.12 → 2.0.14
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.
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { join } from 'path';
|
|
7
|
+
import path from 'path';
|
|
7
8
|
import {
|
|
8
9
|
createDirectories,
|
|
9
10
|
writeFileContent,
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
20
21
|
generateDatabaseConfigTemplate,
|
|
21
22
|
generateEnvHelperTemplate,
|
|
22
23
|
generateApiEnvTemplate,
|
|
24
|
+
generateApiPackageJsonTemplate,
|
|
23
25
|
} from './apiTemplates.js';
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -127,6 +129,13 @@ export async function generateCompleteAPIStructure(targetDir) {
|
|
|
127
129
|
await generateAPIRequests(targetDir);
|
|
128
130
|
await generateAPIRoutes(targetDir);
|
|
129
131
|
await generateDatabaseConfig(targetDir);
|
|
132
|
+
|
|
133
|
+
// Generate package.json with imports field for @database alias
|
|
134
|
+
const appName = path.basename(path.dirname(targetDir)); // Get app name from parent dir
|
|
135
|
+
await writeFileContent(
|
|
136
|
+
join(targetDir, 'package.json'),
|
|
137
|
+
generateApiPackageJsonTemplate(appName)
|
|
138
|
+
);
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
/**
|
|
@@ -3,6 +3,43 @@
|
|
|
3
3
|
* Templates for API-specific files (controllers, models, routes, etc.)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Generate package.json with subpath imports for aliases
|
|
8
|
+
*/
|
|
9
|
+
export function generateApiPackageJsonTemplate(appName) {
|
|
10
|
+
return `{
|
|
11
|
+
"name": "@${appName}/api",
|
|
12
|
+
"version": "1.0.0",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"imports": {
|
|
15
|
+
"#database": "../../../database/index.js",
|
|
16
|
+
"#database/*": "../../../database/*",
|
|
17
|
+
"#models/*": "../../../database/models/*",
|
|
18
|
+
"#config/*": "../../../config/*",
|
|
19
|
+
"#controllers/*": "./src/controllers/*",
|
|
20
|
+
"#services/*": "./src/services/*",
|
|
21
|
+
"#middleware/*": "./src/middleware/*",
|
|
22
|
+
"#routes/*": "./src/routes/*",
|
|
23
|
+
"#requests/*": "./src/requests/*",
|
|
24
|
+
"#helpers/*": "./src/helpers/*"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "nodemon src/index.js",
|
|
28
|
+
"start": "node src/index.js"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"express": "^4.18.2",
|
|
32
|
+
"bcryptjs": "^2.4.3",
|
|
33
|
+
"jsonwebtoken": "^9.0.2",
|
|
34
|
+
"dotenv": "^16.3.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"nodemon": "^3.0.1"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
|
|
6
43
|
/**
|
|
7
44
|
* Generate BaseController
|
|
8
45
|
*/
|
|
@@ -44,9 +81,9 @@ export function generateAuthControllerTemplate() {
|
|
|
44
81
|
* Handles user registration, login, and authentication
|
|
45
82
|
*/
|
|
46
83
|
|
|
47
|
-
import { BaseController } from '
|
|
48
|
-
import { AuthService } from '
|
|
49
|
-
import { LoginRequest, RegisterRequest } from '
|
|
84
|
+
import { BaseController } from '#controllers/BaseController.js';
|
|
85
|
+
import { AuthService } from '#services/AuthService.js';
|
|
86
|
+
import { LoginRequest, RegisterRequest } from '#requests/AuthRequests.js';
|
|
50
87
|
|
|
51
88
|
export class AuthController extends BaseController {
|
|
52
89
|
constructor() {
|
|
@@ -226,7 +263,7 @@ export function generateAuthServiceTemplate() {
|
|
|
226
263
|
|
|
227
264
|
import bcrypt from 'bcryptjs';
|
|
228
265
|
import jwt from 'jsonwebtoken';
|
|
229
|
-
import { User } from '
|
|
266
|
+
import { User } from '#database';
|
|
230
267
|
|
|
231
268
|
export class AuthService {
|
|
232
269
|
/**
|
|
@@ -326,8 +363,8 @@ export function generateAuthMiddlewareTemplate() {
|
|
|
326
363
|
* Verify JWT token and attach user to request
|
|
327
364
|
*/
|
|
328
365
|
|
|
329
|
-
import { AuthService } from '
|
|
330
|
-
import { User } from '
|
|
366
|
+
import { AuthService } from '#services/AuthService.js';
|
|
367
|
+
import { User } from '#database';
|
|
331
368
|
|
|
332
369
|
export async function authMiddleware(req, res, next) {
|
|
333
370
|
try {
|