Skip to content

Commit

Permalink
Merge pull request #448 from feature/370-forcefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
jszuminski authored Nov 27, 2023
2 parents 1933fd1 + 5060e51 commit 8c8b5ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ The format, with its default values are as follows (using the below ordering of
],
"scripts": [
"https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"
]
],
"forceFetch": false
},
"export": {
"infile": false,
Expand Down Expand Up @@ -273,6 +274,7 @@ These are set as variables in your environment. They take precedence over option
- `HIGHCHARTS_CORE_SCRIPTS`: Highcharts core scripts to fetch.
- `HIGHCHARTS_MODULES`: Highcharts modules to fetch.
- `HIGHCHARTS_INDICATORS`: Highcharts indicators to fetch.
- `HIGHCHARTS_FORCE_FETCH`: Should refetch all the scripts after each server rerun.

### Custom code config
- `HIGHCHARTS_ALLOW_CODE_EXECUTION`: If set to true, allow for the execution of arbitrary code when exporting.
Expand Down
18 changes: 9 additions & 9 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const extractVersion = () =>
/**
* Saves the Highcharts part of a config to a manifest file in the cache
*
* @param {object} config - Highcarts related configuration object.
* @param {object} config - Highcharts related configuration object.
* @param {object} fetchedModules - An object that contains mapped names of
* fetched Highcharts modules to use.
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ const fetchScript = async (script, proxyAgent) => {
/**
* Updates the Highcharts cache.
*
* @param {object} config - Highcarts related configuration object.
* @param {object} config - Highcharts related configuration object.
* @param {string} sourcePath - A path to the file where save updated sources.
* @return {object} An object that contains mapped names of fetched Highcharts
* modules to use.
Expand Down Expand Up @@ -202,7 +202,7 @@ export const updateVersion = async (newVersion) =>
/**
* Fetches any missing Highcharts and dependencies
*
* @param {object} config - Highcarts related configuration object.
* @param {object} config - Highcharts related configuration object.
*/
export const checkCache = async (config) => {
let fetchedModules;
Expand All @@ -218,8 +218,12 @@ export const checkCache = async (config) => {
// Create the .cache destination if it doesn't exist already
!existsSync(cachePath) && mkdirSync(cachePath);

// Load the .cache manifest
if (existsSync(manifestPath)) {
// Fetch all the scripts either if manifest.json does not exist
// or if the forceFetch option is enabled
if (!existsSync(manifestPath) || config.forceFetch) {
log(3, '[cache] Fetching and caching Highcharts dependencies.');
fetchedModules = await updateCache(config, sourcePath);
} else {
let requestUpdate = false;

// Read the manifest JSON
Expand Down Expand Up @@ -274,10 +278,6 @@ export const checkCache = async (config) => {
fetchedModules = manifest.modules;
extractVersion();
}
} else {
// So we don't have one yet, which means we need to fetch everything
log(3, '[cache] Fetching and caching Highcharts dependencies.');
fetchedModules = await updateCache(config, sourcePath);
}

// Finally, save the new manifest, which is basically our current config
Expand Down
13 changes: 13 additions & 0 deletions lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ export const defaultConfig = {
type: 'string[]',
description:
'Additional direct scripts/optional dependencies (e.g. moment.js).'
},
forceFetch: {
envLink: 'HIGHCHARTS_FORCE_FETCH',
value: false,
type: 'boolean',
description:
'Should all the scripts be refetched after rerunning the server.'
}
},
export: {
Expand Down Expand Up @@ -520,6 +527,12 @@ export const promptsConfig = {
message: 'Custom scripts',
initial: defaultConfig.highcharts.scripts.value.join(','),
separator: ','
},
{
type: 'toggle',
name: 'forceFetch',
message: 'Should refetch all the scripts after each server rerun',
initial: defaultConfig.highcharts.forceFetch.value
}
],
export: [
Expand Down

0 comments on commit 8c8b5ec

Please sign in to comment.