Skip to content

Commit

Permalink
feat(cli): add cli to better handle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Jun 12, 2022
1 parent bbfd1fe commit 0c7944f
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 16 deletions.
18 changes: 18 additions & 0 deletions apps/cli/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
50 changes: 50 additions & 0 deletions apps/cli/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/cli/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/cli",
"main": "apps/cli/src/main.ts",
"tsConfig": "apps/cli/tsconfig.json"
},
"configurations": {
"production": {
"externalDependencies": "none",
"optimization": true,
"inspect": false
}
}
},
"serve": {
"executor": "@nrwl/node:node",
"options": {
"buildTarget": "cli:build"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/cli/**/*.ts"]
}
},
"test": {
"executor": "nx:run-commands",
"options": {
"cwd": "apps/cli",
"command": "prettier --check ."
},
"dependsOn": [
{
"target": "lint",
"projects": "self"
}
]
}
},
"tags": []
}
114 changes: 114 additions & 0 deletions apps/cli/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { exec } from 'child_process';
import { existsSync } from 'fs';
import * as si from 'systeminformation';
import { inspect, promisify } from 'util';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

const execp = promisify(exec);

const inspectObj = (obj: any): string => {
return inspect(obj, {
showHidden: false,
depth: null,
colors: true,
});
};

yargs(hideBin(process.argv))
.scriptName('yarn cli')
.usage('yarn cli command [options...]')
.command(
'info',
'show general information about your installation',
yargs => yargs,
async () => {
const isDocker = existsSync('/.dockerenv');
const isPodman = existsSync('/run/.containerenv');
const { stdout: yarnVersion } = await execp('yarn --version');
const { stdout: nodeVersion } = await execp('node --version');
const { stdout: dashVersion } = await execp(
'cat package.json | grep version'
);

console.log(
`
INFO
=========
In Docker: ${isDocker}
In Podman: ${isPodman}
Yarn: ${yarnVersion.trim()}
Node: ${nodeVersion.trim()}
Dash: ${dashVersion.replace(/"/g, '').split(':')[1].trim()}
Cwd: ${process.cwd()}
`.trim()
);
}
)
.command(
'raw-data',
'show the raw data that is collected in the backend for specific parts',
yargs =>
yargs
.option('os', {
boolean: true,
describe: 'show raw os info',
})
.option('cpu', {
boolean: true,
describe: 'show raw cpu info',
})
.option('ram', {
boolean: true,
describe: 'show raw ram info',
})
.option('storage', {
boolean: true,
describe: 'show raw storage info',
})
.option('network', {
boolean: true,
describe: 'show raw network info',
})
.option('custom', {
string: true,
describe:
'show custom raw info (provide systeminformation function name)',
}),
async args => {
if (args.os) {
console.log('OS:', inspectObj(await si.osInfo()));
}
if (args.cpu) {
console.log('CPU:', inspectObj(await si.cpu()));
console.log('CPU Load:', inspectObj(await si.currentLoad()));
console.log('CPU Temp:', inspectObj(await si.cpuTemperature()));
}
if (args.ram) {
console.log('Mem:', inspectObj(await si.mem()));
console.log('Mem Layout:', inspectObj(await si.memLayout()));
}
if (args.storage) {
console.log('Disk Layout:', inspectObj(await si.diskLayout()));
console.log('FS Size', inspectObj(await si.fsSize()));
}
if (args.network) {
console.log(
'Network Interfaces:',
inspectObj(await si.networkInterfaces())
);
console.log('Network Stats:', inspectObj(await si.networkStats()));
}
if (args.custom) {
console.log(
`Custom [${args.custom}]`,
inspectObj(await si[args.custom]())
);
}
}
)
.demandCommand(1, 1, 'You need to specify a single command')
.strict()
.parse();
10 changes: 10 additions & 0 deletions apps/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node", "express"]
},
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashdot",
"version": "2.2.1",
"version": "0.0.0",
"description": "dash. - a modern server dashboard",
"license": "MIT",
"private": true,
Expand All @@ -19,6 +19,7 @@
],
"scripts": {
"start": "node .",
"cli": "node dist/apps/cli/main.js",
"build": "nx run-many --target=build --configuration=production --all=true --parallel=true",
"serve": "nx run-many --target=serve --all=true --parallel=true",
"dev": "docker-compose -p dashdot_dev -f ./docker-compose.yml up --remove-orphans",
Expand Down Expand Up @@ -62,7 +63,8 @@
"universal-speedtest": "2.0.5",
"use-color-scheme": "1.1.3",
"util": "0.12.4",
"web-vitals": "2.1.4"
"web-vitals": "2.1.4",
"yargs": "17.5.1"
},
"devDependencies": {
"@babel/core": "7.18.2",
Expand Down
5 changes: 3 additions & 2 deletions workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": 2,
"projects": {
"api": "apps/api",
"view": "apps/view",
"common": "libs/common"
"cli": "apps/cli",
"common": "libs/common",
"view": "apps/view"
}
}
25 changes: 13 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7086,6 +7086,7 @@ __metadata:
use-color-scheme: 1.1.3
util: 0.12.4
web-vitals: 2.1.4
yargs: 17.5.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -18710,33 +18711,33 @@ __metadata:
languageName: node
linkType: hard

"yargs@npm:^16.2.0":
version: 16.2.0
resolution: "yargs@npm:16.2.0"
"yargs@npm:17.5.1, yargs@npm:^17.0.0, yargs@npm:^17.3.1, yargs@npm:^17.4.0":
version: 17.5.1
resolution: "yargs@npm:17.5.1"
dependencies:
cliui: ^7.0.2
escalade: ^3.1.1
get-caller-file: ^2.0.5
require-directory: ^2.1.1
string-width: ^4.2.0
string-width: ^4.2.3
y18n: ^5.0.5
yargs-parser: ^20.2.2
checksum: b14afbb51e3251a204d81937c86a7e9d4bdbf9a2bcee38226c900d00f522969ab675703bee2a6f99f8e20103f608382936034e64d921b74df82b63c07c5e8f59
yargs-parser: ^21.0.0
checksum: 00d58a2c052937fa044834313f07910fd0a115dec5ee35919e857eeee3736b21a4eafa8264535800ba8bac312991ce785ecb8a51f4d2cc8c4676d865af1cfbde
languageName: node
linkType: hard

"yargs@npm:^17.0.0, yargs@npm:^17.3.1, yargs@npm:^17.4.0":
version: 17.5.1
resolution: "yargs@npm:17.5.1"
"yargs@npm:^16.2.0":
version: 16.2.0
resolution: "yargs@npm:16.2.0"
dependencies:
cliui: ^7.0.2
escalade: ^3.1.1
get-caller-file: ^2.0.5
require-directory: ^2.1.1
string-width: ^4.2.3
string-width: ^4.2.0
y18n: ^5.0.5
yargs-parser: ^21.0.0
checksum: 00d58a2c052937fa044834313f07910fd0a115dec5ee35919e857eeee3736b21a4eafa8264535800ba8bac312991ce785ecb8a51f4d2cc8c4676d865af1cfbde
yargs-parser: ^20.2.2
checksum: b14afbb51e3251a204d81937c86a7e9d4bdbf9a2bcee38226c900d00f522969ab675703bee2a6f99f8e20103f608382936034e64d921b74df82b63c07c5e8f59
languageName: node
linkType: hard

Expand Down

0 comments on commit 0c7944f

Please sign in to comment.