@anthonylzq/simba.js 1.7.0 → 1.10.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
@@ -192,6 +192,7 @@ simba -N myProject -D 'This is a test' -a myName -e myEmail@email.com -H
192
192
  - To check the content of the files generated, please check the `example` folder.
193
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).
194
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.
195
196
 
196
197
  ## What is new?
197
198
 
@@ -221,6 +222,8 @@ Here is the list of the packages that are being installed, as `devDependencies`:
221
222
  - [`standard-version`](https://www.npmjs.com/package/standard-version)
222
223
  - [`ts-loader`](https://www.npmjs.com/package/ts-loader)
223
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)
224
227
  - [`typescript`](https://www.npmjs.com/package/typescript)
225
228
  - [`webpack`](https://www.npmjs.com/package/webpack)
226
229
  - [`webpack-cli`](https://www.npmjs.com/package/webpack-cli)
@@ -14,6 +14,12 @@ COPY package.json ./
14
14
 
15
15
  RUN yarn install --prod
16
16
 
17
+ RUN yarn add webpack webpack-node-externals -D
18
+
19
+ RUN yarn build
20
+
21
+ RUN yarn remove webpack webpack-node-externals
22
+
17
23
  COPY dist /app/dist
18
24
 
19
25
  CMD [ "yarn", "start" ]
@@ -12,11 +12,7 @@ module.exports = async projectName => {
12
12
  },
13
13
  root: true,
14
14
  parser: '@typescript-eslint/parser',
15
- plugins: [
16
- '@typescript-eslint',
17
- 'import',
18
- 'prettier'
19
- ],
15
+ plugins: ['@typescript-eslint', 'import', 'prettier'],
20
16
  extends: [
21
17
  'standard',
22
18
  'eslint:recommended',
@@ -27,10 +23,7 @@ module.exports = async projectName => {
27
23
  rules: {
28
24
  '@typescript-eslint/no-var-requires': 'off',
29
25
  '@typescript-eslint/no-empty-interface': 'off',
30
- 'arrow-parens': [
31
- 'error',
32
- 'as-needed'
33
- ],
26
+ 'arrow-parens': ['error', 'as-needed'],
34
27
  'import/extensions': [
35
28
  2,
36
29
  {
@@ -60,37 +53,29 @@ module.exports = async projectName => {
60
53
  }
61
54
  ],
62
55
  'newline-before-return': 'error',
63
- 'object-curly-spacing': [
64
- 'error',
65
- 'always'
66
- ],
56
+ 'object-curly-spacing': ['error', 'always'],
57
+ "object-shorthand": ["error", "always"],
67
58
  'prefer-const': 'error',
68
59
  'prettier/prettier': [
69
60
  'error',
70
61
  {
71
- 'arrowParens': 'avoid',
72
- 'bracketSpacing': true,
73
- 'printWidth': 80,
74
- 'quoteProps': 'as-needed',
75
- 'semi': false,
76
- 'singleQuote': true,
77
- 'tabWidth': 2,
78
- 'trailingComma': 'none'
62
+ arrowParens: 'avoid',
63
+ bracketSpacing: true,
64
+ printWidth: 80,
65
+ quoteProps: 'as-needed',
66
+ semi: false,
67
+ singleQuote: true,
68
+ tabWidth: 2,
69
+ trailingComma: 'none'
79
70
  }
80
71
  ],
81
- radix: [
82
- 'error',
83
- 'as-needed'
84
- ],
72
+ radix: ['error', 'as-needed'],
85
73
  'spaced-comment': ['error', 'always']
86
74
  }
87
75
  }
88
76
  `,
89
77
  eslintFile: '.eslintrc.js',
90
- eslintIgnoreContent: `/dist
91
- .eslintrc.js
92
- webpack.config.js
93
- `,
78
+ eslintIgnoreContent: '/dist',
94
79
  eslintIgnoreFile: '.eslintignore'
95
80
  }
96
81
 
@@ -5,7 +5,7 @@ const writeFile = require('../utils/writeFile')
5
5
  /*
6
6
  * src
7
7
  * |- @types:
8
- * | |- global: content, file
8
+ * | |- index: content, file
9
9
  * |- controllers:
10
10
  * | |- utils:
11
11
  * | | |- messages:
@@ -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,18 +53,17 @@ 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 '../dto-interfaces'
56
+ import { DtoUser } from 'dto-interfaces'
58
57
 
59
58
  declare global {
60
- // This variable is global, so it will be available everywhere in the code
61
- var response = (
62
- error: boolean,
63
- message: unknown,
64
- res: Response,
59
+ interface ResponseProps {
60
+ error: boolean
61
+ message: unknown
62
+ res: Response
65
63
  status: number
66
- ): void => {
67
- res.status(status).send({ error, message })
68
64
  }
65
+ // This variable is global, so it will be available everywhere in the code
66
+ var response: ({ error, message, res, status }: ResponseProps) => void
69
67
 
70
68
  // We can personalize the response and request objects in case we need it by
71
69
  // adding new optional attributes to this interface
@@ -101,8 +99,8 @@ export { User }
101
99
  user: {
102
100
  content: `import httpErrors from 'http-errors'
103
101
 
104
- import { DtoUser } from '../dto-interfaces'
105
- import { IUser, UserModel } from '../models'
102
+ import { DtoUser } from 'dto-interfaces'
103
+ import { IUser, UserModel } from 'models'
106
104
  import { EFU, MFU, GE, errorHandling } from './utils'
107
105
 
108
106
  type Process = {
@@ -164,7 +162,10 @@ class User {
164
162
  try {
165
163
  const usersDeleted = await UserModel.deleteMany({})
166
164
 
167
- if (usersDeleted.acknowledged) return MFU.ALL_USERS_DELETED
165
+ if (usersDeleted.deletedCount >= 1) return MFU.ALL_USERS_DELETED
166
+
167
+ if (usersDeleted.deletedCount === 0)
168
+ throw new httpErrors.BadRequest(EFU.NOTHING_TO_DELETE)
168
169
 
169
170
  throw new httpErrors.InternalServerError(GE.INTERNAL_SERVER_ERROR)
170
171
  } catch (e) {
@@ -258,7 +259,8 @@ export { EFU, MFU, GenericErrors as GE }
258
259
  },
259
260
  user: {
260
261
  content: `enum ErrorForUser {
261
- NOT_FOUND = 'The requested user does not exists'
262
+ NOT_FOUND = 'The requested user does not exists',
263
+ NOTHING_TO_DELETE = 'There is no user to be deleted'
262
264
  }
263
265
 
264
266
  enum MessageForUser {
@@ -353,8 +355,8 @@ export { IUser, UserModel }
353
355
  import swaggerUi from 'swagger-ui-express'
354
356
  import httpErrors from 'http-errors'
355
357
 
356
- import { Home, User } from '../routes'
357
- import { docs } from '../utils'
358
+ import { Home, User } from 'routes'
359
+ import { docs } from 'utils'
358
360
 
359
361
  const routers = [User]
360
362
 
@@ -374,7 +376,12 @@ const applyRoutes = (app: Application): void => {
374
376
  res: Response,
375
377
  next: NextFunction
376
378
  ) => {
377
- response(true, error.message, res, error.status)
379
+ response({
380
+ error: true,
381
+ message: error.message,
382
+ res,
383
+ status: error.status
384
+ })
378
385
  next()
379
386
  }
380
387
  )
@@ -422,6 +429,17 @@ class Server {
422
429
  next()
423
430
  }
424
431
  )
432
+
433
+ // setting up the global response
434
+ global.response = ({
435
+ error,
436
+ message,
437
+ res,
438
+ status
439
+ }: ResponseProps): void => {
440
+ res.status(status).send({ error, message })
441
+ }
442
+
425
443
  applyRoutes(this._app)
426
444
  }
427
445
 
@@ -429,8 +447,6 @@ class Server {
429
447
  this._connection = mongoose.connection
430
448
  const connection = {
431
449
  keepAlive: true,
432
- useCreateIndex: true,
433
- useFindAndModify: false,
434
450
  useNewUrlParser: true,
435
451
  useUnifiedTopology: true
436
452
  }
@@ -496,7 +512,12 @@ export { applyRoutes, Server }
496
512
  const Home = Router()
497
513
 
498
514
  Home.route('').get((req: Request, res: Response) => {
499
- response(false, 'Welcome to your Express Backend!', res, 200)
515
+ response({
516
+ error: false,
517
+ message: 'Welcome to your Express Backend!',
518
+ res,
519
+ status: 200
520
+ })
500
521
  })
501
522
 
502
523
  export { Home }
@@ -516,9 +537,9 @@ export { Home, User }
516
537
  import httpErrors from 'http-errors'
517
538
  import { ValidationError } from 'joi'
518
539
 
519
- import { User as UserC } from '../controllers/user'
520
- import { DtoUser } from '../dto-interfaces'
521
- import { idSchema, userSchema } from '../schemas'
540
+ import { User as UserC } from 'controllers/user'
541
+ import { DtoUser } from 'dto-interfaces'
542
+ import { idSchema, userSchema } from 'schemas'
522
543
 
523
544
  const User = Router()
524
545
 
@@ -536,7 +557,7 @@ User.route('/users')
536
557
 
537
558
  try {
538
559
  const result = await u.process({ type: 'store' })
539
- response(false, result, res, 201)
560
+ response({ error: false, message: result, res, status: 201 })
540
561
  } catch (e) {
541
562
  next(e)
542
563
  }
@@ -552,7 +573,7 @@ User.route('/users')
552
573
 
553
574
  try {
554
575
  const result = await u.process({ type: 'getAll' })
555
- response(false, result, res, 200)
576
+ response({ error: false, message: result, res, status: 200 })
556
577
  } catch (e) {
557
578
  next(e)
558
579
  }
@@ -568,7 +589,7 @@ User.route('/users')
568
589
 
569
590
  try {
570
591
  const result = await u.process({ type: 'deleteAll' })
571
- response(false, result, res, 200)
592
+ response({ error: false, message: result, res, status: 200 })
572
593
  } catch (e) {
573
594
  next(e)
574
595
  }
@@ -590,7 +611,7 @@ User.route('/user/:id')
590
611
  await idSchema.validateAsync(id)
591
612
  const u = new UserC({ id } as DtoUser)
592
613
  const result = await u.process({ type: 'getOne' })
593
- response(false, result, res, 200)
614
+ response({ error: false, message: result, res, status: 200 })
594
615
  } catch (e) {
595
616
  if (e instanceof ValidationError)
596
617
  return next(new httpErrors.UnprocessableEntity(e.message))
@@ -618,7 +639,7 @@ User.route('/user/:id')
618
639
  await userSchema.validateAsync(user)
619
640
  const u = new UserC(user)
620
641
  const result = await u.process({ type: 'update' })
621
- response(false, result, res, 200)
642
+ response({ error: false, message: result, res, status: 200 })
622
643
  } catch (e) {
623
644
  if (e instanceof ValidationError)
624
645
  return next(new httpErrors.UnprocessableEntity(e.message))
@@ -641,7 +662,7 @@ User.route('/user/:id')
641
662
  await idSchema.validateAsync(id)
642
663
  const u = new UserC({ id } as DtoUser)
643
664
  const result = await u.process({ type: 'delete' })
644
- response(false, result, res, 200)
665
+ response({ error: false, message: result, res, status: 200 })
645
666
  } catch (e) {
646
667
  if (e instanceof ValidationError)
647
668
  return next(new httpErrors.UnprocessableEntity(e.message))
@@ -1148,22 +1169,6 @@ DELETE http://localhost:1996/api/user/60e7e3b93b01c1a7aa74cd6b
1148
1169
  export { docs }
1149
1170
  `,
1150
1171
  file: `${projectName}/src/utils/index.ts`
1151
- },
1152
- response: {
1153
- content: `import { Response } from 'express'
1154
-
1155
- const response = (
1156
- error: boolean,
1157
- message: unknown,
1158
- res: Response,
1159
- status: number
1160
- ): void => {
1161
- res.status(status).send({ error, message })
1162
- }
1163
-
1164
- export { response }
1165
- `,
1166
- file: `${projectName}/src/utils/response.ts`
1167
1172
  }
1168
1173
  },
1169
1174
  '.env': {
@@ -1249,7 +1254,6 @@ ${projectName}/src/utils
1249
1254
 
1250
1255
  // /utils
1251
1256
  await writeFile(data.utils.docs.file, data.utils.docs.content)
1252
- await writeFile(data.utils.response.file, data.utils.response.content)
1253
1257
  await writeFile(data.utils.index.file, data.utils.index.content)
1254
1258
 
1255
1259
  // .env
@@ -132,6 +132,8 @@ typings/
132
132
  # .pnp.*
133
133
 
134
134
  # End of https://www.toptal.com/developers/gitignore/api/node,yarn
135
+
136
+ dist
135
137
  `,
136
138
  gitignoreFile: '.gitignore'
137
139
  }
@@ -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
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
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',
@@ -78,6 +78,8 @@ prettier \
78
78
  standard-version \
79
79
  ts-loader \
80
80
  ts-node \
81
+ tsconfig-paths \
82
+ tsconfig-paths-webpack-plugin \
81
83
  typescript \
82
84
  webpack \
83
85
  webpack-cli \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthonylzq/simba.js",
3
- "version": "1.7.0",
3
+ "version": "1.10.0",
4
4
  "description": "set up a modern backend app by running one command",
5
5
  "main": "lib/index.js",
6
6
  "directories": {
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "service": "node ./bin",
12
12
  "release": "standard-version",
13
- "test": "npm run rm && node ./bin -a AnthonyLzq -e sluzquinosa@uni.pe -N example -D 'This is a test'",
13
+ "test": "npm run rm && node ./bin -N example -D 'This is a test' -a AnthonyLzq -e sluzquinosa@uni.pe -l mit -H",
14
14
  "lint": "eslint --ext js lib/ --fix",
15
15
  "rm": "if [ -d \"example\" ]; then rm -rf example; fi"
16
16
  },
@@ -33,11 +33,11 @@
33
33
  "cli-progress": "^3.9.1",
34
34
  "colors": "^1.4.0",
35
35
  "readline-sync": "^1.4.10",
36
- "underscore": "^1.13.1",
36
+ "underscore": "^1.13.2",
37
37
  "yargs": "^17.3.0"
38
38
  },
39
39
  "devDependencies": {
40
- "eslint": "^7.32.0",
40
+ "eslint": "^8.5.0",
41
41
  "eslint-config-prettier": "^8.3.0",
42
42
  "eslint-config-standard": "^16.0.3",
43
43
  "eslint-plugin-import": "^2.25.3",
@@ -52,5 +52,9 @@
52
52
  "bugs": {
53
53
  "url": "https://github.com/AnthonyLzq/simba.js/issues"
54
54
  },
55
- "homepage": "https://github.com/AnthonyLzq/simba.js#readme"
55
+ "homepage": "https://github.com/AnthonyLzq/simba.js#readme",
56
+ "files": [
57
+ "lib",
58
+ "bin"
59
+ ]
56
60
  }
package/CHANGELOG.md DELETED
@@ -1,90 +0,0 @@
1
- # Changelog
2
-
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
-
5
- ## [1.7.0](https://github.com/AnthonyLzq/simba.js/compare/v1.6.0...v1.7.0) (2021-12-12)
6
-
7
-
8
- ### Features
9
-
10
- * updated docs and minor changes ([e6b32ca](https://github.com/AnthonyLzq/simba.js/commit/e6b32ca309603544e3506c9d18717f0e45ef0457))
11
-
12
- ## [1.6.0](https://github.com/AnthonyLzq/simba.js/compare/v1.5.0...v1.6.0) (2021-12-12)
13
-
14
-
15
- ### Features
16
-
17
- * implemented default mongo connection to local database ([1e66e98](https://github.com/AnthonyLzq/simba.js/commit/1e66e982b03eca5c2c3846a10ad827150683da21))
18
-
19
- ## [1.5.0](https://github.com/AnthonyLzq/simba.js/compare/v1.3.1...v1.5.0) (2021-12-12)
20
-
21
-
22
- ### Features
23
-
24
- * moving response function to the global variables and cleaning user route ([52f44aa](https://github.com/AnthonyLzq/simba.js/commit/52f44aadad180816d710b1e03dcc1c809b2be424))
25
- * simplified the code ([dde8f2e](https://github.com/AnthonyLzq/simba.js/commit/dde8f2e27f86f60321af2f12b53546227d0ffe64))
26
-
27
- ## [1.4.0](https://github.com/AnthonyLzq/simba.js/compare/v1.3.1...v1.4.0) (2021-12-12)
28
-
29
-
30
- ### Features
31
-
32
- * simplified the code ([dde8f2e](https://github.com/AnthonyLzq/simba.js/commit/dde8f2e27f86f60321af2f12b53546227d0ffe64))
33
-
34
- ### [1.3.1](https://github.com/AnthonyLzq/simba.js/compare/v1.3.0...v1.3.1) (2021-12-12)
35
-
36
-
37
- ### Features
38
-
39
- * updated docs ([809afaa](https://github.com/AnthonyLzq/simba.js/commit/809afaad2c1c3046fab509842118064ec6a61d5f))
40
-
41
- ## [1.3.0](https://github.com/AnthonyLzq/simba.js/compare/v1.2.0...v1.3.0) (2021-12-12)
42
-
43
-
44
- ### Features
45
-
46
- * implemented eslint rules ([748fb91](https://github.com/AnthonyLzq/simba.js/commit/748fb91a031102855dd7ba08344cc1ec3e181a4f))
47
- * implemented support for global variables (Node.js v16), linted all the code, fixed unlicensed project bug and simplified project structure ([ae4876f](https://github.com/AnthonyLzq/simba.js/commit/ae4876f249ff7dfd16fd4af7e41b3388c7de0f6a))
48
-
49
- ## [1.2.0](https://github.com/AnthonyLzq/simba.js/compare/v1.1.3...v1.2.0) (2021-10-18)
50
-
51
-
52
- ### Features
53
-
54
- * implemented support for project names with more than a word and updated dependencies ([2600413](https://github.com/AnthonyLzq/simba.js/commit/2600413bf7a5ef92e554738066e9bc4aea892f6f))
55
-
56
- ### [1.1.3](https://github.com/AnthonyLzq/simba.js/compare/v1.1.2...v1.1.3) (2021-10-17)
57
-
58
-
59
- ### Bug Fixes
60
-
61
- * fixed bin path ([bf194ff](https://github.com/AnthonyLzq/simba.js/commit/bf194ff21e6aaf63dd1a80c104b8a3567f0887b1))
62
-
63
- ### [1.1.2](https://github.com/AnthonyLzq/simba.js/compare/v1.1.1...v1.1.2) (2021-10-17)
64
-
65
-
66
- ### Bug Fixes
67
-
68
- * updated eslint package (eslint-config-airbnb -> eslint-config-airbnb-base) ([06547bc](https://github.com/AnthonyLzq/simba.js/commit/06547bc618e79f9f6e47e3b0fbd188358befe408))
69
-
70
- ### [1.1.1](https://github.com/AnthonyLzq/simba.js/compare/v1.0.1...v1.1.1) (2021-10-17)
71
-
72
-
73
- ### Features
74
-
75
- * added new eslint package and some new rules ([d79426c](https://github.com/AnthonyLzq/simba.js/commit/d79426c23fc899128d68c8b2e79ed7c5c0e4b18b))
76
-
77
- ### [1.0.1](https://github.com/AnthonyLzq/simba.js/compare/v1.0.0...v1.0.1) (2021-10-01)
78
-
79
-
80
- ### Bug Fixes
81
-
82
- * flag for unlicensed ([6b20a5b](https://github.com/AnthonyLzq/simba.js/commit/6b20a5b8a9ad60e5278b38252849fe5c3b2d54a4))
83
-
84
- ## 1.0.0 (2021-09-28)
85
-
86
-
87
- ### Features
88
-
89
- * first simba.js release ([d10fa01](https://github.com/AnthonyLzq/simba.js/commit/d10fa0199a8bff941da186c33fc16b512295a037))
90
- * updated package name and added standard-version command ([d0d0906](https://github.com/AnthonyLzq/simba.js/commit/d0d09064587a814f97d7a63b865b28a6f05030ad))