jsfetch-term 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/app.js +29 -43
  2. package/package.json +1 -1
package/bin/app.js CHANGED
@@ -1,5 +1,5 @@
1
- import * as child from 'node:child_process';
2
- import * as os from 'node:os';
1
+ import { spawnSync } from 'node:child_process';
2
+ import { platform, userInfo, hostname, arch, uptime, release, version } from 'node:os';
3
3
  import chalk from 'chalk';
4
4
 
5
5
  /**
@@ -10,11 +10,11 @@ function packages(platform) {
10
10
 
11
11
  //if mac os
12
12
  if (platform === 'darwin') {
13
- let directory = child.spawnSync('brew', ['--cellar'], { encoding : 'utf8' });
13
+ let directory = spawnSync('brew', ['--cellar'], { encoding : 'utf8' });
14
14
  let myVar = directory.output[1];
15
15
  let fullText = `${myVar} | wc -l`;
16
16
  let replaced = fullText.replace(/\n|\r/g, "");
17
- return child.spawnSync('ls', [replaced], {shell: true, encoding: 'utf8'}).output[1].trim();
17
+ return spawnSync('ls', [replaced], {shell: true, encoding: 'utf8'}).output[1].trim();
18
18
  }
19
19
 
20
20
  else if (platform === "win32") {
@@ -30,19 +30,17 @@ function timeConvert(time) {
30
30
  let min = time / 60;
31
31
  let hour = time / 3600;
32
32
  let day = time / 86400;
33
- return `time is seconds ${time}, min: ${min}, hour: ${hour}, day: ${day} `;
33
+ return `time is minuet's: ${Math.floor(min)}, hour's: ${Math.floor(hour)}, day's: ${Math.floor(day)} `;
34
34
  }
35
35
 
36
36
  /**
37
37
  * returns the users shell.
38
38
  */
39
39
  function shellCheck(platform) {
40
- if (platform === 'darwin'){
41
- return child.spawnSync(`echo`,['"$SHELL"'], {shell: true, encoding : 'utf8' }).output[1].trim();
42
- }
40
+ if (platform === 'darwin'){return spawnSync(`echo`,['"$SHELL"'], {shell: true, encoding : 'utf8' }).output[1].trim();}
43
41
 
44
42
  else if (platform ==='win32') {
45
- let shell = child.spawnSync('$host.Name', {encoding : 'utf8'})
43
+ let shell = spawnSync('$host.Name', {encoding : 'utf8'})
46
44
  if (shell.output === null) {
47
45
  return "CMD"
48
46
  } else if (shell.output[1].trim() === "ConsoleHost") {
@@ -57,12 +55,12 @@ function getResolution(platform) {
57
55
  //based on platform issue command that gets screen resolution and then
58
56
  if (platform === 'darwin') {
59
57
  const fullText = 'SPDisplaysDataType |grep Resolution';
60
- return child.spawnSync('system_profiler', [`${fullText}`], {shell: true, encoding: 'utf8'}).output[1].trim();
58
+ return spawnSync('system_profiler', [`${fullText}`], {shell: true, encoding: 'utf8'}).output[1].trim();
61
59
  }
62
60
 
63
61
  else if (platform === 'win32') {
64
- let height = child.spawnSync('wmic', ['desktopmonitor', 'get', 'screenheight'], {encoding : 'utf8'});
65
- let width = child.spawnSync('wmic', ['desktopmonitor', 'get', 'screenwidth'], {encoding : 'utf8'});
62
+ let height = spawnSync('wmic', ['desktopmonitor', 'get', 'screenheight'], {encoding : 'utf8'});
63
+ let width = spawnSync('wmic', ['desktopmonitor', 'get', 'screenwidth'], {encoding : 'utf8'});
66
64
  return String(width.output[1].trim().replace( /^\D+/g, '')) + "x"+ String(height.output[1].trim().replace( /^\D+/g, ''));
67
65
  }
68
66
  }
@@ -72,11 +70,8 @@ function getResolution(platform) {
72
70
  * @param {string} platform - devices platform.
73
71
  */
74
72
  function getCPU(platform) {
75
- if (platform === 'darwin') {return macCPU()}
76
-
77
- function macCPU() {
78
- const cpuCommand = child.spawnSync('sysctl', ['-n machdep.cpu.brand_string'], {shell: true, encoding: 'utf8'});
79
- return cpuCommand.output[1].trim();
73
+ if (platform === 'darwin') {return spawnSync('sysctl', ['-n machdep.cpu.brand_string'], {shell: true, encoding: 'utf8'}).output[1].trim()};
74
+ if (platform === 'win32') {//TODO: return cpu
80
75
  }
81
76
  }
82
77
 
@@ -85,20 +80,15 @@ function getCPU(platform) {
85
80
  * @param {string} platform - devices platform.
86
81
  */
87
82
  function getGPU(platform) {
88
- if (platform === 'darwin') {return macGPU()}
89
- if (platform === 'win32') {return windowsGPU()}
90
-
91
- function macGPU() {
83
+ if (platform === 'darwin') {
92
84
  const fullText = 'SPDisplaysDataType |grep Chipset';
93
- return child.spawnSync('system_profiler', [`${fullText}`], {shell: true, encoding: 'utf8'}).output[1].trim();
85
+ return spawnSync('system_profiler', [`${fullText}`], {shell: true, encoding: 'utf8'}).output[1].trim();
94
86
  }
95
-
96
- function windowsGPU() {
97
- let gpu = child.spawnSync('wmic', ['path', 'win32_videoController', 'get', 'name'], {encoding : 'utf8'});
98
- var lines = gpu.output[1].split('\n');
99
- lines.splice(0,1);
100
- lines.splice(1,2);
101
- return lines.join('\n').trim();
87
+ if (platform === 'win32') {
88
+ let gpu = spawnSync('wmic', ['path', 'win32_videoController', 'get', 'name'], {encoding : 'utf8'}).output[1].split('\n');
89
+ gpu.splice(0,1);
90
+ gpu.splice(1,2);
91
+ return gpu.join('\n').trim();
102
92
  }
103
93
  }
104
94
 
@@ -107,16 +97,12 @@ function getCPU(platform) {
107
97
  * @param {string} platform - devices platform.
108
98
  */
109
99
  function getMemory(platform) {
110
- if (platform === 'darwin') {return macMemory()}
111
-
112
- function macMemory() {
100
+ if (platform === 'darwin') {
113
101
  const fullText = 'SPHardwareDataType |grep Memory';
114
- return child.spawnSync('system_profiler', [`${fullText}`], {shell: true, encoding: 'utf8'}).output[1].trim();
115
- }
116
-
117
- function windowsMemory() {
118
-
102
+ return spawnSync('system_profiler', [`${fullText}`], {shell: true, encoding: 'utf8'}).output[1].trim();
119
103
  }
104
+ // if (platform === 'win32') {//TODO: return windows memory
105
+ // }
120
106
  }
121
107
 
122
108
  function displayLogo(platform) {
@@ -142,14 +128,14 @@ function displayLogo(platform) {
142
128
  }
143
129
  }
144
130
 
145
- let name = os.platform()
146
- console.log(chalk.yellow(`${displayLogo(name)}`));
131
+ let name = platform()
132
+ console.log(chalk.cyan(`${displayLogo(name)}`));
147
133
  //TODO: seperate logo from rest of information
148
- console.log(chalk.yellow(`${os.userInfo().username}@${os.hostname()}`));
134
+ console.log(chalk.yellow(`${userInfo().username}@${hostname()}`));
149
135
  console.log('-----------------');
150
- console.log(chalk.blue(`OS: ${name} ${os.release()} ${os.arch()}`));
151
- console.log(chalk.red(`Kernel: ${os.version()}`));
152
- console.log(chalk.red(`Uptime: ${timeConvert(os.uptime())}`));
136
+ console.log(chalk.blue(`OS: ${name} ${release()} ${arch()}`));
137
+ console.log(chalk.red(`Kernel: ${version()}`));
138
+ console.log(chalk.red(`Uptime: ${timeConvert(uptime())}`));
153
139
  console.log(chalk.yellow(`packages: ${packages(name)}`));
154
140
  console.log(chalk.yellow(`shell: ${shellCheck(name)}`));
155
141
  console.log(chalk.yellow(`${getResolution(name)}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsfetch-term",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "neofetch clone in javascript",
5
5
  "main": "app.js",
6
6
  "type": "module",