Refactor Dockerfile to create comprehensive mock API files with TypeScript support. Enhanced mock implementations for auth, scripts, ratings, analytics, collections, and users, ensuring complete interfaces and improved functionality for frontend-only builds.

This commit is contained in:
2025-08-15 22:46:21 +01:00
parent bc481fa798
commit 351304ac27

View File

@ -48,26 +48,123 @@ RUN mkdir -p src/lib/api src/lib/db
RUN echo "export const db = {};" > src/lib/db/index.ts RUN echo "export const db = {};" > src/lib/db/index.ts
RUN echo "export const users = {}; export const scripts = {}; export const ratings = {}; export const scriptVersions = {}; export const scriptAnalytics = {}; export const scriptCollections = {}; export const collectionScripts = {};" > src/lib/db/schema.ts RUN echo "export const users = {}; export const scripts = {}; export const ratings = {}; export const scriptVersions = {}; export const scriptAnalytics = {}; export const scriptCollections = {}; export const collectionScripts = {};" > src/lib/db/schema.ts
# Create mock API index # Create comprehensive mock API files with proper TypeScript support
RUN echo "export const generateId = () => Math.random().toString(36).substr(2, 9); export class ApiError extends Error { constructor(message, status) { super(message); this.status = status; } }" > src/lib/api/index.ts
# Create mock auth API # Mock API index with proper types
RUN echo "export const authApi = { login: async () => ({ token: 'demo', user: { id: '1', username: 'demo' } }), register: async () => ({ token: 'demo', user: { id: '1', username: 'demo' } }), changePassword: async () => ({}), refreshToken: async () => ({ token: 'demo' }) };" > src/lib/api/auth.ts RUN cat > src/lib/api/index.ts << 'EOFILE'
export const generateId = () => Math.random().toString(36).substr(2, 9);
export class ApiError extends Error {
constructor(message: string, public status: number) {
super(message);
this.status = status;
}
}
EOFILE
# Create mock scripts API # Mock auth API with complete interface
RUN echo "export const scriptsApi = { getScripts: async () => ({ scripts: [], total: 0 }), getScript: async () => null, createScript: async () => ({}), updateScript: async () => ({}), deleteScript: async () => ({}), moderateScript: async () => ({}) };" > src/lib/api/scripts.ts RUN cat > src/lib/api/auth.ts << 'EOFILE'
export const authApi = {
login: async (data: any) => ({ token: 'demo', user: { id: '1', username: 'demo' } }),
register: async (data: any) => ({ token: 'demo', user: { id: '1', username: 'demo' } }),
changePassword: async (data: any) => ({}),
refreshToken: async () => ({ token: 'demo' })
};
EOFILE
# Create mock ratings API # Mock scripts API with all required methods
RUN echo "export const ratingsApi = { submitRating: async () => ({}), getUserRating: async () => null, getScriptRatingStats: async () => ({ averageRating: 0, totalRatings: 0, distribution: {} }) };" > src/lib/api/ratings.ts RUN cat > src/lib/api/scripts.ts << 'EOFILE'
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 const scriptsApi = {
getScripts: async (filters?: ScriptFilters) => ({ scripts: [], total: 0 }),
getScriptById: async (id: string) => null,
getPopularScripts: async () => [],
getRecentScripts: async () => [],
createScript: async (data: any) => ({ id: 'mock' }),
updateScript: async (id: string, data: UpdateScriptData, userId: string) => ({ id }),
deleteScript: async (id: string, userId: string) => ({}),
moderateScript: async (id: string, isApproved: boolean, moderatorId: string) => ({ id, isApproved }),
incrementViewCount: async (id: string) => ({}),
incrementDownloadCount: async (id: string) => ({})
};
EOFILE
# Create mock analytics API # Mock ratings API with complete interface
RUN echo "export const analyticsApi = { trackEvent: async () => ({}), getAnalytics: async () => ({ views: [], downloads: [], topScripts: [], userGrowth: [] }) };" > src/lib/api/analytics.ts RUN cat > src/lib/api/ratings.ts << 'EOFILE'
export const ratingsApi = {
submitRating: async (data: any) => ({ scriptId: data.scriptId }),
rateScript: async (data: any) => ({ scriptId: data.scriptId }),
getUserRating: async (scriptId: string, userId?: string) => null,
getScriptRatings: async (scriptId: string) => [],
getScriptRatingStats: async (scriptId: string) => ({ averageRating: 0, totalRatings: 0, distribution: {} }),
deleteRating: async (scriptId: string, userId: string) => ({})
};
EOFILE
# Create mock collections API # Mock analytics API with complete interface
RUN echo "export const collectionsApi = { getCollections: async () => [], createCollection: async () => ({}), updateCollection: async () => ({}), deleteCollection: async () => ({}), addScriptToCollection: async () => ({}), removeScriptFromCollection: async () => ({}) };" > src/lib/api/collections.ts RUN cat > src/lib/api/analytics.ts << 'EOFILE'
export interface AnalyticsFilters {
startDate?: Date;
endDate?: Date;
}
export const analyticsApi = {
trackEvent: async (data: any) => ({}),
getAnalytics: async () => ({ views: [], downloads: [], topScripts: [], userGrowth: [] }),
getAnalyticsEvents: async (filters?: AnalyticsFilters) => [],
getScriptAnalytics: async (scriptId: string) => ({ views: [], downloads: [] }),
getPlatformAnalytics: async () => ({ totalUsers: 0, totalScripts: 0 }),
getUserAnalytics: async (userId: string) => ({ views: [], downloads: [] })
};
EOFILE
# Create mock users API # Mock collections API with complete interface
RUN echo "export const usersApi = { getUser: async () => null, updateUser: async () => ({}), updateUserPermissions: async () => ({}), getAllUsers: async () => ([]), searchUsers: async () => ([]) };" > src/lib/api/users.ts RUN cat > src/lib/api/collections.ts << 'EOFILE'
export interface UpdateCollectionData {
name?: string;
description?: string;
}
export const collectionsApi = {
getCollections: async () => [],
getCollectionById: async (id: string) => null,
getUserCollections: async (userId: string) => [],
getPublicCollections: async () => [],
createCollection: async (data: any) => ({ id: 'mock' }),
updateCollection: async (id: string, data: UpdateCollectionData) => ({ id }),
deleteCollection: async (id: string) => ({}),
addScriptToCollection: async (collectionId: string, scriptId: string) => ({}),
removeScriptFromCollection: async (collectionId: string, scriptId: string) => ({}),
isScriptInCollection: async (collectionId: string, scriptId: string) => false
};
EOFILE
# Mock users API with complete interface
RUN cat > src/lib/api/users.ts << 'EOFILE'
export interface UpdateUserData {
username?: string;
displayName?: string;
bio?: string;
}
export const usersApi = {
getUser: async (id: string) => null,
getUserById: async (id: string) => null,
getAllUsers: async () => [],
searchUsers: async (query: string) => [],
createUser: async (data: any) => ({ id: 'mock' }),
updateUser: async (id: string, data: UpdateUserData) => ({ id }),
updateUserPermissions: async (id: string, permissions: any) => ({ id })
};
EOFILE
# Build the application (frontend only with mocks) # Build the application (frontend only with mocks)
RUN npm run build RUN npm run build