Skip to content

Commit 5fbcd7e

Browse files
use chalk for console formatting
1 parent 3bdabb3 commit 5fbcd7e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/commander/ping.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Command } from 'commander';
2-
import axios from 'axios'; // Import axios for HTTP requests
2+
import axios from 'axios';
3+
import chalk from 'chalk'
34

45
function getSmartUIServerAddress() {
56
const serverAddress = process.env.SMARTUI_SERVER_ADDRESS || 'http://localhost:49152';
@@ -13,23 +14,23 @@ command
1314
.description('Ping the SmartUI server to check if it is running')
1415
.action(async function(this: Command) {
1516
try {
16-
console.log("Pinging server...");
17+
console.log(chalk.yellow("Pinging server..."));
1718
const serverAddress = getSmartUIServerAddress();
18-
console.log(`Pinging server at ${serverAddress} from terminal...`);
19+
console.log(chalk.yellow(`Pinging server at ${serverAddress} from terminal...`));
1920

2021
// Send GET request to the /ping endpoint
2122
const response = await axios.get(`${serverAddress}/ping`);
2223

2324
// Log the response from the server
2425
if (response.status === 200) {
25-
console.log('SmartUI Server is running');
26-
console.log(`Response: ${JSON.stringify(response.data)}`); // Log response data if needed
26+
console.log(chalk.green('SmartUI Server is running'));
27+
console.log(chalk.green(`Response: ${JSON.stringify(response.data)}`)); // Log response data if needed
2728
} else {
28-
console.log('Failed to reach the server');
29+
console.log(chalk.red('Failed to reach the server'));
2930
}
3031
} catch (error: any) {
3132
// Handle any errors during the HTTP request
32-
console.error('SmartUI server is not running', error.message);
33+
console.error(chalk.red('SmartUI server is not running'));
3334
}
3435
});
3536

src/commander/stopServer.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Command } from 'commander';
22
import axios from 'axios'; // Import axios for HTTP requests
3+
import chalk from 'chalk'
34

45
const command = new Command();
56

@@ -13,10 +14,8 @@ command
1314
.description('Stop the SmartUI server')
1415
.action(async function(this: Command) {
1516
try {
16-
console.log("Stopping server from terminal...");
17-
1817
const serverAddress = getSmartUIServerAddress();
19-
console.log(`Stopping server at ${serverAddress} from terminal...`);
18+
console.log(chalk.yellow(`Stopping server at ${serverAddress} from terminal...`));
2019

2120
// Send POST request to the /stop endpoint with the correct headers
2221
const response = await axios.post(`${serverAddress}/stop`, {}, {
@@ -27,14 +26,14 @@ command
2726

2827
// Log the response from the server
2928
if (response.status === 200) {
30-
console.log('Server stopped successfully');
31-
console.log(response.data); // Log response data if needed
29+
console.log(chalk.green('Server stopped successfully'));
30+
console.log(chalk.green(`Response: ${JSON.stringify(response.data)}`)); // Log response data if needed
3231
} else {
33-
console.log('Failed to stop server');
32+
console.log(chalk.red('Failed to stop server'));
3433
}
3534
} catch (error: any) {
3635
// Handle any errors during the HTTP request
37-
console.error('Error while stopping server:', error.message);
36+
console.error(chalk.red('Error while stopping server'));
3837
}
3938
});
4039

0 commit comments

Comments
 (0)