Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed Jan 5, 2025
2 parents 046ce23 + 1423166 commit 2468e10
Show file tree
Hide file tree
Showing 76 changed files with 3,311 additions and 2,916 deletions.
5 changes: 3 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
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
208 changes: 131 additions & 77 deletions README.md

Large diffs are not rendered by default.

61 changes: 34 additions & 27 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 @@ -22,69 +22,76 @@ See LICENSE file in root for details.
*/

import { singleExport, batchExport } from '../lib/chart.js';
import { setOptions } from '../lib/config.js';
import {
printLicense,
printUsage,
printVersion,
setOptions
} from '../lib/config.js';
import { initExport } from '../lib/index.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
* 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 to ending the function
* execution when displaying license, version, or usage information, or when
* 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();
// Display version and license information if requested
if (['-v', '--v'].some((a) => args.includes(a))) {
// Print logo with version and license information
printLicense();
return;
}

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

// Print CLI usage information if no arguments supplied
// Print CLI usage information if no arguments are supplied
if (args.length <= 2) {
printUsage();
return log(
printVersion();
log(
2,
'[cli] The number of provided arguments is too small. Please refer to the help section above.'
'[cli] The number of provided arguments is too small. Please refer to the help section (use --h or --help command).'
);
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, keeping the priority order of setting values
const options = setOptions({}, args, true);

// 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);

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

// Start server
Expand All @@ -97,7 +104,7 @@ async function start() {
} else {
// Perform batch exports
if (options.export.batch) {
// Init a pool for the batch exports
// Init the export mechanism for batch exports
await initExport(options);

// Start batch exports
Expand All @@ -107,7 +114,7 @@ async function start() {
options.pool.minWorkers = 1;
options.pool.maxWorkers = 1;

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

// Start a single export
Expand Down
4 changes: 2 additions & 2 deletions dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 2468e10

Please sign in to comment.