Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _New Features:_

_Enhancements:_

- Got rid of the `colors` package (unnecessary dependency) and replaced it with our internal logic.
- Improved server-related error handling by introducing new centralized error middlewares.
- Improved overall error handling by adding a main try-catch block to correctly capture and log errors occurring throughout the code.
- Introduced two new types of custom errors: `ExportError` for functionality-related errors and `HttpError` for server-related errors.
Expand Down
16 changes: 9 additions & 7 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ import { readFileSync } from 'fs';
import { join } from 'path';

import { __dirname } from './lib/utils.js';

import 'colors';
import { style } from './lib/logger.js';

const pkgFile = JSON.parse(readFileSync(join(__dirname, 'package.json')));

console.log(
`
Highcharts Export Server V${pkgFile.version}
`${style.green}
Highcharts Export Server v${pkgFile.version}

${'This software requires a valid Highcharts license for commercial use.'.yellow}
${style.yellow}This software requires a valid Highcharts license for commercial use.${style.reset}

${style.yellow}
If you do not have a license, one can be obtained here:
${'https://shop.highsoft.com/'.green}
https://shop.highsoft.com/
${style.reset}

To customize your installation (include additional/fewer modules and so on),
please refer to the readme file.
`.green
${style.reset}
`
);
2 changes: 0 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ See LICENSE file in root for details.

*******************************************************************************/

import 'colors';

import { checkAndUpdateCache } from './cache.js';
import {
batchExport,
Expand Down
30 changes: 24 additions & 6 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ See LICENSE file in root for details.

import { appendFile, existsSync, mkdirSync } from 'fs';

// Map of styles (colors, thickness) and their ANSI escape codes
// used instead of the 'colors' package;
export const style = {
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
green: '\x1b[32m',
white: '\x1b[37m',
gray: '\x1b[90m',
reset: '\x1b[0m',
bold: '\x1b[1m',
underline: '\x1b[4m'
};

// The available colors
const colors = ['red', 'yellow', 'blue', 'gray', 'green'];

Expand Down Expand Up @@ -118,7 +132,11 @@ export const log = (...args) => {
if (logging.toConsole) {
console.log.apply(
undefined,
[prefix.toString()[logging.levelsDesc[newLevel - 1].color]].concat(texts)
[
`${style[logging.levelsDesc[newLevel - 1].color]}`,
prefix.toString(),
`${style.reset}`
].concat(texts)
);
}

Expand Down Expand Up @@ -168,11 +186,11 @@ export const logWithStack = (newLevel, error, customMessage) => {
if (logging.toConsole) {
console.log.apply(
undefined,
[prefix.toString()[logging.levelsDesc[newLevel - 1].color]].concat([
mainMessage[colors[newLevel - 1]],
'\n',
stackMessage
])
[
`${style[logging.levelsDesc[newLevel - 1].color]}`,
prefix.toString(),
`${style.reset}`
].concat([mainMessage[colors[newLevel - 1]], '\n', stackMessage])
);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { join } from 'path';
import { fileURLToPath } from 'url';

import { defaultConfig } from '../lib/schemas/config.js';
import { log, logWithStack } from './logger.js';
import { log, style, logWithStack } from './logger.js';

const MAX_BACKOFF_ATTEMPTS = 6;

Expand Down Expand Up @@ -327,8 +327,8 @@ export const printLogo = (noLogo) => {

// Print the logo
console.log(
readFileSync(__dirname + '/msg/startup.msg').toString().bold.yellow,
`v${packageVersion}\n`.bold
`${style.bold} ${style.yellow} ${readFileSync(__dirname + '/msg/startup.msg').toString()}`,
`${style.bold}v${packageVersion}${style.reset}\n`
);
};

Expand All @@ -342,9 +342,9 @@ export function printUsage() {

// Display readme information
console.log(
'\nUsage of CLI arguments:'.bold,
'\n------',
`\nFor more detailed information, visit the readme at: ${readme.bold.yellow}.`
`${style.bold}\nUsage of CLI arguments:${style.reset}
\n------',
\nFor more detailed information, visit the readme at: ${style.bold}${style.yellow}${readme}${style.reset}.`
);

const cycleCategories = (options) => {
Expand All @@ -366,7 +366,7 @@ export function printUsage() {
console.log(
descName,
option.description,
`[Default: ${option.value.toString().bold}]`.blue
`${style.blue}${style.bold}[Default: ${option.value.toString()}] ${style.reset}`
);
}
}
Expand Down
Loading