Skip to content

Commit e0619c8

Browse files
authored
Merge pull request #62 from microservices-suite/repo-engineering/universal-cli
Repo engineering/universal cli
2 parents c507459 + d590e16 commit e0619c8

39 files changed

+669
-363
lines changed

.suite-cli/cli/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Microservices Suite
2+
3+
## suite-cli is the monorepo cli tool aka mono-repo manager
4+
5+
### Installation
6+
- Run `npm install -D @microservices-suite/suite-cli` to save this in your `devDependencies`
7+
8+
### Commands
9+
- `suite add <deps>` installs dependencies

.suite-cli/cli/cli.js

Whitespace-only changes.

.suite-cli/cli/command.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
3+
const {program} = require('commander')
4+
const {addDepsAtWorkspacecmd} = require('.')
5+
program.version('1.0.0')
6+
program.argument('<service>','service to run')
7+
addDepsAtWorkspacecmd
8+
program.option('<mode>','mode to run the server 🚀','dev')
9+
program.action((mode)=>console.log({mode}))
10+
11+
program.parse(process.argv)

.suite-cli/cli/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "@microservices-suite/cli",
3+
"version": "1.0.0",
4+
"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",
5+
"main": "cli.js",
6+
"bin": {
7+
"suite": "./cli.js"
8+
},
9+
"repository": "https://github.com/microservices-suite/node-microservices-suite.git",
10+
"author": "Gilber Andanje <gilbertandanje@gmail.com>",
11+
"license": "MIT",
12+
"private": false,
13+
"keywords": [
14+
"cli"
15+
],
16+
"dependencies": {
17+
"chalk": "4.1.2",
18+
"commander": "^12.0.0",
19+
"figlet": "^1.7.0"
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require('commander');
4+
const { addDepsAtWorkspace, logSuccess, logError } = require('./scripts.module')
5+
const figlet = require('figlet')
6+
7+
console.log(figlet.textSync('Microservices-Suite'))
8+
program
9+
.command('add')
10+
.description('Adds dependencies at given workspace and updates package.json')
11+
.requiredOption('-n, --workspace-name <name>', 'Name of the workspace where to add dependencies')
12+
.option('-d, --workspace-directory <directory>', 'Directory where to look for the workspace. Defaults to "microservices"', 'microservices')
13+
.argument('<packages...>', 'Space-separated list of packages to add')
14+
.action(async(packages, options) => {
15+
try {
16+
const message = await addDepsAtWorkspace({
17+
workspace_name: options.workspaceName,
18+
workspace_directory: options.workspaceDirectory,
19+
packages: packages.join(' ')
20+
});
21+
logSuccess({ message })
22+
} catch (error) {
23+
logError({ error })
24+
}
25+
});
26+
program.parse(process.argv);
27+
module.exports = program
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require('commander');
4+
const { changeDirectory, logInfo, logError, logSuccess } = require('./scripts.module')
5+
const { exit } = require('node:process')
6+
const figlet = require('figlet')
7+
8+
console.log(figlet.textSync('Microservices-Suite'))
9+
program
10+
.description('The function cds into given directory_path')
11+
.argument('<directory_path>', 'The path to the file')
12+
.action((directory_path) => {
13+
try {
14+
changeDirectory({ directory_path });
15+
logSuccess({ message: `Directory found:- ${directory_path}` })
16+
} catch (error) {
17+
switch (error.code) {
18+
case ('ENOENT'):
19+
logError({ error: `Direcotry not found:- ${directory_path}` });
20+
exit(1)
21+
case ('ENOTDIR'):
22+
logError({ error: `Path not directory:- ${directory_path}` });
23+
exit(1)
24+
default:
25+
console.log(error)
26+
27+
}
28+
}
29+
});
30+
program.parse(process.argv);
31+
module.exports = program
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require('commander')
4+
const { checkDocker, getPlatform, logInfo } = require('./scripts.module')
5+
6+
require('./scripts.module')
7+
const figlet = require('figlet')
8+
9+
console.log(figlet.textSync('Microservices-Suite'))
10+
program
11+
.description('Checks if docker is running')
12+
.action(async () => {
13+
const _ = await checkDocker()
14+
logInfo({ message: `Platform : ${`${getPlatform() === 'MacOS' ? '🍏' : 'Linux' ? '🐧' : '🪟'} ${getPlatform()}`} : ${_ ? '✓' : '⚠️'} docker is ${_ ? 'running...' : 'not running. Attempting to start docker...'}` })
15+
})
16+
program.parse(process.argv);
17+
module.exports = program
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require('commander');
4+
const { envFileExists, logInfo, logError } = require('./scriptsmodule')
5+
const { statSync } = require('fs')
6+
const figlet = require('figlet')
7+
8+
console.log(figlet.textSync('Microservices-Suite'))
9+
program
10+
.description('Checks if the file exists at the given path')
11+
.argument('<file_path>', 'The path to the file to check')
12+
.action((file_path) => {
13+
envFileExists({ file_path }) ? logInfo({ message: `${statSync(file_path).isFile() ? 'File' : 'Directory'} found:- ${file_path}` }) : logError({ error: `Path not found:- ${file_path}` })
14+
});
15+
program.parse(process.argv);
16+
module.exports = program
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require('commander');
4+
const { generateDirectoryPath, logInfo } = require('./scripts.module')
5+
const figlet = require('figlet')
6+
7+
console.log(figlet.textSync('Microservices-Suite'))
8+
program
9+
.command('generate-path')
10+
.description('Dynamically generate directory path given workspace_name')
11+
.argument('<workspace-name>', 'Name of the workspace to cd into')
12+
.option('-d, --workspace-directory <directory>', 'Directory where to look for the workspace. Defaults to "microservices"', 'microservices')
13+
.action((workspace_name, options) => {
14+
const path = generateDirectoryPath({
15+
workspace_name,
16+
workspace_directory: options.workspaceDirectory
17+
});
18+
logInfo({ message: path })
19+
});
20+
program.parse(process.argv);
21+
module.exports = program
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require('commander');
4+
const { getPlatform, logInfo } = require('./scripts.module')
5+
const figlet = require('figlet');
6+
const chalk = require('chalk');
7+
8+
console.log(figlet.textSync('Microservices-Suite'))
9+
program
10+
.description('Gets the platorm Os the app is running on')
11+
.action(() => {
12+
logInfo({ message: `Platform: ${getPlatform() === 'MacOS' ? '🍏' : 'Linux' ? '🐧' : '🪟'} ${getPlatform()}` });
13+
});
14+
program.parse(process.argv);
15+
module.exports = program

0 commit comments

Comments
 (0)