nodejs-quickstart-structure 1.6.1 → 1.7.5
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/CHANGELOG.md +19 -0
- package/README.md +9 -7
- package/bin/index.js +1 -0
- package/docs/generateCase.md +126 -76
- package/docs/generatorFlow.md +10 -2
- package/lib/generator.js +9 -2
- package/lib/modules/app-setup.js +7 -2
- package/lib/modules/caching-setup.js +56 -0
- package/lib/modules/config-files.js +26 -5
- package/lib/modules/database-setup.js +13 -1
- package/lib/prompts.js +9 -1
- package/package.json +1 -1
- package/templates/clean-architecture/ts/src/config/swagger.ts.ejs +1 -2
- package/templates/common/.env.example.ejs +39 -0
- package/templates/common/Jenkinsfile.ejs +41 -0
- package/templates/common/README.md.ejs +113 -106
- package/templates/common/caching/clean/js/CreateUser.js.ejs +25 -0
- package/templates/common/caching/clean/js/GetAllUsers.js.ejs +33 -0
- package/templates/common/caching/clean/ts/createUser.ts.ejs +23 -0
- package/templates/common/caching/clean/ts/getAllUsers.ts.ejs +30 -0
- package/templates/common/caching/js/redisClient.js.ejs +71 -0
- package/templates/common/caching/ts/redisClient.ts.ejs +76 -0
- package/templates/common/docker-compose.yml.ejs +156 -139
- package/templates/common/package.json.ejs +4 -0
- package/templates/mvc/js/src/controllers/userController.js.ejs +22 -0
- package/templates/mvc/ts/src/config/swagger.ts.ejs +1 -2
- package/templates/mvc/ts/src/controllers/userController.ts.ejs +22 -0
- /package/templates/db/mysql/{V1__Initial_Setup.sql → V1__Initial_Setup.sql.ejs} +0 -0
- /package/templates/db/postgres/{V1__Initial_Setup.sql → V1__Initial_Setup.sql.ejs} +0 -0
|
@@ -1,139 +1,156 @@
|
|
|
1
|
-
services:
|
|
2
|
-
app:
|
|
3
|
-
build: .
|
|
4
|
-
ports:
|
|
5
|
-
- "${PORT:-3000}:3000"
|
|
6
|
-
<%_ if (database !== 'None' || communication === 'Kafka') { -%>
|
|
7
|
-
depends_on:
|
|
8
|
-
<%_ if (database !== 'None') { -%>
|
|
9
|
-
- db
|
|
10
|
-
<%_ } -%>
|
|
11
|
-
<%_ if (communication === 'Kafka') { -%>
|
|
12
|
-
- kafka
|
|
13
|
-
<%_ } -%>
|
|
14
|
-
<%_ } -%>
|
|
15
|
-
<%_ if (communication === 'Kafka') { -%>
|
|
16
|
-
environment:
|
|
17
|
-
- KAFKA_BROKER=kafka:29092
|
|
18
|
-
- KAFKAJS_NO_PARTITIONER_WARNING=1
|
|
19
|
-
- PORT=3000
|
|
20
|
-
<%_ if (
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
<%_ } -%>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
<%_
|
|
36
|
-
|
|
37
|
-
<%_
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
<%_
|
|
46
|
-
|
|
47
|
-
<%_
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<%_
|
|
61
|
-
image:
|
|
62
|
-
restart: always
|
|
63
|
-
environment:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
image:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
1
|
+
services:
|
|
2
|
+
app:
|
|
3
|
+
build: .
|
|
4
|
+
ports:
|
|
5
|
+
- "${PORT:-3000}:3000"
|
|
6
|
+
<%_ if (database !== 'None' || communication === 'Kafka') { -%>
|
|
7
|
+
depends_on:
|
|
8
|
+
<%_ if (database !== 'None') { -%>
|
|
9
|
+
- db
|
|
10
|
+
<%_ } -%>
|
|
11
|
+
<%_ if (communication === 'Kafka') { -%>
|
|
12
|
+
- kafka
|
|
13
|
+
<%_ } -%>
|
|
14
|
+
<%_ } -%>
|
|
15
|
+
<%_ if (communication === 'Kafka') { -%>
|
|
16
|
+
environment:
|
|
17
|
+
- KAFKA_BROKER=kafka:29092
|
|
18
|
+
- KAFKAJS_NO_PARTITIONER_WARNING=1
|
|
19
|
+
- PORT=3000
|
|
20
|
+
<%_ if (caching === 'Redis') { -%>
|
|
21
|
+
- REDIS_HOST=redis
|
|
22
|
+
- REDIS_PORT=6379
|
|
23
|
+
- REDIS_PASSWORD=
|
|
24
|
+
<%_ } -%>
|
|
25
|
+
<%_ if (database !== 'None') { -%>
|
|
26
|
+
- DB_HOST=db
|
|
27
|
+
<%_ if (database === 'MySQL') { -%>
|
|
28
|
+
- DB_USER=root
|
|
29
|
+
- DB_PASSWORD=root
|
|
30
|
+
- DB_NAME=<%= dbName %>
|
|
31
|
+
<%_ } -%><%_ if (database === 'PostgreSQL') { -%>
|
|
32
|
+
- DB_USER=postgres
|
|
33
|
+
- DB_PASSWORD=root
|
|
34
|
+
- DB_NAME=<%= dbName %>
|
|
35
|
+
<%_ } -%>
|
|
36
|
+
<%_ } -%>
|
|
37
|
+
<%_ } else { -%>
|
|
38
|
+
environment:
|
|
39
|
+
- PORT=3000
|
|
40
|
+
<%_ if (caching === 'Redis') { -%>
|
|
41
|
+
- REDIS_HOST=redis
|
|
42
|
+
- REDIS_PORT=6379
|
|
43
|
+
- REDIS_PASSWORD=
|
|
44
|
+
<%_ } -%>
|
|
45
|
+
<%_ if (database !== 'None') { -%>
|
|
46
|
+
- DB_HOST=db
|
|
47
|
+
<%_ if (database === 'MySQL') { -%>
|
|
48
|
+
- DB_USER=root
|
|
49
|
+
- DB_PASSWORD=root
|
|
50
|
+
- DB_NAME=<%= dbName %>
|
|
51
|
+
<%_ } -%><%_ if (database === 'PostgreSQL') { -%>
|
|
52
|
+
- DB_USER=postgres
|
|
53
|
+
- DB_PASSWORD=root
|
|
54
|
+
- DB_NAME=<%= dbName %>
|
|
55
|
+
<%_ } -%>
|
|
56
|
+
<%_ } -%>
|
|
57
|
+
<%_ } -%>
|
|
58
|
+
<%_ if (database !== 'None') { -%>
|
|
59
|
+
db:
|
|
60
|
+
<%_ if (database === 'MySQL') { -%>
|
|
61
|
+
image: mysql:8.0
|
|
62
|
+
restart: always
|
|
63
|
+
environment:
|
|
64
|
+
MYSQL_ROOT_PASSWORD: root
|
|
65
|
+
MYSQL_DATABASE: <%= dbName %>
|
|
66
|
+
ports:
|
|
67
|
+
- "${DB_PORT:-3306}:3306"
|
|
68
|
+
volumes:
|
|
69
|
+
- ./flyway/sql:/docker-entrypoint-initdb.d
|
|
70
|
+
<%_ } else if (database === 'PostgreSQL') { -%>
|
|
71
|
+
image: postgres:15
|
|
72
|
+
restart: always
|
|
73
|
+
environment:
|
|
74
|
+
POSTGRES_USER: postgres
|
|
75
|
+
POSTGRES_PASSWORD: root
|
|
76
|
+
POSTGRES_DB: <%= dbName %>
|
|
77
|
+
ports:
|
|
78
|
+
- "${DB_PORT:-5432}:5432"
|
|
79
|
+
volumes:
|
|
80
|
+
- ./flyway/sql:/docker-entrypoint-initdb.d
|
|
81
|
+
<%_ } else if (database === 'MongoDB') { -%>
|
|
82
|
+
image: mongo:latest
|
|
83
|
+
restart: always
|
|
84
|
+
environment:
|
|
85
|
+
MONGO_INITDB_DATABASE: <%= dbName %>
|
|
86
|
+
ports:
|
|
87
|
+
- "${DB_PORT:-27017}:27017"
|
|
88
|
+
volumes:
|
|
89
|
+
- mongodb_data:/data/db
|
|
90
|
+
|
|
91
|
+
mongo-migrate:
|
|
92
|
+
image: node:18-alpine
|
|
93
|
+
working_dir: /app
|
|
94
|
+
volumes:
|
|
95
|
+
- .:/app
|
|
96
|
+
command: sh -c "npm install migrate-mongo && npm run migrate"
|
|
97
|
+
environment:
|
|
98
|
+
- DB_HOST=db
|
|
99
|
+
- DB_NAME=<%= dbName %>
|
|
100
|
+
depends_on:
|
|
101
|
+
- db
|
|
102
|
+
<%_ } -%>
|
|
103
|
+
<%_ } -%>
|
|
104
|
+
<%_ if (database !== 'MongoDB' && database !== 'None') { -%>
|
|
105
|
+
flyway:
|
|
106
|
+
image: flyway/flyway
|
|
107
|
+
command: -connectRetries=60 migrate
|
|
108
|
+
volumes:
|
|
109
|
+
- ./flyway/sql:/flyway/sql
|
|
110
|
+
environment:
|
|
111
|
+
<%_ if (database === 'MySQL') { -%>
|
|
112
|
+
FLYWAY_URL: jdbc:mysql://db:3306/<%= dbName %>
|
|
113
|
+
FLYWAY_USER: root
|
|
114
|
+
FLYWAY_PASSWORD: root
|
|
115
|
+
<%_ } -%><%_ if (database === 'PostgreSQL') { -%>
|
|
116
|
+
FLYWAY_URL: jdbc:postgresql://db:5432/<%= dbName %>
|
|
117
|
+
FLYWAY_USER: postgres
|
|
118
|
+
FLYWAY_PASSWORD: root
|
|
119
|
+
<%_ } -%>
|
|
120
|
+
depends_on:
|
|
121
|
+
- db
|
|
122
|
+
<%_ } -%>
|
|
123
|
+
<%_ if (communication === 'Kafka') { -%>
|
|
124
|
+
zookeeper:
|
|
125
|
+
image: confluentinc/cp-zookeeper:7.4.0
|
|
126
|
+
environment:
|
|
127
|
+
ZOOKEEPER_CLIENT_PORT: 2181
|
|
128
|
+
ZOOKEEPER_TICK_TIME: 2000
|
|
129
|
+
ports:
|
|
130
|
+
- "${ZOOKEEPER_PORT:-2181}:2181"
|
|
131
|
+
|
|
132
|
+
kafka:
|
|
133
|
+
image: confluentinc/cp-kafka:7.4.0
|
|
134
|
+
depends_on:
|
|
135
|
+
- zookeeper
|
|
136
|
+
ports:
|
|
137
|
+
- "${KAFKA_PORT:-9092}:9092"
|
|
138
|
+
environment:
|
|
139
|
+
KAFKA_BROKER_ID: 1
|
|
140
|
+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
|
|
141
|
+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
|
|
142
|
+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
|
|
143
|
+
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
|
|
144
|
+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
|
145
|
+
<%_ } -%>
|
|
146
|
+
<%_ if (caching === 'Redis') { -%>
|
|
147
|
+
redis:
|
|
148
|
+
image: redis:alpine
|
|
149
|
+
restart: always
|
|
150
|
+
ports:
|
|
151
|
+
- "${REDIS_PORT:-6379}:6379"
|
|
152
|
+
<%_ } -%>
|
|
153
|
+
<%_ if (database !== 'None') { -%>
|
|
154
|
+
volumes:
|
|
155
|
+
<%= database.toLowerCase() %>_data:
|
|
156
|
+
<%_ } -%>
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
<% } -%>
|
|
33
33
|
<% if (communication === 'Kafka') { %> "kafkajs": "^2.2.4",
|
|
34
34
|
<% } -%>
|
|
35
|
+
<% if (caching === 'Redis') { %> "ioredis": "^5.3.2",
|
|
36
|
+
<% } -%>
|
|
35
37
|
<% if (viewEngine === 'EJS') { %> "ejs": "^3.1.9",
|
|
36
38
|
<% } -%>
|
|
37
39
|
<% if (viewEngine === 'Pug') { %> "pug": "^3.0.2",
|
|
@@ -55,6 +57,8 @@
|
|
|
55
57
|
"@types/cors": "^2.8.17",
|
|
56
58
|
"@types/dotenv": "^8.2.0",
|
|
57
59
|
"@types/hpp": "^0.2.3",
|
|
60
|
+
<% if (caching === 'Redis') { %> "@types/ioredis": "^5.0.0",
|
|
61
|
+
<% } -%>
|
|
58
62
|
<% if (database === 'PostgreSQL') { %> "@types/pg": "^8.10.9",
|
|
59
63
|
<% } -%>
|
|
60
64
|
<%_ if (database === 'MySQL' || database === 'PostgreSQL') { -%>
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
const User = require('../models/User');
|
|
2
2
|
const HTTP_STATUS = require('../utils/httpCodes');
|
|
3
3
|
const logger = require('../utils/logger');
|
|
4
|
+
<%_ if (caching === 'Redis') { -%>
|
|
5
|
+
const redisService = require('../config/redisClient');
|
|
6
|
+
<%_ } -%>
|
|
4
7
|
|
|
5
8
|
const getUsers = async (req, res) => {
|
|
6
9
|
try {
|
|
10
|
+
<%_ if (caching === 'Redis') { -%>
|
|
11
|
+
const users = await redisService.getOrSet('users:all', async () => {
|
|
12
|
+
<%_ if (database === 'MongoDB') { -%>
|
|
13
|
+
return await User.find();
|
|
14
|
+
<%_ } else if (database === 'None') { -%>
|
|
15
|
+
return User.mockData;
|
|
16
|
+
<%_ } else { -%>
|
|
17
|
+
return await User.findAll();
|
|
18
|
+
<%_ } -%>
|
|
19
|
+
}, 60);
|
|
20
|
+
<%_ } else { -%>
|
|
7
21
|
<%_ if (database === 'MongoDB') { -%>
|
|
8
22
|
const users = await User.find();
|
|
9
23
|
<%_ } else if (database === 'None') { -%>
|
|
10
24
|
const users = User.mockData;
|
|
11
25
|
<%_ } else { -%>
|
|
12
26
|
const users = await User.findAll();
|
|
27
|
+
<%_ } -%>
|
|
13
28
|
<%_ } -%>
|
|
14
29
|
res.json(users);
|
|
15
30
|
} catch (error) {
|
|
@@ -24,9 +39,15 @@ const createUser = async (req, res) => {
|
|
|
24
39
|
<%_ if (database === 'None') { -%>
|
|
25
40
|
const newUser = { id: String(User.mockData.length + 1), name, email };
|
|
26
41
|
User.mockData.push(newUser);
|
|
42
|
+
<%_ if (caching === 'Redis') { -%>
|
|
43
|
+
await redisService.del('users:all');
|
|
44
|
+
<%_ } -%>
|
|
27
45
|
res.status(HTTP_STATUS.CREATED).json(newUser);
|
|
28
46
|
<%_ } else { -%>
|
|
29
47
|
const user = await User.create({ name, email });
|
|
48
|
+
<%_ if (caching === 'Redis') { -%>
|
|
49
|
+
await redisService.del('users:all');
|
|
50
|
+
<%_ } -%>
|
|
30
51
|
res.status(HTTP_STATUS.CREATED).json(user);
|
|
31
52
|
<%_ } -%>
|
|
32
53
|
} catch (error) {
|
|
@@ -35,3 +56,4 @@ const createUser = async (req, res) => {
|
|
|
35
56
|
};
|
|
36
57
|
|
|
37
58
|
module.exports = { getUsers, createUser };
|
|
59
|
+
|
|
@@ -2,16 +2,31 @@ import { Request, Response } from 'express';
|
|
|
2
2
|
import User from '@/models/User';
|
|
3
3
|
import { HTTP_STATUS } from '@/utils/httpCodes';
|
|
4
4
|
import logger from '@/utils/logger';
|
|
5
|
+
<%_ if (caching === 'Redis') { -%>
|
|
6
|
+
import redisService from '@/config/redisClient';
|
|
7
|
+
<%_ } -%>
|
|
5
8
|
|
|
6
9
|
export class UserController {
|
|
7
10
|
async getUsers(req: Request, res: Response) {
|
|
8
11
|
try {
|
|
12
|
+
<%_ if (caching === 'Redis') { -%>
|
|
13
|
+
const users = await redisService.getOrSet('users:all', async () => {
|
|
14
|
+
<%_ if (database === 'MongoDB') { -%>
|
|
15
|
+
return await User.find();
|
|
16
|
+
<%_ } else if (database === 'None') { -%>
|
|
17
|
+
return User.mockData;
|
|
18
|
+
<%_ } else { -%>
|
|
19
|
+
return await User.findAll();
|
|
20
|
+
<%_ } -%>
|
|
21
|
+
}, 60);
|
|
22
|
+
<%_ } else { -%>
|
|
9
23
|
<%_ if (database === 'MongoDB') { -%>
|
|
10
24
|
const users = await User.find();
|
|
11
25
|
<%_ } else if (database === 'None') { -%>
|
|
12
26
|
const users = User.mockData;
|
|
13
27
|
<%_ } else { -%>
|
|
14
28
|
const users = await User.findAll();
|
|
29
|
+
<%_ } -%>
|
|
15
30
|
<%_ } -%>
|
|
16
31
|
res.json(users);
|
|
17
32
|
} catch (error) {
|
|
@@ -30,9 +45,15 @@ export class UserController {
|
|
|
30
45
|
<%_ if (database === 'None') { -%>
|
|
31
46
|
const newUser = { id: String(User.mockData.length + 1), name, email };
|
|
32
47
|
User.mockData.push(newUser);
|
|
48
|
+
<%_ if (caching === 'Redis') { -%>
|
|
49
|
+
await redisService.del('users:all');
|
|
50
|
+
<%_ } -%>
|
|
33
51
|
res.status(HTTP_STATUS.CREATED).json(newUser);
|
|
34
52
|
<%_ } else { -%>
|
|
35
53
|
const user = await User.create({ name, email });
|
|
54
|
+
<%_ if (caching === 'Redis') { -%>
|
|
55
|
+
await redisService.del('users:all');
|
|
56
|
+
<%_ } -%>
|
|
36
57
|
res.status(HTTP_STATUS.CREATED).json(user);
|
|
37
58
|
<%_ } -%>
|
|
38
59
|
} catch (error) {
|
|
@@ -45,3 +66,4 @@ export class UserController {
|
|
|
45
66
|
}
|
|
46
67
|
}
|
|
47
68
|
}
|
|
69
|
+
|
|
File without changes
|
|
File without changes
|