Skip to content

Commit

Permalink
format using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed Nov 16, 2024
1 parent 2935475 commit 2badba7
Show file tree
Hide file tree
Showing 21 changed files with 261 additions and 490 deletions.
5 changes: 1 addition & 4 deletions scripts/adopters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ const { resolve } = require('path');
const writeJSON = require('../utils/readAndWriteJson.js');

module.exports = async function buildAdoptersList() {
writeJSON(
'config/adopters.yml',
resolve(__dirname, '../../config', 'adopters.json'),
);
writeJSON('config/adopters.yml', resolve(__dirname, '../../config', 'adopters.json'));
};
67 changes: 27 additions & 40 deletions scripts/build-docs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const sortBy = require('lodash/sortBy');

function buildNavTree(navItems) {
try {
const tree = {
Expand All @@ -10,42 +11,36 @@ function buildNavTree(navItems) {
isSection: true,
rootSectionId: 'welcome',
sectionWeight: 0,
slug: '/docs',
slug: '/docs'
},
children: {},
},
children: {}
}
};

//first we make sure that list of items lists main section items and then sub sections, documents last
const sortedItems = sortBy(navItems, [
'isRootSection',
'weight',
'isSection',
]);
// first we make sure that list of items lists main section items and then sub sections, documents last
const sortedItems = sortBy(navItems, ['isRootSection', 'weight', 'isSection']);

sortedItems.forEach((item) => {
//identify main sections
// identify main sections
if (item.isRootSection) {
tree[item.rootSectionId] = { item, children: {} };
}

//identify subsections
// identify subsections
if (item.parent) {
if (!tree[item.parent]) {
throw new Error(
`Parent section ${item.parent} not found for item ${item.title}`,
);
throw new Error(`Parent section ${item.parent} not found for item ${item.title}`);
}
tree[item.parent].children[item.sectionId] = { item, children: [] };
}

if (!item.isSection) {
if (item.sectionId) {
let section = tree[item.rootSectionId]?.children[item.sectionId];
const section = tree[item.rootSectionId]?.children[item.sectionId];
if (!section) {
tree[item.rootSectionId].children[item.sectionId] = {
item,
children: [],
children: []
};
}
tree[item.rootSectionId].children[item.sectionId].children.push(item);
Expand All @@ -68,7 +63,7 @@ function buildNavTree(navItems) {
return obj;
}, {});

//handling subsections
// handling subsections
if (allChildrenKeys.length > 1) {
for (const key of allChildrenKeys) {
if (allChildren[key].children) {
Expand All @@ -79,9 +74,7 @@ function buildNavTree(navItems) {

// point in slug for specification subgroup to the latest specification version
if (rootKey === 'reference' && key === 'specification') {
allChildren[key].item.href = allChildren[key].children.find(
(c) => c.isPrerelease === undefined,
).slug;
allChildren[key].item.href = allChildren[key].children.find((c) => c.isPrerelease === undefined).slug;
}
}
}
Expand All @@ -101,9 +94,9 @@ const convertDocPosts = (docObject) => {
// certain entries in the DocPosts are either a parent to many posts or itself a post.
docsArray.push(docObject?.item || docObject);
if (docObject.children) {
let children = docObject.children;
const { children } = docObject;
Object.keys(children).forEach((child) => {
let docChildArray = convertDocPosts(children[child]);
const docChildArray = convertDocPosts(children[child]);
docsArray = [...docsArray, ...docChildArray];
});
}
Expand All @@ -115,16 +108,16 @@ const convertDocPosts = (docObject) => {

function addDocButtons(docPosts, treePosts) {
let structuredPosts = [];
let rootSections = [];
const rootSections = [];

try {
// Traversing the whole DocTree and storing each post inside them in sequential order
Object.keys(treePosts).forEach((rootElement) => {
structuredPosts.push(treePosts[rootElement].item);
if (treePosts[rootElement].children) {
let children = treePosts[rootElement].children;
const { children } = treePosts[rootElement];
Object.keys(children).forEach((child) => {
let docChildArray = convertDocPosts(children[child]);
const docChildArray = convertDocPosts(children[child]);
structuredPosts = [...structuredPosts, ...docChildArray];
});
}
Expand All @@ -134,7 +127,7 @@ function addDocButtons(docPosts, treePosts) {
structuredPosts[0] = docPosts.filter((p) => p.slug === '/docs')[0];

// Traversing the structuredPosts in order to add `nextPage` and `prevPage` details for each page
let countDocPages = structuredPosts.length;
const countDocPages = structuredPosts.length;
structuredPosts = structuredPosts.map((post, index) => {
// post item specifying the root Section or sub-section in the docs are excluded as
// they doesn't comprise any Doc Page or content to be shown in website.
Expand All @@ -143,26 +136,23 @@ function addDocButtons(docPosts, treePosts) {
return post;
}

let nextPage = {},
prevPage = {};
let nextPage = {};
let prevPage = {};
let docPost = post;

// checks whether the next page for the current docPost item exists or not
if (index + 1 < countDocPages) {
// checks whether the next item inside structuredPosts is a rootElement or a sectionElement
// if yes, it goes again to a next to next item in structuredPosts to link the nextPage
if (
!structuredPosts[index + 1].isRootElement &&
!structuredPosts[index + 1].isSection
) {
if (!structuredPosts[index + 1].isRootElement && !structuredPosts[index + 1].isSection) {
nextPage = {
title: structuredPosts[index + 1].title,
href: structuredPosts[index + 1].slug,
href: structuredPosts[index + 1].slug
};
} else {
nextPage = {
title: `${structuredPosts[index + 1].title} - ${structuredPosts[index + 2].title}`,
href: structuredPosts[index + 2].slug,
href: structuredPosts[index + 2].slug
};
}
docPost = { ...docPost, nextPage };
Expand All @@ -172,21 +162,18 @@ function addDocButtons(docPosts, treePosts) {
if (index > 0) {
// checks whether the previous item inside structuredPosts is a rootElement or a sectionElement
// if yes, it goes again to a next previous item in structuredPosts to link the prevPage
if (
!structuredPosts[index - 1]?.isRootElement &&
!structuredPosts[index - 1]?.isSection
) {
if (!structuredPosts[index - 1]?.isRootElement && !structuredPosts[index - 1]?.isSection) {
prevPage = {
title: structuredPosts[index - 1].title,
href: structuredPosts[index - 1].slug,
href: structuredPosts[index - 1].slug
};
docPost = { ...docPost, prevPage };
} else {
// additonal check for the first page of Docs so that it doesn't give any Segementation fault
if (index - 2 >= 0) {
prevPage = {
title: `${structuredPosts[index - 1]?.isRootSection ? rootSections[rootSections.length - 2] : rootSections[rootSections.length - 1]} - ${structuredPosts[index - 2].title}`,
href: structuredPosts[index - 2].slug,
href: structuredPosts[index - 2].slug
};
docPost = { ...docPost, prevPage };
}
Expand Down
23 changes: 8 additions & 15 deletions scripts/build-meetings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ async function buildMeetings(writePath) {
try {
auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/calendar'],
credentials: process.env.CALENDAR_SERVICE_ACCOUNT
? JSON.parse(process.env.CALENDAR_SERVICE_ACCOUNT)
: undefined,
credentials: process.env.CALENDAR_SERVICE_ACCOUNT ? JSON.parse(process.env.CALENDAR_SERVICE_ACCOUNT) : undefined
});

calendar = google.calendar({ version: 'v3', auth });
Expand All @@ -22,19 +20,15 @@ async function buildMeetings(writePath) {
let eventsItems;

try {
//cron job runs this always on midnight
// cron job runs this always on midnight
const currentTime = new Date(Date.now()).toISOString();
const timeMin = new Date(
Date.parse(currentTime) - 100 * 24 * 60 * 60 * 1000,
).toISOString();
const timeMax = new Date(
Date.parse(currentTime) + 30 * 24 * 60 * 60 * 1000,
).toISOString();
const timeMin = new Date(Date.parse(currentTime) - 100 * 24 * 60 * 60 * 1000).toISOString();
const timeMax = new Date(Date.parse(currentTime) + 30 * 24 * 60 * 60 * 1000).toISOString();

const eventsList = await calendar.events.list({
calendarId: process.env.CALENDAR_ID,
timeMax: timeMax,
timeMin: timeMin,
timeMax,
timeMin
});

eventsItems = eventsList.data.items.map((e) => {
Expand All @@ -44,9 +38,8 @@ async function buildMeetings(writePath) {
url:
e.extendedProperties?.private &&
`https://github.com/asyncapi/community/issues/${e.extendedProperties.private.ISSUE_ID}`,
banner:
e.extendedProperties?.private && e.extendedProperties.private.BANNER,
date: new Date(e.start.dateTime),
banner: e.extendedProperties?.private && e.extendedProperties.private.BANNER,
date: new Date(e.start.dateTime)
};
});

Expand Down
21 changes: 10 additions & 11 deletions scripts/build-newsroom-videos.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ const fetch = require('node-fetch-2');
async function buildNewsroomVideos(writePath) {
try {
const response = await fetch(
'https://youtube.googleapis.com/youtube/v3/search?' +
new URLSearchParams({
key: process.env.YOUTUBE_TOKEN,
part: 'snippet',
channelId: 'UCIz9zGwDLbrYQcDKVXdOstQ',
eventType: 'completed',
type: 'video',
order: 'Date',
maxResults: 5,
}),
`https://youtube.googleapis.com/youtube/v3/search?${new URLSearchParams({
key: process.env.YOUTUBE_TOKEN,
part: 'snippet',
channelId: 'UCIz9zGwDLbrYQcDKVXdOstQ',
eventType: 'completed',
type: 'video',
order: 'Date',
maxResults: 5
})}`
);

if (!response.ok) {
Expand All @@ -32,7 +31,7 @@ async function buildNewsroomVideos(writePath) {
image_url: video.snippet.thumbnails.high.url,
title: video.snippet.title,
description: video.snippet.description,
videoId: video.id.videoId,
videoId: video.id.videoId
}));

const videoData = JSON.stringify(videoDataItems, null, ' ');
Expand Down
Loading

0 comments on commit 2badba7

Please sign in to comment.