Skip to content

Commit

Permalink
Revert "refactor: improve optional chaining usage and enhance tool va…
Browse files Browse the repository at this point in the history
…lidation logging"

This reverts commit d6b0e2a.
  • Loading branch information
JeelRajodiya committed Dec 30, 2024
1 parent 76dee32 commit a220216
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions scripts/tools/combine-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ async function getFinalTool(toolObject: AsyncAPITool) {
languageFuse = new Fuse(languageList, options);
}
} else {
// eslint-disable-next-line no-unsafe-optional-chaining
for (const language of toolObject?.filters?.language) {
for (const language of toolObject?.filters?.language ?? []) {
const languageSearch = await languageFuse.search(language);

if (languageSearch.length > 0) {
Expand All @@ -95,8 +94,7 @@ async function getFinalTool(toolObject: AsyncAPITool) {
const technologyArray = [];

if (toolObject.filters.technology) {
// eslint-disable-next-line no-unsafe-optional-chaining
for (const technology of toolObject?.filters?.technology) {
for (const technology of toolObject?.filters?.technology ?? []) {
const technologySearch = await technologyFuse.search(technology);

if (technologySearch.length > 0) {
Expand Down Expand Up @@ -125,42 +123,44 @@ async function getFinalTool(toolObject: AsyncAPITool) {
// lists down all the language and technology tags in one JSON file.
const combineTools = async (automatedTools: any, manualTools: any, toolsPath: string, tagsPath: string) => {
try {
// eslint-disable-next-line no-restricted-syntax, guard-for-in
// eslint-disable-next-line no-restricted-syntax
for (const key in automatedTools) {
const finalToolsList = [];
if (Object.prototype.hasOwnProperty.call(automatedTools, key)) {
const finalToolsList = [];

if (automatedTools[key].toolsList.length) {
for (const tool of automatedTools[key].toolsList) {
finalToolsList.push(await getFinalTool(tool));
if (automatedTools[key].toolsList.length) {
for (const tool of automatedTools[key].toolsList) {
finalToolsList.push(await getFinalTool(tool));
}
}
}
if (manualTools[key]?.toolsList?.length) {
for (const tool of manualTools[key].toolsList) {
let isAsyncAPIrepo;
const isValid = await validate(tool);

if (isValid) {
if (tool?.links?.repoUrl) {
const url = new URL(tool.links.repoUrl);

isAsyncAPIrepo = url.href.startsWith('https://github.com/asyncapi/');
} else isAsyncAPIrepo = false;
const toolObject = await createToolObject(tool, '', '', isAsyncAPIrepo);

finalToolsList.push(await getFinalTool(toolObject));
} else {
console.error({
message: 'Tool validation failed',
tool: tool.title,
source: 'manual-tools.json',
errors: validate.errors,
note: 'Script continues execution, error logged for investigation'
});
if (manualTools[key]?.toolsList?.length) {
for (const tool of manualTools[key].toolsList) {
let isAsyncAPIrepo;
const isValid = await validate(tool);

if (isValid) {
if (tool?.links?.repoUrl) {
const url = new URL(tool.links.repoUrl);

isAsyncAPIrepo = url.href.startsWith('https://github.com/asyncapi/');
} else isAsyncAPIrepo = false;
const toolObject = await createToolObject(tool, '', '', isAsyncAPIrepo);

finalToolsList.push(await getFinalTool(toolObject));
} else {
console.error({
message: 'Tool validation failed',
tool: tool.title,
source: 'manual-tools.json',
errors: validate.errors,
note: 'Script continues execution, error logged for investigation'
});
}
}
}
finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title));
finalTools[key].toolsList = finalToolsList;
}
finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title));
finalTools[key].toolsList = finalToolsList;
}
fs.writeFileSync(toolsPath, JSON.stringify(finalTools));
fs.writeFileSync(tagsPath, JSON.stringify({ languages: languageList, technologies: technologyList }));
Expand Down

0 comments on commit a220216

Please sign in to comment.