diff --git a/scripts/patchUrls.js b/scripts/patchUrls.js index 1be9be0c..b8524387 100644 --- a/scripts/patchUrls.js +++ b/scripts/patchUrls.js @@ -81,6 +81,36 @@ const getFiles = (directory) => { }; // getFiles +/** + * The function filters environment variables and returns only the important ones. + * + * @returns {object} + */ +const filterEnvVars = () => { + const vars = process.env; + const valid_keys = [ + "BASE_URL", + "MAIN_CDN", + "DOWNLOADS_CDN", + "API_ENDPOINT", + "USER_API_ENDPOINT", + "APPINSIGHTS_INSTRUMENTATIONKEY" + ] + const filteredVars = {} + + Object.keys(vars).forEach(key => { + // Check if it can be one of the vars to use. + valid_keys.forEach(valid_key => { + if(vars.hasOwnProperty(key) && key.includes(valid_key)) { + filteredVars[key] = vars[key] + } + }) + }) + + return filteredVars +} + + /** * Replaces placeholders formatted as `%key%` with environment * variables defined using the same key. @@ -94,18 +124,17 @@ const main = async () => { files = getFiles(directory), Replacements = { ...extractEnvVars(), - ...process.env + ...filterEnvVars() }; - console.log("+++ extractEnvVars():", extractEnvVars()) - console.log("+++ process.env:", process.env) - console.log("+++ Number of files =", files.length) + console.log("vars:", Replacements) + console.log("vars number:", Object.keys(Replacements).length) let counter = 0; for ( const file of files ) { counter += 1; - console.log(counter, " - ", file) + console.log(counter, " - processing file:", file) const tmpFile = `${ file }.tmp`;