Skip to content

Commit

Permalink
add way to manage basename in cmf.merge
Browse files Browse the repository at this point in the history
  • Loading branch information
smouillour committed Sep 6, 2024
1 parent 5f0acd2 commit 25af3ef
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/scripts-cmf/cmf-settings.merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ function getCmfconfig(cmfconfigPath, onError) {
return cmfconfig;
}

function addBasenameToHref(obj, basename) {
if (typeof obj === 'object' && obj !== null && basename) {
Object.entries(obj).forEach(([key, value]) => {
if (key === 'href' && typeof value === 'string') {
// eslint-disable-next-line no-param-reassign
obj[key] = `${basename}${value}`;
} else {
addBasenameToHref(value, basename);
}
});
}
}

/**
* merge write a json settings file for CMF ready to be served
* @param {Object} options
Expand Down Expand Up @@ -88,6 +101,10 @@ function merge(options, errorCallback, writeToFs = true) {
overrideActions(id, settings);
});
}

if (process.env.BASENAME) {
addBasenameToHref(settings, process.env.BASENAME);
}
}

// extract all keys from a folder
Expand Down

0 comments on commit 25af3ef

Please sign in to comment.