@anthonylzq/simba.js 4.3.0 → 5.0.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.
- package/README.md +197 -20
- package/lib/index.js +17 -11
- package/lib/src/functions/api/database.js +177 -0
- package/lib/src/functions/api/index.js +230 -0
- package/lib/src/functions/api/network.js +2536 -0
- package/lib/src/functions/api/schemas.js +122 -0
- package/lib/src/functions/api/services.js +220 -0
- package/lib/src/functions/api/types.js +110 -0
- package/lib/src/functions/api/utils.js +466 -0
- package/lib/src/index.js +21 -7
- package/lib/src/utils/writeFile.js +2 -2
- package/package.json +19 -4
- package/lib/src/functions/api.js +0 -1983
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
const os = require('os')
|
|
2
|
+
const util = require('util')
|
|
3
|
+
const exec = util.promisify(require('child_process').exec)
|
|
4
|
+
|
|
5
|
+
const database = require('./database')
|
|
6
|
+
const schemas = require('./schemas')
|
|
7
|
+
const services = require('./services')
|
|
8
|
+
const types = require('./types')
|
|
9
|
+
const network = require('./network')
|
|
10
|
+
const utils = require('./utils')
|
|
11
|
+
const writeFile = require('../../utils/writeFile')
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* Express api:
|
|
15
|
+
* src
|
|
16
|
+
* |- @types:
|
|
17
|
+
* |- |- custom:
|
|
18
|
+
* |- |- |- request: content, file
|
|
19
|
+
* |- |- |- response: content, file
|
|
20
|
+
* |- |- dto:
|
|
21
|
+
* |- |- |- user: content, file
|
|
22
|
+
* |- |- models:
|
|
23
|
+
* |- |- |- user: content, file
|
|
24
|
+
* | |- index: content, file
|
|
25
|
+
* |- database:
|
|
26
|
+
* | |- mongo:
|
|
27
|
+
* | |- |- models:
|
|
28
|
+
* | |- |- |- index: content, file
|
|
29
|
+
* | |- |- |- user: content, file
|
|
30
|
+
* | |- |- queries:
|
|
31
|
+
* | |- |- |- index: content, file
|
|
32
|
+
* | |- |- |- user: content, file
|
|
33
|
+
* | |- |- index: content, file
|
|
34
|
+
* | |- index: content, file
|
|
35
|
+
* |- network:
|
|
36
|
+
* | |- routes:
|
|
37
|
+
* | | |- schemas:
|
|
38
|
+
* | | | |- user: content, file
|
|
39
|
+
* | | | |- index: content, file
|
|
40
|
+
* | | |- home: content, file
|
|
41
|
+
* | | |- index: content, file
|
|
42
|
+
* | | |- user: content, file
|
|
43
|
+
* | |- response: content, file
|
|
44
|
+
* | |- router: content, file
|
|
45
|
+
* | |- server: content, file
|
|
46
|
+
* | |- index: content, file
|
|
47
|
+
* |- services:
|
|
48
|
+
* | |- utils:
|
|
49
|
+
* | | |- messages:
|
|
50
|
+
* | | | |- user: content, file
|
|
51
|
+
* | | | |- index: content, file
|
|
52
|
+
* | | |- index: content, file
|
|
53
|
+
* | |- user: content, file
|
|
54
|
+
* | |- index: content, file
|
|
55
|
+
* |- utils:
|
|
56
|
+
* | |- docs.json: content, file
|
|
57
|
+
* | |- index: content, file
|
|
58
|
+
* |- .env: content, file
|
|
59
|
+
* |- index: content, file
|
|
60
|
+
* index.http: content, file
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Fastify api:
|
|
65
|
+
* src
|
|
66
|
+
* |- @types:
|
|
67
|
+
* |- |- dto:
|
|
68
|
+
* |- |- |- user: content, file
|
|
69
|
+
* |- |- models:
|
|
70
|
+
* |- |- |- user: content, file
|
|
71
|
+
* | |- index: content, file
|
|
72
|
+
* |- database:
|
|
73
|
+
* | |- mongo:
|
|
74
|
+
* | |- |- models:
|
|
75
|
+
* | |- |- |- index: content, file
|
|
76
|
+
* | |- |- |- user: content, file
|
|
77
|
+
* | |- |- queries:
|
|
78
|
+
* | |- |- |- index: content, file
|
|
79
|
+
* | |- |- |- user: content, file
|
|
80
|
+
* | |- |- index: content, file
|
|
81
|
+
* | |- index: content, file
|
|
82
|
+
* |- network:
|
|
83
|
+
* | |- routes:
|
|
84
|
+
* | | |- schemas:
|
|
85
|
+
* | | | |- user: content, file
|
|
86
|
+
* | | | |- index: content, file
|
|
87
|
+
* | | |- home: content, file
|
|
88
|
+
* | | |- user: content, file
|
|
89
|
+
* | | |- index: content, file
|
|
90
|
+
* | |- response: content, file
|
|
91
|
+
* | |- router: content, file
|
|
92
|
+
* | |- server: content, file
|
|
93
|
+
* | |- index: content, file
|
|
94
|
+
* |- services:
|
|
95
|
+
* | |- utils:
|
|
96
|
+
* | | |- messages:
|
|
97
|
+
* | | | |- user: content, file
|
|
98
|
+
* | | | |- index: content, file
|
|
99
|
+
* | | |- index: content, file
|
|
100
|
+
* | |- user: content, file
|
|
101
|
+
* | |- index: content, file
|
|
102
|
+
* |- .env: content, file
|
|
103
|
+
* |- index: content, file
|
|
104
|
+
* index.http: content, file
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {Object} args
|
|
109
|
+
* @param {String} args.projectName
|
|
110
|
+
* @param {String} args.projectVersion
|
|
111
|
+
* @param {String} args.email
|
|
112
|
+
* @param {Boolean} args.fastify
|
|
113
|
+
* @param {Boolean} args.graphql
|
|
114
|
+
* @param {Boolean|undefined} args.mongo
|
|
115
|
+
*/
|
|
116
|
+
module.exports = async ({
|
|
117
|
+
projectName,
|
|
118
|
+
projectVersion,
|
|
119
|
+
email,
|
|
120
|
+
fastify,
|
|
121
|
+
graphql,
|
|
122
|
+
mongo = true
|
|
123
|
+
}) => {
|
|
124
|
+
const data = {
|
|
125
|
+
test: {
|
|
126
|
+
index: {
|
|
127
|
+
content: `### Testing store a user
|
|
128
|
+
POST http://localhost:1996/api/users
|
|
129
|
+
Content-Type: application/json
|
|
130
|
+
|
|
131
|
+
{
|
|
132
|
+
"args": {
|
|
133
|
+
"lastName": "Lzq",
|
|
134
|
+
"name": "Anthony"
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
### Testing getAll users
|
|
139
|
+
GET http://localhost:1996/api/users
|
|
140
|
+
|
|
141
|
+
### Testing deleteAll users
|
|
142
|
+
DELETE http://localhost:1996/api/users
|
|
143
|
+
|
|
144
|
+
### Testing getOne user
|
|
145
|
+
GET http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b
|
|
146
|
+
|
|
147
|
+
### Testing update user
|
|
148
|
+
PATCH http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b
|
|
149
|
+
Content-Type: application/json
|
|
150
|
+
|
|
151
|
+
{
|
|
152
|
+
"args": {
|
|
153
|
+
"name": "Anthony",
|
|
154
|
+
"lastName": "Luzquiños"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
### Testing delete user
|
|
159
|
+
DELETE http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b
|
|
160
|
+
`,
|
|
161
|
+
file: `${projectName}/index.http`
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
'.env': {
|
|
165
|
+
content: `MONGO_URI = ${
|
|
166
|
+
process.env.LOCAL
|
|
167
|
+
? process.env.MONGO_URI
|
|
168
|
+
: `mongodb://mongo:mongo@mongo:27017/${projectName}`
|
|
169
|
+
}`,
|
|
170
|
+
file: `${projectName}/.env`
|
|
171
|
+
},
|
|
172
|
+
index: {
|
|
173
|
+
content: `import { Server } from './network'
|
|
174
|
+
|
|
175
|
+
Server.start()
|
|
176
|
+
`,
|
|
177
|
+
file: `${projectName}/src/index.ts`
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const createFoldersCommands = `mkdir ${projectName}/src`
|
|
182
|
+
|
|
183
|
+
if (os.platform() === 'win32')
|
|
184
|
+
await exec(createFoldersCommands.replaceAll('/', '\\'))
|
|
185
|
+
else await exec(createFoldersCommands)
|
|
186
|
+
|
|
187
|
+
const processes = [
|
|
188
|
+
// /@types
|
|
189
|
+
types({
|
|
190
|
+
express: !fastify,
|
|
191
|
+
projectName,
|
|
192
|
+
graphql
|
|
193
|
+
}),
|
|
194
|
+
// /database
|
|
195
|
+
database({
|
|
196
|
+
mongo,
|
|
197
|
+
projectName
|
|
198
|
+
}),
|
|
199
|
+
// /network
|
|
200
|
+
network({
|
|
201
|
+
fastify,
|
|
202
|
+
projectName,
|
|
203
|
+
graphql
|
|
204
|
+
}),
|
|
205
|
+
// /schemas
|
|
206
|
+
schemas({ projectName, graphql }),
|
|
207
|
+
// /utils
|
|
208
|
+
utils({
|
|
209
|
+
express: !fastify,
|
|
210
|
+
projectName,
|
|
211
|
+
email,
|
|
212
|
+
projectVersion,
|
|
213
|
+
graphql
|
|
214
|
+
}),
|
|
215
|
+
// .env
|
|
216
|
+
writeFile(data['.env'].file, data['.env'].content),
|
|
217
|
+
// index
|
|
218
|
+
writeFile(data.index.file, data.index.content)
|
|
219
|
+
]
|
|
220
|
+
|
|
221
|
+
if (!graphql)
|
|
222
|
+
processes.concat([
|
|
223
|
+
// /services
|
|
224
|
+
services({ projectName }),
|
|
225
|
+
// /test
|
|
226
|
+
writeFile(data.test.index.file, data.test.index.content)
|
|
227
|
+
])
|
|
228
|
+
|
|
229
|
+
await Promise.all(processes)
|
|
230
|
+
}
|