Skip to content
Closed

test #4200

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions npm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { runBuildPostList } from './runners/build-post-list-runner';
import { runBuildDashboard } from './runners/build-dashboard-runner';
import { runBuildTools } from './runners/build-tools-runner';
import { runCaseStudies } from './runners/case-studies-runner';
import { runBuildNewsroomVideos } from './runners/build-newsroom-videos-runner';
import { logger } from '../scripts/helpers/logger';
import { runBuildMeetings } from './runners/build-meetings-runner';
import { runBuildFinanceInfoList } from './runners/build-finance-info-list-runner';
import { runBuildAdoptersList } from './runners/build-adopters-list-runner';
import { runBuildPages } from './runners/build-pages-runner';
import { runBuildRss } from './runners/build-rss-runner';

async function main() {
let errorFaced: boolean = false;

const buildTasks = [
{ name: 'posts', task: runBuildPostList },
{ name: 'dashboard', task: runBuildDashboard },
{ name: 'tools', task: runBuildTools },
{ name: 'caseStudies', task: runCaseStudies },
{ name: 'newsroomVideos', task: runBuildNewsroomVideos },
{ name: 'meetings', task: runBuildMeetings },
{ name: 'finance', task: runBuildFinanceInfoList },
{ name: 'adopters', task: runBuildAdoptersList },
{ name: 'pages', task: runBuildPages },
{ name: 'rss', task: runBuildRss }
];

try {
const results = await Promise.allSettled(
buildTasks.map(({ task }) => task())
);

results.forEach((result, index) => {
if (result.status === 'rejected') {
errorFaced = true;
const error = result.reason;

if (error instanceof Error) {
const errorDetails = {
message: error.message,
cause: error.cause,
stack: error.stack
};
logger.error(`Error building ${buildTasks[index].name}:`, errorDetails);
} else {
logger.error(`Error building ${buildTasks[index].name}:`, error);
}
} else {
logger.info(`Successfully executed ${buildTasks[index].name}`);
}
});

if (errorFaced) {
logger.info('Some scripts faced error while running, please check the console for more details');
process.exitCode = 1; // surface the failure to CI so that it can be tracked
} else {
logger.info('Successfully executed all build scripts');
}
} catch (error) {
logger.error('Error executing build scripts:', error);
throw new Error('Error executing build scripts', { cause: error });
}
}

main();
9 changes: 9 additions & 0 deletions npm/runners/build-adopters-list-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { buildAdoptersList } from '@/scripts/adopters';

export async function runBuildAdoptersList() {
try{
await buildAdoptersList();
}catch(error){
throw error;
}
}
Comment on lines +3 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove the unnecessary try-catch block and fix formatting.

The try-catch block serves no purpose since it only rethrows the original error. Additionally, there's a formatting issue with missing space after try.

-export async function runBuildAdoptersList() {
-  try{
-    await buildAdoptersList();
-  }catch(error){
-    throw error;
-  }
-} 
+export async function runBuildAdoptersList() {
+  await buildAdoptersList();
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function runBuildAdoptersList() {
try{
await buildAdoptersList();
}catch(error){
throw error;
}
}
export async function runBuildAdoptersList() {
await buildAdoptersList();
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 7-7: The catch clause that only rethrows the original error is useless.

An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.

(lint/complexity/noUselessCatch)

🤖 Prompt for AI Agents
In npm/runners/build-adopters-list-runner.ts lines 3 to 9, remove the
unnecessary try-catch block that only rethrows the error without handling it,
and fix the formatting by adding a space after the `try` keyword. Simply call
`await buildAdoptersList()` directly inside the async function without wrapping
it in try-catch.

16 changes: 16 additions & 0 deletions npm/runners/build-dashboard-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { start } from "@/scripts/dashboard/build-dashboard";

import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);

export async function runBuildDashboard() {
try {
await start(resolve(currentDirPath, '..', '..', 'dashboard.json'));
}
catch (error) {
throw error;
}
}
Comment on lines +10 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove the useless try-catch block.

The try-catch block only rethrows the original error without adding any value. This makes the code unnecessarily verbose and can be confusing.

Apply this diff to simplify the function:

 export async function runBuildDashboard() {
-    try {
-        await start(resolve(currentDirPath, '..', '..', 'dashboard.json'));
-    }
-    catch (error) {
-        throw error;
-    }
+    await start(resolve(currentDirPath, '..', '..', 'dashboard.json'));
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
await start(resolve(currentDirPath, '..', '..', 'dashboard.json'));
}
catch (error) {
throw error;
}
}
export async function runBuildDashboard() {
await start(resolve(currentDirPath, '..', '..', 'dashboard.json'));
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 14-14: The catch clause that only rethrows the original error is useless.

An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.

(lint/complexity/noUselessCatch)

🤖 Prompt for AI Agents
In npm/runners/build-dashboard-runner.ts around lines 10 to 16, remove the
try-catch block that only rethrows the caught error without any additional
handling. Simply call the start function with await and let any errors propagate
naturally, which simplifies the code and improves readability.

37 changes: 37 additions & 0 deletions npm/runners/build-finance-info-list-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { resolve } from "path";
import fs from "fs";

import { buildFinanceInfoList } from "@/scripts/finance/index";


export async function runBuildFinanceInfoList() {
const financeDir = resolve('.', 'config', 'finance');

// loop through all the files finance in directory and find the latest year to build the finance info list
const yearsList = fs
.readdirSync(financeDir)
// filter out any files that are not numbers
.filter((file) => {
return !Number.isNaN(parseFloat(file));
})
// sort the years in descending order
.sort((a, b) => {
return parseFloat(b) - parseFloat(a);
});

if (yearsList.length === 0) {
throw new Error('No finance data found in the finance directory.');
}
const latestYear = yearsList[0];
try {
await buildFinanceInfoList({
currentDir: '.',
configDir: 'config',
financeDir: 'finance',
year: latestYear,
jsonDataDir: 'json-data'
});
} catch (error) {
throw new Error('Error building finance info list', { cause: error });
}
}
18 changes: 18 additions & 0 deletions npm/runners/build-meetings-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { buildMeetings } from '@/scripts/build-meetings';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);

export async function runBuildMeetings(){
try{
await buildMeetings(resolve(currentDirPath, '../../config', 'meetings.json'));
}catch (error) {
if (error instanceof Error) {
throw new Error(`Build meetings runner failed: ${error.message}`, { cause: error });
} else {
throw new Error(`Build meetings runner failed: ${String(error)}`, { cause: error });
}
}
}
19 changes: 19 additions & 0 deletions npm/runners/build-newsroom-videos-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { buildNewsroomVideos } from "@/scripts/build-newsroom-videos";
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);

export async function runBuildNewsroomVideos() {
try {
await buildNewsroomVideos(resolve(currentDirPath, '../../config', 'newsroom_videos.json'));
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Newsroom videos runner failed: ${error.message}`, { cause: error });
} else {
throw new Error(`Newsroom videos runner failed: ${String(error)}`, { cause: error });
}
}
}
14 changes: 14 additions & 0 deletions npm/runners/build-pages-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ensureDirectoryExists, copyAndRenameFiles } from "@/scripts/build-pages";

const SRC_DIR = 'markdown';
const TARGET_DIR = 'pages';


export function runBuildPages() {
try {
ensureDirectoryExists(TARGET_DIR);
copyAndRenameFiles(SRC_DIR, TARGET_DIR);
} catch (err) {
throw err;
}
}
Comment on lines +7 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove the unnecessary try-catch block.

The try-catch block serves no purpose since it only rethrows the original error without adding any value.

-export function runBuildPages() {
-  try {
-    ensureDirectoryExists(TARGET_DIR);
-    copyAndRenameFiles(SRC_DIR, TARGET_DIR);
-  } catch (err) {
-    throw err;
-  }
-}
+export function runBuildPages() {
+  ensureDirectoryExists(TARGET_DIR);
+  copyAndRenameFiles(SRC_DIR, TARGET_DIR);
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function runBuildPages() {
try {
ensureDirectoryExists(TARGET_DIR);
copyAndRenameFiles(SRC_DIR, TARGET_DIR);
} catch (err) {
throw err;
}
}
export function runBuildPages() {
ensureDirectoryExists(TARGET_DIR);
copyAndRenameFiles(SRC_DIR, TARGET_DIR);
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 12-12: The catch clause that only rethrows the original error is useless.

An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.

(lint/complexity/noUselessCatch)

🤖 Prompt for AI Agents
In npm/runners/build-pages-runner.ts around lines 7 to 14, remove the try-catch
block from the runBuildPages function because it only catches and immediately
rethrows the error without any additional handling. Simply keep the function
body with the calls to ensureDirectoryExists and copyAndRenameFiles directly,
allowing errors to propagate naturally.

9 changes: 9 additions & 0 deletions npm/runners/build-rss-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { rssFeed } from '@/scripts/build-rss';

export async function runBuildRss() {
try {
await rssFeed('blog', 'AsyncAPI Blog', 'Latest news and updates from AsyncAPI.', 'rss.xml');
} catch (err) {
throw err;
}
}
Comment on lines +3 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove the unnecessary try-catch block.

The try-catch block serves no purpose since it only rethrows the original error without adding any value.

-export async function runBuildRss() {
-  try {
-    await rssFeed('blog', 'AsyncAPI Blog', 'Latest news and updates from AsyncAPI.', 'rss.xml');
-  } catch (err) {
-    throw err;
-  }
-}
+export async function runBuildRss() {
+  await rssFeed('blog', 'AsyncAPI Blog', 'Latest news and updates from AsyncAPI.', 'rss.xml');
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function runBuildRss() {
try {
await rssFeed('blog', 'AsyncAPI Blog', 'Latest news and updates from AsyncAPI.', 'rss.xml');
} catch (err) {
throw err;
}
}
export async function runBuildRss() {
await rssFeed(
'blog',
'AsyncAPI Blog',
'Latest news and updates from AsyncAPI.',
'rss.xml'
);
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 7-7: The catch clause that only rethrows the original error is useless.

An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.

(lint/complexity/noUselessCatch)

🤖 Prompt for AI Agents
In npm/runners/build-rss-runner.ts around lines 3 to 9, remove the try-catch
block inside the runBuildRss function because it only catches and rethrows the
error without any additional handling. Simply call await rssFeed(...) directly
and let any errors propagate naturally.

22 changes: 22 additions & 0 deletions npm/runners/build-tools-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { buildTools } from "@/scripts/build-tools";

import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);

export async function runBuildTools() {
try {
const automatedToolsPath = resolve(currentDirPath, '../../config', 'tools-automated.json');
const manualToolsPath = resolve(currentDirPath, '../../config', 'tools-manual.json');
const toolsPath = resolve(currentDirPath, '../../config', 'tools.json');
const tagsPath = resolve(currentDirPath, '../../config', 'all-tags.json');

await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath);
} catch (error) {
throw error;
}
}


22 changes: 22 additions & 0 deletions npm/runners/case-studies-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { buildCaseStudiesList } from '@/scripts/casestudies';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);
const projectRoot = resolve(currentDirPath, '../../');

export async function runCaseStudies() {
try {
const caseStudyDirectory = resolve(projectRoot, 'config', 'casestudies');
if (!fs.existsSync(caseStudyDirectory)) {
console.error(`Directory does not exist: ${caseStudyDirectory}`);
return;
}
const writeFilePath = resolve(projectRoot, 'config', 'case-studies.json');
await buildCaseStudiesList(caseStudyDirectory, writeFilePath);
} catch (error) {
throw error;
}
}
Comment on lines +11 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling consistency.

Multiple issues with the error handling approach:

  1. The try-catch block only rethrows without adding value
  2. Uses console.error instead of logger for consistency
  3. Early return without throwing is inconsistent with error handling patterns

Apply this diff to improve the function:

+import { logger } from '@/scripts/helpers/logger';
 
 export async function runCaseStudies() {
-    try {
-        const caseStudyDirectory = resolve(projectRoot, 'config', 'casestudies');
-        if (!fs.existsSync(caseStudyDirectory)) {
-            console.error(`Directory does not exist: ${caseStudyDirectory}`);
-            return;
-        }
-        const writeFilePath = resolve(projectRoot, 'config', 'case-studies.json');
-        await buildCaseStudiesList(caseStudyDirectory, writeFilePath);
-    } catch (error) {
-        throw error;
-    }
+    const caseStudyDirectory = resolve(projectRoot, 'config', 'casestudies');
+    if (!fs.existsSync(caseStudyDirectory)) {
+        logger.error(`Directory does not exist: ${caseStudyDirectory}`);
+        throw new Error(`Case studies directory not found: ${caseStudyDirectory}`);
+    }
+    const writeFilePath = resolve(projectRoot, 'config', 'case-studies.json');
+    await buildCaseStudiesList(caseStudyDirectory, writeFilePath);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
const caseStudyDirectory = resolve(projectRoot, 'config', 'casestudies');
if (!fs.existsSync(caseStudyDirectory)) {
console.error(`Directory does not exist: ${caseStudyDirectory}`);
return;
}
const writeFilePath = resolve(projectRoot, 'config', 'case-studies.json');
await buildCaseStudiesList(caseStudyDirectory, writeFilePath);
} catch (error) {
throw error;
}
}
import { resolve } from 'path';
import fs from 'fs';
+import { logger } from '@/scripts/helpers/logger';
export async function runCaseStudies() {
- try {
- const caseStudyDirectory = resolve(projectRoot, 'config', 'casestudies');
- if (!fs.existsSync(caseStudyDirectory)) {
- console.error(`Directory does not exist: ${caseStudyDirectory}`);
- return;
- }
- const writeFilePath = resolve(projectRoot, 'config', 'case-studies.json');
- await buildCaseStudiesList(caseStudyDirectory, writeFilePath);
- } catch (error) {
- throw error;
- }
+ const caseStudyDirectory = resolve(projectRoot, 'config', 'casestudies');
+ if (!fs.existsSync(caseStudyDirectory)) {
+ logger.error(`Directory does not exist: ${caseStudyDirectory}`);
+ throw new Error(`Case studies directory not found: ${caseStudyDirectory}`);
+ }
+ const writeFilePath = resolve(projectRoot, 'config', 'case-studies.json');
+ await buildCaseStudiesList(caseStudyDirectory, writeFilePath);
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 20-20: The catch clause that only rethrows the original error is useless.

An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.

(lint/complexity/noUselessCatch)

🤖 Prompt for AI Agents
In npm/runners/case-studies-runner.ts around lines 11 to 22, improve error
handling by removing the redundant try-catch block that only rethrows the error,
replace console.error with the consistent logger.error for error messages, and
instead of early returning when the directory does not exist, throw an
appropriate error to maintain consistent error handling patterns throughout the
function.

46 changes: 46 additions & 0 deletions npm/runners/compose-blog-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import inquirer from 'inquirer';
import { ComposeBlog, ComposePromptType } from '@/scripts/compose';
import { logger } from '@/scripts/helpers/logger';

export async function runComposeBlog(): Promise<string> {
const answers: ComposePromptType = await inquirer.prompt([
{
name: 'title',
message: 'Enter post title:',
type: 'input'
},
{
name: 'excerpt',
message: 'Enter post excerpt:',
type: 'input'
},
{
name: 'tags',
message: 'Any Tags? Separate them with , or leave empty if no tags.',
type: 'input'
},
{
name: 'type',
message: 'Enter the post type:',
type: 'list',
choices: ['Communication', 'Community', 'Engineering', 'Marketing', 'Strategy', 'Video']
},
{
name: 'canonical',
message: 'Enter the canonical URL if any:',
type: 'input'
}
]);

try {
return await ComposeBlog(answers);
} catch (error: any) {
logger.error(error);
if (error.isTtyError) {
logger.error("Prompt couldn't be rendered in the current environment");
} else {
logger.error('Something went wrong, sorry!');
}
throw error;
}
}
24 changes: 24 additions & 0 deletions scripts/adopters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { writeJSON } from './utils/readAndWriteJson';

/**
* Converts the YAML adopters configuration to a JSON file.
*
* This asynchronous function reads the adopters configuration from
* "config/adopters.yml" and converts its content to JSON format. It then writes
* the resulting JSON data to "adopters.json" in the configuration directory determined
* by resolving the current file's directory with "../../config". The operation is
* performed using the writeJSON utility.
*
* @returns {Promise<void>} Resolves when the adopters list has been built and written to JSON.
*/
export async function buildAdoptersList(): Promise<void> {
try {
const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);
await writeJSON('config/adopters.yml', resolve(currentDirPath, '../../config', 'adopters.json'));
} catch (error) {
throw error;
}
}
18 changes: 11 additions & 7 deletions scripts/adopters/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

import { writeJSON } from '../helpers/readAndWriteJson';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);

/**
* Converts the YAML adopters configuration to a JSON file.
*
Expand All @@ -14,7 +10,15 @@ const currentDirPath = dirname(currentFilePath);
* the resulting JSON data to "adopters.json" in the configuration directory determined
* by resolving the current file's directory with "../../config". The operation is
* performed using the writeJSON utility.
*
* @returns {Promise<void>} Resolves when the adopters list has been built and written to JSON.
*/
export async function buildAdoptersList() {
writeJSON('config/adopters.yml', resolve(currentDirPath, '../../config', 'adopters.json'));
}
export async function buildAdoptersList(): Promise<void> {
try {
const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);
await writeJSON('config/adopters.yml', resolve(currentDirPath, '../../config', 'adopters.json'));
} catch (error) {
throw error;
}
}
19 changes: 4 additions & 15 deletions scripts/build-meetings.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { writeFileSync } from 'fs';
import { google } from 'googleapis';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

import { logger } from './helpers/logger';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirPath = dirname(currentFilePath);

import dotenv from 'dotenv';
dotenv.config();
/**
* Fetches meeting events from Google Calendar within a predefined time window and writes the formatted data to a file.
*
Expand All @@ -17,7 +13,7 @@ const currentDirPath = dirname(currentFilePath);
*
* @throws {Error} When authentication fails, the calendar API returns an invalid structure, or required event details are missing.
*/
async function buildMeetings(writePath: string) {
export async function buildMeetings(writePath: string) {
let auth;
let calendar;

Expand Down Expand Up @@ -85,11 +81,4 @@ async function buildMeetings(writePath: string) {
} catch (err) {
throw new Error(`Failed to fetch or process events: ${(err as Error).message}`);
}
}

/* istanbul ignore next */
if (process.argv[1] === fileURLToPath(import.meta.url)) {
buildMeetings(resolve(currentDirPath, '../config', 'meetings.json'));
}

export { buildMeetings };
}
Loading
Loading