Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

downstream script #133

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions downstream.js
Original file line number Diff line number Diff line change
@@ -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!');
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading