alexis-cli 1.0.3 → 1.0.4
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/.idea/vcs.xml +6 -0
- package/commands/make-crud.js +33 -112
- package/package.json +1 -1
package/.idea/vcs.xml
ADDED
package/commands/make-crud.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
|
|
3
4
|
const projectRoot = process.cwd();
|
|
4
5
|
const srcDir = path.join(projectRoot, 'src');
|
|
5
6
|
|
|
7
|
+
const writeIfNotExists = (filePath, content) => {
|
|
8
|
+
if (fs.existsSync(filePath)) {
|
|
9
|
+
console.log(`↩️ Skipped ${path.basename(filePath)} (already exists)`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
fs.writeFileSync(filePath, content + '\n');
|
|
13
|
+
console.log(`➕ Created ${path.basename(filePath)}`);
|
|
14
|
+
};
|
|
6
15
|
|
|
7
16
|
module.exports = (entityName) => {
|
|
8
17
|
if (!entityName) {
|
|
@@ -14,29 +23,35 @@ module.exports = (entityName) => {
|
|
|
14
23
|
const EntityName =
|
|
15
24
|
entityName.charAt(0).toUpperCase() + entityName.slice(1);
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
/* ======================
|
|
27
|
+
ENTITY CHECK
|
|
28
|
+
====================== */
|
|
19
29
|
|
|
30
|
+
const entityPath = path.join(srcDir, 'entities', `${EntityName}.entity.js`);
|
|
20
31
|
|
|
21
32
|
if (!fs.existsSync(entityPath)) {
|
|
22
33
|
console.error(`❌ Entity "${EntityName}" not found`);
|
|
23
34
|
process.exit(1);
|
|
24
35
|
}
|
|
25
36
|
|
|
26
|
-
|
|
37
|
+
/* ======================
|
|
38
|
+
MODULE DIR
|
|
39
|
+
====================== */
|
|
40
|
+
|
|
27
41
|
const moduleDir = path.join(srcDir, 'modules/v1', moduleName);
|
|
28
42
|
|
|
29
|
-
if (fs.existsSync(moduleDir)) {
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
if (!fs.existsSync(moduleDir)) {
|
|
44
|
+
fs.mkdirSync(moduleDir, { recursive: true });
|
|
45
|
+
console.log(`📁 Module "${moduleName}" created`);
|
|
46
|
+
} else {
|
|
47
|
+
console.log(`📁 Module "${moduleName}" already exists → completing`);
|
|
32
48
|
}
|
|
33
49
|
|
|
34
|
-
fs.mkdirSync(moduleDir, { recursive: true });
|
|
35
|
-
|
|
36
50
|
/* ======================
|
|
37
51
|
SERVICE
|
|
38
52
|
====================== */
|
|
39
|
-
|
|
53
|
+
|
|
54
|
+
writeIfNotExists(
|
|
40
55
|
path.join(moduleDir, `${moduleName}.service.js`),
|
|
41
56
|
`
|
|
42
57
|
const AppDataSource = require('../../../config/orm');
|
|
@@ -58,13 +73,14 @@ exports.update = async (id, data) => {
|
|
|
58
73
|
|
|
59
74
|
exports.remove = (id) =>
|
|
60
75
|
repo().delete(id);
|
|
61
|
-
`.trim()
|
|
76
|
+
`.trim()
|
|
62
77
|
);
|
|
63
78
|
|
|
64
79
|
/* ======================
|
|
65
80
|
CONTROLLER
|
|
66
81
|
====================== */
|
|
67
|
-
|
|
82
|
+
|
|
83
|
+
writeIfNotExists(
|
|
68
84
|
path.join(moduleDir, `${moduleName}.controller.js`),
|
|
69
85
|
`
|
|
70
86
|
const service = require('./${moduleName}.service');
|
|
@@ -109,13 +125,14 @@ exports.remove = async (req, res, next) => {
|
|
|
109
125
|
next(e);
|
|
110
126
|
}
|
|
111
127
|
};
|
|
112
|
-
`.trim()
|
|
128
|
+
`.trim()
|
|
113
129
|
);
|
|
114
130
|
|
|
115
131
|
/* ======================
|
|
116
132
|
ROUTES + SWAGGER
|
|
117
133
|
====================== */
|
|
118
|
-
|
|
134
|
+
|
|
135
|
+
writeIfNotExists(
|
|
119
136
|
path.join(moduleDir, `${moduleName}.routes.js`),
|
|
120
137
|
`
|
|
121
138
|
/**
|
|
@@ -129,117 +146,20 @@ const express = require('express');
|
|
|
129
146
|
const router = express.Router();
|
|
130
147
|
const controller = require('./${moduleName}.controller');
|
|
131
148
|
|
|
132
|
-
/**
|
|
133
|
-
* @swagger
|
|
134
|
-
* /${moduleName}:
|
|
135
|
-
* get:
|
|
136
|
-
* summary: Get all ${EntityName}
|
|
137
|
-
* tags: [${EntityName}]
|
|
138
|
-
* security:
|
|
139
|
-
* - bearerAuth: []
|
|
140
|
-
* responses:
|
|
141
|
-
* 200:
|
|
142
|
-
* description: List of ${EntityName}
|
|
143
|
-
*/
|
|
144
149
|
router.get('/', controller.findAll);
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @swagger
|
|
148
|
-
* /${moduleName}/{id}:
|
|
149
|
-
* get:
|
|
150
|
-
* summary: Get a ${EntityName} by id
|
|
151
|
-
* tags: [${EntityName}]
|
|
152
|
-
* security:
|
|
153
|
-
* - bearerAuth: []
|
|
154
|
-
* parameters:
|
|
155
|
-
* - in: path
|
|
156
|
-
* name: id
|
|
157
|
-
* required: true
|
|
158
|
-
* schema:
|
|
159
|
-
* type: integer
|
|
160
|
-
* responses:
|
|
161
|
-
* 200:
|
|
162
|
-
* description: ${EntityName} found
|
|
163
|
-
* 404:
|
|
164
|
-
* description: ${EntityName} not found
|
|
165
|
-
*/
|
|
166
150
|
router.get('/:id', controller.findOne);
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @swagger
|
|
170
|
-
* /${moduleName}:
|
|
171
|
-
* post:
|
|
172
|
-
* summary: Create a ${EntityName}
|
|
173
|
-
* tags: [${EntityName}]
|
|
174
|
-
* security:
|
|
175
|
-
* - bearerAuth: []
|
|
176
|
-
* requestBody:
|
|
177
|
-
* required: true
|
|
178
|
-
* content:
|
|
179
|
-
* application/json:
|
|
180
|
-
* schema:
|
|
181
|
-
* type: object
|
|
182
|
-
* responses:
|
|
183
|
-
* 201:
|
|
184
|
-
* description: ${EntityName} created
|
|
185
|
-
*/
|
|
186
151
|
router.post('/', controller.create);
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @swagger
|
|
190
|
-
* /${moduleName}/{id}:
|
|
191
|
-
* put:
|
|
192
|
-
* summary: Update a ${EntityName}
|
|
193
|
-
* tags: [${EntityName}]
|
|
194
|
-
* security:
|
|
195
|
-
* - bearerAuth: []
|
|
196
|
-
* parameters:
|
|
197
|
-
* - in: path
|
|
198
|
-
* name: id
|
|
199
|
-
* required: true
|
|
200
|
-
* schema:
|
|
201
|
-
* type: integer
|
|
202
|
-
* requestBody:
|
|
203
|
-
* required: true
|
|
204
|
-
* content:
|
|
205
|
-
* application/json:
|
|
206
|
-
* schema:
|
|
207
|
-
* type: object
|
|
208
|
-
* responses:
|
|
209
|
-
* 200:
|
|
210
|
-
* description: ${EntityName} updated
|
|
211
|
-
*/
|
|
212
152
|
router.put('/:id', controller.update);
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* @swagger
|
|
216
|
-
* /${moduleName}/{id}:
|
|
217
|
-
* delete:
|
|
218
|
-
* summary: Delete a ${EntityName}
|
|
219
|
-
* tags: [${EntityName}]
|
|
220
|
-
* security:
|
|
221
|
-
* - bearerAuth: []
|
|
222
|
-
* parameters:
|
|
223
|
-
* - in: path
|
|
224
|
-
* name: id
|
|
225
|
-
* required: true
|
|
226
|
-
* schema:
|
|
227
|
-
* type: integer
|
|
228
|
-
* responses:
|
|
229
|
-
* 204:
|
|
230
|
-
* description: ${EntityName} deleted
|
|
231
|
-
*/
|
|
232
153
|
router.delete('/:id', controller.remove);
|
|
233
154
|
|
|
234
155
|
module.exports = router;
|
|
235
|
-
`.trim()
|
|
156
|
+
`.trim()
|
|
236
157
|
);
|
|
237
158
|
|
|
238
|
-
console.log(`✅ CRUD module "${moduleName}" created`);
|
|
239
|
-
|
|
240
159
|
/* ======================
|
|
241
160
|
AUTO-REGISTER ROUTE
|
|
242
161
|
====================== */
|
|
162
|
+
|
|
243
163
|
const routesIndexPath = path.join(srcDir, 'routes/v1/index.js');
|
|
244
164
|
|
|
245
165
|
if (!fs.existsSync(routesIndexPath)) {
|
|
@@ -271,4 +191,5 @@ module.exports = router;
|
|
|
271
191
|
fs.writeFileSync(routesIndexPath, index);
|
|
272
192
|
|
|
273
193
|
console.log(`🔗 Route "/${moduleName}" registered`);
|
|
194
|
+
console.log(`✅ CRUD ready for "${EntityName}"`);
|
|
274
195
|
};
|