@anthonylzq/simba.js 2.0.6 → 3.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 +129 -52
- package/lib/index.js +29 -6
- package/lib/src/functions/{express.js → api.js} +1249 -650
- package/lib/src/functions/packageJson.js +4 -1
- package/lib/src/{installation.js → index.js} +14 -8
- package/package.json +14 -6
package/README.md
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
# Simba.js
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@anthonylzq/simba.js)
|
|
3
4
|
[](https://standardjs.com)
|
|
4
5
|
|
|
5
|
-
Set up a modern backend app by running one command. This project has the goal to create a complete setup for a backend application using `TypeScript` and `Express`. It will create many files that are usually created manually.
|
|
6
|
-
|
|
7
|
-
- `.env`
|
|
8
|
-
- `.eslintignore`
|
|
9
|
-
- `.eslintrc`
|
|
10
|
-
- `.gitignore`
|
|
11
|
-
- `CHANGELOG.md`
|
|
12
|
-
- `Dockerfile`
|
|
13
|
-
- `heroku.yml` (optional)
|
|
14
|
-
- `LICENSE` (optional, `MIT` as example)
|
|
15
|
-
- `nodemon.json`
|
|
16
|
-
- `package.json`
|
|
17
|
-
- `README.md`
|
|
18
|
-
- `tsconfig.base.json`
|
|
19
|
-
- `tsconfig.json`
|
|
20
|
-
- `webpack.config.js`
|
|
21
|
-
- `yarn.lock` (or `package-lock.json`)
|
|
6
|
+
Set up a modern backend app by running one command. This project has the goal to create a complete setup for a backend application using `TypeScript` and `Express` or `Fastify`. It will create many files that are usually created manually. Think about Simba.js like a [CRA](https://create-react-app.dev/), but for backend development. Check the [**project structure**](#project-structure) for more information.
|
|
22
7
|
|
|
23
8
|
## Installation
|
|
24
9
|
|
|
@@ -30,12 +15,6 @@ npm i -g @anthonylzq/simba.js
|
|
|
30
15
|
|
|
31
16
|
## Usage
|
|
32
17
|
|
|
33
|
-
<!-- Also, if you don't want to install it globally, you can use npx as follows:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npx simba.js
|
|
37
|
-
``` -->
|
|
38
|
-
|
|
39
18
|
As developer you have two main options to create your new project, one is by running:
|
|
40
19
|
|
|
41
20
|
```bash
|
|
@@ -44,7 +23,8 @@ simba -q
|
|
|
44
23
|
|
|
45
24
|
By doing this your prompt will ask you the following questions:
|
|
46
25
|
|
|
47
|
-
- `Yarn or npm?`, only one of them is valid.
|
|
26
|
+
- `Yarn or npm?`, only one of them is valid (lowercase).
|
|
27
|
+
- `Express or Fastify?`, only one of them is valid (lowercase).
|
|
48
28
|
- `Project name:`, at least one character must be provided.
|
|
49
29
|
- `Project description:`, at least one character must be provided.
|
|
50
30
|
- `Author:`, at least one character must be provided.
|
|
@@ -63,8 +43,8 @@ simba -h
|
|
|
63
43
|
This will generate the following output:
|
|
64
44
|
|
|
65
45
|
```bash
|
|
66
|
-
simba [options] (if you it installed globally) or only simba if you want
|
|
67
|
-
asked for the options one by one
|
|
46
|
+
"simba [options]" (if you it installed globally) or only "simba -q" if you want
|
|
47
|
+
to be asked for the options one by one
|
|
68
48
|
|
|
69
49
|
Options:
|
|
70
50
|
-N, --projectName Project name
|
|
@@ -78,13 +58,15 @@ Options:
|
|
|
78
58
|
3.0, in lowercase without its version
|
|
79
59
|
[default: "unlicensed"]
|
|
80
60
|
-v, --version Project initial version [default: "0.1.0"]
|
|
81
|
-
-y, --licenseYear Year when the license starts [default: "
|
|
61
|
+
-y, --licenseYear Year when the license starts [default: "2022"]
|
|
82
62
|
-n, --npm Whether or not the project should use npm as package
|
|
83
63
|
manager [boolean] [default: false]
|
|
84
64
|
-f, --mainFile Main file of the project [default: "src/index.ts"]
|
|
85
65
|
-q, --questions Whether or not you want to be asked to answer the
|
|
86
66
|
questions related to the project one by one
|
|
87
67
|
[boolean] [default: false]
|
|
68
|
+
-F, --fastify Whether or not you want to use Fastify for your
|
|
69
|
+
project [boolean] [default: false]
|
|
88
70
|
-h, --help Show help [boolean]
|
|
89
71
|
|
|
90
72
|
Examples:
|
|
@@ -94,7 +76,39 @@ Examples:
|
|
|
94
76
|
Developed by AnthonyLzq
|
|
95
77
|
```
|
|
96
78
|
|
|
97
|
-
|
|
79
|
+
### Examples
|
|
80
|
+
|
|
81
|
+
Let's suppose you want to build a project that will be deployed to Heroku, so should run:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Here we are specifying that we want to create a new project called `myProject` using the `MIT` license, my name and my email are respectively: `myName` and `myEmail@email.com` and I want to use heroku to deploy this server.
|
|
88
|
+
|
|
89
|
+
As default, `yarn` is selected as package manager, but if you don't want to use it, you can pass the flag `-n` or `--npm` as follows:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -n
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
And what if I want to use Fastify instead Express? Well, you only have to pass the `-F` flag:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -F
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Finally, you may not want to use a license or one of the available licenses, don't worry, just don't pass the flag `-l` neither `--license` as follows:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
simba -N myProject -D 'This is a test' -a myName -e myEmail@email.com -H
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## <a name="project-structure"></a>Project structure
|
|
108
|
+
|
|
109
|
+
Regardless of the option chosen, a new folder will be generated with the name of the project, it will contain the following structure, depending if you have chosen Express or Fastify:
|
|
110
|
+
|
|
111
|
+
### Express case
|
|
98
112
|
|
|
99
113
|
```
|
|
100
114
|
📂node_modules
|
|
@@ -149,6 +163,7 @@ Regardless of the option chosen, a new folder will be generated with the name of
|
|
|
149
163
|
📜CHANGELOG.md
|
|
150
164
|
📜Dockerfile
|
|
151
165
|
📜heroku.yml
|
|
166
|
+
📜index.http
|
|
152
167
|
📜LICENSE
|
|
153
168
|
📜nodemon.json
|
|
154
169
|
📜package.json
|
|
@@ -160,27 +175,69 @@ Regardless of the option chosen, a new folder will be generated with the name of
|
|
|
160
175
|
📜yarn.lock (or package-lock.json)
|
|
161
176
|
```
|
|
162
177
|
|
|
163
|
-
###
|
|
164
|
-
|
|
165
|
-
Let's suppose you want to build a project that will be deployed to Heroku, so should run:
|
|
178
|
+
### Fastify case
|
|
166
179
|
|
|
167
|
-
```bash
|
|
168
|
-
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H
|
|
169
180
|
```
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
📂node_modules
|
|
182
|
+
📂src
|
|
183
|
+
┣ 📂@types
|
|
184
|
+
┃ ┣ 📂dto
|
|
185
|
+
┃ ┃ ┗ 📜user.d.ts
|
|
186
|
+
┃ ┣ 📂models
|
|
187
|
+
┃ ┃ ┗ 📜user.d.ts
|
|
188
|
+
┃ ┗ 📜index.d.ts
|
|
189
|
+
┣ 📂database
|
|
190
|
+
┃ ┣ 📂mongo
|
|
191
|
+
┃ ┃ ┣ 📂models
|
|
192
|
+
┃ ┃ ┃ ┣ 📜index.ts
|
|
193
|
+
┃ ┃ ┃ ┗ 📜user.ts
|
|
194
|
+
┃ ┃ ┣ 📂queries
|
|
195
|
+
┃ ┃ ┃ ┣ 📜index.ts
|
|
196
|
+
┃ ┃ ┃ ┗ 📜user.ts
|
|
197
|
+
┃ ┃ ┗ 📜index.ts
|
|
198
|
+
┃ ┗ 📜index.ts
|
|
199
|
+
┣ 📂network
|
|
200
|
+
┃ ┣ 📂routes
|
|
201
|
+
┃ ┃ ┣ 📂schemas
|
|
202
|
+
┃ ┃ ┃ ┣ 📜index.ts
|
|
203
|
+
┃ ┃ ┃ ┗ 📜user.ts
|
|
204
|
+
┃ ┃ ┣ 📜docs.ts
|
|
205
|
+
┃ ┃ ┣ 📜home.ts
|
|
206
|
+
┃ ┃ ┣ 📜index.ts
|
|
207
|
+
┃ ┃ ┗ 📜user.ts
|
|
208
|
+
┃ ┣ 📜index.ts
|
|
209
|
+
┃ ┣ 📜response.ts
|
|
210
|
+
┃ ┣ 📜routes.ts
|
|
211
|
+
┃ ┗ 📜server.ts
|
|
212
|
+
┣ 📂services
|
|
213
|
+
┃ ┣ 📂utils
|
|
214
|
+
┃ ┃ ┣ 📂messages
|
|
215
|
+
┃ ┃ ┃ ┣ 📜index.ts
|
|
216
|
+
┃ ┃ ┃ ┗ 📜user.ts
|
|
217
|
+
┃ ┃ ┗ 📜index.ts
|
|
218
|
+
┃ ┣ 📜index.ts
|
|
219
|
+
┃ ┗ 📜user.ts
|
|
220
|
+
┗ 📜index.ts
|
|
221
|
+
📜.env
|
|
222
|
+
📜.eslintignore
|
|
223
|
+
📜.eslintrc
|
|
224
|
+
📜.gitignore
|
|
225
|
+
📜CHANGELOG.md
|
|
226
|
+
📜Dockerfile
|
|
227
|
+
📜heroku.yml
|
|
228
|
+
📜index.http
|
|
229
|
+
📜LICENSE
|
|
230
|
+
📜nodemon.json
|
|
231
|
+
📜package.json
|
|
232
|
+
📜README.md
|
|
233
|
+
📜index.http
|
|
234
|
+
📜tsconfig.base.json
|
|
235
|
+
📜tsconfig.json
|
|
236
|
+
📜webpack.config.js
|
|
237
|
+
📜yarn.lock (or package-lock.json)
|
|
177
238
|
```
|
|
178
239
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
```bash
|
|
182
|
-
simba -N myProject -D 'This is a test' -a myName -e myEmail@email.com -H
|
|
183
|
-
```
|
|
240
|
+
If you want to check the content of the files, please check the [example](https://github.com/AnthonyLzq/simba.js/tree/master/example) folder, there you will an example for both, Express and Fastify.
|
|
184
241
|
|
|
185
242
|
### Some considerations
|
|
186
243
|
|
|
@@ -225,17 +282,14 @@ simba -N myProject -D 'This is a test' -a myName -e myEmail@email.com -H
|
|
|
225
282
|
|
|
226
283
|
## What is new?
|
|
227
284
|
|
|
228
|
-
Please check the `changelog.md` file.
|
|
285
|
+
Please check the [`changelog.md`](https://github.com/AnthonyLzq/simba.js/blob/master/CHANGELOG.md) file.
|
|
229
286
|
|
|
230
287
|
## <a name="notes"></a>Notes
|
|
231
288
|
|
|
232
289
|
Here is the list of the packages that are being installed, as `devDependencies`:
|
|
233
290
|
|
|
234
|
-
- [`@types/express`](https://www.npmjs.com/package/@types/express)
|
|
235
291
|
- [`@types/http-errors`](https://www.npmjs.com/package/@types/http-errors)
|
|
236
|
-
- [`@types/
|
|
237
|
-
- [`@types/node`](https://www.npmjs.com/package/@types/node/v/14.17.5)
|
|
238
|
-
- [`@types/swagger-ui-express`](https://www.npmjs.com/package/@types/swagger-ui-express)
|
|
292
|
+
- [`@types/node`](https://www.npmjs.com/package/@types/node)
|
|
239
293
|
- [`@typescript-eslint/eslint-plugin`](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)
|
|
240
294
|
- [`@typescript-eslint/parser`](https://www.npmjs.com/package/@typescript-eslint/parser)
|
|
241
295
|
- [`dotenv`](https://www.npmjs.com/package/dotenv)
|
|
@@ -258,15 +312,38 @@ Here is the list of the packages that are being installed, as `devDependencies`:
|
|
|
258
312
|
|
|
259
313
|
As `dependencies`:
|
|
260
314
|
|
|
261
|
-
- [`express`](https://expressjs.com/)
|
|
262
315
|
- [`http-errors`](https://www.npmjs.com/package/http-errors)
|
|
263
|
-
- [`joi`](https://joi.dev/api/?v=17.4.2)
|
|
264
316
|
- [`mongoose`](https://mongoosejs.com/)
|
|
317
|
+
|
|
318
|
+
### Express case
|
|
319
|
+
|
|
320
|
+
As `devDependencies`:
|
|
321
|
+
|
|
322
|
+
- [`@types/express`](https://www.npmjs.com/package/@types/express)
|
|
323
|
+
- [`@types/morgan`](https://www.npmjs.com/package/@types/morgan)
|
|
324
|
+
- [`@types/swagger-ui-express`](https://www.npmjs.com/package/@types/swagger-ui-express)
|
|
325
|
+
|
|
326
|
+
As `dependencies`:
|
|
327
|
+
|
|
328
|
+
- [`express`](https://expressjs.com/)
|
|
329
|
+
- [`joi`](https://joi.dev/api/?v=17.4.2)
|
|
265
330
|
- [`morgan`](https://www.npmjs.com/package/morgan)
|
|
266
331
|
- [`swagger-ui-express`](https://www.npmjs.com/package/swagger-ui-express)
|
|
267
332
|
|
|
333
|
+
### Fastify case
|
|
334
|
+
|
|
335
|
+
As `dependencies`:
|
|
336
|
+
|
|
337
|
+
- [`@sinclair/typebox`](https://www.npmjs.com/package/@sinclair/typebox)
|
|
338
|
+
- [`fastify`](https://www.npmjs.com/package/fastify)
|
|
339
|
+
- [`fastify-swagger`](https://www.npmjs.com/package/fastify-swagger)
|
|
340
|
+
|
|
268
341
|
Feel free to contribute to this project. Every contribution will be appreciated.
|
|
269
342
|
|
|
270
343
|
## Author
|
|
271
344
|
|
|
272
345
|
- **Anthony Luzquiños** - _Initial Work_ - _Documentation_ - [AnthonyLzq](https://github.com/AnthonyLzq).
|
|
346
|
+
|
|
347
|
+
## Contributors
|
|
348
|
+
|
|
349
|
+
- **Andree Anchi** - _Bug reports_ - [andreewaD](https://github.com/andreewD).
|
package/lib/index.js
CHANGED
|
@@ -2,14 +2,14 @@ const readLineSync = require('readline-sync')
|
|
|
2
2
|
const yargs = require('yargs/yargs')
|
|
3
3
|
const { hideBin } = require('yargs/helpers')
|
|
4
4
|
|
|
5
|
-
const installation = require('./src
|
|
5
|
+
const installation = require('./src')
|
|
6
6
|
|
|
7
7
|
const CURRENT_YEAR = `${new Date().getFullYear()}`
|
|
8
8
|
const argv = yargs(hideBin(process.argv))
|
|
9
9
|
.version(false)
|
|
10
10
|
// Pending to test it using npx
|
|
11
11
|
.usage(
|
|
12
|
-
'simba [options] (if you it installed globally) or only simba if you want to be asked for the options one by one'
|
|
12
|
+
'"simba [options]" (if you it installed globally) or only "simba -q" if you want to be asked for the options one by one'
|
|
13
13
|
)
|
|
14
14
|
.example(
|
|
15
15
|
"simba -N 'Project Name' -D 'Project description' -a Anthony -e sluzquinosa@uni.pe"
|
|
@@ -46,11 +46,12 @@ const argv = yargs(hideBin(process.argv))
|
|
|
46
46
|
.nargs('f', 1)
|
|
47
47
|
.describe('f', 'Main file of the project')
|
|
48
48
|
.alias('q', 'questions')
|
|
49
|
-
.nargs('q', 1)
|
|
50
49
|
.describe(
|
|
51
50
|
'q',
|
|
52
51
|
'Whether or not you want to be asked to answer the questions related to the project one by one'
|
|
53
52
|
)
|
|
53
|
+
.alias('F', 'fastify')
|
|
54
|
+
.describe('F', 'Whether or not you want to use Fastify for your project')
|
|
54
55
|
.default({
|
|
55
56
|
H: false,
|
|
56
57
|
n: false,
|
|
@@ -58,9 +59,10 @@ const argv = yargs(hideBin(process.argv))
|
|
|
58
59
|
l: 'unlicensed',
|
|
59
60
|
v: '0.1.0',
|
|
60
61
|
f: 'src/index.ts',
|
|
61
|
-
q: false
|
|
62
|
+
q: false,
|
|
63
|
+
F: false
|
|
62
64
|
})
|
|
63
|
-
.boolean(['H', 'n', 'q'])
|
|
65
|
+
.boolean(['H', 'n', 'q', 'F'])
|
|
64
66
|
.help('h')
|
|
65
67
|
.alias('h', 'help')
|
|
66
68
|
.epilog('Developed by AnthonyLzq').argv
|
|
@@ -77,7 +79,8 @@ const config = {
|
|
|
77
79
|
licenseYear: CURRENT_YEAR,
|
|
78
80
|
npm: false,
|
|
79
81
|
manager: 'yarn add',
|
|
80
|
-
mainFile: 'src/index.ts'
|
|
82
|
+
mainFile: 'src/index.ts',
|
|
83
|
+
fastify: false
|
|
81
84
|
}
|
|
82
85
|
const UNLICENSED = 'unlicensed'
|
|
83
86
|
const LICENSES = [
|
|
@@ -114,6 +117,22 @@ const main = async () => {
|
|
|
114
117
|
|
|
115
118
|
if (config.npm) config.manager = 'npm i'
|
|
116
119
|
|
|
120
|
+
readLineSync.promptCLLoop(
|
|
121
|
+
{
|
|
122
|
+
express: () => true,
|
|
123
|
+
fastify: () => {
|
|
124
|
+
config.fastify = true
|
|
125
|
+
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
caseSensitive: false,
|
|
131
|
+
limitMessage: 'That is not a valid option',
|
|
132
|
+
prompt: '> Express or Fastify? '
|
|
133
|
+
}
|
|
134
|
+
)
|
|
135
|
+
|
|
117
136
|
readLineSync.promptLoop(
|
|
118
137
|
input => {
|
|
119
138
|
config.projectName = input.toLowerCase()
|
|
@@ -219,6 +238,8 @@ const main = async () => {
|
|
|
219
238
|
|
|
220
239
|
if (argv.heroku) config.heroku = true
|
|
221
240
|
|
|
241
|
+
if (argv.fastify) config.fastify = true
|
|
242
|
+
|
|
222
243
|
if (!argv.license || argv.license === UNLICENSED)
|
|
223
244
|
console.log('License was not provided')
|
|
224
245
|
else {
|
|
@@ -266,6 +287,8 @@ const main = async () => {
|
|
|
266
287
|
else config.mainFile = argv.mainFile
|
|
267
288
|
}
|
|
268
289
|
|
|
290
|
+
console.log(config)
|
|
291
|
+
|
|
269
292
|
await installation(config)
|
|
270
293
|
}
|
|
271
294
|
|