chore: formatting fixes

This commit is contained in:
haritabh-z01 2025-06-28 11:02:07 +05:30
parent dd6af5e879
commit 119a46c339
167 changed files with 4507 additions and 3248 deletions

View file

@ -1,19 +1,19 @@
#!/usr/bin/env node
import { promises as fs } from 'fs';
import path from 'path';
import { rimraf } from 'rimraf';
import { promises as fs } from "fs";
import path from "path";
import { rimraf } from "rimraf";
// Parse command line arguments
const args = process.argv.slice(2);
const DRY_RUN = args.includes('--dry-run');
const VERBOSE = args.includes('--verbose');
const DRY_RUN = args.includes("--dry-run");
const VERBOSE = args.includes("--verbose");
// Configuration - use the same paths as in fetch-content.mts
const CONTENT_DIR = path.join(process.cwd(), 'content');
const PUBLIC_DIR = path.join(process.cwd(), 'public');
const LOCAL_BLOG_DIR = path.join(CONTENT_DIR, 'blogs');
const LOCAL_BLOG_IMAGES_DIR = path.join(PUBLIC_DIR, 'blog');
const CONTENT_DIR = path.join(process.cwd(), "content");
const PUBLIC_DIR = path.join(process.cwd(), "public");
const LOCAL_BLOG_DIR = path.join(CONTENT_DIR, "blogs");
const LOCAL_BLOG_IMAGES_DIR = path.join(PUBLIC_DIR, "blog");
/**
* Checks if a directory exists
@ -49,9 +49,9 @@ async function removeDirectory(directory: string): Promise<void> {
* Cleans up the blog content and images
*/
async function cleanupContent(): Promise<void> {
console.log('Starting content cleanup...');
console.log("Starting content cleanup...");
if (DRY_RUN) {
console.log('*** DRY RUN MODE - No files will be deleted ***');
console.log("*** DRY RUN MODE - No files will be deleted ***");
}
try {
@ -68,15 +68,17 @@ async function cleanupContent(): Promise<void> {
console.log(`Found blog images directory: ${LOCAL_BLOG_IMAGES_DIR}`);
await removeDirectory(LOCAL_BLOG_IMAGES_DIR);
} else if (VERBOSE) {
console.log(`Blog images directory does not exist: ${LOCAL_BLOG_IMAGES_DIR}`);
console.log(
`Blog images directory does not exist: ${LOCAL_BLOG_IMAGES_DIR}`,
);
}
console.log('Content cleanup completed successfully!');
console.log("Content cleanup completed successfully!");
} catch (error) {
console.error('Error during cleanup:', error);
console.error("Error during cleanup:", error);
process.exit(1);
}
}
// Run the script
cleanupContent();
cleanupContent();

View file

@ -1,43 +1,49 @@
#!/usr/bin/env node
// Load environment variables from .env files
import * as dotenv from 'dotenv';
import path from 'path';
import { S3Client, ListObjectsV2Command, GetObjectCommand } from '@aws-sdk/client-s3';
import { createWriteStream, promises as fs } from 'fs';
import { pipeline } from 'stream/promises';
import * as dotenv from "dotenv";
import path from "path";
import {
S3Client,
ListObjectsV2Command,
GetObjectCommand,
} from "@aws-sdk/client-s3";
import { createWriteStream, promises as fs } from "fs";
import { pipeline } from "stream/promises";
// Configure dotenv to load environment variables
dotenv.config();
// Parse command line arguments
const args = process.argv.slice(2);
const DRY_RUN = args.includes('--dry-run');
const SKIP_ERRORS = args.includes('--skip-errors');
const DRY_RUN = args.includes("--dry-run");
const SKIP_ERRORS = args.includes("--skip-errors");
// Log environment variables for debugging
console.log('AWS Credentials:', {
accessKeyId: process.env.AWS_ACCESS_KEY_ID ? '****' : undefined,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ? '****' : undefined
console.log("AWS Credentials:", {
accessKeyId: process.env.AWS_ACCESS_KEY_ID ? "****" : undefined,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ? "****" : undefined,
});
// Configuration
const BUCKET_NAME = process.env.S3_BUCKET_NAME || 'amical-www';
const ENDPOINT = process.env.S3_ENDPOINT || 'https://s3.wasabisys.com';
const BLOG_PREFIX = process.env.BLOG_PREFIX || 'blog/';
const BLOG_IMAGES_PREFIX = process.env.BLOG_IMAGES_PREFIX || 'blog-images/';
const CONTENT_DIR = path.join(process.cwd(), 'content');
const PUBLIC_DIR = path.join(process.cwd(), 'public');
const LOCAL_BLOG_DIR = path.join(CONTENT_DIR, 'blogs');
const LOCAL_BLOG_IMAGES_DIR = path.join(PUBLIC_DIR, 'blog');
const BUCKET_NAME = process.env.S3_BUCKET_NAME || "amical-www";
const ENDPOINT = process.env.S3_ENDPOINT || "https://s3.wasabisys.com";
const BLOG_PREFIX = process.env.BLOG_PREFIX || "blog/";
const BLOG_IMAGES_PREFIX = process.env.BLOG_IMAGES_PREFIX || "blog-images/";
const CONTENT_DIR = path.join(process.cwd(), "content");
const PUBLIC_DIR = path.join(process.cwd(), "public");
const LOCAL_BLOG_DIR = path.join(CONTENT_DIR, "blogs");
const LOCAL_BLOG_IMAGES_DIR = path.join(PUBLIC_DIR, "blog");
// Check if we have AWS credentials
const HAS_AWS_CREDENTIALS = !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY);
const HAS_AWS_CREDENTIALS = !!(
process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY
);
// S3 client configuration
const s3ClientConfig: any = {
endpoint: ENDPOINT,
region: process.env.AWS_REGION || 'us-east-1', // Required but may not matter for Wasabi
region: process.env.AWS_REGION || "us-east-1", // Required but may not matter for Wasabi
forcePathStyle: true, // Required for Wasabi
};
@ -48,16 +54,23 @@ if (HAS_AWS_CREDENTIALS) {
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
};
} else if (!DRY_RUN) {
console.warn('Warning: AWS credentials not found. S3 operations will be skipped.');
console.warn(
"Warning: AWS credentials not found. S3 operations will be skipped.",
);
if (SKIP_ERRORS) {
console.warn('Running with --skip-errors flag. Will continue without fetching content.');
console.warn(
"Running with --skip-errors flag. Will continue without fetching content.",
);
} else {
console.error('AWS credentials are required for content fetch. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.');
console.error(
"AWS credentials are required for content fetch. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.",
);
}
}
// Initialize S3 client only if we have credentials or in dry run mode
const s3Client = (HAS_AWS_CREDENTIALS || DRY_RUN) ? new S3Client(s3ClientConfig) : null;
const s3Client =
HAS_AWS_CREDENTIALS || DRY_RUN ? new S3Client(s3ClientConfig) : null;
/**
* Ensures that a directory exists, creating it and all parent directories if necessary
@ -99,7 +112,9 @@ async function listObjects(prefix: string): Promise<string[]> {
// Skip S3 operations if we don't have credentials
if (!s3Client) {
console.log(`Skipping S3 operations for prefix: ${prefix} (no credentials)`);
console.log(
`Skipping S3 operations for prefix: ${prefix} (no credentials)`,
);
return [];
}
@ -134,7 +149,10 @@ async function listObjects(prefix: string): Promise<string[]> {
}
}
async function downloadFile(key: string, destinationPath: string): Promise<void> {
async function downloadFile(
key: string,
destinationPath: string,
): Promise<void> {
if (DRY_RUN) {
console.log(`[DRY RUN] Would download: ${key} to ${destinationPath}`);
return;
@ -171,11 +189,11 @@ async function downloadFile(key: string, destinationPath: string): Promise<void>
}
async function fetchBlogContent(): Promise<void> {
console.log('Starting content fetch from S3...');
console.log("Starting content fetch from S3...");
if (DRY_RUN) {
console.log('*** DRY RUN MODE - No files will be downloaded ***');
console.log("*** DRY RUN MODE - No files will be downloaded ***");
} else if (!HAS_AWS_CREDENTIALS) {
console.log('*** NO CREDENTIALS MODE - S3 operations will be skipped ***');
console.log("*** NO CREDENTIALS MODE - S3 operations will be skipped ***");
}
console.log(`Bucket: ${BUCKET_NAME}`);
console.log(`Endpoint: ${ENDPOINT}`);
@ -191,12 +209,16 @@ async function fetchBlogContent(): Promise<void> {
// Skip S3 operations if we don't have credentials
if (!HAS_AWS_CREDENTIALS && !DRY_RUN) {
console.log('Skipping S3 operations due to missing credentials.');
console.log("Skipping S3 operations due to missing credentials.");
if (SKIP_ERRORS) {
console.log('Build process will continue without fetching content due to --skip-errors flag.');
console.log(
"Build process will continue without fetching content due to --skip-errors flag.",
);
return;
} else {
throw new Error('AWS credentials are required for content fetch. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.');
throw new Error(
"AWS credentials are required for content fetch. Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.",
);
}
}
@ -205,7 +227,7 @@ async function fetchBlogContent(): Promise<void> {
const blogFiles = await listObjects(BLOG_PREFIX);
if (blogFiles.length === 0) {
console.log('No blog files found.');
console.log("No blog files found.");
} else {
console.log(`Found ${blogFiles.length} blog files.`);
@ -221,11 +243,15 @@ async function fetchBlogContent(): Promise<void> {
await downloadFile(key, destinationPath);
downloadedCount++;
} catch (error) {
console.error(`Failed to download ${key}. Continuing with next file.`);
console.error(
`Failed to download ${key}. Continuing with next file.`,
);
}
}
console.log(`Successfully downloaded ${downloadedCount} of ${blogFiles.length} blog files.`);
console.log(
`Successfully downloaded ${downloadedCount} of ${blogFiles.length} blog files.`,
);
}
// Fetch blog images
@ -233,7 +259,7 @@ async function fetchBlogContent(): Promise<void> {
const imageFiles = await listObjects(BLOG_IMAGES_PREFIX);
if (imageFiles.length === 0) {
console.log('No image files found.');
console.log("No image files found.");
} else {
console.log(`Found ${imageFiles.length} image files.`);
@ -249,18 +275,24 @@ async function fetchBlogContent(): Promise<void> {
await downloadFile(key, destinationPath);
downloadedCount++;
} catch (error) {
console.error(`Failed to download ${key}. Continuing with next file.`);
console.error(
`Failed to download ${key}. Continuing with next file.`,
);
}
}
console.log(`Successfully downloaded ${downloadedCount} of ${imageFiles.length} image files.`);
console.log(
`Successfully downloaded ${downloadedCount} of ${imageFiles.length} image files.`,
);
}
console.log('\nContent fetch completed successfully!');
console.log("\nContent fetch completed successfully!");
} catch (error) {
console.error('Error fetching content:', error);
console.error("Error fetching content:", error);
if (SKIP_ERRORS) {
console.warn('Continuing build process despite errors due to --skip-errors flag.');
console.warn(
"Continuing build process despite errors due to --skip-errors flag.",
);
} else {
process.exit(1);
}

View file

@ -1,46 +1,42 @@
import fs from 'fs';
import { globby } from 'globby';
import prettier from 'prettier';
import path from 'path';
import fs from "fs";
import { globby } from "globby";
import prettier from "prettier";
import path from "path";
async function generate() {
const prettierConfig = await prettier.resolveConfig('./.prettierrc');
const prettierConfig = await prettier.resolveConfig("./.prettierrc");
// Ensure directories exist
fs.mkdirSync('public', { recursive: true });
fs.mkdirSync('out', { recursive: true });
fs.mkdirSync("public", { recursive: true });
fs.mkdirSync("out", { recursive: true });
// Get static pages
const pages = await globby([
'app/**/page.tsx',
'!app/**/_*/**',
'!app/**/api/**',
'!app/docs/**', // Exclude docs directory as we'll handle it separately
"app/**/page.tsx",
"!app/**/_*/**",
"!app/**/api/**",
"!app/docs/**", // Exclude docs directory as we'll handle it separately
]);
// Get doc pages from the build output
const docPages = await globby(['out/docs/**/*.html'])
.then(pages => pages
.map(page => page
.replace('out', '')
.replace('/index.html', '')
.replace('.html', '')
const docPages = await globby(["out/docs/**/*.html"]).then((pages) =>
pages
.map((page) =>
page.replace("out", "").replace("/index.html", "").replace(".html", ""),
)
.filter(page => !page.includes('/_'))
);
.filter((page) => !page.includes("/_")),
);
// Get blog pages from the build output
const blogPages = await globby(['out/blog/**/*.html'])
.then(pages => pages
.map(page => page
.replace('out', '')
.replace('/index.html', '')
.replace('.html', '')
const blogPages = await globby(["out/blog/**/*.html"]).then((pages) =>
pages
.map((page) =>
page.replace("out", "").replace("/index.html", "").replace(".html", ""),
)
.filter(page => !page.includes('/_') && !page.includes('/blog/index'))
);
.filter((page) => !page.includes("/_") && !page.includes("/blog/index")),
);
const baseUrl = 'https://amical.ai';
const baseUrl = "https://amical.ai";
const sitemap = `
<?xml version="1.0" encoding="UTF-8"?>
@ -49,17 +45,17 @@ async function generate() {
// Add static pages
...pages.map((page) => {
const path = page
.replace('app', '')
.replace('/page.tsx', '')
.replace('/(home)', '')
.replace(/\[\[\.\.\..*?\]\]/, '');
.replace("app", "")
.replace("/page.tsx", "")
.replace("/(home)", "")
.replace(/\[\[\.\.\..*?\]\]/, "");
// Skip dynamic routes with parameters
if (path.includes('[') || path.includes(']')) {
return '';
if (path.includes("[") || path.includes("]")) {
return "";
}
const route = path === '' ? '' : path;
const route = path === "" ? "" : path;
return `
<url>
@ -80,14 +76,16 @@ async function generate() {
</url>
`,
// Add doc pages
...docPages.map((path) => `
...docPages.map(
(path) => `
<url>
<loc>${baseUrl}${path}</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>daily</changefreq>
<priority>0.7</priority>
</url>
`),
`,
),
// Add blog index page
`
<url>
@ -98,32 +96,34 @@ async function generate() {
</url>
`,
// Add blog pages
...blogPages.map((path) => `
...blogPages.map(
(path) => `
<url>
<loc>${baseUrl}${path}</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
`),
`,
),
]
.filter(Boolean)
.join('')}
.join("")}
</urlset>
`;
const formatted = await prettier.format(sitemap, {
...prettierConfig,
parser: 'html',
parser: "html",
});
fs.writeFileSync('public/sitemap.xml', formatted);
fs.writeFileSync('out/sitemap.xml', formatted);
fs.writeFileSync("public/sitemap.xml", formatted);
fs.writeFileSync("out/sitemap.xml", formatted);
console.log('✅ Generated sitemap.xml');
console.log("✅ Generated sitemap.xml");
}
generate().catch((err) => {
console.error(err);
process.exit(1);
});
});