@anthonylzq/simba.js 7.0.1 → 7.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/lib/index.js +22 -19
- package/lib/src/functions/api/express.js +7 -7
- package/lib/src/functions/api/fastify.js +8 -8
- package/lib/src/functions/index.js +16 -0
- package/lib/src/functions/packageJson.js +12 -1
- package/lib/src/index.js +18 -15
- package/package.json +6 -6
- package/lib/src/functions/nodemon.js +0 -25
package/lib/index.js
CHANGED
|
@@ -92,6 +92,8 @@ const argv = yargs(hideBin(process.argv))
|
|
|
92
92
|
.alias('h', 'help')
|
|
93
93
|
.epilog('Developed by AnthonyLzq').argv
|
|
94
94
|
|
|
95
|
+
const PROJECT_VERSION = '0.1.0'
|
|
96
|
+
const MAIN_FILE = 'src/index.ts'
|
|
95
97
|
/** @type {Config} */
|
|
96
98
|
const config = {
|
|
97
99
|
author: '',
|
|
@@ -100,11 +102,11 @@ const config = {
|
|
|
100
102
|
projectDescription: '',
|
|
101
103
|
heroku: false,
|
|
102
104
|
license: 'unlicensed',
|
|
103
|
-
version:
|
|
105
|
+
version: PROJECT_VERSION,
|
|
104
106
|
licenseYear: CURRENT_YEAR,
|
|
105
107
|
npm: false,
|
|
106
108
|
manager: 'yarn add',
|
|
107
|
-
mainFile:
|
|
109
|
+
mainFile: MAIN_FILE,
|
|
108
110
|
fastify: false,
|
|
109
111
|
graphql: false,
|
|
110
112
|
tests: true,
|
|
@@ -210,17 +212,12 @@ const main = async () => {
|
|
|
210
212
|
limitMessage: 'That is not a valid email!'
|
|
211
213
|
})
|
|
212
214
|
config.version = readLineSync.question('> Project version (0.1.0): ')
|
|
213
|
-
config.version = config.version === '' ?
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
LICENSES,
|
|
217
|
-
'> Select your license: ',
|
|
218
|
-
{
|
|
215
|
+
config.version = config.version === '' ? PROJECT_VERSION : config.version
|
|
216
|
+
config.license = LICENSES[
|
|
217
|
+
readLineSync.keyInSelect(LICENSES, '> Select your license: ', {
|
|
219
218
|
cancel: false
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
config.license = LICENSES[licensePos]
|
|
219
|
+
})
|
|
220
|
+
]
|
|
224
221
|
.toLowerCase()
|
|
225
222
|
.replace(/ /g, '-')
|
|
226
223
|
.replace('d', '')
|
|
@@ -249,6 +246,7 @@ const main = async () => {
|
|
|
249
246
|
}
|
|
250
247
|
)
|
|
251
248
|
config.mainFile = readLineSync.question('> Main file (src/index.ts): ')
|
|
249
|
+
config.mainFile = config.mainFile === '' ? MAIN_FILE : config.mainFile
|
|
252
250
|
config.tests = readLineSync.keyInYNStrict(
|
|
253
251
|
'> Would you want to have a basic suit of tests with Jest? ',
|
|
254
252
|
{
|
|
@@ -265,13 +263,18 @@ const main = async () => {
|
|
|
265
263
|
)
|
|
266
264
|
else config.ghat = false
|
|
267
265
|
|
|
268
|
-
config.database =
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
266
|
+
config.database =
|
|
267
|
+
DATABASES[
|
|
268
|
+
Object.keys(DATABASES)[
|
|
269
|
+
readLineSync.keyInSelect(
|
|
270
|
+
Object.keys(DATABASES),
|
|
271
|
+
'> Select your database: ',
|
|
272
|
+
{
|
|
273
|
+
cancel: false
|
|
274
|
+
}
|
|
275
|
+
)
|
|
276
|
+
]
|
|
277
|
+
]
|
|
275
278
|
} else {
|
|
276
279
|
if (!argv.author) return console.log('Error! An author is required!')
|
|
277
280
|
else config.author = argv.author
|
|
@@ -124,7 +124,7 @@ import { HttpLogger } from 'express-pino-logger'
|
|
|
124
124
|
|
|
125
125
|
const ENVIRONMENTS_WITHOUT_RECONNECTION = ['ci', 'local']
|
|
126
126
|
const dbConnection = async (
|
|
127
|
-
logger
|
|
127
|
+
logger?: HttpLogger['logger']
|
|
128
128
|
): Promise<{
|
|
129
129
|
connect: () => Promise<typeof import('mongoose')>
|
|
130
130
|
disconnect: () => Promise<void>
|
|
@@ -136,10 +136,10 @@ const dbConnection = async (
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
connection.on('connected', () => {
|
|
139
|
-
logger
|
|
139
|
+
logger?.info('Mongo connection established.')
|
|
140
140
|
})
|
|
141
141
|
connection.on('reconnected', () => {
|
|
142
|
-
logger
|
|
142
|
+
logger?.info('Mongo connection reestablished')
|
|
143
143
|
})
|
|
144
144
|
connection.on('disconnected', () => {
|
|
145
145
|
if (
|
|
@@ -147,7 +147,7 @@ const dbConnection = async (
|
|
|
147
147
|
process.env.NODE_ENV as string
|
|
148
148
|
)
|
|
149
149
|
) {
|
|
150
|
-
logger
|
|
150
|
+
logger?.info(
|
|
151
151
|
'Mongo connection disconnected. Trying to reconnected to Mongo...'
|
|
152
152
|
)
|
|
153
153
|
setTimeout(() => {
|
|
@@ -160,11 +160,11 @@ const dbConnection = async (
|
|
|
160
160
|
}
|
|
161
161
|
})
|
|
162
162
|
connection.on('close', () => {
|
|
163
|
-
logger
|
|
163
|
+
logger?.info('Mongo connection closed')
|
|
164
164
|
})
|
|
165
165
|
connection.on('error', (e: Error) => {
|
|
166
|
-
logger
|
|
167
|
-
logger
|
|
166
|
+
logger?.info('Mongo connection error:')
|
|
167
|
+
logger?.error(e)
|
|
168
168
|
})
|
|
169
169
|
|
|
170
170
|
return {
|
|
@@ -91,7 +91,7 @@ import { FastifyLoggerInstance } from 'fastify'
|
|
|
91
91
|
|
|
92
92
|
const ENVIRONMENTS_WITHOUT_RECONNECTION = ['ci', 'local']
|
|
93
93
|
const dbConnection = async (
|
|
94
|
-
logger
|
|
94
|
+
logger?: FastifyLoggerInstance
|
|
95
95
|
): Promise<{
|
|
96
96
|
connect: () => Promise<typeof import('mongoose')>
|
|
97
97
|
disconnect: () => Promise<void>
|
|
@@ -103,10 +103,10 @@ const dbConnection = async (
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
connection.on('connected', () => {
|
|
106
|
-
logger
|
|
106
|
+
logger?.info('Mongo connection established.')
|
|
107
107
|
})
|
|
108
108
|
connection.on('reconnected', () => {
|
|
109
|
-
logger
|
|
109
|
+
logger?.info('Mongo connection reestablished')
|
|
110
110
|
})
|
|
111
111
|
connection.on('disconnected', () => {
|
|
112
112
|
if (
|
|
@@ -114,7 +114,7 @@ const dbConnection = async (
|
|
|
114
114
|
process.env.NODE_ENV as string
|
|
115
115
|
)
|
|
116
116
|
) {
|
|
117
|
-
logger
|
|
117
|
+
logger?.info(
|
|
118
118
|
'Mongo connection disconnected. Trying to reconnected to Mongo...'
|
|
119
119
|
)
|
|
120
120
|
setTimeout(() => {
|
|
@@ -127,11 +127,11 @@ const dbConnection = async (
|
|
|
127
127
|
}
|
|
128
128
|
})
|
|
129
129
|
connection.on('close', () => {
|
|
130
|
-
logger
|
|
130
|
+
logger?.info('Mongo connection closed')
|
|
131
131
|
})
|
|
132
132
|
connection.on('error', (e: Error) => {
|
|
133
|
-
logger
|
|
134
|
-
logger
|
|
133
|
+
logger?.info('Mongo connection error:')
|
|
134
|
+
logger?.error(e)
|
|
135
135
|
})
|
|
136
136
|
|
|
137
137
|
return {
|
|
@@ -336,7 +336,7 @@ import * as models from './models'
|
|
|
336
336
|
let sequelize: Sequelize
|
|
337
337
|
|
|
338
338
|
const dbConnection = async (
|
|
339
|
-
logger
|
|
339
|
+
logger?: FastifyLoggerInstance
|
|
340
340
|
): Promise<{
|
|
341
341
|
connect: () => Promise<Sequelize>
|
|
342
342
|
disconnect: () => Promise<void>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
api: require('./api'),
|
|
3
|
+
changelog: require('./changelog'),
|
|
4
|
+
docker: require('./docker'),
|
|
5
|
+
eslint: require('./eslint'),
|
|
6
|
+
ghat: require('./ghat'),
|
|
7
|
+
gitignore: require('./gitignore'),
|
|
8
|
+
herokuF: require('./heroku'),
|
|
9
|
+
licenseF: require('./license'),
|
|
10
|
+
packageJson: require('./packageJson'),
|
|
11
|
+
readme: require('./readme'),
|
|
12
|
+
testsF: require('./tests'),
|
|
13
|
+
tsconfig: require('./tsconfig'),
|
|
14
|
+
ghatF: require('./ghat'),
|
|
15
|
+
webpack: require('./webpack')
|
|
16
|
+
}
|
|
@@ -47,7 +47,18 @@ module.exports = async ({
|
|
|
47
47
|
: ''
|
|
48
48
|
}
|
|
49
49
|
"dependencies": {},
|
|
50
|
-
"devDependencies": {}
|
|
50
|
+
"devDependencies": {},
|
|
51
|
+
"nodemonConfig": {
|
|
52
|
+
"watch": [
|
|
53
|
+
".env",
|
|
54
|
+
"src"
|
|
55
|
+
],
|
|
56
|
+
"ext": "ts",
|
|
57
|
+
"ignore": [
|
|
58
|
+
"src/**/*.test.ts"
|
|
59
|
+
],
|
|
60
|
+
"exec": "npx ts-node -r dotenv/config ./src/index"
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
`
|
|
53
64
|
await writeFile(`${projectName}/${data.file}`, data.content)
|
package/lib/src/index.js
CHANGED
|
@@ -3,20 +3,21 @@ const colors = require('colors')
|
|
|
3
3
|
const util = require('util')
|
|
4
4
|
const exec = util.promisify(require('child_process').exec)
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const {
|
|
7
|
+
packageJson,
|
|
8
|
+
readme,
|
|
9
|
+
changelog,
|
|
10
|
+
licenseF,
|
|
11
|
+
gitignore,
|
|
12
|
+
tsconfig,
|
|
13
|
+
eslint,
|
|
14
|
+
webpack,
|
|
15
|
+
docker,
|
|
16
|
+
herokuF,
|
|
17
|
+
api,
|
|
18
|
+
testsF,
|
|
19
|
+
ghatF
|
|
20
|
+
} = require('./functions')
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* @param {Number} process number of process
|
|
@@ -96,6 +97,9 @@ module.exports = async ({
|
|
|
96
97
|
case 'sqlServer':
|
|
97
98
|
prodPackages +=
|
|
98
99
|
' sequelize sequelize-typescript sequelize-typescript-migration-lts tedious'
|
|
100
|
+
break
|
|
101
|
+
default:
|
|
102
|
+
throw new Error('Wrong database')
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
const expressDevPackages =
|
|
@@ -156,7 +160,6 @@ webpack-node-externals`
|
|
|
156
160
|
changelog(projectName),
|
|
157
161
|
gitignore(projectName),
|
|
158
162
|
tsconfig(projectName, dbIsSQL),
|
|
159
|
-
nodemon(projectName),
|
|
160
163
|
eslint({ projectName, tests, dbIsSQL }),
|
|
161
164
|
webpack(projectName),
|
|
162
165
|
docker(projectName),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anthonylzq/simba.js",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "set up a modern backend app by running one command",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -101,18 +101,18 @@
|
|
|
101
101
|
"cli-progress": "^3.11.2",
|
|
102
102
|
"colors": "^1.4.0",
|
|
103
103
|
"readline-sync": "^1.4.10",
|
|
104
|
-
"underscore": "^1.13.
|
|
105
|
-
"yargs": "^17.
|
|
104
|
+
"underscore": "^1.13.6",
|
|
105
|
+
"yargs": "^17.6.0"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
|
-
"dotenv": "^16.0.
|
|
109
|
-
"eslint": "^8.
|
|
108
|
+
"dotenv": "^16.0.3",
|
|
109
|
+
"eslint": "^8.26.0",
|
|
110
110
|
"eslint-config-prettier": "^8.5.0",
|
|
111
111
|
"eslint-config-standard": "^17.0.0",
|
|
112
112
|
"eslint-plugin-import": "^2.26.0",
|
|
113
113
|
"eslint-plugin-node": "^11.1.0",
|
|
114
114
|
"eslint-plugin-prettier": "^4.2.1",
|
|
115
|
-
"eslint-plugin-promise": "^6.
|
|
115
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
116
116
|
"prettier": "^2.7.1",
|
|
117
117
|
"standard-version": "^9.5.0"
|
|
118
118
|
},
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const writeFile = require('../utils/writeFile')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {String} projectName
|
|
5
|
-
* @returns {Promise<void>}
|
|
6
|
-
*/
|
|
7
|
-
module.exports = async projectName => {
|
|
8
|
-
const data = {
|
|
9
|
-
nodemonContent: `{
|
|
10
|
-
"watch": [
|
|
11
|
-
".env",
|
|
12
|
-
"src"
|
|
13
|
-
],
|
|
14
|
-
"ext": "ts",
|
|
15
|
-
"ignore": [
|
|
16
|
-
"src/**/*.test.ts"
|
|
17
|
-
],
|
|
18
|
-
"exec": "npx ts-node -r dotenv/config ./src/index"
|
|
19
|
-
}
|
|
20
|
-
`,
|
|
21
|
-
nodemonFile: 'nodemon.json'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
await writeFile(`${projectName}/${data.nodemonFile}`, data.nodemonContent)
|
|
25
|
-
}
|