@anthonylzq/simba.js 6.2.1 → 7.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 +74 -20
- package/lib/index.js +49 -18
- package/lib/src/functions/api/database.js +4 -4
- package/lib/src/functions/api/express.js +1989 -0
- package/lib/src/functions/api/fastify.js +2033 -0
- package/lib/src/functions/api/index.js +36 -140
- package/lib/src/functions/api/services.js +5 -5
- package/lib/src/functions/eslint.js +8 -3
- package/lib/src/functions/ghat.js +2 -1
- package/lib/src/functions/tests.js +20 -15
- package/lib/src/functions/tsconfig.js +7 -2
- package/lib/src/index.js +36 -27
- package/lib/src/utils/constants.js +2 -2
- package/package.json +66 -27
- package/lib/src/functions/api/network.js +0 -2444
package/README.md
CHANGED
|
@@ -55,43 +55,47 @@ This will generate the following output:
|
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
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
|
|
58
|
+
to be asked for the options one by one.
|
|
59
59
|
|
|
60
60
|
Options:
|
|
61
|
-
-N, --projectName Project name
|
|
62
|
-
-D, --projectDescription Project description
|
|
63
|
-
-a, --author Author of the project
|
|
64
|
-
-e, --email Email of the author
|
|
61
|
+
-N, --projectName Project name.
|
|
62
|
+
-D, --projectDescription Project description.
|
|
63
|
+
-a, --author Author of the project.
|
|
64
|
+
-e, --email Email of the author.
|
|
65
65
|
-H, --heroku Whether or not the project will be deployed
|
|
66
|
-
using Heroku
|
|
66
|
+
using Heroku. [boolean] [default: false]
|
|
67
67
|
-l, --license Type of license for the project, it can be one
|
|
68
68
|
of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0
|
|
69
|
-
and AGPL 3.0, in lowercase without its version
|
|
69
|
+
and AGPL 3.0, in lowercase without its version.
|
|
70
70
|
[default: "unlicensed"]
|
|
71
|
-
-v, --version Project initial version
|
|
72
|
-
-y, --licenseYear Year when the license starts
|
|
71
|
+
-v, --version Project initial version. [default: "0.1.0"]
|
|
72
|
+
-y, --licenseYear Year when the license starts. [default: "2022"]
|
|
73
73
|
-n, --npm Whether or not the project should use npm as
|
|
74
|
-
package manager
|
|
75
|
-
-f, --mainFile Main file of the project
|
|
74
|
+
package manager. [boolean] [default: false]
|
|
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
|
|
78
|
-
the questions related to the project one by
|
|
79
|
-
|
|
78
|
+
the questions related to the project one by
|
|
79
|
+
one. [boolean] [default: false]
|
|
80
80
|
-F, --fastify Whether or not you want to use Fastify for your
|
|
81
|
-
project
|
|
81
|
+
project. [boolean] [default: false]
|
|
82
82
|
-g, --graphql Whether or not you want to use GraphQL for your
|
|
83
|
-
project
|
|
83
|
+
project. [boolean] [default: false]
|
|
84
84
|
-t, --tests Whether or not you want to have a basic suit of
|
|
85
|
-
unit tests with Jest
|
|
85
|
+
unit tests with Jest.[boolean] [default: false]
|
|
86
86
|
--ghat, --gh-action-tests Whether or not you want to have a GitHub Action
|
|
87
|
-
with a CI for your tests. If this
|
|
88
|
-
to true, the tests flag must be
|
|
89
|
-
|
|
87
|
+
with a CI for your tests and linting. If this
|
|
88
|
+
option is set to true, the tests flag must be
|
|
89
|
+
set to true. [default: false]
|
|
90
|
+
-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"]
|
|
90
94
|
-h, --help Show help [boolean]
|
|
91
95
|
|
|
92
96
|
Examples:
|
|
93
97
|
simba -N 'Project Name' -D 'Project description' -a Anthony -e
|
|
94
|
-
sluzquinosa@uni.pe -l mit -F
|
|
98
|
+
sluzquinosa@uni.pe -l mit -F -t -d mongo --ghat
|
|
95
99
|
|
|
96
100
|
Developed by AnthonyLzq
|
|
97
101
|
```
|
|
@@ -118,6 +122,12 @@ What if I want to use Fastify instead Express? Well, you only have to pass the `
|
|
|
118
122
|
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -F
|
|
119
123
|
```
|
|
120
124
|
|
|
125
|
+
If I want to use a relational database instead MongoDB? Well, you only have to pass the `-d` flag:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
simba -N myProject -D 'This is a test' -l mit -a myName -e myEmail@email.com -H -F -d postgresql
|
|
129
|
+
```
|
|
130
|
+
|
|
121
131
|
And how can I use GraphQL? Well, you only have to pass the `-g` flag:
|
|
122
132
|
|
|
123
133
|
```bash
|
|
@@ -142,8 +152,12 @@ Also, if you are interested in the folder structure of each case, please take a
|
|
|
142
152
|
|
|
143
153
|
- [Express case](./projectStructureExamples/express.txt)
|
|
144
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)
|
|
145
157
|
- [Fastify case](./projectStructureExamples/fastify.txt)
|
|
146
158
|
- [Fastify-GraphQL case](./../projectStructureExamples/fastify-graphql.txt)
|
|
159
|
+
- [Fastify-GraphQL-Sequelize case](./../projectStructureExamples/fastify-sequelize-graphql.txt)
|
|
160
|
+
- [Fastify-Sequelize case](./../projectStructureExamples/fastify-sequelize-graphql.txt)
|
|
147
161
|
|
|
148
162
|
### Some considerations
|
|
149
163
|
|
|
@@ -186,6 +200,7 @@ Also, if you are interested in the folder structure of each case, please take a
|
|
|
186
200
|
- Finally, `git` will be initialized and a list of libraries will be installed. Check the [**notes**](#notes).
|
|
187
201
|
- 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.
|
|
188
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.
|
|
189
204
|
|
|
190
205
|
## Who uses Simba.js?
|
|
191
206
|
|
|
@@ -306,6 +321,45 @@ As `dependencies`:
|
|
|
306
321
|
|
|
307
322
|
Feel free to contribute to this project. Every contribution will be appreciated.
|
|
308
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
|
+
|
|
332
|
+
#### PostgreSQL case
|
|
333
|
+
|
|
334
|
+
As `dependencies`:
|
|
335
|
+
|
|
336
|
+
- [`pg`](https://www.npmjs.com/package/pg)
|
|
337
|
+
- [`pg-hstore`](https://www.npmjs.com/package/pg-hstore)
|
|
338
|
+
|
|
339
|
+
#### MySql case
|
|
340
|
+
|
|
341
|
+
As `dependencies`:
|
|
342
|
+
|
|
343
|
+
- [`mysql2`](https://www.npmjs.com/package/mysql2)
|
|
344
|
+
|
|
345
|
+
#### MariaDB case
|
|
346
|
+
|
|
347
|
+
As `dependencies`:
|
|
348
|
+
|
|
349
|
+
- [`mariadb`](https://www.npmjs.com/package/mariadb)
|
|
350
|
+
|
|
351
|
+
#### Sqlite case
|
|
352
|
+
|
|
353
|
+
As `dependencies`:
|
|
354
|
+
|
|
355
|
+
- [`sqlite3`](https://www.npmjs.com/package/sqlite3)
|
|
356
|
+
|
|
357
|
+
#### SQLServer case
|
|
358
|
+
|
|
359
|
+
As `dependencies`:
|
|
360
|
+
|
|
361
|
+
- [`tedious`](https://www.npmjs.com/package/tedious)
|
|
362
|
+
|
|
309
363
|
## Author
|
|
310
364
|
|
|
311
365
|
- **Anthony Luzquiños** - _Initial Work_ - _Documentation_ - [AnthonyLzq](https://github.com/AnthonyLzq).
|
package/lib/index.js
CHANGED
|
@@ -9,61 +9,70 @@ 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 -q" 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
|
-
"simba -N 'Project Name' -D 'Project description' -a Anthony -e sluzquinosa@uni.pe -l mit -F
|
|
15
|
+
"simba -N 'Project Name' -D 'Project description' -a Anthony -e sluzquinosa@uni.pe -l mit -F -t -d mongo --ghat"
|
|
16
16
|
)
|
|
17
17
|
.alias('N', 'projectName')
|
|
18
18
|
.nargs('N', 1)
|
|
19
|
-
.describe('N', 'Project name')
|
|
19
|
+
.describe('N', 'Project name.')
|
|
20
20
|
.alias('D', 'projectDescription')
|
|
21
21
|
.nargs('D', 1)
|
|
22
|
-
.describe('D', 'Project description')
|
|
22
|
+
.describe('D', 'Project description.')
|
|
23
23
|
.alias('a', 'author')
|
|
24
24
|
.nargs('a', 1)
|
|
25
|
-
.describe('a', 'Author of the project')
|
|
25
|
+
.describe('a', 'Author of the project.')
|
|
26
26
|
.alias('e', 'email')
|
|
27
27
|
.nargs('e', 1)
|
|
28
|
-
.describe('e', 'Email of the author')
|
|
28
|
+
.describe('e', 'Email of the author.')
|
|
29
29
|
.alias('H', 'heroku')
|
|
30
|
-
.describe('H', 'Whether or not the project will be deployed using Heroku')
|
|
30
|
+
.describe('H', 'Whether or not the project will be deployed using Heroku.')
|
|
31
31
|
.alias('l', 'license')
|
|
32
32
|
.nargs('l', 1)
|
|
33
33
|
.describe(
|
|
34
34
|
'l',
|
|
35
|
-
'Type of license for the project, it can be one of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0 and AGPL 3.0, in lowercase without its version'
|
|
35
|
+
'Type of license for the project, it can be one of: MIT, Apache 2.0, MPL 2.0, LGPL 3.0, GPL 3.0 and AGPL 3.0, in lowercase without its version.'
|
|
36
36
|
)
|
|
37
37
|
.alias('v', 'version')
|
|
38
38
|
.nargs('v', 1)
|
|
39
|
-
.describe('v', 'Project initial version')
|
|
39
|
+
.describe('v', 'Project initial version.')
|
|
40
40
|
.alias('y', 'licenseYear')
|
|
41
41
|
.nargs('y', 1)
|
|
42
|
-
.describe('y', 'Year when the license starts')
|
|
42
|
+
.describe('y', 'Year when the license starts.')
|
|
43
43
|
.alias('n', 'npm')
|
|
44
|
-
.describe(
|
|
44
|
+
.describe(
|
|
45
|
+
'n',
|
|
46
|
+
'Whether or not the project should use npm as package manager.'
|
|
47
|
+
)
|
|
45
48
|
.alias('f', 'mainFile')
|
|
46
49
|
.nargs('f', 1)
|
|
47
|
-
.describe('f', 'Main file of the project')
|
|
50
|
+
.describe('f', 'Main file of the project.')
|
|
48
51
|
.alias('q', 'questions')
|
|
49
52
|
.describe(
|
|
50
53
|
'q',
|
|
51
|
-
'Whether or not you want to be asked to answer the questions related to the project one by one'
|
|
54
|
+
'Whether or not you want to be asked to answer the questions related to the project one by one.'
|
|
52
55
|
)
|
|
53
56
|
.alias('F', 'fastify')
|
|
54
|
-
.describe('F', 'Whether or not you want to use Fastify for your project')
|
|
57
|
+
.describe('F', 'Whether or not you want to use Fastify for your project.')
|
|
55
58
|
.alias('g', 'graphql')
|
|
56
|
-
.describe('g', 'Whether or not you want to use GraphQL for your project')
|
|
59
|
+
.describe('g', 'Whether or not you want to use GraphQL for your project.')
|
|
57
60
|
.alias('t', 'tests')
|
|
58
61
|
.describe(
|
|
59
62
|
't',
|
|
60
|
-
'Whether or not you want to have a basic suit of unit tests with Jest'
|
|
63
|
+
'Whether or not you want to have a basic suit of unit tests with Jest.'
|
|
61
64
|
)
|
|
62
65
|
.alias('ghat', 'gh-action-tests')
|
|
63
66
|
.describe(
|
|
64
67
|
'ghat',
|
|
65
68
|
'Whether or not you want to have a GitHub Action with a CI for your tests and linting. If this option is set to true, the tests flag must be set to true.'
|
|
66
69
|
)
|
|
70
|
+
.describe(
|
|
71
|
+
'd',
|
|
72
|
+
'Which database you want to use, available databases are: MongoDB, PostgreSQL, MySQL, MariaDB, Sqlite and Microsoft SQL Server.'
|
|
73
|
+
)
|
|
74
|
+
.alias('d', 'database')
|
|
75
|
+
.nargs('d', 1)
|
|
67
76
|
.default({
|
|
68
77
|
H: false,
|
|
69
78
|
n: false,
|
|
@@ -75,7 +84,8 @@ const argv = yargs(hideBin(process.argv))
|
|
|
75
84
|
F: false,
|
|
76
85
|
g: false,
|
|
77
86
|
t: false,
|
|
78
|
-
ghat: false
|
|
87
|
+
ghat: false,
|
|
88
|
+
d: 'mongo'
|
|
79
89
|
})
|
|
80
90
|
.boolean(['H', 'n', 'q', 'F', 'g', 't'])
|
|
81
91
|
.help('h')
|
|
@@ -98,7 +108,8 @@ const config = {
|
|
|
98
108
|
fastify: false,
|
|
99
109
|
graphql: false,
|
|
100
110
|
tests: true,
|
|
101
|
-
ghat: true
|
|
111
|
+
ghat: true,
|
|
112
|
+
database: 'mongo'
|
|
102
113
|
}
|
|
103
114
|
const UNLICENSED = 'unlicensed'
|
|
104
115
|
const LICENSES = [
|
|
@@ -109,6 +120,14 @@ const LICENSES = [
|
|
|
109
120
|
'GPL 3.0',
|
|
110
121
|
'AGPL 3.0'
|
|
111
122
|
]
|
|
123
|
+
const DATABASES = {
|
|
124
|
+
MongoDB: 'mongo',
|
|
125
|
+
PostgreSQL: 'postgres',
|
|
126
|
+
MySQL: 'mysql',
|
|
127
|
+
MariaDB: 'mariadb',
|
|
128
|
+
Sqlite: 'sqlite',
|
|
129
|
+
'Microsoft SQL Server': 'sqlServer'
|
|
130
|
+
}
|
|
112
131
|
const POSSIBLE_LICENSES = ['mit', 'apache', 'mpl', 'lgpl', 'gpl', 'agpl']
|
|
113
132
|
const ONE_CHARACTER_REGEXP = /^\w/
|
|
114
133
|
const YEAR_REGEXP = /^\d{4}$/
|
|
@@ -245,6 +264,14 @@ const main = async () => {
|
|
|
245
264
|
}
|
|
246
265
|
)
|
|
247
266
|
else config.ghat = false
|
|
267
|
+
|
|
268
|
+
config.database = readLineSync.keyInSelect(
|
|
269
|
+
Object.keys(DATABASES),
|
|
270
|
+
'> Select your database: ',
|
|
271
|
+
{
|
|
272
|
+
cancel: false
|
|
273
|
+
}
|
|
274
|
+
)
|
|
248
275
|
} else {
|
|
249
276
|
if (!argv.author) return console.log('Error! An author is required!')
|
|
250
277
|
else config.author = argv.author
|
|
@@ -327,6 +354,8 @@ const main = async () => {
|
|
|
327
354
|
return console.log(
|
|
328
355
|
'GitHub Action for tests can not be set to true if the tests flag is set to false'
|
|
329
356
|
)
|
|
357
|
+
|
|
358
|
+
if (argv.database) config.database = argv.database
|
|
330
359
|
}
|
|
331
360
|
|
|
332
361
|
await installation(config)
|
|
@@ -349,4 +378,6 @@ module.exports = main
|
|
|
349
378
|
* @property {String} mainFile main file of the project
|
|
350
379
|
* @property {Boolean} fastify true means that the project will be using Fastify
|
|
351
380
|
* @property {Boolean} graphql true means that the project will be using GraphQL
|
|
381
|
+
* @property {'mongo'|'postgres'|'mysql'|'mariadb'|'sqlite'|'sqlServer'} database project database
|
|
382
|
+
* @property {Boolean} tests true means that the project will have tests
|
|
352
383
|
*/
|
|
@@ -57,7 +57,7 @@ const dbConnection = async (
|
|
|
57
57
|
'Mongo connection disconnected. Trying to reconnected to Mongo...'
|
|
58
58
|
)
|
|
59
59
|
setTimeout(() => {
|
|
60
|
-
connect(process.env.
|
|
60
|
+
connect(process.env.DB_URI as string, {
|
|
61
61
|
...connection,
|
|
62
62
|
connectTimeoutMS: 3000,
|
|
63
63
|
socketTimeoutMS: 3000
|
|
@@ -74,7 +74,7 @@ const dbConnection = async (
|
|
|
74
74
|
})
|
|
75
75
|
|
|
76
76
|
return {
|
|
77
|
-
connect: () => connect(process.env.
|
|
77
|
+
connect: () => connect(process.env.DB_URI as string, connectionConfig),
|
|
78
78
|
disconnect: () => connection.close()
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -113,7 +113,7 @@ const dbConnection = async (
|
|
|
113
113
|
'Mongo connection disconnected. Trying to reconnected to Mongo...'
|
|
114
114
|
)
|
|
115
115
|
setTimeout(() => {
|
|
116
|
-
connect(process.env.
|
|
116
|
+
connect(process.env.DB_URI as string, {
|
|
117
117
|
...connection,
|
|
118
118
|
connectTimeoutMS: 3000,
|
|
119
119
|
socketTimeoutMS: 3000
|
|
@@ -130,7 +130,7 @@ const dbConnection = async (
|
|
|
130
130
|
})
|
|
131
131
|
|
|
132
132
|
return {
|
|
133
|
-
connect: () => connect(process.env.
|
|
133
|
+
connect: () => connect(process.env.DB_URI as string, connectionConfig),
|
|
134
134
|
disconnect: () => connection.close()
|
|
135
135
|
}
|
|
136
136
|
}
|