Skip to content

Commit 7911dfd

Browse files
authored
Merge pull request #145 from microservices-suite/repo-engineering/universal-cli
Repo engineering/universal cli
2 parents 7f05c88 + 6e7d465 commit 7911dfd

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

.suite-cli/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microservices-suite/cli",
3-
"version": "2.1.0-1",
3+
"version": "3.0.0",
44
"description": "This is the CLI tool for running the microservices-suite monorepo. It contains functionalities and tools required for automation and managing the repo across supported platforms. Works on Windows,MacOS and Linux as well as support to some extend other variants like SunOS, IBM AIX, FreeBSD, OpenBSD and more",
55
"main": "cli.js",
66
"repository": "https://github.com/microservices-suite/node-microservices-suite.git",

.suite-cli/cli/scripts/assets/dockerComposeContent.asset.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module.exports = ({ services, webserver, krakend_port, env }) => {
22
const servicesConfig = services.map(service => `
3-
${service.toLowerCase().replace(/\s+/g, '-')}:
3+
${service.name.toLowerCase().replace(/\s+/g, '-')}:
44
build:
55
dockerfile: Dockerfile.dev
6-
context: ../../../microservices/${service}
6+
context: ../../../microservices/${service.name}
77
ports:
8-
- "${krakend_port}:${krakend_port}"
8+
- "${service.port}:${service.port}"
99
volumes:
1010
- /app/node_modules
11-
- ../../../microservices/${service}:/app
11+
- ../../../microservices/${service.name}:/app
1212
depends_on:
1313
rabbitmq:
1414
condition: service_healthy
1515
`).join('');
1616

1717
// Collect all service names for the 'depends_on' section of the web server
18-
const serviceNames = services.map(service => service.toLowerCase().replace(/\s+/g, '-'));
18+
const serviceNames = services.map(service => service.name.toLowerCase().replace(/\s+/g, '-'));
1919

2020
return `
2121
version: '3.8'

.suite-cli/cli/scripts/assets/krakendConfigContent.asset.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@ module.exports = ({
99
// Health check for all services
1010
const suiteStatusCheckBackends = services.map((service) => `
1111
{
12-
"host": ["http://${service.toLowerCase()}:${service.port}"],
12+
"host": ["http://${service.name.toLowerCase()}:${service.port}"],
1313
"url_pattern": "/",
1414
"mapping": {
15-
"message": "${service.toLowerCase()}"
15+
"message": "${service.name.toLowerCase()}"
1616
}
1717
}`).join(',\n');
1818

1919
// List all services
2020
const allServicesListBackends = services.map((service) => `
2121
{
22-
"host": ["http://${service.toLowerCase()}:${service.port}"],
23-
"url_pattern": "/api/${api_version}/${service.toLowerCase()}s",
22+
"host": ["http://${service.name.toLowerCase()}:${service.port}"],
23+
"url_pattern": "/api/${api_version}/${service.name.toLowerCase()}s",
2424
"mapping": {
25-
"data": "${service.toLowerCase()}s"
25+
"data": "${service.name.toLowerCase()}s"
2626
}
2727
}`).join(',\n');
2828

2929
// Each service backend
3030
const eachServiceListBackends = [services[0]].map((service) => `
3131
{
32-
"host": ["http://${service.toLowerCase()}:${service.port}"],
33-
"url_pattern": "/api/${api_version}/${service.toLowerCase()}s",
32+
"host": ["http://${service.name.toLowerCase()}:${service.port}"],
33+
"url_pattern": "/api/${api_version}/${service.name.toLowerCase()}s",
3434
"mapping": {
35-
"data": "${service.toLowerCase()}s"
35+
"data": "${service.name.toLowerCase()}s"
3636
}
3737
}`).join(',\n');
3838

@@ -59,8 +59,8 @@ module.exports = ({
5959
"backend": [${allServicesListBackends}]
6060
},
6161
{
62-
"@comment": "Fetch all data from the ${services[0].toLowerCase()} service",
63-
"endpoint": "/api/${api_version}/${services[0].toLowerCase()}s",
62+
"@comment": "Fetch all data from the ${services[0].name.toLowerCase()} service",
63+
"endpoint": "/api/${api_version}/${services[0].name.toLowerCase()}s",
6464
"method": "GET",
6565
"backend": [${eachServiceListBackends}]
6666
}

.suite-cli/cli/scripts/scripts.module.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,14 +1628,22 @@ const getDependencies = ({ type, workspace }) => {
16281628
const scaffoldGateways = async ({ answers }) => {
16291629
const { webserver } = readFileContent({ currentDir: cwd() });
16301630
const { projectName } = readFileContent({ currentDir: cwd() });
1631-
const { apps } = answers;
1631+
let { apps } = answers;
16321632
const project_root = generatRootPath({ currentDir: cwd() });
1633-
1633+
const service_objects = getExistingServices({ currentDir: cwd() });
1634+
// add port to services in each app eg ['auth']=>[{name:'auth',port:9001}]
1635+
apps = apps.map((app) => {
1636+
app.services.map((name, i) => {
1637+
const service_object = service_objects.find((s) => s.name === name);
1638+
app.services[i] = { name, port: service_object.port }
1639+
})
1640+
return app
1641+
})
16341642
await Promise.all(apps.map(async (app) => {
16351643
console.log('---------------------------------------------')
16361644
console.log(`🦧${app.name}-gateway`)
16371645
return scaffoldGateway({ project_root, app, answers, webserver, projectName })
1638-
1646+
16391647
}))
16401648
}
16411649

@@ -1644,7 +1652,6 @@ const scaffoldGateway = ({ project_root, app, answers, webserver, projectName })
16441652
const webserver_dir = join(app_directory, webserver);
16451653
const krakend_dir = join(app_directory, 'krakend');
16461654
const services = app.services;
1647-
const nginx_services = getExistingServices({ currentDir: cwd() });
16481655
// Remove the directory if it already exists
16491656
if (existsSync(krakend_dir)) {
16501657
rmSync(krakend_dir, { recursive: true });
@@ -1668,7 +1675,7 @@ const scaffoldGateway = ({ project_root, app, answers, webserver, projectName })
16681675
ora().succeed(`Generated docker-compose configs at: ${app_directory}`)
16691676
switch (webserver) {
16701677
case 'nginx':
1671-
generateNginxConfiguration({ services:nginx_services, webserver_dir });
1678+
generateNginxConfiguration({ services, webserver_dir });
16721679
break
16731680
default:
16741681
ora().info('Handling other webservers');

0 commit comments

Comments
 (0)