Skip to content

Commit

Permalink
Merge pull request #13 from IgniteUI/mkirova/react-verison-config
Browse files Browse the repository at this point in the history
Add versioning handling for react.
  • Loading branch information
dkamburov authored Oct 30, 2023
2 parents ca3e704 + b17787b commit 60165c9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
42 changes: 42 additions & 0 deletions react.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"en": {
"development": {
"url": "https://dev.infragistics.com",
"gaID": "GTM-WLXLBZD",
"versions": "https://staging.infragistics.com/react-docs/react-api-docs-versions.json",
"typedoc_default_url": "https://staging.infragistics.com/products/ignite-ui-react/api/docs/typescript/latest/"
},
"staging": {
"url": "https://staging.infragistics.com",
"gaID": "GTM-NCKNPN",
"versions": "https://staging.infragistics.com/react-docs/react-api-docs-versions.json",
"typedoc_default_url": "https://staging.infragistics.com/products/ignite-ui-react/api/docs/typescript/latest/"
},
"production": {
"url": "https://www.infragistics.com",
"gaID": "GTM-T65CF7",
"versions": "https://www.infragistics.com/react-docs/react-api-docs-versions-prod.json",
"typedoc_default_url": "https://www.infragistics.com/products/ignite-ui-react/api/docs/typescript/latest/"
}
},
"jp": {
"development": {
"url": "https://jp.dev.infragistics.com",
"gaID": "GTM-NNHVMC7",
"versions": "https://jp.staging.infragistics.com/react-docs/react-api-docs-versions-jp.json",
"typedoc_default_url": "https://jp.staging.infragistics.com/products/ignite-ui-react/api/docs/typescript/latest/"
},
"staging": {
"url": "https://jp.staging.infragistics.com",
"gaID": "GTM-WLWSDK",
"versions": "https://jp.staging.infragistics.com/react-docs/react-api-docs-versions-jp.json",
"typedoc_default_url": "https://jp.staging.infragistics.com/products/ignite-ui-react/api/docs/typescript/latest/"
},
"production": {
"url": "https://jp.infragistics.com",
"gaID": "GTM-KVNSWJ",
"versions": "https://jp.infragistics.com/react-docs/react-api-docs-versions-prod-jp.json",
"typedoc_default_url": "https://jp.infragistics.com/products/ignite-ui-react/api/docs/typescript/latest/"
}
}
}
12 changes: 5 additions & 7 deletions src/assets/js/src/versioning/tag-versions.req.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(function () {
let baseUrl = $('body').data('base-url');
const versionsJson = $('body').data('api-versions-json');

const defaultUrl = $('body').data('default-url');
$.ajax({
url: versionsJson,
type: "get",
Expand All @@ -14,20 +13,19 @@
const select = $('#versions');

folders = folders.reverse();

baseUrl += "/products/ignite-ui-angular/docs/";
folders.forEach(function (f) {
const versionUrl = defaultUrl.replace("typescript/latest'", f + "/typescript")
select.append($('<option>', {
value: baseUrl + f + "/typescript",
value: versionUrl,
text: f
}));
});

const version = folders.filter(function(v){ return window.location.href.indexOf(v) >= 0;})[0];
if (version) {
select.val(baseUrl + version + "/typescript");
select.val(versionUrl);
} else {
select.val(baseUrl + folders[0] + "/typescript");
select.val(versionUrl);
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/layouts/default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const defaultLayout = (context: DefaultThemeRenderContext, props: PageEve
const baseUrl = getConfigData(context, 'url');
const apiJsonFile = getConfigData(context, 'versions');
const searchPath = getConfigData(context, 'assets/js/search.json');
const defaultUrl = getConfigData(context, 'typedoc_default_url')
const gaID = getConfigData(context, 'gaID');
return (
<html class="default no-js" lang="en">
Expand Down Expand Up @@ -51,7 +52,7 @@ export const defaultLayout = (context: DefaultThemeRenderContext, props: PageEve
{analytics(context)}
{context.hook("head.end")}
</head>
<body id="body" data-base-url={baseUrl} data-api-versions-json={apiJsonFile}>
<body id="body" data-base-url={baseUrl} data-api-versions-json={apiJsonFile} default-url={defaultUrl}>
{context.hook('body.begin')}
{/* Google Tag Manager (noscript) */}
<noscript>
Expand Down
19 changes: 16 additions & 3 deletions src/utils/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ export function stringify(data: unknown) {
}

export function getConfigData(context: DefaultThemeRenderContext, prop: string, lang?: string): string {
const fileName = 'config.json';
const product = context.options.getValue('product') as string;
const prodArr = product.split('-');
const prodName = prodArr[prodArr.length - 1];
const fileName = prodName == 'angular' ? 'config.json' : prodName + '.config.json';
const filePath = getConfigFilePath(fileName);

const normalizedPath = path.join(__dirname, '..' , fileName);
const config = JSON.parse(fs.readFileSync(normalizedPath, 'utf8'));
const config = JSON.parse(fs.readFileSync(filePath, 'utf8'));
const settingOpt = context.options.getValue('localize') as string;
const getLang = lang ? lang : settingOpt;

Expand All @@ -109,3 +112,13 @@ export function getConfigData(context: DefaultThemeRenderContext, prop: string,
const res = data ? data[prop] : '';
return res;
}

export function getConfigFilePath(fileName: string) : string {
const normalizedPath = path.join(__dirname, '..' , fileName);
if (fs.existsSync(normalizedPath)) {
return normalizedPath;
} else {
// fallback to default config
return path.join(__dirname, '..' , 'config.json');
}
}
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const config = {
patterns: [
{
context: path.resolve(__dirname),
from: "config.json",
from: "*config.json",
to: path.resolve(__dirname, "dist"),
},
],
Expand Down

0 comments on commit 60165c9

Please sign in to comment.