Skip to content

Commit

Permalink
Renamed core, modules and indicators for better understanding.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed Apr 11, 2024
1 parent 7e65874 commit 0947f26
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 37 deletions.
6 changes: 3 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# HIGHCHARTS CONFIG
HIGHCHARTS_VERSION = latest
HIGHCHARTS_CDN_URL = https://code.highcharts.com/
HIGHCHARTS_CORE =
HIGHCHARTS_MODULES =
HIGHCHARTS_INDICATORS =
HIGHCHARTS_CORE_SCRIPTS =
HIGHCHARTS_MODULE_SCRIPTS =
HIGHCHARTS_INDICATOR_SCRIPTS =
HIGHCHARTS_FORCE_FETCH = false
HIGHCHARTS_CACHE_PATH =
HIGHCHARTS_ADMIN_TOKEN =
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _Enhancements:_
- Added a new logging level (`5`) for benchmarking logs.
- Added legacy names of options to the `defaultConfig` and `mapToNewConfig` function in order to support the old, PhantomJS-based structure of options.
- Reordered the `error` and `info` arguments in the callback of the `startExport` function.
- Renamed the `HIGHCHARTS_CORE_SCRIPTS` environment variable to `HIGHCHARTS_CORE`.
- Renamed the `HIGHCHARTS_MODULES` and `HIGHCHARTS_INDICATORS` environment variables respectively to `HIGHCHARTS_MODULE_SCRIPTS` and `HIGHCHARTS_INDICATOR_SCRIPTS`.
- Renamed the `scripts` property of the config options to `customScripts`.
- Renamed the `initPool` function to `initExport` in the main module.
- Renamed the `init` function to `initPool` in the pool module.
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ There are four main ways of loading configurations:

The JSON below represents the default configuration stored in the `lib/schemas/config.js` file. If no `.env` file is found (more details on the file and environment variables below), these options will be used.

The format, along with its default values, is as follows (using the recommended ordering of core scripts and modules below):
The format, along with its default values, is as follows (using the recommended ordering of core and module scripts below):

```
{
Expand All @@ -97,12 +97,12 @@ The format, along with its default values, is as follows (using the recommended
"highcharts": {
"version": "latest",
"cdnURL": "https://code.highcharts.com/",
"core": [
"coreScripts": [
"highcharts",
"highcharts-more",
"highcharts-3d"
],
"modules": [
"moduleScripts": [
"stock",
"map",
"gantt",
Expand Down Expand Up @@ -167,7 +167,7 @@ The format, along with its default values, is as follows (using the recommended
"heikinashi",
"flowmap"
],
"indicators": [
"indicatorScripts": [
"indicators-all"
],
"customScripts": [
Expand Down Expand Up @@ -267,9 +267,9 @@ These variables are set in your environment and take precedence over options fro

- `HIGHCHARTS_VERSION`: Highcharts version to use (defaults to `latest`).
- `HIGHCHARTS_CDN_URL`: Highcharts CDN URL of scripts to be used (defaults to `https://code.highcharts.com/`).
- `HIGHCHARTS_CORE`: Highcharts core scripts to fetch (defaults to ``).
- `HIGHCHARTS_MODULES`: Highcharts modules to fetch (defaults to ``).
- `HIGHCHARTS_INDICATORS`: Highcharts indicators to fetch (defaults to ``).
- `HIGHCHARTS_CORE_SCRIPTS`: Highcharts core scripts to fetch (defaults to ``).
- `HIGHCHARTS_MODULE_SCRIPTS`: Highcharts module scripts to fetch (defaults to ``).
- `HIGHCHARTS_INDICATOR_SCRIPTS`: Highcharts indicator scripts to fetch (defaults to ``).
- `HIGHCHARTS_FORCE_FETCH`: The flag that determines whether to refetch all scripts after each server rerun (defaults to `false`).
- `HIGHCHARTS_CACHE_PATH`: In which directory should the fetched Highcharts scripts be placed (defaults to `.cache`).
- `HIGHCHARTS_ADMIN_TOKEN`: An authentication token that is required to switch the Highcharts version on the server at runtime (defaults to ``).
Expand Down
15 changes: 9 additions & 6 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,16 @@ export const updateCache = async (
const fetchedModules = {};
try {
cache.sources = await fetchScripts(
[...highchartsOptions.core.map((c) => `${cdnURL}${hcVersion}${c}`)],
[
...highchartsOptions.modules.map((m) =>
...highchartsOptions.coreScripts.map((c) => `${cdnURL}${hcVersion}${c}`)
],
[
...highchartsOptions.moduleScripts.map((m) =>
m === 'map'
? `${cdnURL}maps/${hcVersion}modules/${m}`
: `${cdnURL}${hcVersion}modules/${m}`
),
...highchartsOptions.indicators.map(
...highchartsOptions.indicatorScripts.map(
(i) => `${cdnURL}stock/${hcVersion}indicators/${i}`
)
],
Expand Down Expand Up @@ -333,8 +335,9 @@ export const checkAndUpdateCache = async (options) => {
manifest.modules = moduleMap;
}

const { modules, core, indicators } = highcharts;
const numberOfModules = modules.length + core.length + indicators.length;
const { coreScripts, moduleScripts, indicatorScripts } = highcharts;
const numberOfModules =
coreScripts.length + moduleScripts.length + indicatorScripts.length;

// Compare the loaded highcharts config with the contents in cache.
// If there are changes, fetch requested modules and products,
Expand All @@ -353,7 +356,7 @@ export const checkAndUpdateCache = async (options) => {
requestUpdate = true;
} else {
// Check each module, if anything is missing refetch everything
requestUpdate = (highcharts.modules || []).some((moduleName) => {
requestUpdate = (moduleScripts || []).some((moduleName) => {
if (!manifest.modules[moduleName]) {
log(
2,
Expand Down
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export const manualConfig = async (configFileName) => {

await prompts(allQuestions, {
onSubmit: async (prompt, answer) => {
// Get the default modules
if (prompt.name === 'modules') {
// Get the default module scripts
if (prompt.name === 'moduleScripts') {
answer = answer.length
? answer.map((module) => prompt.choices[module])
: prompt.choices;
Expand Down
6 changes: 3 additions & 3 deletions lib/envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export const Config = z.object({
})
)
.transform((value) => (value !== '' ? value : undefined)),
HIGHCHARTS_CORE: v.array(scriptsNames.core),
HIGHCHARTS_MODULES: v.array(scriptsNames.modules),
HIGHCHARTS_INDICATORS: v.array(scriptsNames.indicators),
HIGHCHARTS_CORE_SCRIPTS: v.array(scriptsNames.core),
HIGHCHARTS_MODULE_SCRIPTS: v.array(scriptsNames.modules),
HIGHCHARTS_INDICATOR_SCRIPTS: v.array(scriptsNames.indicators),
HIGHCHARTS_FORCE_FETCH: v.boolean(),
HIGHCHARTS_CACHE_PATH: v.string(),
HIGHCHARTS_ADMIN_TOKEN: v.string(),
Expand Down
16 changes: 8 additions & 8 deletions lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@ export const defaultConfig = {
envLink: 'HIGHCHARTS_CDN_URL',
description: 'The CDN URL for Highcharts scripts to be used.'
},
core: {
coreScripts: {
value: scriptsNames.core,
type: 'string[]',
envLink: 'HIGHCHARTS_CORE',
envLink: 'HIGHCHARTS_CORE_SCRIPTS',
description: 'The core Highcharts scripts to fetch.'
},
modules: {
moduleScripts: {
value: scriptsNames.modules,
type: 'string[]',
envLink: 'HIGHCHARTS_MODULES',
envLink: 'HIGHCHARTS_MODULE_SCRIPTS',
description: 'The modules of Highcharts to fetch.'
},
indicators: {
indicatorScripts: {
value: scriptsNames.indicators,
type: 'string[]',
envLink: 'HIGHCHARTS_INDICATORS',
envLink: 'HIGHCHARTS_INDICATOR_SCRIPTS',
description: 'The indicators of Highcharts to fetch.'
},
customScripts: {
Expand Down Expand Up @@ -599,10 +599,10 @@ export const promptsConfig = {
},
{
type: 'multiselect',
name: 'modules',
name: 'moduleScripts',
message: 'Available modules',
instructions: 'Space: Select specific, A: Select all, Enter: Confirm.',
choices: defaultConfig.highcharts.modules.value
choices: defaultConfig.highcharts.moduleScripts.value
},
{
type: 'list',
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/envs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ describe('Environment variables should be correctly parsed', () => {
expect(() => Config.partial().parse(env)).toThrow();
});

test('CORE, MODULES, INDICATORS scripts should be arrays', () => {
test('CORE, MODULE, INDICATOR scripts should be arrays', () => {
const env = {
HIGHCHARTS_CORE: 'core1, core2, highcharts',
HIGHCHARTS_MODULES: 'module1, map, module2',
HIGHCHARTS_INDICATORS: 'indicators-all, indicator1, indicator2'
HIGHCHARTS_CORE_SCRIPTS: 'core1, core2, highcharts',
HIGHCHARTS_MODULE_SCRIPTS: 'module1, map, module2',
HIGHCHARTS_INDICATOR_SCRIPTS: 'indicators-all, indicator1, indicator2'
};

const parsed = Config.partial().parse(env);

expect(parsed.HIGHCHARTS_CORE).toEqual(['highcharts']);
expect(parsed.HIGHCHARTS_MODULES).toEqual(['map']);
expect(parsed.HIGHCHARTS_INDICATORS).toEqual(['indicators-all']);
expect(parsed.HIGHCHARTS_CORE_SCRIPTS).toEqual(['highcharts']);
expect(parsed.HIGHCHARTS_MODULE_SCRIPTS).toEqual(['map']);
expect(parsed.HIGHCHARTS_INDICATOR_SCRIPTS).toEqual(['indicators-all']);
});

test('HIGHCHARTS_FORCE_FETCH should be a boolean', () => {
Expand Down

0 comments on commit 0947f26

Please sign in to comment.