Skip to content

Commit

Permalink
Merge branch 'enhancement/websockets' into enhancement/resource-perfo…
Browse files Browse the repository at this point in the history
…rmance-and-memory
  • Loading branch information
PaulDalek authored Feb 3, 2025
2 parents cc1b4c6 + b260d43 commit 8b73b4c
Show file tree
Hide file tree
Showing 102 changed files with 4,931 additions and 4,621 deletions.
6 changes: 4 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PUPPETEER_ARGS =

# HIGHCHARTS CONFIG
HIGHCHARTS_VERSION = latest
HIGHCHARTS_CDN_URL = https://code.highcharts.com/
HIGHCHARTS_CDN_URL = https://code.highcharts.com
HIGHCHARTS_FORCE_FETCH = false
HIGHCHARTS_CACHE_PATH = .cache
HIGHCHARTS_ADMIN_TOKEN =
Expand All @@ -17,6 +17,7 @@ EXPORT_INFILE =
EXPORT_INSTR =
EXPORT_OPTIONS =
EXPORT_SVG =
EXPORT_BATCH =
EXPORT_OUTFILE =
EXPORT_TYPE = png
EXPORT_CONSTR = chart
Expand All @@ -30,7 +31,6 @@ EXPORT_DEFAULT_WIDTH = 600
EXPORT_DEFAULT_SCALE = 1
EXPORT_GLOBAL_OPTIONS =
EXPORT_THEME_OPTIONS =
EXPORT_BATCH =
EXPORT_RASTERIZATION_TIMEOUT = 1500

# CUSTOM LOGIC CONFIG
Expand All @@ -46,6 +46,7 @@ CUSTOM_LOGIC_CREATE_CONFIG =
SERVER_ENABLE = false
SERVER_HOST = 0.0.0.0
SERVER_PORT = 7801
SERVER_UPLOAD_LIMIT = 3
SERVER_BENCHMARKING = false

# SERVER PROXY CONFIG
Expand Down Expand Up @@ -99,6 +100,7 @@ OTHER_NO_LOGO = false
OTHER_HARD_RESET_PAGE = false
OTHER_BROWSER_SHELL_MODE = true
OTHER_CONNECTION_OVER_PIPE = false
OTHER_VALIDATION = true

# DEBUG CONFIG
DEBUG_ENABLE = false
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

<!-- Please describe how to reproduce the issue. -->
<!-- If you can, please include a curl fetch that demonstrates the issue, e.g. -->
<!-- curl -H "Content-Type: application/json" -X POST -d '{"infile":{ <CHART OPTIONS HERE> }' 127.0.0.1:7801 -o mychart.png -->
<!-- curl -H "Content-Type: application/json" -X POST -d '{"options":{ <CHART OPTIONS HERE> }' 127.0.0.1:7801 -o mychart.png -->
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Highcharts Export Server

Copyright (c) 2016-2024, Highsoft
Copyright (c) 2016-2025, Highsoft

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
277 changes: 165 additions & 112 deletions README.md

Large diffs are not rendered by default.

106 changes: 61 additions & 45 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Highcharts Export Server
Copyright (c) 2016-2024, Highsoft
Copyright (c) 2016-2025, Highsoft
Licenced under the MIT licence.
Expand All @@ -16,107 +16,123 @@ See LICENSE file in root for details.
/**
* @overview This module serves as the entry point for the Highcharts Export
* Server. It provides functionality for starting the server, performing batch
* or single chart exports, and managing configuration options. It supports both
* CLI and server-based usage, allowing flexible integration for generating
* Highcharts exports in various environments.
* or single chart exports, managing manual configuration options through
* the prompts functionality, and updating options with values from the passed
* CLI arguments. It supports both CLI and server-based usage, enabling
* integration for generating Highcharts exports in various environments.
*/

import { singleExport, batchExport } from '../lib/chart.js';
import { setOptions } from '../lib/config.js';
import { batchExport, singleExport } from '../lib/chart.js';
import { setCliOptions } from '../lib/config.js';
import { initExport } from '../lib/index.js';
import { printInfo, printUsage } from '../lib/info.js';
import { log, logWithStack } from '../lib/logger.js';
import { manualConfig } from '../lib/prompt.js';
import { shutdownCleanUp } from '../lib/resourceRelease.js';
import { printLicense, printVersion } from '../lib/utils.js';
import { printUsage } from '../lib/schemas/config.js';

import { startServer } from '../lib/server/server.js';

import ExportError from '../lib/errors/ExportError.js';

/**
* The primary function to initiate the server or perform the direct export.
* Logs an error if it occurs during the execution and gracefully shut down
* The primary function to initiate the server or perform the direct CLI export.
* Logs an error if it occurs during the execution and gracefully shuts down
* the process.
*
* @async
* @function start
*
* @throws {ExportError} Throws an `ExportError` if no valid options are
* provided.
* @returns {Promise<void>} A Promise that resolves when the function execution
* ends after displaying the logo with license and version information, showing
* the CLI usage details, or triggering manual configuration using the prompts
* functionality.
*
* @throws {ExportError} Throws an `ExportError` if no valid options
* are provided.
*/
async function start() {
try {
// Get the CLI arguments
const args = process.argv;

// Display license information if requested
if (['-v', '--v'].includes(args[args.length - 1])) {
// Print logo with the version and license information
return printLicense();
// If no arguments are supplied
if (args.length <= 2) {
// Print logo with version and license information
printInfo();
log(
2,
'[cli] The number of provided arguments is too small. Please refer to the help section (use --h or --help command).'
);
return;
}

// Display help information if requested
if (['-h', '--h', '-help', '--help'].includes(args[args.length - 1])) {
// Print CLI usage information
return printUsage();
// Display version and license information if requested
if (['-v', '--v'].some((a) => args.includes(a))) {
// Print logo with version and license information
printInfo();
return;
}

// Print CLI usage information if no arguments supplied
if (args.length <= 2) {
// Display help information if requested
if (['-h', '--h', '-help', '--help'].some((a) => args.includes(a))) {
// Print CLI usage information
printUsage();
return log(
2,
'[cli] The number of provided arguments is too small. Please refer to the help section above.'
);
return;
}

// Set the options, keeping the priority order of setting values:
// 1. Options from the `lib/schemas/config.js` file
// 2. Options from a custom JSON file (loaded by the `loadConfig` argument)
// 3. Options from the environment variables (the `.env` file)
// 4. Options from the CLI
const options = setOptions(null, args, true);
// Set the options from CLI, keeping the priority order of setting values
const options = setCliOptions(args);

// If all options correctly parsed
// If all options are correctly parsed
if (options) {
// Print initial logo or text with the version
printVersion(options.other.noLogo);
// Print initial logo or text with the version information
printInfo(options.other.noLogo, true);

// In this case we want to prepare config manually
if (options.customLogic.createConfig) {
return manualConfig(options.customLogic.createConfig);
manualConfig(
options.customLogic.createConfig,
options.customLogic.allowCodeExecution
);
return;
}

// Start server
if (options.server.enable) {
// Init the export mechanism for the server configuration
await initExport(options);
await initExport();

// Run the server
await startServer(options.server);
await startServer();
} else {
// Perform batch exports
if (options.export.batch) {
// Init a pool for the batch exports
await initExport(options);
// Init the export mechanism for batch exports
await initExport();

// Start batch exports
await batchExport(options);
await batchExport({
export: options.export,
customLogic: options.customLogic
});
} else {
// No need for multiple workers in case of a single CLI export
options.pool.minWorkers = 1;
options.pool.maxWorkers = 1;

// Init a pool for one export
await initExport(options);
// Init the export mechanism for a single export
await initExport();

// Start a single export
await singleExport(options);
await singleExport({
export: options.export,
customLogic: options.customLogic
});
}
}
} else {
throw new ExportError(
'[cli] No valid options provided. Please check your input and try again.',
'[cli] No valid options found. Please check your input and try again.',
400
);
}
Expand Down
2 changes: 0 additions & 2 deletions dist/index.cjs

This file was deleted.

2 changes: 0 additions & 2 deletions dist/index.esm.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.esm.js.map

This file was deleted.

Loading

0 comments on commit 8b73b4c

Please sign in to comment.