@anthonylzq/simba.js 5.1.0 → 6.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 +4 -1
- package/lib/index.js +42 -4
- package/lib/src/functions/api/database.js +139 -15
- package/lib/src/functions/api/index.js +4 -2
- package/lib/src/functions/api/network.js +164 -256
- package/lib/src/functions/api/schemas.js +18 -29
- package/lib/src/functions/api/services.js +7 -9
- package/lib/src/functions/api/types.js +0 -1
- package/lib/src/functions/docker.js +20 -4
- package/lib/src/functions/eslint.js +40 -12
- package/lib/src/functions/ghat.js +65 -0
- package/lib/src/functions/gitignore.js +1 -0
- package/lib/src/functions/packageJson.js +11 -2
- package/lib/src/functions/tests.js +615 -0
- package/lib/src/index.js +24 -13
- package/lib/src/utils/constants.js +3 -0
- package/package.json +38 -27
|
@@ -46,6 +46,10 @@ const user = Type.Object({
|
|
|
46
46
|
|
|
47
47
|
type User = Static<typeof user>
|
|
48
48
|
|
|
49
|
+
const userWithId = Type.Intersect([user, Type.Object({ id })])
|
|
50
|
+
|
|
51
|
+
type UserWithId = Static<typeof userWithId>
|
|
52
|
+
|
|
49
53
|
const userDto = Type.Object({
|
|
50
54
|
id: Type.Optional(id),
|
|
51
55
|
lastName: Type.String(),
|
|
@@ -56,19 +60,28 @@ const userDto = Type.Object({
|
|
|
56
60
|
|
|
57
61
|
type UserDTO = Static<typeof userDto>
|
|
58
62
|
|
|
59
|
-
const
|
|
63
|
+
const storeUserDto = Type.Object({
|
|
60
64
|
args: user
|
|
61
65
|
})
|
|
62
66
|
|
|
63
|
-
type
|
|
64
|
-
|
|
65
|
-
export {
|
|
67
|
+
type StoreUserDTO = Static<typeof storeUserDto>
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
userDto,
|
|
71
|
+
UserDTO,
|
|
72
|
+
userWithId,
|
|
73
|
+
UserWithId,
|
|
74
|
+
user,
|
|
75
|
+
User,
|
|
76
|
+
storeUserDto,
|
|
77
|
+
StoreUserDTO
|
|
78
|
+
}
|
|
66
79
|
`,
|
|
67
80
|
file: `${projectName}/src/schemas/user.ts`
|
|
68
81
|
}
|
|
69
82
|
}
|
|
70
83
|
|
|
71
|
-
if (graphql)
|
|
84
|
+
if (graphql)
|
|
72
85
|
schemas.index.content = `import { Static, Type } from '@sinclair/typebox'
|
|
73
86
|
import Ajv from 'ajv/dist/2019.js'
|
|
74
87
|
import addFormats from 'ajv-formats'
|
|
@@ -90,30 +103,6 @@ const ajv = addFormats(new Ajv(), ['email'])
|
|
|
90
103
|
export { id, ID, idSchema, IDSchema, ajv }
|
|
91
104
|
export * from './user'
|
|
92
105
|
`
|
|
93
|
-
schemas.user.content = `import { Static, Type } from '@sinclair/typebox'
|
|
94
|
-
|
|
95
|
-
import { id } from '.'
|
|
96
|
-
|
|
97
|
-
const user = Type.Object({
|
|
98
|
-
lastName: Type.String(),
|
|
99
|
-
name: Type.String()
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
type User = Static<typeof user>
|
|
103
|
-
|
|
104
|
-
const userDto = Type.Object({
|
|
105
|
-
id: Type.Optional(id),
|
|
106
|
-
lastName: Type.String(),
|
|
107
|
-
name: Type.String(),
|
|
108
|
-
createdAt: Type.Optional(Type.String()),
|
|
109
|
-
updatedAt: Type.Optional(Type.String())
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
type UserDTO = Static<typeof userDto>
|
|
113
|
-
|
|
114
|
-
export { userDto, UserDTO, user, User }
|
|
115
|
-
`
|
|
116
|
-
}
|
|
117
106
|
|
|
118
107
|
await Promise.all([
|
|
119
108
|
writeFile(schemas.index.file, schemas.index.content),
|
|
@@ -25,7 +25,7 @@ ${projectName}/src/services/utils/messages`
|
|
|
25
25
|
content: `import httpErrors from 'http-errors'
|
|
26
26
|
|
|
27
27
|
import { store, remove, get, update } from 'database'
|
|
28
|
-
import { UserDTO } from 'schemas'
|
|
28
|
+
import { User, UserDTO, UserWithId } from 'schemas'
|
|
29
29
|
import { EFU, MFU, GE, errorHandling } from './utils'
|
|
30
30
|
|
|
31
31
|
type Process = {
|
|
@@ -34,8 +34,8 @@ type Process = {
|
|
|
34
34
|
|
|
35
35
|
type Arguments = {
|
|
36
36
|
id?: string
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
user?: User
|
|
38
|
+
userWithId?: UserWithId
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
class UserService {
|
|
@@ -66,12 +66,10 @@ class UserService {
|
|
|
66
66
|
|
|
67
67
|
async #store(): Promise<UserDTO> {
|
|
68
68
|
try {
|
|
69
|
-
if (!this.#args.
|
|
69
|
+
if (!this.#args.user)
|
|
70
70
|
throw new httpErrors.UnprocessableEntity(GE.INTERNAL_SERVER_ERROR)
|
|
71
71
|
|
|
72
|
-
const result = await store(
|
|
73
|
-
...this.#args.userDtoWithoutId
|
|
74
|
-
})
|
|
72
|
+
const result = await store(this.#args.user)
|
|
75
73
|
|
|
76
74
|
return result
|
|
77
75
|
} catch (e) {
|
|
@@ -122,10 +120,10 @@ class UserService {
|
|
|
122
120
|
|
|
123
121
|
async #update(): Promise<UserDTO> {
|
|
124
122
|
try {
|
|
125
|
-
if (!this.#args.
|
|
123
|
+
if (!this.#args.userWithId || !this.#args.userWithId.id)
|
|
126
124
|
throw new httpErrors.UnprocessableEntity(GE.INTERNAL_SERVER_ERROR)
|
|
127
125
|
|
|
128
|
-
const updatedUser = await update(this.#args.
|
|
126
|
+
const updatedUser = await update(this.#args.userWithId)
|
|
129
127
|
|
|
130
128
|
if (!updatedUser) throw new httpErrors.NotFound(EFU.NOT_FOUND)
|
|
131
129
|
|
|
@@ -10,7 +10,7 @@ module.exports = async projectName => {
|
|
|
10
10
|
|
|
11
11
|
WORKDIR /app
|
|
12
12
|
|
|
13
|
-
COPY
|
|
13
|
+
COPY . ./
|
|
14
14
|
|
|
15
15
|
RUN yarn install --prod
|
|
16
16
|
|
|
@@ -20,12 +20,28 @@ RUN yarn build
|
|
|
20
20
|
|
|
21
21
|
RUN yarn remove webpack webpack-node-externals tsconfig-paths-webpack-plugin
|
|
22
22
|
|
|
23
|
-
COPY dist /app/dist
|
|
24
|
-
|
|
25
23
|
CMD [ "yarn", "start" ]
|
|
26
24
|
`,
|
|
27
|
-
dockerFile: 'Dockerfile'
|
|
25
|
+
dockerFile: 'Dockerfile',
|
|
26
|
+
dockerIgnoreContent: `.eslintignore
|
|
27
|
+
.eslintrc
|
|
28
|
+
.gitignore
|
|
29
|
+
CHANGELOG.md
|
|
30
|
+
Dockerfile
|
|
31
|
+
heroku.yml
|
|
32
|
+
*.http
|
|
33
|
+
LICENSE
|
|
34
|
+
nodemon.json
|
|
35
|
+
README.md
|
|
36
|
+
|
|
37
|
+
# optionally you may want to ignore the .env file, but that depends on your own implementation
|
|
38
|
+
.env`,
|
|
39
|
+
dockerIgnoreFile: '.dockerignore'
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
await writeFile(`${projectName}/${data.dockerFile}`, data.dockerContent)
|
|
43
|
+
await writeFile(
|
|
44
|
+
`${projectName}/${data.dockerIgnoreFile}`,
|
|
45
|
+
data.dockerIgnoreContent
|
|
46
|
+
)
|
|
31
47
|
}
|
|
@@ -8,11 +8,17 @@ module.exports = async projectName => {
|
|
|
8
8
|
const data = {
|
|
9
9
|
eslintContent: `{
|
|
10
10
|
"env": {
|
|
11
|
-
"node": true
|
|
11
|
+
"node": true,
|
|
12
|
+
"jest/globals": true
|
|
12
13
|
},
|
|
13
14
|
"root": true,
|
|
14
15
|
"parser": "@typescript-eslint/parser",
|
|
15
|
-
"plugins": [
|
|
16
|
+
"plugins": [
|
|
17
|
+
"@typescript-eslint",
|
|
18
|
+
"import",
|
|
19
|
+
"prettier",
|
|
20
|
+
"jest"
|
|
21
|
+
],
|
|
16
22
|
"extends": [
|
|
17
23
|
"standard",
|
|
18
24
|
"eslint:recommended",
|
|
@@ -23,7 +29,10 @@ module.exports = async projectName => {
|
|
|
23
29
|
"rules": {
|
|
24
30
|
"@typescript-eslint/no-var-requires": "off",
|
|
25
31
|
"@typescript-eslint/no-empty-interface": "off",
|
|
26
|
-
"arrow-parens": [
|
|
32
|
+
"arrow-parens": [
|
|
33
|
+
"error",
|
|
34
|
+
"as-needed"
|
|
35
|
+
],
|
|
27
36
|
"import/extensions": [
|
|
28
37
|
2,
|
|
29
38
|
{
|
|
@@ -35,9 +44,17 @@ module.exports = async projectName => {
|
|
|
35
44
|
"import/no-extraneous-dependencies": [
|
|
36
45
|
"error",
|
|
37
46
|
{
|
|
38
|
-
"devDependencies": [
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
"devDependencies": [
|
|
48
|
+
"**/*.test.ts",
|
|
49
|
+
"webpack.config.js",
|
|
50
|
+
"jest.config.ts"
|
|
51
|
+
],
|
|
52
|
+
"optionalDependencies": [
|
|
53
|
+
"**/*.test.ts"
|
|
54
|
+
],
|
|
55
|
+
"peerDependencies": [
|
|
56
|
+
"**/*.test.ts"
|
|
57
|
+
]
|
|
41
58
|
}
|
|
42
59
|
],
|
|
43
60
|
"max-len": [
|
|
@@ -53,8 +70,14 @@ module.exports = async projectName => {
|
|
|
53
70
|
}
|
|
54
71
|
],
|
|
55
72
|
"newline-before-return": "error",
|
|
56
|
-
"object-curly-spacing": [
|
|
57
|
-
|
|
73
|
+
"object-curly-spacing": [
|
|
74
|
+
"error",
|
|
75
|
+
"always"
|
|
76
|
+
],
|
|
77
|
+
"object-shorthand": [
|
|
78
|
+
"error",
|
|
79
|
+
"always"
|
|
80
|
+
],
|
|
58
81
|
"prefer-const": "error",
|
|
59
82
|
"prettier/prettier": [
|
|
60
83
|
"error",
|
|
@@ -69,11 +92,16 @@ module.exports = async projectName => {
|
|
|
69
92
|
"trailingComma": "none"
|
|
70
93
|
}
|
|
71
94
|
],
|
|
72
|
-
"radix": [
|
|
73
|
-
|
|
95
|
+
"radix": [
|
|
96
|
+
"error",
|
|
97
|
+
"as-needed"
|
|
98
|
+
],
|
|
99
|
+
"spaced-comment": [
|
|
100
|
+
"error",
|
|
101
|
+
"always"
|
|
102
|
+
]
|
|
74
103
|
}
|
|
75
|
-
}
|
|
76
|
-
`,
|
|
104
|
+
}`,
|
|
77
105
|
eslintFile: '.eslintrc',
|
|
78
106
|
eslintIgnoreContent: '/dist',
|
|
79
107
|
eslintIgnoreFile: '.eslintignore'
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const { platform } = require('os')
|
|
2
|
+
const { promisify } = require('util')
|
|
3
|
+
const exec = promisify(require('child_process').exec)
|
|
4
|
+
const writeFile = require('../utils/writeFile')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {String} projectName
|
|
8
|
+
* @param {'yarn add'|'npm i'} manager
|
|
9
|
+
* @returns {Promise<void>}
|
|
10
|
+
*/
|
|
11
|
+
module.exports = async (projectName, manager) => {
|
|
12
|
+
const createFoldersCommand = `mkdir ${projectName}/.github \
|
|
13
|
+
${projectName}/.github/workflows`
|
|
14
|
+
const managerName = manager.split()[0]
|
|
15
|
+
|
|
16
|
+
if (platform() === 'win32')
|
|
17
|
+
await exec(createFoldersCommand.replaceAll('/', '\\'))
|
|
18
|
+
else await exec(createFoldersCommand)
|
|
19
|
+
|
|
20
|
+
const data = {
|
|
21
|
+
test: {
|
|
22
|
+
content: `name: Tests - ${projectName}
|
|
23
|
+
|
|
24
|
+
on: [push]
|
|
25
|
+
|
|
26
|
+
jobs:
|
|
27
|
+
test:
|
|
28
|
+
name: Testing Simba.js API
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
|
|
31
|
+
steps:
|
|
32
|
+
- name: Check out Git repository
|
|
33
|
+
uses: actions/checkout@v3
|
|
34
|
+
with:
|
|
35
|
+
fetch-depth: 0
|
|
36
|
+
|
|
37
|
+
- name: Set up Node.js
|
|
38
|
+
uses: actions/setup-node@v3
|
|
39
|
+
with:
|
|
40
|
+
node-version: 16.x
|
|
41
|
+
|
|
42
|
+
- name: Install Node.js dependencies
|
|
43
|
+
run: ${
|
|
44
|
+
managerName === 'yarn' ? 'yarn install --frozen-lockfile' : 'npm ci'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- name: Revert changes into the ${
|
|
48
|
+
managerName === 'yarn' ? 'yarn.lock' : 'package-lock.json'
|
|
49
|
+
} file
|
|
50
|
+
run: git checkout -- ${
|
|
51
|
+
managerName === 'yarn' ? 'yarn.lock' : 'package-lock.json'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- name: Run test
|
|
55
|
+
run: ${managerName === 'yarn' ? 'yarn' : 'npm run'} test:ci
|
|
56
|
+
env:
|
|
57
|
+
MONGO_URI: \${{ secrets.MONGO_URI }}
|
|
58
|
+
NODE_ENV: ci
|
|
59
|
+
`,
|
|
60
|
+
file: `${projectName}/.github/workflows/test.yml`
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await writeFile(data.test.file, data.test.content)
|
|
65
|
+
}
|
|
@@ -10,7 +10,8 @@ module.exports = async ({
|
|
|
10
10
|
projectDescription,
|
|
11
11
|
projectVersion,
|
|
12
12
|
license,
|
|
13
|
-
mainFile
|
|
13
|
+
mainFile,
|
|
14
|
+
tests
|
|
14
15
|
}) => {
|
|
15
16
|
const data = {
|
|
16
17
|
content: '',
|
|
@@ -31,7 +32,14 @@ module.exports = async ({
|
|
|
31
32
|
"lint": "eslint src/* --ext .ts --fix",
|
|
32
33
|
"service": "nodemon",
|
|
33
34
|
"start": "node dist/index.js",
|
|
34
|
-
"release": "standard-version"
|
|
35
|
+
"release": "standard-version"\
|
|
36
|
+
${
|
|
37
|
+
tests
|
|
38
|
+
? `,
|
|
39
|
+
"test:ci": "jest --ci -i",
|
|
40
|
+
"test:local": "NODE_ENV=local jest --ci -i"`
|
|
41
|
+
: ''
|
|
42
|
+
}
|
|
35
43
|
},
|
|
36
44
|
"author": "${author}",${
|
|
37
45
|
license !== 'unlicensed'
|
|
@@ -53,4 +61,5 @@ module.exports = async ({
|
|
|
53
61
|
* @property {String} projectVersion
|
|
54
62
|
* @property {'unlicensed'|'mit'|'apache-2.0'|'mpl-2.0'|'lgpl-3.0'|'gpl-3.0'|'agpl-3.0'} license
|
|
55
63
|
* @property {String} mainFle
|
|
64
|
+
* @property {Boolean} tests
|
|
56
65
|
*/
|