Skip to content

Commit 17386a8

Browse files
committed
refactor: reorganize cli structure
1 parent 5cb79e8 commit 17386a8

19 files changed

+193
-112
lines changed

.suite-cli/cli/README.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
# Microservices Suite
22

3-
## suite-cli is the monorepo cli tool aka mono-repo manager
3+
## suite-cli: Monorepo CLI Tool (The mono-repo Manager 🦧)
44

55
### Installation
6-
- Run `npm install -D @microservices-suite/suite-cli` to save this in your `devDependencies`
76

8-
### Commands
9-
- `suite add <deps>` installs dependencies
7+
To install `suite-cli` and save it in your `devDependencies`, run the following command:
8+
9+
```bash
10+
npm install -D @microservices-suite/suite-cli
11+
```
12+
13+
### Usage
14+
```bash
15+
suite add <deps>
16+
```
17+
18+
```bash
19+
suite add express axios
20+
```

.suite-cli/cli/cli.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
const figlet = require('figlet')
4+
const { program } = require("commander");
5+
console.log(figlet.textSync('Microservices-Suite'))
6+
const {
7+
addDepsAtWorkspace,
8+
installDepsAtWorkspace,
9+
changeDirectory,
10+
isMatch,
11+
logSuccess,
12+
logError,
13+
logInfoMessage,
14+
pathExists,
15+
generateDirectoryPath,
16+
checkDocker,
17+
getPlatform,
18+
startDocker
19+
} = require("./scripts");
20+
21+
const [, , command, ...args] = process.argv;
22+
console.log({ command, args })
23+
switch (command) {
24+
case add:
25+
addDepsAtWorkspace(args)
26+
case add:
27+
installDepsAtWorkspace(args)
28+
case add:
29+
logInfoMessage(args)
30+
case add:
31+
logError(args)
32+
case add:
33+
logSuccess(args)
34+
case add:
35+
changeDirectory(args)
36+
case add:
37+
isMatch(args)
38+
case add:
39+
generateDirectoryPath(args)
40+
case add:
41+
checkDocker(args)
42+
case add:
43+
getPlatform(args)
44+
case add:
45+
pathExists(args)
46+
case add:
47+
startDocker(args)
48+
}

.suite-cli/cli/command.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21

32
const {program} = require('commander')
43
const {addDepsAtWorkspacecmd} = require('.')

.suite-cli/cli/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
"version": "1.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",
6-
"bin": {
7-
"suite": "./cli.js"
8-
},
96
"repository": "https://github.com/microservices-suite/node-microservices-suite.git",
107
"author": "Gilber Andanje <gilbertandanje@gmail.com>",
118
"license": "MIT",

.suite-cli/cli/scripts/addDepsAtWorkspace.cmd.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
#!/usr/bin/env node
21

3-
const { program } = require('commander');
42
const { addDepsAtWorkspace, logSuccess, logError } = require('./scripts.module')
5-
const figlet = require('figlet')
3+
const { program } = require('commander');
4+
65

7-
console.log(figlet.textSync('Microservices-Suite'))
86
program
97
.command('add')
108
.description('Adds dependencies at given workspace and updates package.json')
119
.requiredOption('-n, --workspace-name <name>', 'Name of the workspace where to add dependencies')
1210
.option('-d, --workspace-directory <directory>', 'Directory where to look for the workspace. Defaults to "microservices"', 'microservices')
1311
.argument('<packages...>', 'Space-separated list of packages to add')
14-
.action(async(packages, options) => {
12+
.action(async (packages, options) => {
1513
try {
1614
const message = await addDepsAtWorkspace({
1715
workspace_name: options.workspaceName,

.suite-cli/cli/scripts/changeDirectory.cmd.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#!/usr/bin/env node
21

3-
const { program } = require('commander');
4-
const { changeDirectory, logInfo, logError, logSuccess } = require('./scripts.module')
52
const { exit } = require('node:process')
6-
const figlet = require('figlet')
3+
const { changeDirectory, logError, logSuccess } = require('./scripts.module')
4+
const { program } = require('commander');
5+
76

8-
console.log(figlet.textSync('Microservices-Suite'))
97
program
108
.description('The function cds into given directory_path')
119
.argument('<directory_path>', 'The path to the file')

.suite-cli/cli/scripts/checkDocker.cmd.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
#!/usr/bin/env node
21

3-
const { program } = require('commander')
42
const { checkDocker, getPlatform, logInfo } = require('./scripts.module')
3+
const { program } = require('commander')
54

6-
require('./scripts.module')
7-
const figlet = require('figlet')
85

9-
console.log(figlet.textSync('Microservices-Suite'))
106
program
117
.description('Checks if docker is running')
128
.action(async () => {

.suite-cli/cli/scripts/envFileExists.cmd.js

-16
This file was deleted.

.suite-cli/cli/scripts/generateDirectoryPath.cmd.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#!/usr/bin/env node
21

3-
const { program } = require('commander');
42
const { generateDirectoryPath, logInfo } = require('./scripts.module')
5-
const figlet = require('figlet')
3+
const { program } = require('commander');
4+
65

7-
console.log(figlet.textSync('Microservices-Suite'))
86
program
97
.command('generate-path')
108
.description('Dynamically generate directory path given workspace_name')

.suite-cli/cli/scripts/getPlatform.cmd.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#!/usr/bin/env node
21

3-
const { program } = require('commander');
42
const { getPlatform, logInfo } = require('./scripts.module')
5-
const figlet = require('figlet');
6-
const chalk = require('chalk');
3+
const { program } = require('commander');
4+
75

8-
console.log(figlet.textSync('Microservices-Suite'))
96
program
107
.description('Gets the platorm Os the app is running on')
118
.action(() => {

.suite-cli/cli/scripts/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module.exports.generateDirectoryPath=require('./generateDirectoryPath.cmd'),
22
module.exports.changeDirectory=require('./changeDirectory.cmd'),
3-
module.exports.envFileExists=require('./envFileExists.cmd'),
3+
module.exports.pathExists=require('./pathExists.cmd'),
44
module.exports.logInfoMessage=require('./logInfoMessage.cmd'),
55
module.exports.logErrorMessage=require('./logErrorMessage.cmd'),
66
module.exports.logSuccessMessage=require('./logSuccessMessage.cmd'),
77
module.exports.isMatch=require('./isMatch.cmd'),
88
module.exports.getPlatform=require('./getPlatform.cmd'),
9-
module.exports.checkDockerCmd=require('./checkDocker.cmd'),
10-
module.exports.installDepsAtWorkspaceCmd=require('./installDepsAtWorkspace.cmd'),
11-
module.exports.addDepsAtWorkspacecmd=require('./addDepsAtWorkspace.cmd')
9+
module.exports.checkDocker=require('./checkDocker.cmd'),
10+
module.exports.startDocker=require('./startDocker.cmd'),
11+
module.exports.installDepsAtWorkspace=require('./installDepsAtWorkspace.cmd'),
12+
module.exports.addDepsAtWorkspace=require('./addDepsAtWorkspace.cmd')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
const { installDepsAtWorkspace, logSuccess, logError } = require('./scripts.module')
3+
const { program } = require('commander');
4+
5+
6+
program
7+
.command('add')
8+
.description('Adds dependencies at given workspace and updates package.json')
9+
.requiredOption('-n, --workspace-name <name>', 'Name of the workspace where to add dependencies')
10+
.option('-d, --workspace-directory <directory>', 'Directory where to look for the workspace. Defaults to "microservices"', 'microservices')
11+
.argument('<packages...>', 'Space-separated list of packages to add')
12+
.action(async (packages, options) => {
13+
try {
14+
const message = await installDepsAtWorkspace({
15+
workspace_name: options.workspaceName,
16+
workspace_directory: options.workspaceDirectory,
17+
packages: packages.join(' ')
18+
});
19+
logSuccess({ message })
20+
} catch (error) {
21+
logError({ error })
22+
}
23+
});
24+
program.parse(process.argv);
25+
module.exports = program

.suite-cli/cli/scripts/isMatch.cmd.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#!/usr/bin/env node
21

2+
const { isMatch, logSuccess } = require('./scripts.module')
33
const { program } = require('commander');
4-
const { isMatch, logSuccess, l, logSuccessogError } = require('./scripts.module')
5-
const figlet = require('figlet');
6-
const chalk = require('chalk');
74

8-
console.log(figlet.textSync('Microservices-Suite'))
5+
96
program
107
.description('Compares if 2 values match')
118
.argument('<a>', 'first value')

.suite-cli/cli/scripts/logErrorMessage.cmd.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#!/usr/bin/env node
21

3-
const { program } = require('commander');
42
const { logError } = require('./scripts.module')
5-
const figlet = require('figlet');
3+
const { program } = require('commander');
4+
65

7-
console.log(figlet.textSync('Microservices-Suite'))
86
program
97
.description('Prints Error message to screen')
108
.argument('<error>', 'Error to display to console')

.suite-cli/cli/scripts/logInfoMessage.cmd.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#!/usr/bin/env node
21

3-
const { program } = require('commander');
42
const { logInfo } = require('./scripts.module')
5-
const figlet = require('figlet');
6-
const chalk = require('chalk');
3+
const { program } = require('commander');
4+
75

8-
console.log(figlet.textSync('Microservices-Suite'))
96
program
107
.description('Prints informational message to screen')
118
.argument('<message>', 'Info to display to console')

.suite-cli/cli/scripts/logSuccessMessage.cmd.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#!/usr/bin/env node
21

2+
const { logSuccess } = require('./scripts.module')
33
const { program } = require('commander');
4-
const { logSuccess } = require('./scriptsmodule')
5-
const figlet = require('figlet');
6-
const chalk = require('chalk');
74

8-
console.log(figlet.textSync('Microservices-Suite'))
5+
96
program
107
.description('Prints success message to screen')
118
.argument('<message>', 'Message to display to console')
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
const { pathExists, logInfo, logError } = require('./scripts.module')
3+
const { program } = require('commander');
4+
const { statSync } = require('fs')
5+
6+
7+
program
8+
.description('Checks if the file exists at the given path')
9+
.argument('<file_path>', 'The path to the file to check')
10+
.action((file_path) => {
11+
pathExists({ file_path }) ? logInfo({ message: `${statSync(file_path).isFile() ? 'File' : 'Directory'} found:- ${file_path}` }) : logError({ error: `Path not found:- ${file_path}` })
12+
});
13+
program.parse(process.argv);
14+
module.exports = program

0 commit comments

Comments
 (0)