diff --git a/downstream.js b/downstream.js new file mode 100755 index 0000000..985b4b2 --- /dev/null +++ b/downstream.js @@ -0,0 +1,97 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const path = require('path'); + +const constantsPath = path.join('src', 'constants', 'links.ts'); +const localesPath = path.join('locales'); +const localeFile = path.join(localesPath, 'en', 'plugin__kuadrant-console-plugin.json'); + +const upstreamName = 'Kuadrant'; +const downstreamName = 'Connectivity Link'; + +const upstreamDocumentation = 'https://docs.kuadrant.io'; +const upstreamReleaseNotes = 'https://github.com/Kuadrant/kuadrant-operator/releases'; +const upstreamQuickStarts = + 'https://docs.kuadrant.io/latest/kuadrant-operator/doc/user-guides/secure-protect-connect/'; +const upstreamHighlights = 'https://kuadrant.io/blog/'; + +const downstreamDocumentation = + 'https://docs.redhat.com/en/documentation/red_hat_connectivity_link/1.0'; +const downstreamReleaseNotes = + 'https://docs.kuadrant.io/html-single/release_notes_for_connectivity_link_1.0/index'; +const downstreamQuickStarts = + 'https://docs.redhat.com/latest/red-hat-connectivity-link/doc/user-guides/secure-protect-connect/'; // Example +const downstreamHighlights = 'https://connectivity-link.io/blog/'; // Example + +const isUpstream = process.argv.includes('--upstream'); + +const nameToReplace = isUpstream ? downstreamName : upstreamName; +const nameToInsert = isUpstream ? upstreamName : downstreamName; +const docsLinkToReplace = isUpstream ? downstreamDocumentation : upstreamDocumentation; +const docsLinkToInsert = isUpstream ? upstreamDocumentation : downstreamDocumentation; +const releaseNotesToReplace = isUpstream ? downstreamReleaseNotes : upstreamReleaseNotes; +const releaseNotesToInsert = isUpstream ? upstreamReleaseNotes : downstreamReleaseNotes; +const quickStartsToReplace = isUpstream ? downstreamQuickStarts : upstreamQuickStarts; +const quickStartsToInsert = isUpstream ? upstreamQuickStarts : downstreamQuickStarts; +const highlightsToReplace = isUpstream ? downstreamHighlights : upstreamHighlights; +const highlightsToInsert = isUpstream ? upstreamHighlights : downstreamHighlights; + +function updateJsonValues(filePath, searchValue, replaceValue) { + try { + const content = fs.readFileSync(filePath, 'utf-8'); + const jsonContent = JSON.parse(content); + + let updated = false; + + Object.keys(jsonContent).forEach((key) => { + if (jsonContent[key].includes(searchValue)) { + jsonContent[key] = jsonContent[key].replace(new RegExp(searchValue, 'g'), replaceValue); + updated = true; + } + }); + + if (updated) { + fs.writeFileSync(filePath, JSON.stringify(jsonContent, null, 2)); + console.log(`Updated values in ${filePath}`); + } else { + console.log(`No changes made to ${filePath}`); + } + } catch (error) { + console.error(`Failed to update ${filePath}: ${error}`); + } +} + +function updateFileContent(filePath, replacements) { + try { + let content = fs.readFileSync(filePath, 'utf-8'); + let updatedContent = content; + + replacements.forEach(({ searchValue, replaceValue }) => { + updatedContent = updatedContent.replace(new RegExp(searchValue, 'g'), replaceValue); + }); + + if (content !== updatedContent) { + fs.writeFileSync(filePath, updatedContent); + console.log(`Updated content in ${filePath}`); + } else { + console.log(`No changes made to ${filePath}`); + } + } catch (error) { + console.error(`Failed to update ${filePath}: ${error}`); + } +} + +console.log(`Updating locale files to ${isUpstream ? 'upstream' : 'downstream'}...`); +updateJsonValues(localeFile, nameToReplace, nameToInsert); + +console.log(`Updating constants.links.ts to ${isUpstream ? 'upstream' : 'downstream'}...`); + +updateFileContent(constantsPath, [ + { searchValue: docsLinkToReplace, replaceValue: docsLinkToInsert }, + { searchValue: releaseNotesToReplace, replaceValue: releaseNotesToInsert }, + { searchValue: quickStartsToReplace, replaceValue: quickStartsToInsert }, + { searchValue: highlightsToReplace, replaceValue: highlightsToInsert }, +]); + +console.log('Update complete!'); diff --git a/package.json b/package.json index 29f52f1..f599bcb 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,9 @@ "cypress-merge": "mochawesome-merge ./integration-tests/screenshots/cypress_report*.json > ./integration-tests/screenshots/cypress.json", "cypress-generate": "marge -o ./integration-tests/screenshots/ -f cypress-report -t 'Kuadrant OpenShift Console Plugin Cypress Test Results' -p 'OpenShift Cypress Plugin Template Test Results' --showPassed false --assetsDir ./integration-tests/screenshots/cypress/assets ./integration-tests/screenshots/cypress.json", "cypress-postreport": "yarn cypress-merge && yarn cypress-generate", - "webpack": "node -r ts-node/register ./node_modules/.bin/webpack" + "webpack": "node -r ts-node/register ./node_modules/.bin/webpack", + "downstream-replacements": "node downstream.js && yarn i18n && yarn lint", + "upstream-replacements": "node downstream.js --upstream && yarn i18n && yarn lint" }, "devDependencies": { "@cypress/webpack-preprocessor": "^5.15.5",