#!/usr/bin/env node const fs = require('fs'); const path = require('path'); console.log('🔄 Switching to mock APIs for building...'); // Remove real APIs if (fs.existsSync('src/lib/api')) { fs.rmSync('src/lib/api', { recursive: true }); } if (fs.existsSync('src/lib/db')) { fs.rmSync('src/lib/db', { recursive: true }); } // Create mock directories fs.mkdirSync('src/lib/api', { recursive: true }); fs.mkdirSync('src/lib/db', { recursive: true }); // Create mock db files fs.writeFileSync('src/lib/db/index.ts', 'export const db = {};'); fs.writeFileSync('src/lib/db/schema.ts', 'export const users = {}; export const scripts = {}; export const ratings = {}; export const scriptVersions = {}; export const scriptAnalytics = {}; export const scriptCollections = {}; export const collectionScripts = {};'); // Create mock API files const mockIndex = `import { nanoid } from "nanoid"; export const generateId = () => nanoid(); export class ApiError extends Error { constructor(message: string, public status: number = 500) { super(message); this.name = "ApiError"; } } export * from "./scripts"; export * from "./users"; export * from "./ratings"; export * from "./analytics"; export * from "./collections"; export * from "./auth";`; const mockAuth = `export interface LoginCredentials { email: string; password: string; } export interface RegisterData { email: string; username: string; displayName: string; password: string; } export interface AuthToken { token: string; user: any; } export async function login(credentials: LoginCredentials): Promise { return { token: "demo-token", user: { id: "1", username: "demo", email: "demo@example.com", displayName: "Demo User", isAdmin: false, isModerator: false } }; } export async function register(data: RegisterData): Promise { return { token: "demo-token", user: { id: "1", username: data.username, email: data.email, displayName: data.displayName, isAdmin: false, isModerator: false } }; } export async function refreshToken(token: string): Promise { return { token: "demo-token", user: { id: "1", username: "demo", email: "demo@example.com", displayName: "Demo User", isAdmin: false, isModerator: false } }; } export async function changePassword(userId: string, currentPassword: string, newPassword: string): Promise { return true; }`; const mockScripts = `export interface ScriptFilters { search?: string; categories?: string[]; compatibleOs?: string[]; sortBy?: string; limit?: number; isApproved?: boolean; } export interface UpdateScriptData { name?: string; description?: string; content?: string; } export interface CreateScriptData { name: string; description: string; content: string; categories: string[]; compatibleOs: string[]; tags?: string[]; } export async function getScripts(filters?: ScriptFilters) { return { scripts: [], total: 0 }; } export async function getScriptById(id: string) { return null; } export async function getPopularScripts() { return []; } export async function getRecentScripts() { return []; } export async function createScript(data: CreateScriptData, userId: string) { return { id: "mock-script-id", ...data, authorId: userId }; } export async function updateScript(id: string, data: UpdateScriptData, userId: string) { return { id, ...data }; } export async function deleteScript(id: string, userId: string) { return { success: true }; } export async function moderateScript(id: string, isApproved: boolean, moderatorId: string) { return { id, isApproved }; } export async function incrementViewCount(id: string) { return { success: true }; } export async function incrementDownloadCount(id: string) { return { success: true }; }`; const mockRatings = `export interface CreateRatingData { scriptId: string; userId: string; rating: number; } export async function rateScript(data: CreateRatingData) { return { id: "mock-rating-id", ...data, createdAt: new Date(), updatedAt: new Date() }; } export async function getUserRating(scriptId: string, userId: string) { return null; } export async function getScriptRatings(scriptId: string) { return []; } export async function getScriptRatingStats(scriptId: string) { return { averageRating: 0, totalRatings: 0, distribution: [] }; } export async function deleteRating(scriptId: string, userId: string) { return { success: true }; }`; const mockAnalytics = `export interface TrackEventData { scriptId: string; eventType: string; userId?: string; userAgent?: string; ipAddress?: string; referrer?: string; } export interface AnalyticsFilters { scriptId?: string; eventType?: string; startDate?: Date; endDate?: Date; userId?: string; } export async function trackEvent(data: TrackEventData) { return { success: true }; } export async function getAnalyticsEvents(filters?: AnalyticsFilters) { return []; } export async function getScriptAnalytics(scriptId: string, days?: number) { return { eventCounts: [], dailyActivity: [], referrers: [], periodDays: days || 30 }; } export async function getPlatformAnalytics(days?: number) { return { totals: { totalScripts: 0, approvedScripts: 0, pendingScripts: 0 }, activityByType: [], popularScripts: [], dailyTrends: [], periodDays: days || 30 }; } export async function getUserAnalytics(userId: string, days?: number) { return { userScripts: [], recentActivity: [], periodDays: days || 30 }; }`; const mockCollections = `export interface CreateCollectionData { name: string; description?: string; authorId: string; isPublic?: boolean; } export interface UpdateCollectionData { name?: string; description?: string; isPublic?: boolean; } export async function createCollection(data: CreateCollectionData) { return { id: "mock-collection-id", ...data, createdAt: new Date(), updatedAt: new Date() }; } export async function getCollectionById(id: string) { return null; } export async function getUserCollections(userId: string) { return []; } export async function getPublicCollections(limit?: number, offset?: number) { return []; } export async function updateCollection(id: string, data: UpdateCollectionData, userId: string) { return { id, ...data, updatedAt: new Date() }; } export async function deleteCollection(id: string, userId: string) { return { success: true }; } export async function addScriptToCollection(collectionId: string, scriptId: string, userId: string) { return { id: "mock-collection-script-id", collectionId, scriptId, addedAt: new Date() }; } export async function removeScriptFromCollection(collectionId: string, scriptId: string, userId: string) { return { success: true }; } export async function isScriptInCollection(collectionId: string, scriptId: string) { return false; }`; const mockUsers = `export interface CreateUserData { email: string; username: string; displayName: string; avatarUrl?: string; bio?: string; } export interface UpdateUserData { username?: string; displayName?: string; avatarUrl?: string; bio?: string; } export async function createUser(data: CreateUserData) { return { id: "mock-user-id", ...data, isAdmin: false, isModerator: false, createdAt: new Date(), updatedAt: new Date() }; } export async function getUserById(id: string) { return null; } export async function getUserByEmail(email: string) { return null; } export async function getUserByUsername(username: string) { return null; } export async function updateUser(id: string, data: UpdateUserData) { return { id, ...data, updatedAt: new Date() }; } export async function updateUserPermissions(id: string, permissions: any) { return { id, ...permissions, updatedAt: new Date() }; } export async function searchUsers(query: string, limit?: number) { return []; } export async function getAllUsers(limit?: number, offset?: number) { return []; }`; fs.writeFileSync('src/lib/api/index.ts', mockIndex); fs.writeFileSync('src/lib/api/auth.ts', mockAuth); fs.writeFileSync('src/lib/api/scripts.ts', mockScripts); fs.writeFileSync('src/lib/api/ratings.ts', mockRatings); fs.writeFileSync('src/lib/api/analytics.ts', mockAnalytics); fs.writeFileSync('src/lib/api/collections.ts', mockCollections); fs.writeFileSync('src/lib/api/users.ts', mockUsers); console.log('✅ Switched to mock APIs! You can now run "npm run build"'); console.log('📝 To restore real APIs, run: node restore-apis.cjs');