Skip to content

Commit

Permalink
fix(deps): fix breaking changes from systeminformation dependency (#37)
Browse files Browse the repository at this point in the history
* fix(deps): fix breaking changes from systeminformation dependency
  • Loading branch information
golota60 committed Apr 9, 2021
1 parent 3a6509c commit 0da9160
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 73 deletions.
28 changes: 13 additions & 15 deletions src/helpers/systeminformation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import os from 'os';
import { errorMessage, bitstoMegabytes } from './helpers';
import { GpuControllers, GpuDisplays, MemoryInterface, OsInfoInterface } from '../interfaces/systeminformation';
import sysinf from 'systeminformation';

interface DisplayAndGraphicsCard {
displays: Array<string>;
gpuInfo: Array<string>;
}

interface MemoryInfoInterface {
free: string;
used: string;
Expand All @@ -25,20 +18,25 @@ export const getEndianness = (): string => {
}
};

export const getDisplaysAndGraphicsCards = async (): Promise<DisplayAndGraphicsCard> => {
interface DisplaysAndGraphicsCardsInterface {
gpuInfo: Array<string>;
displays: Array<string>;
}

export const getDisplaysAndGraphicsCards = async (): Promise<DisplaysAndGraphicsCardsInterface> => {
try {
const gpu = await sysinf.graphics();

const gpuInfo = gpu.controllers.reduce(
(_acc: Array<string>, _gpu: GpuControllers) => (_gpu.model ? [..._acc, _gpu.model] : [..._acc]),
(_acc: Array<string>, _gpu: sysinf.Systeminformation.GraphicsControllerData) =>
_gpu.model ? [..._acc, _gpu.model] : [..._acc],
[],
);
const displays = gpu.displays.reduce(
(_acc: Array<string>, _gpu: GpuDisplays) =>
_gpu.resolutionx && _gpu.resolutiony ? [..._acc, `${_gpu.resolutionx}x${_gpu.resolutiony}`] : [..._acc],
(_acc: Array<string>, _gpu: sysinf.Systeminformation.GraphicsDisplayData) =>
_gpu.resolutionX && _gpu.resolutionY ? [..._acc, `${_gpu.resolutionX}x${_gpu.resolutionY}`] : [..._acc],
[],
);

return {
gpuInfo,
displays,
Expand All @@ -53,7 +51,7 @@ export const getDisplaysAndGraphicsCards = async (): Promise<DisplayAndGraphicsC

export const getMemoryInfo = async (): Promise<MemoryInfoInterface> => {
try {
const memory: MemoryInterface = await sysinf.mem();
const memory: sysinf.Systeminformation.MemData = await sysinf.mem();

const free: number = memory ? bitstoMegabytes(memory.free) : 0;
const used: number = memory ? bitstoMegabytes(memory.used) : 0;
Expand All @@ -75,7 +73,7 @@ export const getMemoryInfo = async (): Promise<MemoryInfoInterface> => {

export const getOsInfo = async (): Promise<string> => {
try {
const osInfo: Array<OsInfoInterface> = await sysinf.users();
const osInfo: Array<sysinf.Systeminformation.UserData> = await sysinf.users();

return osInfo ? osInfo[0].user : '';
} catch {
Expand All @@ -90,7 +88,7 @@ export const getShellInfo = async (): Promise<string> => {
if (os.platform() === 'win32') {
//windows doesn't support .shell() feature
try {
const osInfo: OsInfoInterface[] = await sysinf.users();
const osInfo: Array<sysinf.Systeminformation.UserData> = await sysinf.users();
return osInfo ? osInfo[0].tty : '';
} catch {
return errorMessage;
Expand Down
56 changes: 0 additions & 56 deletions src/interfaces/systeminformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,3 @@ export interface MemoryInfoInterface {
used: string;
total: string;
}

export interface SystemInformation {
graphicsInfo: DisplayAndGraphicsCard;
memoryInfo: MemoryInfoInterface;
osInfo: {
username: string;
};
shellInfo: string;
}

export interface GpuControllers {
vendor: string;
model: string;
bus: string;
vram: number;
vramDynamic: boolean;
}

export interface GpuDisplays {
vendor: string;
model: string;
main: boolean;
builtin: boolean;
connection: string;
resolutionx: number;
resolutiony: number;
sizex: number;
sizey: number;
pixeldepth: number;
currentResX: number;
currentResY: number;
positionX: number;
positionY: number;
currentRefreshRate: number;
}

export interface MemoryInterface {
total: number;
free: number;
used: number;
active: number;
available: number;
buffcache: number;
swaptotal: number;
swapused: number;
swapfree: number;
}

export interface OsInfoInterface {
user: string;
tty: string;
date: string;
time: string;
ip: string;
command: string;
}
12 changes: 10 additions & 2 deletions src/yayfetch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env node

import { SystemInformation } from './interfaces/systeminformation';
import { DisplayAndGraphicsCard, MemoryInfoInterface } from './interfaces/systeminformation';

import os from 'os';
import yargs from 'yargs';
import chalk from 'chalk';
import inquirer from 'inquirer';
import columnify from 'columnify';
import { uptimeInMinutes, returnInPink, yayfetchASCII, printInTwoColumns } from './helpers/helpers';
import {
getEndianness,
Expand Down Expand Up @@ -35,6 +34,15 @@ const promptQuestions = {
],
};

export interface SystemInformation {
graphicsInfo: DisplayAndGraphicsCard;
memoryInfo: MemoryInfoInterface;
osInfo: {
username: string;
};
shellInfo: string;
}

const getSystemInformation = async (): Promise<SystemInformation> => ({
graphicsInfo: await getDisplaysAndGraphicsCards(),
memoryInfo: await getMemoryInfo(),
Expand Down

0 comments on commit 0da9160

Please sign in to comment.