Refactor Dockerfile to utilize printf for creating comprehensive mock API files, ensuring reliable multiline content. Updated mock implementations for auth, scripts, ratings, analytics, collections, and users to maintain complete interfaces for frontend-only builds.
This commit is contained in:
113
Dockerfile
113
Dockerfile
@ -48,123 +48,28 @@ RUN mkdir -p src/lib/api src/lib/db
|
||||
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
|
||||
|
||||
# Create comprehensive mock API files with proper TypeScript support
|
||||
# Create comprehensive mock API files using printf for reliable multiline content
|
||||
|
||||
# Mock API index with proper types
|
||||
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
|
||||
RUN printf 'export const generateId = () => Math.random().toString(36).substr(2, 9);\nexport class ApiError extends Error {\n constructor(message: string, public status: number) {\n super(message);\n this.status = status;\n }\n}' > src/lib/api/index.ts
|
||||
|
||||
# Mock auth API with complete interface
|
||||
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
|
||||
# Mock auth API with complete interface
|
||||
RUN printf 'export const authApi = {\n login: async (data: any) => ({ token: "demo", user: { id: "1", username: "demo" } }),\n register: async (data: any) => ({ token: "demo", user: { id: "1", username: "demo" } }),\n changePassword: async (data: any) => ({}),\n refreshToken: async () => ({ token: "demo" })\n};' > src/lib/api/auth.ts
|
||||
|
||||
# Mock scripts API with all required methods
|
||||
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
|
||||
RUN printf 'export interface ScriptFilters {\n search?: string;\n categories?: string[];\n compatibleOs?: string[];\n sortBy?: string;\n limit?: number;\n isApproved?: boolean;\n}\nexport interface UpdateScriptData {\n name?: string;\n description?: string;\n content?: string;\n}\nexport const scriptsApi = {\n getScripts: async (filters?: ScriptFilters) => ({ scripts: [], total: 0 }),\n getScriptById: async (id: string) => null,\n getPopularScripts: async () => [],\n getRecentScripts: async () => [],\n createScript: async (data: any) => ({ id: "mock" }),\n updateScript: async (id: string, data: UpdateScriptData, userId: string) => ({ id }),\n deleteScript: async (id: string, userId: string) => ({}),\n moderateScript: async (id: string, isApproved: boolean, moderatorId: string) => ({ id, isApproved }),\n incrementViewCount: async (id: string) => ({}),\n incrementDownloadCount: async (id: string) => ({})\n};' > src/lib/api/scripts.ts
|
||||
|
||||
# Mock ratings API with complete interface
|
||||
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
|
||||
RUN printf 'export const ratingsApi = {\n submitRating: async (data: any) => ({ scriptId: data.scriptId }),\n rateScript: async (data: any) => ({ scriptId: data.scriptId }),\n getUserRating: async (scriptId: string, userId?: string) => null,\n getScriptRatings: async (scriptId: string) => [],\n getScriptRatingStats: async (scriptId: string) => ({ averageRating: 0, totalRatings: 0, distribution: {} }),\n deleteRating: async (scriptId: string, userId: string) => ({})\n};' > src/lib/api/ratings.ts
|
||||
|
||||
# Mock analytics API with complete interface
|
||||
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
|
||||
RUN printf 'export interface AnalyticsFilters {\n startDate?: Date;\n endDate?: Date;\n}\nexport const analyticsApi = {\n trackEvent: async (data: any) => ({}),\n getAnalytics: async () => ({ views: [], downloads: [], topScripts: [], userGrowth: [] }),\n getAnalyticsEvents: async (filters?: AnalyticsFilters) => [],\n getScriptAnalytics: async (scriptId: string) => ({ views: [], downloads: [] }),\n getPlatformAnalytics: async () => ({ totalUsers: 0, totalScripts: 0 }),\n getUserAnalytics: async (userId: string) => ({ views: [], downloads: [] })\n};' > src/lib/api/analytics.ts
|
||||
|
||||
# Mock collections API with complete interface
|
||||
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
|
||||
RUN printf 'export interface UpdateCollectionData {\n name?: string;\n description?: string;\n}\nexport const collectionsApi = {\n getCollections: async () => [],\n getCollectionById: async (id: string) => null,\n getUserCollections: async (userId: string) => [],\n getPublicCollections: async () => [],\n createCollection: async (data: any) => ({ id: "mock" }),\n updateCollection: async (id: string, data: UpdateCollectionData) => ({ id }),\n deleteCollection: async (id: string) => ({}),\n addScriptToCollection: async (collectionId: string, scriptId: string) => ({}),\n removeScriptFromCollection: async (collectionId: string, scriptId: string) => ({}),\n isScriptInCollection: async (collectionId: string, scriptId: string) => false\n};' > src/lib/api/collections.ts
|
||||
|
||||
# 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
|
||||
RUN printf 'export interface UpdateUserData {\n username?: string;\n displayName?: string;\n bio?: string;\n}\nexport const usersApi = {\n getUser: async (id: string) => null,\n getUserById: async (id: string) => null,\n getAllUsers: async () => [],\n searchUsers: async (query: string) => [],\n createUser: async (data: any) => ({ id: "mock" }),\n updateUser: async (id: string, data: UpdateUserData) => ({ id }),\n updateUserPermissions: async (id: string, permissions: any) => ({ id })\n};' > src/lib/api/users.ts
|
||||
|
||||
# Build the application (frontend only with mocks)
|
||||
RUN npm run build
|
||||
|
Reference in New Issue
Block a user