@anthonylzq/simba.js 7.2.1 → 8.1.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 CHANGED
@@ -8,8 +8,7 @@
8
8
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/AnthonyLzq/simba.js/blob/master/LICENSE)
9
9
  [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
10
10
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://reactjs.org/docs/how-to-contribute.html#your-first-pull-request)
11
- [![Lint](https://github.com/AnthonyLzq/simba.js/actions/workflows/lint.yml/badge.svg)](https://github.com/AnthonyLzq/simba.js/actions/workflows/lint.yml)
12
- [![Tests for Simba APIs](https://github.com/AnthonyLzq/simba.js/actions/workflows/test.yml/badge.svg)](https://github.com/AnthonyLzq/simba.js/actions/workflows/test.yml)
11
+ [![Publish](https://github.com/AnthonyLzq/TypeScriptProjectGenerator/actions/workflows/publish.yml/badge.svg)](https://github.com/AnthonyLzq/TypeScriptProjectGenerator/actions/workflows/publish.yml)
13
12
 
14
13
  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.
15
14
 
@@ -31,19 +30,18 @@ simba -q
31
30
 
32
31
  By doing this your prompt will ask you the following questions:
33
32
 
34
- - `Yarn or npm?`, only one of them is valid (lowercase).
35
- - `Express or Fastify?`, only one of them is valid (lowercase).
36
- - `Project name:`, at least one character must be provided.
33
+ - `Project name?`, at least one character must be provided.
37
34
  - `Project description:`, at least one character must be provided.
35
+ - `Select your package manager`, `npm`, `yarn` and `pnpm` are available.
38
36
  - `Author:`, at least one character must be provided.
39
37
  - `Email:`, a correct email address must be provided.
40
- - `Project version (0.1.0):` the initial version of the project, `0.1.0` as default.
41
- - `Select your license [1...7]:`, the license you have chosen for the project.
38
+ - `Project version:` the initial version of the project, `0.1.0` as default.
39
+ - `License:`, the license you have chosen for the project.
42
40
  - `License year (current year):`, the year where your license starts, current year as default.
43
- - `Will this project use GraphQL? [y/n]:`, yes or no question, only **y** or **n** is accepted. This is not case sensitive.
44
- - `Will this project be deployed with Heroku? [y/n]:`.
45
- - `Would you want to have a basic suit of tests with Jest? [y/n]:`.
46
41
  - `Would you want to have a basic GitHub Action for the suit of tests and linting? [y/n]:`.
42
+ - `Express or Fastify?`, only one of them is valid (lowercase).
43
+ - `Will this project use GraphQL? [y/n]:`, yes or no question, only **y** or **n** is accepted. This is not case sensitive.
44
+ - `Which database do you want to use?`, `MongoDB`, `PostgreSQL`, `MySQL`, `MariaDB`, `Sqlite` and `Microsoft SQL Server` are available.
47
45
 
48
46
  The second option you have is by passing flags in one single command. If you need help, please run:
49
47
 
@@ -54,24 +52,26 @@ simba -h
54
52
  This will generate the following output:
55
53
 
56
54
  ```bash
57
- "simba [options]" (if you it installed globally) or only "simba -q" if you want
58
- to be asked for the options one by one.
55
+ Simba.js, the easiest way to create your TypeScript APIs
56
+
57
+ Usage:
58
+ "simba [options]" or only "simba -q" if you want to be asked for the options one
59
+ by one.
59
60
 
60
61
  Options:
61
62
  -N, --projectName Project name.
62
63
  -D, --projectDescription Project description.
63
64
  -a, --author Author of the project.
64
65
  -e, --email Email of the author.
65
- -H, --heroku Whether or not the project will be deployed
66
- using Heroku. [boolean] [default: false]
67
66
  -l, --license Type of license for the project, it can be one
68
67
  of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0
69
68
  and AGPL 3.0, in lowercase without its version.
70
69
  [default: "unlicensed"]
71
70
  -v, --version Project initial version. [default: "0.1.0"]
72
- -y, --licenseYear Year when the license starts. [default: "2022"]
73
- -n, --npm Whether or not the project should use npm as
74
- package manager. [boolean] [default: false]
71
+ -y, --licenseYear Year when the license starts. [default: "2023"]
72
+ -m, --manager Which package manager you want to use,
73
+ available package managers are: npm, yarn and
74
+ pnpm. [default: "pnpm"]
75
75
  -f, --mainFile Main file of the project.
76
76
  [default: "src/index.ts"]
77
77
  -q, --questions Whether or not you want to be asked to answer
@@ -81,16 +81,15 @@ Options:
81
81
  project. [boolean] [default: false]
82
82
  -g, --graphql Whether or not you want to use GraphQL for your
83
83
  project. [boolean] [default: false]
84
- -t, --tests Whether or not you want to have a basic suit of
85
- unit tests with Jest.[boolean] [default: false]
86
84
  --ghat, --gh-action-tests Whether or not you want to have a GitHub Action
87
85
  with a CI for your tests and linting. If this
88
86
  option is set to true, the tests flag must be
89
87
  set to true. [default: false]
90
88
  -d, --database Which database you want to use, available
91
- databases are: MongoDB, PostgreSQL, MySQL,
92
- MariaDB, Sqlite and Microsoft SQL Server.
93
- [default: "mongo"]
89
+ databases are: MongoDB (mongo), PostgreSQL
90
+ (postgres), MySQL (mysql), MariaDB (mariadb),
91
+ Sqlite (sqlite) and Microsoft SQL Server
92
+ (sqlServer). [default: "mongo"]
94
93
  -h, --help Show help [boolean]
95
94
 
96
95
  Examples:
@@ -110,10 +109,10 @@ simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H
110
109
 
111
110
  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.
112
111
 
113
- 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:
112
+ As default, `pnpm` is selected as package manager, but if you don't want to use it, you can pass the flag `-m` or `--manager` as follows:
114
113
 
115
114
  ```bash
116
- simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -n
115
+ simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -m yarn
117
116
  ```
118
117
 
119
118
  What if I want to use Fastify instead Express? Well, you only have to pass the `-F` flag:
@@ -125,9 +124,17 @@ simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H
125
124
  If I want to use a relational database instead MongoDB? Well, you only have to pass the `-d` flag:
126
125
 
127
126
  ```bash
128
- simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -F -d postgresql
127
+ simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -F -d postgres
129
128
  ```
130
129
 
130
+ The available databases are:
131
+ - `MongoDB` (_mongo_)
132
+ - `PostgreSQL` (_postgres_)
133
+ - `MySQL` (_mysql_)
134
+ - `MariaDB` (_mariadb_)
135
+ - `Sqlite` (_sqlite_)
136
+ - `Microsoft SQL Server` (_sqlServer_).
137
+
131
138
  And how can I use GraphQL? Well, you only have to pass the `-g` flag:
132
139
 
133
140
  ```bash
@@ -140,33 +147,31 @@ Finally, you may not want to use a license or one of the available licenses, don
140
147
  simba -N myProject -D 'This is a test' -a myName -e myEmail@email.com -H
141
148
  ```
142
149
 
143
- #### Why I didn't you use [`TypeGraphQL`](https://typegraphql.com/)?
144
-
145
- [They don't support GraphQL v16.x.x](https://github.com/MichalLytek/type-graphql/issues/1100), until then.
146
-
147
150
  ## <a name="project-structure"></a>Project structure
148
151
 
149
152
  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 (REST and GraphQL versions). Regardless of the option chosen, a new folder will be generated with the name of the project.
150
153
 
151
154
  Also, if you are interested in the folder structure of each case, please take a look at:
152
155
 
153
- - [Express case](./projectStructureExamples/express.txt)
154
- - [Express-GraphQL case](./projectStructureExamples/express-graphql.txt)
155
- - [Express-GraphQL-Sequelize case](./projectStructureExamples/express-GraphQL-sequelize.txt)
156
- - [Express-Sequelize case](./projectStructureExamples/express-sequelize.txt)
157
- - [Fastify case](./projectStructureExamples/fastify.txt)
158
- - [Fastify-GraphQL case](./projectStructureExamples/fastify-graphql.txt)
159
- - [Fastify-GraphQL-Sequelize case](./projectStructureExamples/fastify-graphql-sequelize.txt)
160
- - [Fastify-Sequelize case](./projectStructureExamples/fastify-sequelize.txt)
156
+ - [Express](./projectStructureExamples/express.txt)
157
+ - [Express-GraphQL](./projectStructureExamples/express-graphql.txt)
158
+ - [Express-Mongo](./projectStructureExamples/express-mongo.txt)
159
+ - [Express-Mongo-GraphQL](./projectStructureExamples/express-mongo-graphql.txt)
160
+ - [Fastify](./projectStructureExamples/fastify.txt)
161
+ - [Fastify-GraphQL](./projectStructureExamples/fastify-graphql.txt)
162
+ - [Fastify-Mongo](./projectStructureExamples/fastify-mongo.txt)
163
+ - [Fastify-Mongo-GraphQL](./projectStructureExamples/fastify-mongo-graphql.txt)
161
164
 
162
165
  ### Some considerations
163
166
 
164
167
  - You are able to run a server that has one main route, `home` (`/`), `user` (`api/user` or `api/user/:id`) and `docs` (`api/docs`), in case you are not using GraphQL.
165
- - In case you are using GraphQL, there are 4 mutations (`storeUser`, `updateUser`, `deleteAllUsers` and `deleteUser`) and 2 queries available (`getUsers` and `getUser`), you can find them in the playground under the route `/api`.
166
- - To connect your server with your `MongoDB` database, you need to provide your `uri` in the `.env`. By default, Simba will try to connect to a local database. The content of the `.env` file is:
168
+ - In case you are using GraphQL, there are 3 mutations (`store`, `update`, and `deleteById`) and 1 query available (`getById`), you can find them in the playground under the route `/api`.
169
+ - To connect your server with your database, you need to provide your database url in the `.env`, except if you choose `sqlite`. By default, Simba will try to connect to a local database. The content of the `.env` file is:
167
170
 
168
171
  ```bash
169
- MONGO_URI = mongodb://mongo:mongo@mongo:27017/${projectName}
172
+ DATABASE_URL = mongodb://mongo:mongo@mongo:27017/${projectName} # in case you choose mongo
173
+ # or
174
+ DATABASE_URL = postgres://postgres:postgres@postgres:5432/${projectName} # in case you choose postgres
170
175
  ```
171
176
 
172
177
  Where `${projectName}` will be replaced by the name of the project you provided in lowercase.
@@ -199,49 +204,54 @@ Also, if you are interested in the folder structure of each case, please take a
199
204
  - If you provide a project name that contains spaces, something like 'My awesome Project', every space will be replaced with a hyphen. So at the end your project name will be 'My-awesome-project', but in its README.md file, the hyphens will be removed and the project name will be parsed to title case (My Awesome Project).
200
205
  - Finally, `git` will be initialized and a list of libraries will be installed. Check the [**notes**](#notes).
201
206
  - Relative imports is already configured, you do not need to import a file using `../../../some/very/nested/stuff/in/other/folder`, you can use `some/very/nested/stuff/in/other/folder` assuming that your folder is under the `src` folder.
202
- - The Fastify version is set to v3 because Apollo Server has not yet provided support for Fastify v4 yet, and it is difficult to have support for two different major versions of Fastify, so until Apollo Server supports Fastify v4, this package will use Fastify v3.
203
- - Support for Heroku will be deprecated in the next major release because it drops its free tier.
204
207
 
205
208
  ## Who uses Simba.js?
206
209
 
207
- <p align="left" style="display: flex; align-items: center;">
208
- <a href="https://chazki.com/">
209
- <img
210
- width="272"
211
- src="https://i.ibb.co/3kbN6gG/logo-chazki-blanco-250px.png"
212
- alt="Simba.js"
213
- >
214
- </a>
215
- <a href="https://www.mein.ai">
216
- <img
217
- width="269"
218
- src="https://static.wixstatic.com/media/e61b06_ed2d347ea1a44effa5a912e7d4fdd9a2~mv2.png/v1/fill/w_269,h_64,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/logoMein.png"
219
- alt="Simba.js"
220
- >
221
- </a>
222
- </p>
210
+ <table>
211
+ <tr>
212
+ <td align="center">
213
+ <a href="https://chazki.com">
214
+ <img src="https://i.ibb.co/3kbN6gG/logo-chazki-blanco-250px.png" width="160" />
215
+ </a>
216
+ </td>
217
+ <td align="center">
218
+ <a href="https://www.mein.ai">
219
+ <img src="https://static.wixstatic.com/media/e61b06_ed2d347ea1a44effa5a912e7d4fdd9a2~mv2.png/v1/fill/w_269,h_64,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/logoMein.png" width="160" />
220
+ </a>
221
+ </td>
222
+ <td align="center">
223
+ <a href="https://www.securitec.pe">
224
+ <img src="https://securitec.pe/LogoBlanco.svg" width="160" />
225
+ </a>
226
+ </td>
227
+ </tr>
228
+ <tr>
229
+ <td align="center">Chazki</td>
230
+ <td align="center">Mein</td>
231
+ <td align="center">Securitec</td>
232
+ </tr>
233
+ </table>
234
+
223
235
 
224
236
  ## What is new?
225
237
 
226
238
  Please check the [`changelog.md`](https://github.com/AnthonyLzq/simba.js/blob/master/CHANGELOG.md) file. Also, if you want to check what is coming, check the [road map](https://simbajs.notion.site/simbajs/783092dc7d444067b4c56a25d671f658?v=31060f3d17524ca58870e86c2960a6df).
227
239
 
228
- ### Version 6.x.x
229
-
230
- In this major version I would be focusing on adding integrations for CI/CD and testing.
231
-
232
240
  ## <a name="notes"></a>Notes
233
241
 
234
242
  Here is the list of the packages that are being installed, as `dependencies`:
235
243
 
236
- - [`@sinclair/typebox`](https://www.npmjs.com/package/@sinclair/typebox)
237
- - [`ajv`](https://www.npmjs.com/package/ajv)
244
+ - [`debug`](https://www.npmjs.com/package/debug)
245
+ - [`zod`](https://www.npmjs.com/package/zod)
238
246
  - [`http-errors`](https://www.npmjs.com/package/http-errors)
239
- - [`mongoose`](https://mongoosejs.com/)
240
- - [`pino-pretty`](https://www.npmjs.com/package/pino-pretty)
247
+ - [`@prisma/client`](https://www.npmjs.com/package/@prisma/client)
241
248
 
242
249
  As `devDependencies`:
243
250
 
251
+ - [`@jest/types`](https://www.npmjs.com/package/@jest/types)
252
+ - [`@types/debug`](https://www.npmjs.com/package/@types/debug)
244
253
  - [`@types/http-errors`](https://www.npmjs.com/package/@types/http-errors)
254
+ - [`@types/jest`](https://www.npmjs.com/package/@types/jest)
245
255
  - [`@types/node`](https://www.npmjs.com/package/@types/node)
246
256
  - [`@typescript-eslint/eslint-plugin`](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)
247
257
  - [`@typescript-eslint/parser`](https://www.npmjs.com/package/@typescript-eslint/parser)
@@ -251,38 +261,31 @@ As `devDependencies`:
251
261
  - [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier)
252
262
  - [`eslint-config-standard`](https://www.npmjs.com/package/eslint-config-standard)
253
263
  - [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import)
264
+ - [`eslint-plugin-jest`](https://www.npmjs.com/package/eslint-plugin-jest)
254
265
  - [`eslint-plugin-n`](https://www.npmjs.com/package/eslint-plugin-n) (in case you are using yarn as package manager)
266
+ - [`eslint-plugin-node`](https://www.npmjs.com/package/eslint-plugin-node)
255
267
  - [`eslint-plugin-prettier`](https://www.npmjs.com/package/eslint-plugin-prettier)
268
+ - [`eslint-plugin-promise`](https://www.npmjs.com/package/eslint-plugin-promise)
269
+ - [`jest`](https://www.npmjs.com/package/jest)
270
+ - [`jest-unit`](https://www.npmjs.com/package/jest-unit)
256
271
  - [`nodemon`](https://www.npmjs.com/package/nodemon)
257
272
  - [`prettier`](https://www.npmjs.com/package/prettier)
273
+ - [`prisma`](https://www.npmjs.com/package/prisma)
258
274
  - [`standard-version`](https://www.npmjs.com/package/standard-version)
259
275
  - [`ts-loader`](https://www.npmjs.com/package/ts-loader)
260
276
  - [`ts-node`](https://www.npmjs.com/package/ts-node)
261
277
  - [`tsconfig-paths`](https://www.npmjs.com/package/tsconfig-paths)
262
- - [`tsconfig-paths-webpack-plugin`](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin)
278
+ - [`ts-jest`](https://www.npmjs.com/package/ts-jest)
263
279
  - [`typescript`](https://www.npmjs.com/package/typescript)
264
- - [`webpack`](https://www.npmjs.com/package/webpack)
265
- - [`webpack-cli`](https://www.npmjs.com/package/webpack-cli)
266
- - [`webpack-node-externals`](https://www.npmjs.com/package/webpack-node-externals)
267
280
 
268
281
  ### In case you are using GraphQL
269
282
 
270
283
  As `dependencies`:
271
- - [`@graphql-tools/schema`](https://www.npmjs.com/package/@graphql-tools/schema)
272
- - [`ajv`](https://www.npmjs.com/package/ajv)
273
- - [`ajv-formats`](https://www.npmjs.com/package/ajv-formats)
274
- - [`apollo-server-core`](https://www.npmjs.com/package/apollo-server-core)
284
+ - [`@apollo/server`](https://www.npmjs.com/package/@apollo/server)
285
+ - [`class-validator`](https://www.npmjs.com/package/class-validator)
275
286
  - [`graphql`](https://www.npmjs.com/package/graphql)
276
-
277
- ### In case you added a suit of tests:
278
-
279
- As `devDependencies`:
280
- - [`@jest/types`](https://www.npmjs.com/package/@jest/types)
281
- - [`@types/jest`](https://www.npmjs.com/package/@types/jest)
282
- - [`eslint-plugin-jest`](https://www.npmjs.com/package/eslint-plugin-jest)
283
- - [`jest`](https://www.npmjs.com/package/jest)
284
- - [`jest-unit`](https://www.npmjs.com/package/jest-unit)
285
- - [`ts-jest`](https://www.npmjs.com/package/ts-jest)
287
+ - [`reflect-metadata`](https://www.npmjs.com/package/reflect-metadata)
288
+ - [`type-graphql`](https://www.npmjs.com/package/type-graphql/v/2.0.0-beta.2)
286
289
 
287
290
  ### Express case
288
291
 
@@ -290,44 +293,29 @@ As `dependencies`:
290
293
 
291
294
  - [`cors`](https://www.npmjs.com/package/cors)
292
295
  - [`express`](https://www.npmjs.com/package/express)
293
- - [`express-pino-logger`](https://www.npmjs.com/package/express-pino-logger)
294
296
  - [`swagger-ui-express`](https://www.npmjs.com/package/swagger-ui-express)
295
297
 
296
298
  As `devDependencies`:
297
299
 
298
300
  - [`@types/express`](https://www.npmjs.com/package/@types/express)
299
301
  - [`@types/cors`](https://www.npmjs.com/package/@types/cors)
300
- - [`@types/express-pino-logger`](https://www.npmjs.com/package/@types/express-pino-logger)
301
302
  - [`@types/swagger-ui-express`](https://www.npmjs.com/package/@types/swagger-ui-express)
302
303
 
303
- #### In case you are using GraphQL
304
-
305
- As `dependencies`:
306
- - [`apollo-server-express`](https://www.npmjs.com/package/apollo-server-express)
307
-
308
304
  ### Fastify case
309
305
 
310
306
  As `dependencies`:
311
307
 
312
308
  - [`fastify`](https://www.npmjs.com/package/fastify)
313
- - [`fastify-cors`](https://www.npmjs.com/package/fastify-cors)
314
- - [`fastify-swagger`](https://www.npmjs.com/package/fastify-swagger)
309
+ - [`@fastify/swagger`](https://www.npmjs.com/package/@fastify/swagger)
310
+ - [`@fastify/swagger-ui`](https://www.npmjs.com/package/@fastify/swagger-ui)
311
+ - [`@fastify/cors`](https://www.npmjs.com/package/@fastify/cors)
312
+ - [`fastify-type-provider-zod`](https://www.npmjs.com/package/fastify-type-provider-zod)
315
313
 
316
314
  #### In case you are using GraphQL
317
315
 
318
316
  As `dependencies`:
319
- - [`apollo-server-fastify`](https://www.npmjs.com/package/apollo-server-fastify)
320
- - [`apollo-server-plugin-base`](https://www.npmjs.com/package/apollo-server-plugin-base)
317
+ - [`@as-integrations/fastify`](https://www.npmjs.com/package/@as-integrations/fastify)
321
318
 
322
- Feel free to contribute to this project. Every contribution will be appreciated.
323
-
324
- ### In case you are using a relational database
325
-
326
- As `dependencies`:
327
-
328
- - [`sequelize`](https://www.npmjs.com/package/sequelize)
329
- - [`sequelize-typescript`](https://www.npmjs.com/package/sequelize-typescript)
330
- - [`sequelize-typescript-migration-lts`](https://www.npmjs.com/package/sequelize-typescript-migration-lts)
331
319
 
332
320
  #### PostgreSQL case
333
321
 
@@ -360,6 +348,8 @@ As `dependencies`:
360
348
 
361
349
  - [`tedious`](https://www.npmjs.com/package/tedious)
362
350
 
351
+ Feel free to contribute to this project. Every contribution will be appreciated.
352
+
363
353
  ## Author
364
354
 
365
355
  - **Anthony Luzquiños** - _Initial Work_ - _Documentation_ - [AnthonyLzq](https://github.com/AnthonyLzq).
package/bin/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ process.on('SIGINT', () => {
3
+ console.log('\nSimba.js process cancelled\n')
4
+ process.exit()
5
+ })
2
6
 
3
7
  const main = require('../lib')
4
8