Skip to content

Commit

Permalink
Various config, linting and formatting corrections, touch #456.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed May 31, 2024
1 parent e175c5a commit 3dcfedd
Show file tree
Hide file tree
Showing 18 changed files with 9,127 additions and 608 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
dist/*
dist/
6 changes: 3 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
node: true
node: true,
es2024: true
},
root: true,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
Expand Down
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#### Expected behaviour


#### Actual behaviour

<!-- screenshots welcome! -->

#### Reproduction steps
<!-- Please describe how to reproduce the issue. -->

<!-- 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 -->

34 changes: 17 additions & 17 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x.x'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x.x'

- name: Install Dependencies
run: npm ci
- name: Install Dependencies
run: npm ci

- name: Build Project
run: npm run build
- name: Build Project
run: npm run build

- name: Commit and Push /dist Directory
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -f dist/
git commit -m "Build the dist files after merge."
git push -f
- name: Commit and Push /dist Directory
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -f dist/
git commit -m "Build the dist files after merge."
git push -f
2 changes: 1 addition & 1 deletion .github/workflows/eslint-check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ESLint check

on: [ pull_request ]
on: [pull_request]

jobs:
eslint:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Unit tests

on:
pull_request:
branches: [ master ]
branches: [master]

jobs:
testing:
Expand All @@ -23,4 +23,4 @@ jobs:
- name: Run unit tests
run: npm run unit:test
env:
CI: true
CI: true
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
npx lint-staged
npm run unit:test
3 changes: 2 additions & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"lib/**/\*.{js,json}": ["eslint", "npx prettier --write"]
"*.{js,ts}": ["npm run lint"],
"*.{json,css,md}": ["npm run format"]
}
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
samples/cli/infile_not_json.json
node_modules/
dist/*
README.md
dist/
7 changes: 4 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"endOfLine": "auto",
"tabWidth": 2,
"printWidth": 80,
"trailingComma": "none"
"semi": true,
"singleQuote": true
}
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ These variables are set in your environment and take precedence over options fro
- `OTHER_BROWSER_SHELL_MODE`: Decides whether to enable older but much more performant _shell_ mode for the browser (defaults to `true`).

### Debugging Config

- `DEBUG_ENABLE`: Enables or disables debug mode for the underlying browser (defaults to `false`).
- `DEBUG_HEADLESS`: Controls the mode in which the browser is launched when in the debug mode (defaults to `true`).
- `DEBUG_DEVTOOLS`: Decides whether to enable DevTools when the browser is in a headful state (defaults to `false`).
Expand Down Expand Up @@ -501,6 +502,7 @@ It is recommended to run the server using [pm2](https://www.npmjs.com/package/pm
## Available Endpoints

- POST

- `/`: An endpoint for exporting charts.
- `/:filename` - An endpoint for exporting charts with a specified filename parameter to save the chart to. The file will be downloaded with the _{filename}.{type}_ name (the `noDownload` must be set to **false**).
- `/change_hc_version/:newVersion`: An authenticated endpoint allowing the modification of the Highcharts version on the server through the use of a token.
Expand Down Expand Up @@ -585,25 +587,30 @@ This package supports both CommonJS and ES modules.
**highcharts-export-server module**

- `server`: The server instance which offers the following functions:

- `async startServer(serverConfig)`: The same as `startServer` described below.

- `{Object} serverConfig`: The server configuration object.

- `closeServers()`: Closes all servers associated with Express app instance.

- `getServers()`: Get all servers associated with Express app instance.

- `enableRateLimiting(limitConfig)`: Enable rate limiting for the server.

- `{Object} limitConfig`: Configuration object for rate limiting.

- `getExpress()`: Get the Express instance.

- `getApp()`: Get the Express app instance.

- `use(path, ...middlewares)`: Apply middleware(s) to a specific path.

- `{string} path`: The path to which the middleware(s) should be applied.
- `{...Function} middlewares`: The middleware functions to be applied.

- `get(path, ...middlewares)`: Set up a route with GET method and apply middleware(s).

- `{string} path`: The route path.
- `{...Function} middlewares`: The middleware functions to be applied.

Expand All @@ -612,55 +619,70 @@ This package supports both CommonJS and ES modules.
- `{...Function} middlewares`: The middleware functions to be applied.

- `async startServer(serverConfig)`: Starts an HTTP server based on the provided configuration. The `serverConfig` object contains all server related properties (see the `server` section in the `lib/schemas/config.js` file for a reference).

- `{Object} serverConfig`: The server configuration object.

- `async initExport(options)`: Initializes the export process. Tasks such as configuring logging, checking cache and sources, and initializing the pool of resources happen during this stage. Function that is required to be called before trying to export charts or setting a server. The `options` is an object that contains all options.

- `{Object} options`: All export options.

- `async singleExport(options)`: Starts a single export process based on the specified options. Runs the `startExport` underneath.

- `{Object} options`: The options object containing configuration for a single export.

- `async batchExport(options)`: Starts a batch export process for multiple charts based on the information in the batch option. The batch is a string in the following format: `"infile1.json=outfile1.png;infile2.json=outfile2.png;..."`. Runs the `startExport` underneath.

- `{Object} options`: The options object containing configuration for a batch export.

- `async startExport(settings, endCallback)`: Starts an export process. The `settings` contains final options gathered from all possible sources (config, env, cli, json). The `endCallback` is called when the export is completed, with an error object as the first argument and the second containing the base64 respresentation of a chart.

- `{Object} settings`: The settings object containing export configuration.
- `{function} endCallback`: The callback function to be invoked upon finalizing work or upon error occurance of the exporting process.

- `async initPool(config)`: Initializes the export pool with the provided configuration, creating a browser instance and setting up worker resources.

- `{Object} config`: Configuration options for the export pool along with custom puppeteer arguments for the puppeteer.launch function.

- `async killPool()`: Kills all workers in the pool, destroys the pool, and closes the browser instance.

- `setOptions(userOptions, args)`: Initializes and sets the general options for the server instace, keeping the principle of the options load priority. It accepts optional userOptions and args from the CLI.

- `{Object} userOptions`: User-provided options for customization.
- `{Array} args`: Command-line arguments for additional configuration (CLI usage).

- `async shutdownCleanUp(exitCode)`: Clean up function to trigger before ending process for the graceful shutdown.

- `{number} exitCode`: An exit code for the process.exit() function.

- `log(...args)`: Logs a message. Accepts a variable amount of arguments. Arguments after `level` will be passed directly to console.log, and/or will be joined and appended to the log file.

- `{any} args`: An array of arguments where the first is the log level and the rest are strings to build a message with.

- `logWithStack(newLevel, error, customMessage)`: Logs an error message with its stack trace. Optionally, a custom message can be provided.

- `{number} newLevel`: The log level.
- `{Error} error`: The error object.
- `{string} customMessage`: An optional custom message to be logged along with the error.

- `setLogLevel(newLevel)`: Sets the log level to the specified value. Log levels are (0 = no logging, 1 = error, 2 = warning, 3 = notice, 4 = verbose or 5 = benchmark).

- `{number} newLevel`: The new log level to be set.

- `enableFileLogging(logDest, logFile)`: Enables file logging with the specified destination and log file.

- `{string} logDest`: The destination path for log files.
- `{string} logFile`: The log file name.

- `mapToNewConfig(oldOptions)`: Maps old-structured (PhantomJS) options to a new configuration format (Puppeteer).

- `{Object} oldOptions`: Old-structured options to be mapped.

- `async manualConfig(configFileName)`: Allows manual configuration based on specified prompts and saves the configuration to a file.

- `{string} configFileName`: The name of the configuration file.

- `printLogo(noLogo)`: Prints the Highcharts Export Server logo and version information.

- `{boolean} noLogo`: If **true**, only prints version information without the logo.

- `printUsage()`: Prints the usage information for CLI arguments. If required, it can list properties recursively.
Expand Down Expand Up @@ -696,12 +718,14 @@ If you depend on any of the above options, the optimal approach is to directly c
If you need to set the `height` or `width` of the chart, it can be done in two ways:

Set it in the `chart` config under:
- [`chart.height`](https://api.highcharts.com/highcharts/chart.height).
- [`chart.width`](https://api.highcharts.com/highcharts/chart.width).

- [`chart.height`](https://api.highcharts.com/highcharts/chart.height).
- [`chart.width`](https://api.highcharts.com/highcharts/chart.width).

Set it in the `exporting` config under:
- [`exporting.sourceHeight`](https://api.highcharts.com/highcharts/exporting.sourceHeight).
- [`exporting.sourceWidth`](https://api.highcharts.com/highcharts/exporting.sourceWidth).

- [`exporting.sourceHeight`](https://api.highcharts.com/highcharts/exporting.sourceHeight).
- [`exporting.sourceWidth`](https://api.highcharts.com/highcharts/exporting.sourceWidth).

The latter is preferred, as it allows you to set separate sizing when exporting and when displaying the chart on your web page.

Expand Down
2 changes: 1 addition & 1 deletion install.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const pkgFile = JSON.parse(readFileSync(join(__dirname, 'package.json')));

console.log(
`
Highcharts Export Server V${pkgFile.version}
Highcharts Export Server v${pkgFile.version}
${'This software requires a valid Highcharts license for commercial use.'.yellow}
Expand Down
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"restartable": "rs",
"ext": ".ts,.js,.json",
"watch": ["bin/", "lib/"],
"ignore": ["node_modules/**/node_modules"]
"ignore": ["node_modules/", "node_modules/**/node_modules"]
}
Loading

0 comments on commit 3dcfedd

Please sign in to comment.