@anthonylzq/simba.js 1.4.0 → 1.8.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/CHANGELOG.md +37 -0
- package/README.md +25 -14
- package/lib/index.js +10 -8
- package/lib/src/functions/docker.js +6 -0
- package/lib/src/functions/eslint.js +1 -4
- package/lib/src/functions/express.js +61 -46
- package/lib/src/functions/gitignore.js +2 -0
- package/lib/src/functions/tsconfig.js +3 -2
- package/lib/src/functions/webpack.js +7 -1
- package/lib/src/installation.js +8 -6
- package/package.json +1 -1
- package/.eslintrc +0 -64
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.8.0](https://github.com/AnthonyLzq/simba.js/compare/v1.7.0...v1.8.0) (2021-12-13)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* implemented baseUrl config with ts and webpack to avoid "../../.. ..." ([9b9e9d2](https://github.com/AnthonyLzq/simba.js/commit/9b9e9d20cae8b4bbdaef58364220512514dac1a4))
|
|
11
|
+
* updated docker file and ignored git folder to be generated manually by docker ([33c1b0d](https://github.com/AnthonyLzq/simba.js/commit/33c1b0df9cfac4e686ece884aa3102e9ad49e6ab))
|
|
12
|
+
* updated docs ([ba72b64](https://github.com/AnthonyLzq/simba.js/commit/ba72b643ea45af7ce7dd7a9adaf8b4f27eacd266))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* fixed eslint ignore ([1405884](https://github.com/AnthonyLzq/simba.js/commit/1405884ab10cf869d6811fbf588ba0b0efb04de2))
|
|
18
|
+
* fixed mongo connection ([57f8580](https://github.com/AnthonyLzq/simba.js/commit/57f85803701253be2308b1c45f537db5b59c92d4))
|
|
19
|
+
|
|
20
|
+
## [1.7.0](https://github.com/AnthonyLzq/simba.js/compare/v1.6.0...v1.7.0) (2021-12-12)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* updated docs and minor changes ([e6b32ca](https://github.com/AnthonyLzq/simba.js/commit/e6b32ca309603544e3506c9d18717f0e45ef0457))
|
|
26
|
+
|
|
27
|
+
## [1.6.0](https://github.com/AnthonyLzq/simba.js/compare/v1.5.0...v1.6.0) (2021-12-12)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* implemented default mongo connection to local database ([1e66e98](https://github.com/AnthonyLzq/simba.js/commit/1e66e982b03eca5c2c3846a10ad827150683da21))
|
|
33
|
+
|
|
34
|
+
## [1.5.0](https://github.com/AnthonyLzq/simba.js/compare/v1.3.1...v1.5.0) (2021-12-12)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
* moving response function to the global variables and cleaning user route ([52f44aa](https://github.com/AnthonyLzq/simba.js/commit/52f44aadad180816d710b1e03dcc1c809b2be424))
|
|
40
|
+
* simplified the code ([dde8f2e](https://github.com/AnthonyLzq/simba.js/commit/dde8f2e27f86f60321af2f12b53546227d0ffe64))
|
|
41
|
+
|
|
5
42
|
## [1.4.0](https://github.com/AnthonyLzq/simba.js/compare/v1.3.1...v1.4.0) (2021-12-12)
|
|
6
43
|
|
|
7
44
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Simba.js
|
|
2
2
|
|
|
3
|
+
[](https://standardjs.com)
|
|
4
|
+
|
|
3
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. Currently the following files are being created:
|
|
4
6
|
|
|
5
7
|
- `.env`
|
|
@@ -59,14 +61,14 @@ simba -h
|
|
|
59
61
|
This will generate the following output:
|
|
60
62
|
|
|
61
63
|
```bash
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
simba [options] (if you it installed globally) or only simba if you want to be
|
|
65
|
+
asked for the options one by one
|
|
64
66
|
|
|
65
67
|
Options:
|
|
66
|
-
-a, --author Author of the project
|
|
67
|
-
-e, --email Email of the author
|
|
68
68
|
-N, --projectName Project name
|
|
69
69
|
-D, --projectDescription Project description
|
|
70
|
+
-a, --author Author of the project
|
|
71
|
+
-e, --email Email of the author
|
|
70
72
|
-H, --heroku Whether or not the project will be deployed using
|
|
71
73
|
Heroku [boolean] [default: false]
|
|
72
74
|
-l, --license Type of license for the project, it can be one of:
|
|
@@ -84,8 +86,8 @@ Options:
|
|
|
84
86
|
-h, --help Show help [boolean]
|
|
85
87
|
|
|
86
88
|
Examples:
|
|
87
|
-
simba
|
|
88
|
-
|
|
89
|
+
simba -N "Project Name" -D "Project description -a Anthony -e
|
|
90
|
+
sluzquinosa@uni.pe"
|
|
89
91
|
|
|
90
92
|
Developed by AnthonyLzq
|
|
91
93
|
```
|
|
@@ -139,28 +141,34 @@ Regardless of the option chosen, a new folder will be generated with the name of
|
|
|
139
141
|
Let's suppose you want to build a project that will be deployed to Heroku, so should run:
|
|
140
142
|
|
|
141
143
|
```bash
|
|
142
|
-
simba -
|
|
144
|
+
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H
|
|
143
145
|
```
|
|
144
146
|
|
|
145
|
-
Here we are specifying that we want to create a new project called `myProject` using the `MIT` license,
|
|
147
|
+
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.
|
|
146
148
|
|
|
147
|
-
As default, `yarn` is selected as package manager, but you don't want to use it,
|
|
149
|
+
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:
|
|
148
150
|
|
|
149
151
|
```bash
|
|
150
|
-
simba -
|
|
152
|
+
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -n
|
|
151
153
|
```
|
|
152
154
|
|
|
153
155
|
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:
|
|
154
156
|
|
|
155
157
|
```bash
|
|
156
|
-
simba -
|
|
158
|
+
simba -N myProject -D 'This is a test' -a myName -e myEmail@email.com -H
|
|
157
159
|
```
|
|
158
160
|
|
|
159
161
|
### Some considerations
|
|
160
162
|
|
|
161
163
|
- This project is based in other project from my own, [`typescript-project-generator`](https://www.npmjs.com/package/typescript-project-generator), but only considering the `express-mongoose-node` part.
|
|
162
|
-
- You are able to run a server that has one main route, `home` (`/`),
|
|
163
|
-
- To connect your server with your `MongoDB` database, you need to provide your `uri` in the `.env`.
|
|
164
|
+
- You are able to run a server that has one main route, `home` (`/`), `user` (`api/user` or `api/user/:userId`) and `docs` (`api/docs`).
|
|
165
|
+
- 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:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
MONGO_URI = mongodb://mongo:mongo@mongo:27017/${projectName}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Where `${projectName}` will be replaced by the name of the project you provided in lowercase.
|
|
164
172
|
- Once you have done that, now you can perform the following `HTTP REQUEST`: `GET`, `POST`, `PATCH` and `DELETE`.
|
|
165
173
|
- In order to use global variables, just add the one you need in the `src/@types/index.d.ts` file, and add a new `var` with its type to the `global` interface, as follows:
|
|
166
174
|
```ts
|
|
@@ -184,6 +192,7 @@ simba -a myName -e myEmail@email.com -N myProject -D 'This is a test' -H
|
|
|
184
192
|
- To check the content of the files generated, please check the `example` folder.
|
|
185
193
|
- 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).
|
|
186
194
|
- Finally, `git` will be initialized and a list of libraries will be installed. Check the [**notes**](#notes).
|
|
195
|
+
- 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.
|
|
187
196
|
|
|
188
197
|
## What is new?
|
|
189
198
|
|
|
@@ -202,8 +211,8 @@ Here is the list of the packages that are being installed, as `devDependencies`:
|
|
|
202
211
|
- [`@typescript-eslint/parser`](https://www.npmjs.com/package/@typescript-eslint/parser)
|
|
203
212
|
- [`dotenv`](https://www.npmjs.com/package/dotenv)
|
|
204
213
|
- [`eslint`](https://www.npmjs.com/package/eslint)
|
|
205
|
-
- [`eslint-config-airbnb-typescript`](https://www.npmjs.com/package/eslint-config-airbnb-typescript)
|
|
206
214
|
- [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier)
|
|
215
|
+
- [`eslint-config-standard`](https://www.npmjs.com/package/eslint-config-standard)
|
|
207
216
|
- [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import)
|
|
208
217
|
- [`eslint-plugin-prettier`](https://www.npmjs.com/package/eslint-plugin-prettier)
|
|
209
218
|
- [`eslint-plugin-sort-keys-fix`](https://www.npmjs.com/package/eslint-plugin-sort-keys-fix)
|
|
@@ -213,6 +222,8 @@ Here is the list of the packages that are being installed, as `devDependencies`:
|
|
|
213
222
|
- [`standard-version`](https://www.npmjs.com/package/standard-version)
|
|
214
223
|
- [`ts-loader`](https://www.npmjs.com/package/ts-loader)
|
|
215
224
|
- [`ts-node`](https://www.npmjs.com/package/ts-node)
|
|
225
|
+
- [`tsconfig-paths`](https://www.npmjs.com/package/tsconfig-paths)
|
|
226
|
+
- [`tsconfig-paths-webpack-plugin`](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin)
|
|
216
227
|
- [`typescript`](https://www.npmjs.com/package/typescript)
|
|
217
228
|
- [`webpack`](https://www.npmjs.com/package/webpack)
|
|
218
229
|
- [`webpack-cli`](https://www.npmjs.com/package/webpack-cli)
|
package/lib/index.js
CHANGED
|
@@ -7,24 +7,25 @@ const installation = require('./src/installation')
|
|
|
7
7
|
const CURRENT_YEAR = `${new Date().getFullYear()}`
|
|
8
8
|
const argv = yargs(hideBin(process.argv))
|
|
9
9
|
.version(false)
|
|
10
|
+
// Pending to test it using npx
|
|
10
11
|
.usage(
|
|
11
|
-
'
|
|
12
|
+
'simba [options] (if you it installed globally) or only simba if you want to be asked for the options one by one'
|
|
12
13
|
)
|
|
13
14
|
.example(
|
|
14
|
-
'simba
|
|
15
|
+
'simba -N "Project Name" -D "Project description -a Anthony -e sluzquinosa@uni.pe"'
|
|
15
16
|
)
|
|
16
|
-
.alias('a', 'author')
|
|
17
|
-
.nargs('a', 1)
|
|
18
|
-
.describe('a', 'Author of the project')
|
|
19
|
-
.alias('e', 'email')
|
|
20
|
-
.nargs('e', 1)
|
|
21
|
-
.describe('e', 'Email of the author')
|
|
22
17
|
.alias('N', 'projectName')
|
|
23
18
|
.nargs('N', 1)
|
|
24
19
|
.describe('N', 'Project name')
|
|
25
20
|
.alias('D', 'projectDescription')
|
|
26
21
|
.nargs('D', 1)
|
|
27
22
|
.describe('D', 'Project description')
|
|
23
|
+
.alias('a', 'author')
|
|
24
|
+
.nargs('a', 1)
|
|
25
|
+
.describe('a', 'Author of the project')
|
|
26
|
+
.alias('e', 'email')
|
|
27
|
+
.nargs('e', 1)
|
|
28
|
+
.describe('e', 'Email of the author')
|
|
28
29
|
.alias('H', 'heroku')
|
|
29
30
|
.describe('H', 'Whether or not the project will be deployed using Heroku')
|
|
30
31
|
.alias('l', 'license')
|
|
@@ -45,6 +46,7 @@ const argv = yargs(hideBin(process.argv))
|
|
|
45
46
|
.nargs('f', 1)
|
|
46
47
|
.describe('f', 'Main file of the project')
|
|
47
48
|
.alias('q', 'questions')
|
|
49
|
+
.nargs('q', 1)
|
|
48
50
|
.describe(
|
|
49
51
|
'q',
|
|
50
52
|
'Whether or not you want to be asked to answer the questions related to the project one by one'
|
|
@@ -35,7 +35,6 @@ const writeFile = require('../utils/writeFile')
|
|
|
35
35
|
* | |- index.http: content, file
|
|
36
36
|
* |- utils:
|
|
37
37
|
* | |- docs.json: content, file
|
|
38
|
-
* | |- response: content, file
|
|
39
38
|
* | |- index: content, file
|
|
40
39
|
* |- .env: content, file
|
|
41
40
|
* |- index: content, file
|
|
@@ -54,11 +53,18 @@ module.exports = async (projectName, projectVersion, email) => {
|
|
|
54
53
|
import { IncomingHttpHeaders } from 'http'
|
|
55
54
|
import { Request, Response } from 'express'
|
|
56
55
|
|
|
57
|
-
import { DtoUser } from '
|
|
56
|
+
import { DtoUser } from 'dto-interfaces'
|
|
58
57
|
|
|
59
58
|
declare global {
|
|
60
59
|
// This variable is global, so it will be available everywhere in the code
|
|
61
|
-
var
|
|
60
|
+
var response = (
|
|
61
|
+
error: boolean,
|
|
62
|
+
message: unknown,
|
|
63
|
+
res: Response,
|
|
64
|
+
status: number
|
|
65
|
+
): void => {
|
|
66
|
+
res.status(status).send({ error, message })
|
|
67
|
+
}
|
|
62
68
|
|
|
63
69
|
// We can personalize the response and request objects in case we need it by
|
|
64
70
|
// adding new optional attributes to this interface
|
|
@@ -94,8 +100,8 @@ export { User }
|
|
|
94
100
|
user: {
|
|
95
101
|
content: `import httpErrors from 'http-errors'
|
|
96
102
|
|
|
97
|
-
import { DtoUser } from '
|
|
98
|
-
import { IUser, UserModel } from '
|
|
103
|
+
import { DtoUser } from 'dto-interfaces'
|
|
104
|
+
import { IUser, UserModel } from 'models'
|
|
99
105
|
import { EFU, MFU, GE, errorHandling } from './utils'
|
|
100
106
|
|
|
101
107
|
type Process = {
|
|
@@ -346,8 +352,8 @@ export { IUser, UserModel }
|
|
|
346
352
|
import swaggerUi from 'swagger-ui-express'
|
|
347
353
|
import httpErrors from 'http-errors'
|
|
348
354
|
|
|
349
|
-
import { Home, User } from '
|
|
350
|
-
import {
|
|
355
|
+
import { Home, User } from 'routes'
|
|
356
|
+
import { docs } from 'utils'
|
|
351
357
|
|
|
352
358
|
const routers = [User]
|
|
353
359
|
|
|
@@ -422,8 +428,6 @@ class Server {
|
|
|
422
428
|
this._connection = mongoose.connection
|
|
423
429
|
const connection = {
|
|
424
430
|
keepAlive: true,
|
|
425
|
-
useCreateIndex: true,
|
|
426
|
-
useFindAndModify: false,
|
|
427
431
|
useNewUrlParser: true,
|
|
428
432
|
useUnifiedTopology: true
|
|
429
433
|
}
|
|
@@ -485,7 +489,6 @@ export { applyRoutes, Server }
|
|
|
485
489
|
routes: {
|
|
486
490
|
home: {
|
|
487
491
|
content: `import { Response, Request, Router } from 'express'
|
|
488
|
-
import { response } from '../utils'
|
|
489
492
|
|
|
490
493
|
const Home = Router()
|
|
491
494
|
|
|
@@ -499,7 +502,7 @@ export { Home }
|
|
|
499
502
|
},
|
|
500
503
|
index: {
|
|
501
504
|
content: `import { Home } from './home'
|
|
502
|
-
import { User } from './
|
|
505
|
+
import { User } from './user'
|
|
503
506
|
|
|
504
507
|
export { Home, User }
|
|
505
508
|
`,
|
|
@@ -507,18 +510,22 @@ export { Home, User }
|
|
|
507
510
|
},
|
|
508
511
|
user: {
|
|
509
512
|
content: `import { Router, NextFunction } from 'express'
|
|
513
|
+
import httpErrors from 'http-errors'
|
|
514
|
+
import { ValidationError } from 'joi'
|
|
510
515
|
|
|
511
|
-
import {
|
|
512
|
-
import {
|
|
513
|
-
import {
|
|
514
|
-
import { DtoUser } from '../dto-interfaces'
|
|
515
|
-
import { idSchema, userSchema } from '../schemas'
|
|
516
|
+
import { User as UserC } from 'controllers/user'
|
|
517
|
+
import { DtoUser } from 'dto-interfaces'
|
|
518
|
+
import { idSchema, userSchema } from 'schemas'
|
|
516
519
|
|
|
517
520
|
const User = Router()
|
|
518
521
|
|
|
519
522
|
User.route('/users')
|
|
520
523
|
.post(
|
|
521
|
-
async (
|
|
524
|
+
async (
|
|
525
|
+
req: CustomRequest,
|
|
526
|
+
res: CustomResponse,
|
|
527
|
+
next: NextFunction
|
|
528
|
+
): Promise<void> => {
|
|
522
529
|
const {
|
|
523
530
|
body: { args }
|
|
524
531
|
} = req
|
|
@@ -533,7 +540,11 @@ User.route('/users')
|
|
|
533
540
|
}
|
|
534
541
|
)
|
|
535
542
|
.get(
|
|
536
|
-
async (
|
|
543
|
+
async (
|
|
544
|
+
req: CustomRequest,
|
|
545
|
+
res: CustomResponse,
|
|
546
|
+
next: NextFunction
|
|
547
|
+
): Promise<void> => {
|
|
537
548
|
const u = new UserC()
|
|
538
549
|
|
|
539
550
|
try {
|
|
@@ -545,7 +556,11 @@ User.route('/users')
|
|
|
545
556
|
}
|
|
546
557
|
)
|
|
547
558
|
.delete(
|
|
548
|
-
async (
|
|
559
|
+
async (
|
|
560
|
+
req: CustomRequest,
|
|
561
|
+
res: CustomResponse,
|
|
562
|
+
next: NextFunction
|
|
563
|
+
): Promise<void> => {
|
|
549
564
|
const u = new UserC()
|
|
550
565
|
|
|
551
566
|
try {
|
|
@@ -559,7 +574,11 @@ User.route('/users')
|
|
|
559
574
|
|
|
560
575
|
User.route('/user/:id')
|
|
561
576
|
.get(
|
|
562
|
-
async (
|
|
577
|
+
async (
|
|
578
|
+
req: CustomRequest,
|
|
579
|
+
res: CustomResponse,
|
|
580
|
+
next: NextFunction
|
|
581
|
+
): Promise<void> => {
|
|
563
582
|
const {
|
|
564
583
|
params: { id }
|
|
565
584
|
} = req
|
|
@@ -570,13 +589,19 @@ User.route('/user/:id')
|
|
|
570
589
|
const result = await u.process({ type: 'getOne' })
|
|
571
590
|
response(false, result, res, 200)
|
|
572
591
|
} catch (e) {
|
|
573
|
-
if (e
|
|
592
|
+
if (e instanceof ValidationError)
|
|
593
|
+
return next(new httpErrors.UnprocessableEntity(e.message))
|
|
594
|
+
|
|
574
595
|
next(e)
|
|
575
596
|
}
|
|
576
597
|
}
|
|
577
598
|
)
|
|
578
599
|
.patch(
|
|
579
|
-
async (
|
|
600
|
+
async (
|
|
601
|
+
req: CustomRequest,
|
|
602
|
+
res: CustomResponse,
|
|
603
|
+
next: NextFunction
|
|
604
|
+
): Promise<void> => {
|
|
580
605
|
const {
|
|
581
606
|
body: { args },
|
|
582
607
|
params: { id }
|
|
@@ -592,13 +617,19 @@ User.route('/user/:id')
|
|
|
592
617
|
const result = await u.process({ type: 'update' })
|
|
593
618
|
response(false, result, res, 200)
|
|
594
619
|
} catch (e) {
|
|
595
|
-
if (e
|
|
620
|
+
if (e instanceof ValidationError)
|
|
621
|
+
return next(new httpErrors.UnprocessableEntity(e.message))
|
|
622
|
+
|
|
596
623
|
next(e)
|
|
597
624
|
}
|
|
598
625
|
}
|
|
599
626
|
)
|
|
600
627
|
.delete(
|
|
601
|
-
async (
|
|
628
|
+
async (
|
|
629
|
+
req: CustomRequest,
|
|
630
|
+
res: CustomResponse,
|
|
631
|
+
next: NextFunction
|
|
632
|
+
): Promise<void> => {
|
|
602
633
|
const {
|
|
603
634
|
params: { id }
|
|
604
635
|
} = req
|
|
@@ -609,7 +640,9 @@ User.route('/user/:id')
|
|
|
609
640
|
const result = await u.process({ type: 'delete' })
|
|
610
641
|
response(false, result, res, 200)
|
|
611
642
|
} catch (e) {
|
|
612
|
-
if (e
|
|
643
|
+
if (e instanceof ValidationError)
|
|
644
|
+
return next(new httpErrors.UnprocessableEntity(e.message))
|
|
645
|
+
|
|
613
646
|
next(e)
|
|
614
647
|
}
|
|
615
648
|
}
|
|
@@ -617,7 +650,7 @@ User.route('/user/:id')
|
|
|
617
650
|
|
|
618
651
|
export { User }
|
|
619
652
|
`,
|
|
620
|
-
file: `${projectName}/src/routes/
|
|
653
|
+
file: `${projectName}/src/routes/user.ts`
|
|
621
654
|
}
|
|
622
655
|
},
|
|
623
656
|
schemas: {
|
|
@@ -1108,31 +1141,14 @@ DELETE http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b
|
|
|
1108
1141
|
},
|
|
1109
1142
|
index: {
|
|
1110
1143
|
content: `import docs from './docs.json'
|
|
1111
|
-
import { response } from './response'
|
|
1112
1144
|
|
|
1113
|
-
export { docs
|
|
1145
|
+
export { docs }
|
|
1114
1146
|
`,
|
|
1115
1147
|
file: `${projectName}/src/utils/index.ts`
|
|
1116
|
-
},
|
|
1117
|
-
response: {
|
|
1118
|
-
content: `import { Response } from 'express'
|
|
1119
|
-
|
|
1120
|
-
const response = (
|
|
1121
|
-
error: boolean,
|
|
1122
|
-
message: unknown,
|
|
1123
|
-
res: Response,
|
|
1124
|
-
status: number
|
|
1125
|
-
): void => {
|
|
1126
|
-
res.status(status).send({ error, message })
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
export { response }
|
|
1130
|
-
`,
|
|
1131
|
-
file: `${projectName}/src/utils/response.ts`
|
|
1132
1148
|
}
|
|
1133
1149
|
},
|
|
1134
1150
|
'.env': {
|
|
1135
|
-
content:
|
|
1151
|
+
content: `MONGO_URI = mongodb://mongo:mongo@mongo:27017/${projectName}`,
|
|
1136
1152
|
file: `${projectName}/.env`
|
|
1137
1153
|
},
|
|
1138
1154
|
index: {
|
|
@@ -1214,7 +1230,6 @@ ${projectName}/src/utils
|
|
|
1214
1230
|
|
|
1215
1231
|
// /utils
|
|
1216
1232
|
await writeFile(data.utils.docs.file, data.utils.docs.content)
|
|
1217
|
-
await writeFile(data.utils.response.file, data.utils.response.content)
|
|
1218
1233
|
await writeFile(data.utils.index.file, data.utils.index.content)
|
|
1219
1234
|
|
|
1220
1235
|
// .env
|
|
@@ -8,7 +8,8 @@ module.exports = async projectName => {
|
|
|
8
8
|
const data = {
|
|
9
9
|
tsconfigContent: `{
|
|
10
10
|
"ts-node": {
|
|
11
|
-
"files": true
|
|
11
|
+
"files": true,
|
|
12
|
+
"require": ["tsconfig-paths/register"]
|
|
12
13
|
},
|
|
13
14
|
"compilerOptions": {
|
|
14
15
|
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
@@ -52,7 +53,7 @@ module.exports = async projectName => {
|
|
|
52
53
|
|
|
53
54
|
/* Module Resolution Options */
|
|
54
55
|
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
|
|
55
|
-
|
|
56
|
+
"baseUrl": "./src", /* Base directory to resolve non-absolute module names. */
|
|
56
57
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
57
58
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
58
59
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
@@ -8,6 +8,7 @@ module.exports = async projectName => {
|
|
|
8
8
|
const data = {
|
|
9
9
|
webpackContent: `const path = require('path')
|
|
10
10
|
const nodeExternals = require('webpack-node-externals')
|
|
11
|
+
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
|
|
11
12
|
|
|
12
13
|
module.exports = {
|
|
13
14
|
context: __dirname,
|
|
@@ -28,7 +29,12 @@ module.exports = {
|
|
|
28
29
|
__dirname: false
|
|
29
30
|
},
|
|
30
31
|
resolve: {
|
|
31
|
-
extensions: ['.ts', '.js']
|
|
32
|
+
extensions: ['.ts', '.js'],
|
|
33
|
+
plugins: [
|
|
34
|
+
new TsconfigPathsPlugin({
|
|
35
|
+
baseUrl: './src'
|
|
36
|
+
})
|
|
37
|
+
]
|
|
32
38
|
},
|
|
33
39
|
output: {
|
|
34
40
|
filename: 'index.js',
|
package/lib/src/installation.js
CHANGED
|
@@ -58,7 +58,11 @@ module.exports = async ({
|
|
|
58
58
|
|
|
59
59
|
const prodPackages = `${manager} express mongoose morgan http-errors joi swagger-ui-express`
|
|
60
60
|
const devPackages = `${manager} -D \
|
|
61
|
+
@types/express \
|
|
62
|
+
@types/http-errors \
|
|
63
|
+
@types/morgan \
|
|
61
64
|
@types/node \
|
|
65
|
+
@types/swagger-ui-express \
|
|
62
66
|
@typescript-eslint/eslint-plugin \
|
|
63
67
|
@typescript-eslint/parser \
|
|
64
68
|
dotenv \
|
|
@@ -71,17 +75,15 @@ eslint-plugin-sort-keys-fix \
|
|
|
71
75
|
eslint-plugin-typescript-sort-keys \
|
|
72
76
|
nodemon \
|
|
73
77
|
prettier \
|
|
78
|
+
standard-version \
|
|
74
79
|
ts-loader \
|
|
75
80
|
ts-node \
|
|
81
|
+
tsconfig-paths \
|
|
82
|
+
tsconfig-paths-webpack-plugin \
|
|
76
83
|
typescript \
|
|
77
84
|
webpack \
|
|
78
85
|
webpack-cli \
|
|
79
|
-
webpack-node-externals
|
|
80
|
-
@types/express \
|
|
81
|
-
@types/morgan \
|
|
82
|
-
@types/swagger-ui-express \
|
|
83
|
-
@types/http-errors \
|
|
84
|
-
standard-version`
|
|
86
|
+
webpack-node-externals`
|
|
85
87
|
|
|
86
88
|
bar.start(process, i)
|
|
87
89
|
|
package/package.json
CHANGED
package/.eslintrc
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true
|
|
4
|
-
},
|
|
5
|
-
"root": true,
|
|
6
|
-
"plugins": [
|
|
7
|
-
"import",
|
|
8
|
-
"prettier"
|
|
9
|
-
],
|
|
10
|
-
"extends": [
|
|
11
|
-
"standard",
|
|
12
|
-
"eslint:recommended",
|
|
13
|
-
"prettier"
|
|
14
|
-
],
|
|
15
|
-
"rules": {
|
|
16
|
-
"@typescript-eslint/no-var-requires": "off",
|
|
17
|
-
"arrow-parens": [
|
|
18
|
-
"error",
|
|
19
|
-
"as-needed"
|
|
20
|
-
],
|
|
21
|
-
"import/no-extraneous-dependencies": [
|
|
22
|
-
"error",
|
|
23
|
-
{
|
|
24
|
-
"devDependencies": true
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
"max-len": [
|
|
28
|
-
"error",
|
|
29
|
-
{
|
|
30
|
-
"code": 80,
|
|
31
|
-
"ignoreComments": true,
|
|
32
|
-
"ignoreRegExpLiterals": true,
|
|
33
|
-
"ignoreTemplateLiterals": true,
|
|
34
|
-
"ignoreTrailingComments": true,
|
|
35
|
-
"ignoreStrings": true,
|
|
36
|
-
"ignoreUrls": true
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
"newline-before-return": "error",
|
|
40
|
-
"object-curly-spacing": [
|
|
41
|
-
"error",
|
|
42
|
-
"always"
|
|
43
|
-
],
|
|
44
|
-
"prefer-const": "error",
|
|
45
|
-
"prettier/prettier": [
|
|
46
|
-
"error",
|
|
47
|
-
{
|
|
48
|
-
"arrowParens": "avoid",
|
|
49
|
-
"bracketSpacing": true,
|
|
50
|
-
"printWidth": 80,
|
|
51
|
-
"quoteProps": "as-needed",
|
|
52
|
-
"semi": false,
|
|
53
|
-
"singleQuote": true,
|
|
54
|
-
"tabWidth": 2,
|
|
55
|
-
"trailingComma": "none"
|
|
56
|
-
}
|
|
57
|
-
],
|
|
58
|
-
"radix": [
|
|
59
|
-
"error",
|
|
60
|
-
"as-needed"
|
|
61
|
-
],
|
|
62
|
-
"spaced-comment": ["error", "always"]
|
|
63
|
-
}
|
|
64
|
-
}
|