Skip to content

Commit

Permalink
parse care app env in care config
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar committed Jan 27, 2025
1 parent 2e1af39 commit a5b3417
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
30 changes: 25 additions & 5 deletions care.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,31 @@ const careConfig = {
},

careApps: env.REACT_ENABLED_APPS
? env.REACT_ENABLED_APPS.split(",").map((app) => ({
branch: app.split("@")[1],
name: app.split("@")[0].split("/")[1],
package: app.split("@")[0],
}))
? env.REACT_ENABLED_APPS.split(",").map((app) => {
const [module, cdn] = app.split("@");
const [org, repo] = module.split("/");

if (!org || !repo) {
throw new Error(
`Invalid plug configuration: ${module}. Expected 'org/repo@url'.`,
);
}

let url = "";
if (!cdn) {
url = `https://${org}.github.io/${repo}`;
}

if (!url.startsWith("http")) {
url = `${cdn.includes("localhost") ? "http" : "https"}://${cdn}`;
}

return {
url: new URL(url).toString(),
name: repo,
package: module,
};
})
: [],

plotsConfigUrl:
Expand Down
20 changes: 1 addition & 19 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,8 @@ export const LANGUAGES = {
hi: "हिन्दी",
} as const;

function toURL(input: string) {
input = input.trim();
if (!input.startsWith("http://") && !input.startsWith("https://")) {
if (input.startsWith("localhost")) {
return `http://${input}`;
} else {
return `https://${input}`;
}
}
return input;
}

const namespaceToUrl = (namespace: string) => {
const careApp = careConfig.careApps.find((app) => app.name === namespace);

if (!careApp) {
return "";
}

return toURL(careApp.branch);
return careConfig.careApps.find((app) => app.name === namespace)?.url ?? "";
};

i18n
Expand Down

0 comments on commit a5b3417

Please sign in to comment.