import { writeFile, mkdir, readdir, readFile, unlink } from 'fs/promises'; import { join } from 'path'; import { env } from '../../env.js'; import type { Script, ScriptCard, GitHubFile } from '../../types/script'; import { repositoryService } from './repositoryService'; import { listDirectory, downloadRawFile } from '~/server/lib/gitProvider'; export class GitHubJsonService { private branch: string | null = null; private jsonFolder: string | null = null; private localJsonDirectory: string | null = null; private scriptCache: Map = new Map(); constructor() { // Initialize lazily to avoid accessing env vars during module load } private initializeConfig() { if (this.branch === null) { this.branch = env.REPO_BRANCH; this.jsonFolder = env.JSON_FOLDER; this.localJsonDirectory = join(process.cwd(), 'scripts', 'json'); } } private async downloadJsonFile(repoUrl: string, filePath: string): Promise