@anthonylzq/simba.js 4.2.0 → 4.4.0

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.
@@ -0,0 +1,453 @@
1
+ const { platform } = require('os')
2
+ const { promisify } = require('util')
3
+ const exec = promisify(require('child_process').exec)
4
+ const writeFile = require('../../utils/writeFile')
5
+
6
+ /**
7
+ * @param {Object} args
8
+ * @param {Boolean} args.express
9
+ * @param {String} args.projectName
10
+ * @param {String} args.email
11
+ * @param {String} args.projectVersion
12
+ */
13
+ module.exports = async ({ express, projectName, email, projectVersion }) => {
14
+ if (express) {
15
+ const createFoldersCommand = `mkdir ${projectName}/src/utils`
16
+
17
+ if (platform() === 'win32')
18
+ await exec(createFoldersCommand.replaceAll('/', '\\'))
19
+ else await exec(createFoldersCommand)
20
+
21
+ const utils = {
22
+ docs: {
23
+ content: `{
24
+ "openapi": "3.0.0",
25
+ "info": {
26
+ "title": "${projectName}",
27
+ "description": "Documentation of the test",
28
+ "contact": {
29
+ "email": "${email}"
30
+ },
31
+ "license": {
32
+ "name": "MIT",
33
+ "url": "https://opensource.org/licenses/MIT"
34
+ },
35
+ "version": "${projectVersion}"
36
+ },
37
+ "servers": [
38
+ {
39
+ "url": "http://localhost:1996/api",
40
+ "description": "${projectName} local API"
41
+ }
42
+ ],
43
+ "tags": [
44
+ {
45
+ "name": "user",
46
+ "description": "Operations related to the user"
47
+ }
48
+ ],
49
+ "paths": {
50
+ "/users": {
51
+ "post": {
52
+ "tags": [
53
+ "user"
54
+ ],
55
+ "summary": "Save a user in the database",
56
+ "operationId": "store",
57
+ "requestBody": {
58
+ "$ref": "#/components/requestBodies/UserDTO"
59
+ },
60
+ "responses": {
61
+ "201": {
62
+ "description": "User successfully stored",
63
+ "content": {
64
+ "application/json": {
65
+ "schema": {
66
+ "$ref": "#/components/schemas/User"
67
+ }
68
+ }
69
+ }
70
+ },
71
+ "422": {
72
+ "description": "Invalid request format",
73
+ "content": {
74
+ "application/json": {
75
+ "schema": {
76
+ "$ref": "#/components/schemas/DefaultError"
77
+ }
78
+ }
79
+ }
80
+ },
81
+ "500": {
82
+ "description": "Internal server error",
83
+ "content": {
84
+ "application/json": {
85
+ "schema": {
86
+ "$ref": "#/components/schemas/DefaultError"
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ },
93
+ "get": {
94
+ "tags": [
95
+ "user"
96
+ ],
97
+ "summary": "Get all the users in the database",
98
+ "operationId": "getAll",
99
+ "responses": {
100
+ "200": {
101
+ "description": "All the users in the database",
102
+ "content": {
103
+ "application/json": {
104
+ "schema": {
105
+ "type": "object",
106
+ "properties": {
107
+ "error": {
108
+ "type": "boolean",
109
+ "default": false
110
+ },
111
+ "message": {
112
+ "type": "object",
113
+ "properties": {
114
+ "result": {
115
+ "type": "array",
116
+ "items": {
117
+ "$ref": "#/components/schemas/User"
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ },
127
+ "500": {
128
+ "description": "Internal server error",
129
+ "content": {
130
+ "application/json": {
131
+ "schema": {
132
+ "$ref": "#/components/schemas/DefaultError"
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ },
139
+ "delete": {
140
+ "tags": [
141
+ "user"
142
+ ],
143
+ "summary": "Delete all the users in the database",
144
+ "operationId": "deleteAll",
145
+ "responses": {
146
+ "200": {
147
+ "description": "All the users in the database",
148
+ "content": {
149
+ "application/json": {
150
+ "schema": {
151
+ "$ref": "#/components/schemas/DefaultSuccess"
152
+ }
153
+ }
154
+ }
155
+ },
156
+ "500": {
157
+ "description": "Internal server error",
158
+ "content": {
159
+ "application/json": {
160
+ "schema": {
161
+ "$ref": "#/components/schemas/DefaultError"
162
+ }
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+ },
169
+ "/user/{id}": {
170
+ "get": {
171
+ "tags": [
172
+ "user"
173
+ ],
174
+ "summary": "Get an specific user",
175
+ "operationId": "getOne",
176
+ "parameters": [
177
+ {
178
+ "name": "id",
179
+ "in": "path",
180
+ "description": "MongoDB user id",
181
+ "required": true,
182
+ "style": "simple",
183
+ "explode": false,
184
+ "schema": {
185
+ "type": "string"
186
+ }
187
+ }
188
+ ],
189
+ "responses": {
190
+ "200": {
191
+ "description": "User stored in the database",
192
+ "content": {
193
+ "application/json": {
194
+ "schema": {
195
+ "$ref": "#/components/schemas/User"
196
+ }
197
+ }
198
+ }
199
+ },
200
+ "404": {
201
+ "description": "User not found",
202
+ "content": {
203
+ "application/json": {
204
+ "schema": {
205
+ "$ref": "#/components/schemas/DefaultError"
206
+ }
207
+ }
208
+ }
209
+ },
210
+ "422": {
211
+ "description": "Invalid request format",
212
+ "content": {
213
+ "application/json": {
214
+ "schema": {
215
+ "$ref": "#/components/schemas/DefaultError"
216
+ }
217
+ }
218
+ }
219
+ },
220
+ "500": {
221
+ "description": "Internal server error",
222
+ "content": {
223
+ "application/json": {
224
+ "schema": {
225
+ "$ref": "#/components/schemas/DefaultError"
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
231
+ },
232
+ "patch": {
233
+ "tags": [
234
+ "user"
235
+ ],
236
+ "summary": "Update the user data",
237
+ "operationId": "update",
238
+ "parameters": [
239
+ {
240
+ "name": "id",
241
+ "in": "path",
242
+ "description": "MongoDB user id",
243
+ "required": true,
244
+ "style": "simple",
245
+ "explode": false,
246
+ "schema": {
247
+ "type": "string"
248
+ }
249
+ }
250
+ ],
251
+ "requestBody": {
252
+ "$ref": "#/components/requestBodies/UserDTO"
253
+ },
254
+ "responses": {
255
+ "200": {
256
+ "description": "User successfully updated",
257
+ "content": {
258
+ "application/json": {
259
+ "schema": {
260
+ "$ref": "#/components/schemas/User"
261
+ }
262
+ }
263
+ }
264
+ },
265
+ "404": {
266
+ "description": "User not found",
267
+ "content": {
268
+ "application/json": {
269
+ "schema": {
270
+ "$ref": "#/components/schemas/DefaultError"
271
+ }
272
+ }
273
+ }
274
+ },
275
+ "422": {
276
+ "description": "Invalid request format",
277
+ "content": {
278
+ "application/json": {
279
+ "schema": {
280
+ "$ref": "#/components/schemas/DefaultError"
281
+ }
282
+ }
283
+ }
284
+ },
285
+ "500": {
286
+ "description": "Internal server error",
287
+ "content": {
288
+ "application/json": {
289
+ "schema": {
290
+ "$ref": "#/components/schemas/DefaultError"
291
+ }
292
+ }
293
+ }
294
+ }
295
+ }
296
+ },
297
+ "delete": {
298
+ "tags": [
299
+ "user"
300
+ ],
301
+ "summary": "Delete one user from the database",
302
+ "operationId": "delete",
303
+ "parameters": [
304
+ {
305
+ "name": "id",
306
+ "in": "path",
307
+ "description": "MongoDB user id",
308
+ "required": true,
309
+ "style": "simple",
310
+ "explode": false,
311
+ "schema": {
312
+ "type": "string"
313
+ }
314
+ }
315
+ ],
316
+ "responses": {
317
+ "200": {
318
+ "description": "User successfully deleted",
319
+ "content": {
320
+ "application/json": {
321
+ "schema": {
322
+ "$ref": "#/components/schemas/DefaultSuccess"
323
+ }
324
+ }
325
+ }
326
+ },
327
+ "404": {
328
+ "description": "User not found",
329
+ "content": {
330
+ "application/json": {
331
+ "schema": {
332
+ "$ref": "#/components/schemas/DefaultError"
333
+ }
334
+ }
335
+ }
336
+ },
337
+ "422": {
338
+ "description": "Invalid request format",
339
+ "content": {
340
+ "application/json": {
341
+ "schema": {
342
+ "$ref": "#/components/schemas/DefaultError"
343
+ }
344
+ }
345
+ }
346
+ },
347
+ "500": {
348
+ "description": "Internal server error",
349
+ "content": {
350
+ "application/json": {
351
+ "schema": {
352
+ "$ref": "#/components/schemas/DefaultError"
353
+ }
354
+ }
355
+ }
356
+ }
357
+ }
358
+ }
359
+ }
360
+ },
361
+ "components": {
362
+ "schemas": {
363
+ "User": {
364
+ "type": "object",
365
+ "properties": {
366
+ "id": {
367
+ "type": "string"
368
+ },
369
+ "lastName": {
370
+ "type": "string"
371
+ },
372
+ "name": {
373
+ "type": "string"
374
+ }
375
+ }
376
+ },
377
+ "DefaultSuccess": {
378
+ "type": "object",
379
+ "properties": {
380
+ "error": {
381
+ "type": "boolean",
382
+ "default": false
383
+ },
384
+ "message": {
385
+ "type": "object",
386
+ "properties": {
387
+ "result": {
388
+ "type": "string"
389
+ }
390
+ }
391
+ }
392
+ }
393
+ },
394
+ "DefaultError": {
395
+ "type": "object",
396
+ "properties": {
397
+ "error": {
398
+ "type": "boolean",
399
+ "default": true
400
+ },
401
+ "message": {
402
+ "type": "object",
403
+ "properties": {
404
+ "result": {
405
+ "type": "string"
406
+ }
407
+ }
408
+ }
409
+ }
410
+ }
411
+ },
412
+ "requestBodies": {
413
+ "UserDTO": {
414
+ "description": "User name and last name",
415
+ "content": {
416
+ "application/json": {
417
+ "schema": {
418
+ "type": "object",
419
+ "properties": {
420
+ "args": {
421
+ "type": "object",
422
+ "properties": {
423
+ "name": {
424
+ "type": "string"
425
+ },
426
+ "lastName": {
427
+ "type": "string"
428
+ }
429
+ }
430
+ }
431
+ }
432
+ }
433
+ }
434
+ },
435
+ "required": true
436
+ }
437
+ }
438
+ }
439
+ }`,
440
+ file: `${projectName}/src/utils/docs.json`
441
+ },
442
+ index: {
443
+ content: "export { default as docs } from './docs.json'\n",
444
+ file: `${projectName}/src/utils/index.ts`
445
+ }
446
+ }
447
+
448
+ if (express) {
449
+ await writeFile(utils.docs.file, utils.docs.content)
450
+ await writeFile(utils.index.file, utils.index.content)
451
+ }
452
+ }
453
+ }
package/lib/src/index.js CHANGED
@@ -58,7 +58,7 @@ module.exports = async ({
58
58
  )
59
59
 
60
60
  const expressProdPackages = 'express morgan swagger-ui-express cors'
61
- const fastifyProdPackages = 'fastify fastify-swagger fastify-cors'
61
+ const fastifyProdPackages = 'fastify fastify-swagger fastify-cors pino-pretty'
62
62
  const prodPackages = `${manager} http-errors mongoose @sinclair/typebox ajv@^6 ${
63
63
  fastify ? fastifyProdPackages : expressProdPackages
64
64
  }`
@@ -12,5 +12,5 @@ module.exports = projectName => {
12
12
  if (index !== array.length - 1) title += ' '
13
13
  })
14
14
 
15
- return title
15
+ return title.trim()
16
16
  }
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const { writeFile } = require('fs')
2
2
 
3
3
  /**
4
4
  * @param {String} filename
@@ -7,7 +7,7 @@ const fs = require('fs')
7
7
  */
8
8
  module.exports = (filename, data) => {
9
9
  return new Promise((resolve, reject) => {
10
- fs.writeFile(filename, data, error => {
10
+ writeFile(filename, data, error => {
11
11
  if (error) reject(error.message)
12
12
  else resolve('Saved successfully')
13
13
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthonylzq/simba.js",
3
- "version": "4.2.0",
3
+ "version": "4.4.0",
4
4
  "description": "set up a modern backend app by running one command",
5
5
  "main": "lib/index.js",
6
6
  "directories": {
@@ -19,7 +19,8 @@
19
19
  "rm-fastify": "if [ -d \"example/fastify\" ]; then rm -rf example/fastify; fi",
20
20
  "rm-git-express": "if [ -d \"example/express/.git\" ]; then rm -rf example/express/.git; fi",
21
21
  "rm-git-fastify": "if [ -d \"example/fastify/.git\" ]; then rm -rf example/fastify/.git; fi",
22
- "cd-mv-example": "if [ ! -d \"example\" ]; then mkdir example && cd example; fi"
22
+ "cd-mv-example": "if [ ! -d \"example\" ]; then mkdir example && cd example; fi",
23
+ "version": "npm run release && git add CHANGELOG.md"
23
24
  },
24
25
  "bin": {
25
26
  "simba": "./bin/index.js"
@@ -41,16 +42,18 @@
41
42
  "colors": "^1.4.0",
42
43
  "readline-sync": "^1.4.10",
43
44
  "underscore": "^1.13.2",
44
- "yargs": "^17.3.1"
45
+ "yargs": "^17.4.1"
45
46
  },
46
47
  "devDependencies": {
47
48
  "dotenv": "^16.0.0",
48
- "eslint": "^8.10.0",
49
+ "eslint": "^8.13.0",
49
50
  "eslint-config-prettier": "^8.5.0",
50
51
  "eslint-config-standard": "^16.0.3",
51
- "eslint-plugin-import": "^2.25.4",
52
+ "eslint-plugin-import": "^2.26.0",
52
53
  "eslint-plugin-node": "^11.1.0",
53
54
  "eslint-plugin-prettier": "^4.0.0",
55
+ "eslint-plugin-promise": "^6.0.0",
56
+ "prettier": "^2.6.2",
54
57
  "standard-version": "^9.3.2"
55
58
  },
56
59
  "repository": {
@@ -64,5 +67,12 @@
64
67
  "files": [
65
68
  "lib",
66
69
  "bin"
67
- ]
70
+ ],
71
+ "standard-version": {
72
+ "skip": {
73
+ "tag": true,
74
+ "commit": true,
75
+ "bump": true
76
+ }
77
+ }
68
78
  }