-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add cli to better handle issues
- Loading branch information
1 parent
bbfd1fe
commit 0c7944f
Showing
7 changed files
with
212 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters