Skip to content

Commit eeda746

Browse files
authored
Merge pull request #121 from microservices-suite/repo-engineering/universal-cli
Repo engineering/universal cli
2 parents cb6f897 + e822fcc commit eeda746

File tree

5 files changed

+121
-45
lines changed

5 files changed

+121
-45
lines changed

.suite-cli/cli/README.md

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,128 @@
22

33
## suite-cli: Monorepo CLI Tool (The mono-repo Manager 🦧)
44

5+
### Intro
6+
- Suite-CLI is a cross-platform easy to use command line interface for managing monorepos.
7+
- Build and ship quickly with code-generator `suite generate` that helps you scaffold resources so you can focus on the core functionality and reduce project setup overhead.
8+
- Suite uses consistent and intuitive syntax for commands both in development and CI.
9+
Example
10+
```bash
11+
yarn workspace @microservices-suite/utilities run dev
12+
```
13+
The same command with suite-CLI
14+
```bash
15+
suite start utilities
16+
```
17+
- The CLI uses automation and smart algorithmns to run otherwise repetetive tasks and orchestrate complex workflows with simple commands.
18+
- Streamline building & publishing docker images
19+
- Easily maintain and publish private packages to npm registry using `suite {library_name} release`
20+
- Streamline containerization with docker and scale with kubernetes both in development and production.
21+
522
### Installation
623

724
In this guide we describe using `npm` to install packages. Other package managers may be used at your discretion. With npm, you have several options available for managing how your OS command line resolves the location of the `suite CLI` binary file. Here, we describe installing the `suite` binary globally using the -g option. This provides a measure of convenience, and is the approach we assume throughout the documentation. Note that installing any `npm` package globally leaves the responsibility of ensuring they're running the correct version up to the user. It also means that if you have different projects, each will run the same version of the CLI. A reasonable alternative is to use the npx program, built into the npm cli (or similar features with other package managers) to ensure that you run a managed version of the `Suite` CLI. We recommend you consult the npx documentation and/or your DevOps support staff for more information.To install `suite-cli` globally, run the following command:
825

926
Install the CLI globally using the `npm install -g` command (see the **Note** above for details about global installs).
1027

11-
```bash
12-
npm install -g @microservices-suite/cli
13-
```
28+
```bash
29+
npm install @microservices-suite/cli -g
30+
```
1431
**HINT**
1532
Alternatively, you can use this command `npx @microservices-suite/cli@latest` without installing the cli globally.
1633

34+
### Prerequisites(required)
35+
- Suite uses `yarn workspaces` to generate and manage your monorepo. You need to install yarn globally to smoothly run our CLI.
36+
- Install yarn globally(You may need superuser priviledges).
37+
```bash
38+
sudo npm install yarn -g
39+
```
40+
- Using brew on Mac
41+
```bash
42+
brew install yarn
43+
```
44+
- In development, suite uses `nodemon` and `symbolic links(symlinks)` to watch your code changes in target files in vanilla mode as well as dockerized apps with mapped volumes.
45+
```bash
46+
sudo npm install nodemon -g
47+
```
48+
### Prerequisites(optional)
49+
- To be able to containerize your application you will need to install `docker` on your machine, however, it is not required. You can still run your services in `vanilla mode` using `nodemon` in development mode and `PM2` in production.
50+
- Install docker for Linux 👉 [here ](https://docs.docker.com/desktop/install/linux-install/)
51+
- Install docker for Mac 👉 [here ](https://docs.docker.com/desktop/install/mac-install/)
52+
- Install docker for Windows 👉 [here ](https://docs.docker.com/desktop/install/windows-install/)
53+
- To simulate scaling with kubernetes on your local machine you will need to install `minikube,kubectl,virtul machine(virtualBox)`
54+
- Install your platform's VirtualBox binary 👉 [here ](https://www.virtualbox.org/wiki/Downloads)
55+
- Install your platform's minikube binary 👉 [here ](https://minikube.sigs.k8s.io/docs/start/)
56+
- Install `kubectl` the CLI for communicating with kubernetes clusters within the Virtual Machine which simulates one development node configured by `minikube`
57+
- Linux binary
58+
```bash
59+
https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
60+
```
61+
- Mac(Intel chip) binary
62+
```bash
63+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
64+
```
65+
- Windows binary
66+
```bash
67+
curl.exe -LO "https://dl.k8s.io/release/v1.30.0/bin/windows/amd64/kubectl.exe"
68+
```
69+
- Install `PM2` to run your components in prod
70+
```bash
71+
npm install pm2 -g
72+
```
73+
1774
### Basic workflow
1875
- Once installed, you can invoke CLI commands directly from your OS command line through the `suite` executable. See the available `suite` commands by entering the following:
19-
```bash
20-
suite --help
21-
```
22-
23-
- Get help on an individual command using the following construct. Substitute any command, like `host`, `docker:start`, etc., where you see `start` in the example below to get detailed help on that command:
24-
```bash
25-
suite start --help
26-
```
76+
```bash
77+
suite --help
78+
```
2779

2880
### Scaffold new repo
2981
- Suite-CLI can help you quickly initialize a new monorepo project and save you alot of project setup and devops overhead. The new project comes ready with our standard file structure with version control and workspaces configured to start code sharing and realize the full power of symlinking:
30-
```bash
31-
suite generate
32-
```
82+
```bash
83+
suite generate
84+
```
3385

3486
- This is an interactive command that progressively builds the project by selecting options for the name, API architecture to work with, webservers of choice and more.
3587
- When done generating your project you can still generate other components piece-wise like microservice, library or workspace. This makes your development work easier as it automatically builds your package.json or better yet generates a valid workspace compatible with the current project.
3688

3789
### Install dependencies at workspace
3890
- This command lets you install dependencies with more control for where to install. This leverages no-hoisting feature to deliver symlinking close to the relevant workspace.
39-
```bash
40-
suite add <@microservices-suite/<workspace_name>> express axios
41-
```
91+
```bash
92+
suite add <@microservices-suite/<workspace_name>> express axios
93+
```
4294

4395
### Docker instances management
4496
- Suite has abstracted away the complexity of working with `docker compose` and `vanilla docker` commands in monorepo environment by using `suite's` concise and consistent syntax
4597
- Run `docker volume|system prune -f`
46-
```bash
47-
suite prune [-fav]
48-
```
98+
```bash
99+
suite prune [-fav]
100+
```
49101
- This command works behaves exactly as docker and if `[-v-a]` flags are passed they specify you are targeting `volumes or al(volumes & system)`.
50102
- This is part of house keeping that suite exposes to clean up your environemnt when its blotted with dangling images or containers and volumes.
51-
```bash
52-
suite docker:start
53-
```
103+
```bash
104+
suite docker:start
105+
```
54106
- Start all services in vanilla mode
55107
- If mode is not specified this command spins services in development environment
56108
- The mode must match the env extension `.env.[mode]` except production `.env` which does not have an extension
57109
- you can pass services to start separated with spaces eg `suite start -v supplier-service customer-service`
58110
- If no services are specified suite spins all services in the `@microservices-suite` workspace
59-
```bash
60-
suite start -v <...services>
61-
```
111+
```bash
112+
suite start -v <...services>
113+
```
62114
- Start services with docker compose
63115
- If mode is not specified this command spins services in development environment
64116
- The mode must match the env extension `.env.[mode]` except production `.env` which does not have an extension
65117
- you can pass services to start separated with spaces eg `suite start -v supplier-service customer-service`
66118
- If no services are specified suite spins all services in the `@microservices-suite` workspace
67-
```bash
68-
suite start <service-name...>
69-
```
119+
```bash
120+
suite start <service-name...>
121+
```
70122
### Package management and release
71123
- To easily release your builds and generate changelogs, suite makes it easy using `suite release` command
72124
- To publish to npm registry any shared libray simply run the `suite release` passing the name of the library
73125
- Suite will automatically figure out what library in your workspace you are targeting and initiate an interactive release workflow where you will specify the semver.
74126
- To run this command succesfully you need to create one `automation & publish` `auth_token` on your private registry and then run `npm or yarn login`
75-
```bash
76-
suite release [package]
77-
```
127+
```bash
128+
suite release [package]
129+
```

.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.0.2",
3+
"version": "2.0.3",
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/scripts.module.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,20 +1216,40 @@ const generateMCSHelper = ({ project_root, answers }) => {
12161216
* @returns {Promise<void>} A Promise that resolves when the release process is completed.
12171217
*/
12181218
const releasePackage = async ({ package }) => {
1219-
const package_json_path = join(cwd(), 'package.json');
1219+
try {
1220+
const package_json_path = join(cwd(), 'package.json');
1221+
1222+
// Read the package.json file
1223+
console.log({ package_json_path })
1224+
const { workspace_name } = retrieveWorkSpaceName({ package_json_path });
1225+
if (package) {
1226+
logInfo({ message: `Looking for package: ${workspace_name}/${package}` });
1227+
await executeCommand('yarn', ['workspace', `${workspace_name}/${package}`, 'release']);
1228+
} else {
1229+
await executeCommand('yarn', ['generate:release'], { cwd: cwd() });
1230+
}
1231+
} catch (error) {
1232+
console.error('Error occurred:', error);
1233+
}
1234+
}
12201235

1221-
// Read the package.json file
1222-
const { workspace_name } = retrieveWorkSpaceName({ package_json_path });
1223-
package && logInfo({ message: `Looking for package: ${workspace_name}/${package}` });
1224-
package && spawn('yarn', ['workspace', `${workspace_name}/${package}`, 'release'], {
1225-
stdio: 'inherit'
1226-
})
1227-
!package && spawn('yarn', ['generate:release'], {
1228-
stdio: 'inherit',
1229-
cwd: cwd()
1230-
})
1236+
const executeCommand =(command, args, options) => {
1237+
return new Promise(async(resolve, reject) => {
1238+
const child = await spawn(command, args, options);
1239+
child.on('close', (code) => {
1240+
if (code !== 0) {
1241+
reject(new Error(`Command ${command} ${args.join(' ')} failed with code ${code}`));
1242+
} else {
1243+
resolve();
1244+
}
1245+
});
1246+
child.on('error', (err) => {
1247+
reject(err);
1248+
});
1249+
});
12311250
}
12321251

1252+
12331253
/**
12341254
* Retrieves the workspace name from the package.json file.
12351255
* @param {Object} options - Options for retrieving the workspace name.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33

4+
## v1.6.3
5+
6+
[compare changes](https://github.com/microservices-suite/node-microservices-suite/compare/v2.0.2...v1.6.3)
7+
48
## v1.6.2
59

610
[compare changes](https://github.com/microservices-suite/node-microservices-suite/compare/v2.0.2-0...v1.6.2)

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/microservices",
3-
"version": "1.6.2",
3+
"version": "1.6.3",
44
"description": "This is the central orchestration point for our microservices-based platform, encompassing user management, email communications, file upload handling, and role-based access control services. It serves as the backbone of our application's backend, facilitating seamless interaction, development, and scaling of individual microservices. The workspace is designed to streamline the development process, ensuring dependency consistency, and simplifying the build and deployment workflows across all services.\nThis root workspace enables our development teams to:\n- Manage dependencies for all services in a unified manner, reducing conflicts and easing updates.\n- Utilize shared configurations, such as ESLint rules, TypeScript configurations, and shared utility libraries, to maintain coding standards and reduce redundancy across services.\n- Implement global scripts for tasks like testing, linting, and deployment that can run across all services, ensuring consistency and efficiency in our development pipeline.\n- Leverage the workspace's structure for local development, allowing for easy testing of interactions between services without the need for deploying or configuring external environments.",
55
"keywords": [],
66
"author": "Gilbert Andanje",

0 commit comments

Comments
 (0)