Skip to content

Commit

Permalink
Merge pull request #182 from gaeacodes/dev
Browse files Browse the repository at this point in the history
fixes linting for navdata, enhances linting for navbar/sidebar
  • Loading branch information
gcharang authored Dec 20, 2023
2 parents e02d04d + 6dc4ffa commit c80fe3c
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions utils/js/file_presence_structure_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "fs";
import * as path from "path";

const sidebarNavData = JSON.parse(fs.readFileSync("./src/data/sidebar.json", 'utf8'))
const navbarNavData = JSON.parse(fs.readFileSync("./src/data/sidebar.json", 'utf8'))
const navbarNavData = JSON.parse(fs.readFileSync("./src/data/navbar.json", 'utf8'))

function walkDir(dirPath, callback) {
fs.readdirSync(dirPath).forEach((file) => {
Expand Down Expand Up @@ -80,23 +80,45 @@ if (invalidFilenames.length > 0) {
throw new Error("following file names are invalid. Either can't form valid url or has uppercase letters in them: " + JSON.stringify(invalidFilenames))
}

const pagesArray = [];
const sidebarPagesArray = [];
const navbarPagesArray = [];

function readTitleLinksAndHrefs(data) {
function readTitleLinksAndHrefsNavbar(data){
Object.keys(data).forEach(function (key) {
var dropdown = data[key];
dropdown.items.forEach(function (item) {
if(!item.link.endsWith("/")) {
throw new Error(`In navbar.json, link: ${item.link} should end with /`)
}
navbarPagesArray.push(item.link)
});
});
}

function readTitleLinksAndHrefsSidebar(data) {
Object.keys(data).forEach(function (key) {
var navigation = data[key];
Object.keys(navigation).forEach(function (navigationKey) {
if(!navigationKey.endsWith("/")) {
throw new Error(`In sidebar.json, navigationKey: ${navigationKey} should end with /`)
}
var sections = navigation[navigationKey];
sections.forEach(function (page) {
if (page.titleLink && page.links.length > 0) {
throw new Error("To be able to have collapsible sections in left sidebar, title with titlelink can't have sub-items. 'page.titleLink': " + page.titleLink)
}
if (page.titleLink) {
pagesArray.push(page.titleLink);
if(!page.titleLink.endsWith("/")) {
throw new Error(`In sidebar.json, titleLink: ${page.titleLink} should end with /`)
}
sidebarPagesArray.push(page.titleLink);
}
if (page.links) {
if (page.links) {
for (const link of page.links) {
pagesArray.push(link.href);
if(!link.href.endsWith("/")) {
throw new Error(`In sidebar.json, link: ${link.href} should end with /`)
}
sidebarPagesArray.push(link.href);
}
}
});
Expand All @@ -106,24 +128,26 @@ function readTitleLinksAndHrefs(data) {

// Read titleLinks and links.href values from antaraFrameworkPageNavigation

readTitleLinksAndHrefs(sidebarNavData);
readTitleLinksAndHrefs(navbarNavData);
readTitleLinksAndHrefsSidebar(sidebarNavData);
readTitleLinksAndHrefsNavbar(navbarNavData);

function compareArrays(fileNames, pagesArray) {
var differences = [];
fileNames.forEach(function (element) {
if (!pagesArray.includes(element)) {
differences.push(element);
fileNames.forEach(function (fileName) {
if (!pagesArray.includes(fileName)) {
differences.push(fileName);
}
});

return differences;
}

//pages present in the file system but not in sidebar
var pagesNotInSidebar = compareArrays(fileNames, pagesArray);
var pagesNotInSidebar = compareArrays(fileNames, sidebarPagesArray);
//pages present in the sidebar but not in file system
var pagesNotInFileSystem = compareArrays(pagesArray, fileNames);
var pagesInSidebarNotInFileSystem = compareArrays(sidebarPagesArray, fileNames);

var pagesInNavbarNotInFileSystem = compareArrays(navbarPagesArray, fileNames)

function removeUndefinedStrings(array) {
return array.filter(function (element) {
Expand All @@ -141,11 +165,19 @@ ${pagesNotInSidebar.join("\n")}
`;
}

if (pagesNotInFileSystem.length > 0) {
if (pagesInSidebarNotInFileSystem.length > 0) {
errorString =
errorString +
`\npages present in the sidebar but not in file system:
${pagesNotInFileSystem.join("\n")}
${pagesInSidebarNotInFileSystem.join("\n")}
`;
}

if (pagesInNavbarNotInFileSystem.length > 0) {
errorString =
errorString +
`\npages present in the navbar but not in file system:
${pagesInNavbarNotInFileSystem.join("\n")}
`;
}

Expand Down

0 comments on commit c80fe3c

Please sign in to comment.