@anthonylzq/simba.js 7.2.0 → 8.0.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 +94 -104
- package/bin/index.js +4 -0
- package/lib/index.js +155 -194
- package/lib/src/functions/api/database.js +194 -233
- package/lib/src/functions/api/express.js +270 -1572
- package/lib/src/functions/api/fastify.js +250 -1579
- package/lib/src/functions/api/index.js +34 -24
- package/lib/src/functions/api/schemas.js +40 -58
- package/lib/src/functions/api/services.js +147 -135
- package/lib/src/functions/api/utils.js +78 -102
- package/lib/src/functions/docker.js +32 -23
- package/lib/src/functions/eslint.js +9 -7
- package/lib/src/functions/ghat.js +35 -26
- package/lib/src/functions/index.js +1 -3
- package/lib/src/functions/packageJson.js +10 -21
- package/lib/src/functions/tests.js +88 -375
- package/lib/src/functions/tsconfig.js +9 -9
- package/lib/src/index.js +31 -50
- package/lib/src/utils/constants.js +36 -1
- package/lib/src/utils/index.js +5 -0
- package/package.json +66 -59
- package/lib/src/functions/heroku.js +0 -16
- package/lib/src/functions/webpack.js +0 -51
|
@@ -5,27 +5,79 @@ const writeFile = require('../../utils/writeFile')
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {Object} args
|
|
8
|
-
* @param {Boolean} args.
|
|
8
|
+
* @param {Boolean} args.fastify
|
|
9
9
|
* @param {String} args.projectName
|
|
10
10
|
* @param {String} args.email
|
|
11
11
|
* @param {String} args.projectVersion
|
|
12
|
-
* @param {String} args.
|
|
12
|
+
* @param {String} args.graphQL
|
|
13
13
|
*/
|
|
14
14
|
module.exports = async ({
|
|
15
|
-
|
|
15
|
+
fastify,
|
|
16
16
|
projectName,
|
|
17
17
|
email,
|
|
18
18
|
projectVersion,
|
|
19
|
-
|
|
19
|
+
graphQL
|
|
20
20
|
}) => {
|
|
21
|
-
|
|
22
|
-
const createFoldersCommand = `mkdir ${projectName}/src/utils`
|
|
21
|
+
const createFoldersCommand = `mkdir ${projectName}/src/utils`
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
if (platform() === 'win32')
|
|
24
|
+
await exec(createFoldersCommand.replaceAll('/', '\\'))
|
|
25
|
+
else await exec(createFoldersCommand)
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
const utils = {
|
|
28
|
+
index: {
|
|
29
|
+
content: `${
|
|
30
|
+
fastify ? '' : "export { default as docs } from './docs.json'\n"
|
|
31
|
+
}export * from './Logger'\n`,
|
|
32
|
+
file: `${projectName}/src/utils/index.ts`
|
|
33
|
+
},
|
|
34
|
+
logger: {
|
|
35
|
+
content: `import { Debugger } from 'debug'
|
|
36
|
+
|
|
37
|
+
export interface Log {
|
|
38
|
+
log({
|
|
39
|
+
origin,
|
|
40
|
+
method,
|
|
41
|
+
value,
|
|
42
|
+
content
|
|
43
|
+
}: {
|
|
44
|
+
origin?: string
|
|
45
|
+
method: string
|
|
46
|
+
value: string
|
|
47
|
+
content: unknown
|
|
48
|
+
}): void
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class Logger implements Log {
|
|
52
|
+
#debug: Debugger
|
|
53
|
+
|
|
54
|
+
constructor(debug: Debugger) {
|
|
55
|
+
this.#debug = debug
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
log({
|
|
59
|
+
origin,
|
|
60
|
+
method,
|
|
61
|
+
value,
|
|
62
|
+
content
|
|
63
|
+
}: {
|
|
64
|
+
origin: string
|
|
65
|
+
method: string
|
|
66
|
+
value: string
|
|
67
|
+
content: unknown
|
|
68
|
+
}) {
|
|
69
|
+
this.#debug(
|
|
70
|
+
\`\${origin} -> \${method} ~ value: \${value} ~ content: \${JSON.stringify(
|
|
71
|
+
content
|
|
72
|
+
)}\`
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { Logger }\n`,
|
|
78
|
+
file: `${projectName}/src/utils/Logger.ts`
|
|
79
|
+
},
|
|
80
|
+
...(!fastify && {
|
|
29
81
|
docs: {
|
|
30
82
|
content: `{
|
|
31
83
|
"openapi": "3.0.0",
|
|
@@ -53,9 +105,9 @@ module.exports = async ({
|
|
|
53
105
|
"description": "Operations related to the user"
|
|
54
106
|
}
|
|
55
107
|
]
|
|
56
|
-
${
|
|
57
|
-
|
|
58
|
-
|
|
108
|
+
${
|
|
109
|
+
!graphQL
|
|
110
|
+
? `,
|
|
59
111
|
"paths": {
|
|
60
112
|
"/users": {
|
|
61
113
|
"post": {
|
|
@@ -99,81 +151,6 @@ ${
|
|
|
99
151
|
}
|
|
100
152
|
}
|
|
101
153
|
}
|
|
102
|
-
},
|
|
103
|
-
"get": {
|
|
104
|
-
"tags": [
|
|
105
|
-
"user"
|
|
106
|
-
],
|
|
107
|
-
"summary": "Get all the users in the database",
|
|
108
|
-
"operationId": "getAll",
|
|
109
|
-
"responses": {
|
|
110
|
-
"200": {
|
|
111
|
-
"description": "All the users in the database",
|
|
112
|
-
"content": {
|
|
113
|
-
"application/json": {
|
|
114
|
-
"schema": {
|
|
115
|
-
"type": "object",
|
|
116
|
-
"properties": {
|
|
117
|
-
"error": {
|
|
118
|
-
"type": "boolean",
|
|
119
|
-
"default": false
|
|
120
|
-
},
|
|
121
|
-
"message": {
|
|
122
|
-
"type": "object",
|
|
123
|
-
"properties": {
|
|
124
|
-
"result": {
|
|
125
|
-
"type": "array",
|
|
126
|
-
"items": {
|
|
127
|
-
"$ref": "#/components/schemas/User"
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
"500": {
|
|
138
|
-
"description": "Internal server error",
|
|
139
|
-
"content": {
|
|
140
|
-
"application/json": {
|
|
141
|
-
"schema": {
|
|
142
|
-
"$ref": "#/components/schemas/DefaultError"
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
"delete": {
|
|
150
|
-
"tags": [
|
|
151
|
-
"user"
|
|
152
|
-
],
|
|
153
|
-
"summary": "Delete all the users in the database",
|
|
154
|
-
"operationId": "deleteAll",
|
|
155
|
-
"responses": {
|
|
156
|
-
"200": {
|
|
157
|
-
"description": "All the users in the database",
|
|
158
|
-
"content": {
|
|
159
|
-
"application/json": {
|
|
160
|
-
"schema": {
|
|
161
|
-
"$ref": "#/components/schemas/DefaultSuccess"
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
"500": {
|
|
167
|
-
"description": "Internal server error",
|
|
168
|
-
"content": {
|
|
169
|
-
"application/json": {
|
|
170
|
-
"schema": {
|
|
171
|
-
"$ref": "#/components/schemas/DefaultError"
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
154
|
}
|
|
178
155
|
},
|
|
179
156
|
"/user/{id}": {
|
|
@@ -446,21 +423,20 @@ ${
|
|
|
446
423
|
}
|
|
447
424
|
}
|
|
448
425
|
}
|
|
449
|
-
}`
|
|
450
|
-
|
|
451
|
-
}`,
|
|
426
|
+
}`
|
|
427
|
+
: '}'
|
|
428
|
+
}`,
|
|
452
429
|
file: `${projectName}/src/utils/docs.json`
|
|
453
|
-
},
|
|
454
|
-
index: {
|
|
455
|
-
content: "export { default as docs } from './docs.json'\n",
|
|
456
|
-
file: `${projectName}/src/utils/index.ts`
|
|
457
430
|
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
if (express)
|
|
461
|
-
await Promise.all([
|
|
462
|
-
writeFile(utils.docs.file, utils.docs.content),
|
|
463
|
-
writeFile(utils.index.file, utils.index.content)
|
|
464
|
-
])
|
|
431
|
+
})
|
|
465
432
|
}
|
|
433
|
+
|
|
434
|
+
const processes = [
|
|
435
|
+
writeFile(utils.index.file, utils.index.content),
|
|
436
|
+
writeFile(utils.logger.file, utils.logger.content)
|
|
437
|
+
]
|
|
438
|
+
|
|
439
|
+
if (!fastify) processes.push(writeFile(utils.docs.file, utils.docs.content))
|
|
440
|
+
|
|
441
|
+
await Promise.all(processes)
|
|
466
442
|
}
|
|
@@ -1,47 +1,56 @@
|
|
|
1
1
|
const writeFile = require('../utils/writeFile')
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @param {
|
|
4
|
+
* @param {Object} args
|
|
5
|
+
* @param {String} args.projectName
|
|
6
|
+
* @param {String} args.manager
|
|
5
7
|
* @returns {Promise<void>}
|
|
6
8
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
// TODO: add the correct package manager
|
|
10
|
+
module.exports = async ({ projectName, manager }) => {
|
|
11
|
+
const managerName = manager.split(' ')[0]
|
|
10
12
|
|
|
13
|
+
const data = {
|
|
14
|
+
dockerContent: `FROM node:18-alpine
|
|
15
|
+
${managerName === 'pnpm' ? '\nRUN corepack enable\n' : ''}
|
|
11
16
|
WORKDIR /app
|
|
12
17
|
|
|
13
18
|
COPY . ./
|
|
14
19
|
|
|
15
|
-
RUN
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
RUN ${
|
|
21
|
+
managerName === 'yarn' ? 'yarn' : managerName === 'npm' ? 'npm' : 'pnpm'
|
|
22
|
+
} i
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
RUN yarn remove webpack webpack-node-externals tsconfig-paths-webpack-plugin
|
|
22
|
-
|
|
23
|
-
CMD [ "yarn", "start" ]
|
|
24
|
-
`,
|
|
24
|
+
CMD [ "${managerName}", "start" ]`,
|
|
25
25
|
dockerFile: 'Dockerfile',
|
|
26
26
|
dockerIgnoreContent: `.eslintignore
|
|
27
27
|
.eslintrc
|
|
28
|
+
|
|
29
|
+
.git
|
|
28
30
|
.gitignore
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*.http
|
|
31
|
+
.github
|
|
32
|
+
|
|
33
|
+
*.md
|
|
33
34
|
LICENSE
|
|
35
|
+
|
|
36
|
+
*.http
|
|
34
37
|
nodemon.json
|
|
35
|
-
|
|
38
|
+
|
|
39
|
+
jest.config.ts
|
|
40
|
+
*.log
|
|
41
|
+
|
|
42
|
+
test
|
|
36
43
|
|
|
37
44
|
# optionally you may want to ignore the .env file, but that depends on your own implementation
|
|
38
45
|
.env`,
|
|
39
46
|
dockerIgnoreFile: '.dockerignore'
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
await
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
await Promise.all([
|
|
50
|
+
writeFile(`${projectName}/${data.dockerFile}`, data.dockerContent),
|
|
51
|
+
writeFile(
|
|
52
|
+
`${projectName}/${data.dockerIgnoreFile}`,
|
|
53
|
+
data.dockerIgnoreContent
|
|
54
|
+
)
|
|
55
|
+
])
|
|
47
56
|
}
|
|
@@ -3,22 +3,23 @@ const writeFile = require('../utils/writeFile')
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {Object} args
|
|
5
5
|
* @param {String} args.projectName
|
|
6
|
-
* @param {Boolean} args.tests
|
|
7
6
|
* @param {Boolean} args.dbIsSQL
|
|
8
7
|
* @returns {Promise<void>}
|
|
9
8
|
*/
|
|
10
|
-
module.exports = async ({ projectName,
|
|
9
|
+
module.exports = async ({ projectName, dbIsSQL }) => {
|
|
11
10
|
const data = {
|
|
12
11
|
eslintContent: `{
|
|
13
12
|
"env": {
|
|
14
|
-
"node": true
|
|
13
|
+
"node": true,
|
|
14
|
+
"jest": true
|
|
15
15
|
},
|
|
16
16
|
"root": true,
|
|
17
17
|
"parser": "@typescript-eslint/parser",
|
|
18
18
|
"plugins": [
|
|
19
19
|
"@typescript-eslint",
|
|
20
20
|
"import",
|
|
21
|
-
"prettier"
|
|
21
|
+
"prettier",
|
|
22
|
+
"jest"
|
|
22
23
|
],
|
|
23
24
|
"extends": [
|
|
24
25
|
"standard",
|
|
@@ -47,9 +48,10 @@ module.exports = async ({ projectName, tests, dbIsSQL }) => {
|
|
|
47
48
|
{
|
|
48
49
|
"devDependencies": [
|
|
49
50
|
"**/*.test.ts",
|
|
50
|
-
"webpack.config.js"
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
"webpack.config.js",
|
|
52
|
+
"jest.config.ts"${
|
|
53
|
+
dbIsSQL ? ',\n "src/database/postgres/config.js"' : ''
|
|
54
|
+
}
|
|
53
55
|
],
|
|
54
56
|
"optionalDependencies": [
|
|
55
57
|
"**/*.test.ts"
|
|
@@ -5,7 +5,7 @@ const writeFile = require('../utils/writeFile')
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {String} projectName
|
|
8
|
-
* @param {'yarn add'|'npm i'} manager
|
|
8
|
+
* @param {'yarn add'|'npm i'|'pnpm i'} manager
|
|
9
9
|
* @returns {Promise<void>}
|
|
10
10
|
*/
|
|
11
11
|
module.exports = async (projectName, manager) => {
|
|
@@ -37,27 +37,31 @@ jobs:
|
|
|
37
37
|
- name: Set up Node.js
|
|
38
38
|
uses: actions/setup-node@v3
|
|
39
39
|
with:
|
|
40
|
-
node-version:
|
|
41
|
-
|
|
40
|
+
node-version: 18.x
|
|
41
|
+
${
|
|
42
|
+
managerName === 'pnpm'
|
|
43
|
+
? `
|
|
44
|
+
- name: Setup pnpm
|
|
45
|
+
uses: pnpm/action-setup@v2
|
|
46
|
+
with:
|
|
47
|
+
version: 6.x.x\n`
|
|
48
|
+
: ''
|
|
49
|
+
}
|
|
42
50
|
- name: Install Node.js dependencies
|
|
43
51
|
run: ${
|
|
44
|
-
managerName === 'yarn'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} file
|
|
50
|
-
run: git checkout -- ${
|
|
51
|
-
managerName === 'yarn' ? 'yarn.lock' : 'package-lock.json'
|
|
52
|
+
managerName === 'yarn'
|
|
53
|
+
? 'yarn install --frozen-lockfile'
|
|
54
|
+
: managerName
|
|
55
|
+
? 'pnpm i --frozen-lockfile'
|
|
56
|
+
: 'npm ci'
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
- name: Run linters
|
|
55
|
-
uses: wearerequired/lint-action@
|
|
60
|
+
uses: wearerequired/lint-action@v2
|
|
56
61
|
with:
|
|
57
62
|
auto_fix: true
|
|
58
63
|
eslint: true
|
|
59
|
-
eslint_extensions: js
|
|
60
|
-
`,
|
|
64
|
+
eslint_extensions: js\n`,
|
|
61
65
|
file: `${projectName}/.github/workflows/lint.yml`
|
|
62
66
|
},
|
|
63
67
|
test: {
|
|
@@ -80,24 +84,29 @@ jobs:
|
|
|
80
84
|
- name: Set up Node.js
|
|
81
85
|
uses: actions/setup-node@v3
|
|
82
86
|
with:
|
|
83
|
-
node-version:
|
|
84
|
-
|
|
87
|
+
node-version: 18.x
|
|
88
|
+
${
|
|
89
|
+
managerName === 'pnpm'
|
|
90
|
+
? `
|
|
91
|
+
- name: Setup pnpm
|
|
92
|
+
uses: pnpm/action-setup@v2
|
|
93
|
+
with:
|
|
94
|
+
version: 6.x.x\n`
|
|
95
|
+
: ''
|
|
96
|
+
}
|
|
85
97
|
- name: Install Node.js dependencies
|
|
86
98
|
run: ${
|
|
87
|
-
managerName === 'yarn'
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} file
|
|
93
|
-
run: git checkout -- ${
|
|
94
|
-
managerName === 'yarn' ? 'yarn.lock' : 'package-lock.json'
|
|
99
|
+
managerName === 'yarn'
|
|
100
|
+
? 'yarn install --frozen-lockfile'
|
|
101
|
+
: managerName
|
|
102
|
+
? 'pnpm i --frozen-lockfile'
|
|
103
|
+
: 'npm ci'
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
- name: Run test
|
|
98
|
-
run: ${managerName === '
|
|
107
|
+
run: ${managerName === 'npm' ? 'npm' : managerName} test:ci
|
|
99
108
|
env:
|
|
100
|
-
|
|
109
|
+
DATABASE_URL: \${{ secrets.DATABASE_URL }}
|
|
101
110
|
NODE_ENV: ci
|
|
102
111
|
`,
|
|
103
112
|
file: `${projectName}/.github/workflows/test.yml`
|
|
@@ -5,12 +5,10 @@ module.exports = {
|
|
|
5
5
|
eslint: require('./eslint'),
|
|
6
6
|
ghat: require('./ghat'),
|
|
7
7
|
gitignore: require('./gitignore'),
|
|
8
|
-
herokuF: require('./heroku'),
|
|
9
8
|
licenseF: require('./license'),
|
|
10
9
|
packageJson: require('./packageJson'),
|
|
11
10
|
readme: require('./readme'),
|
|
12
11
|
testsF: require('./tests'),
|
|
13
12
|
tsconfig: require('./tsconfig'),
|
|
14
|
-
ghatF: require('./ghat')
|
|
15
|
-
webpack: require('./webpack')
|
|
13
|
+
ghatF: require('./ghat')
|
|
16
14
|
}
|
|
@@ -10,15 +10,10 @@ module.exports = async ({
|
|
|
10
10
|
projectDescription,
|
|
11
11
|
projectVersion,
|
|
12
12
|
license,
|
|
13
|
-
mainFile
|
|
14
|
-
tests
|
|
13
|
+
mainFile
|
|
15
14
|
}) => {
|
|
16
15
|
const data = {
|
|
17
|
-
content:
|
|
18
|
-
file: 'package.json'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
data.content = `{
|
|
16
|
+
content: `{
|
|
22
17
|
"name": "${projectName
|
|
23
18
|
.toLowerCase()
|
|
24
19
|
.replaceAll(' ', '-')
|
|
@@ -27,19 +22,12 @@ module.exports = async ({
|
|
|
27
22
|
"main": "${mainFile}",
|
|
28
23
|
"description": "${projectDescription}",
|
|
29
24
|
"scripts": {
|
|
30
|
-
"build:dev": "webpack --mode development",
|
|
31
|
-
"build": "webpack --mode production",
|
|
32
25
|
"lint": "eslint src/* --ext .ts --fix",
|
|
33
26
|
"service": "nodemon",
|
|
34
|
-
"start": "node
|
|
35
|
-
"release": "standard-version"
|
|
36
|
-
${
|
|
37
|
-
tests
|
|
38
|
-
? `,
|
|
27
|
+
"start": "ts-node src/index.ts",
|
|
28
|
+
"release": "standard-version",
|
|
39
29
|
"test:ci": "jest --ci -i",
|
|
40
|
-
"test:local": "NODE_ENV=local jest --ci -i"
|
|
41
|
-
: ''
|
|
42
|
-
}
|
|
30
|
+
"test:local": "NODE_ENV=local jest --ci -i --setupFiles dotenv/config"
|
|
43
31
|
},
|
|
44
32
|
"author": "${author}",${
|
|
45
33
|
license !== 'unlicensed'
|
|
@@ -57,10 +45,12 @@ module.exports = async ({
|
|
|
57
45
|
"ignore": [
|
|
58
46
|
"src/**/*.test.ts"
|
|
59
47
|
],
|
|
60
|
-
"exec": "npx ts-node -r dotenv/config ./src/index"
|
|
48
|
+
"exec": "DEBUG=App:* npx ts-node -r dotenv/config ./src/index"
|
|
61
49
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
50
|
+
}\n`,
|
|
51
|
+
file: 'package.json'
|
|
52
|
+
}
|
|
53
|
+
|
|
64
54
|
await writeFile(`${projectName}/${data.file}`, data.content)
|
|
65
55
|
}
|
|
66
56
|
|
|
@@ -72,5 +62,4 @@ module.exports = async ({
|
|
|
72
62
|
* @property {String} projectVersion
|
|
73
63
|
* @property {'unlicensed'|'mit'|'apache-2.0'|'mpl-2.0'|'lgpl-3.0'|'gpl-3.0'|'agpl-3.0'} license
|
|
74
64
|
* @property {String} mainFle
|
|
75
|
-
* @property {Boolean} tests
|
|
76
65
|
*/
|