Refactor Dockerfile to enhance mock API structure by consolidating and expanding mock database and API files. Updated mock implementations for auth, scripts, ratings, analytics, collections, and users to include additional functionalities and improve overall API consistency for frontend-only builds.
This commit is contained in:
67
Dockerfile
67
Dockerfile
@ -31,60 +31,31 @@ RUN rm -rf src/lib/db || true
|
||||
|
||||
# Create mock API layer for frontend demo
|
||||
RUN mkdir -p src/lib/api src/lib/db
|
||||
RUN echo "export const db = {}; export * from './mock';" > src/lib/db/index.ts
|
||||
RUN echo "export const users = {}; export const scripts = {};" > src/lib/db/schema.ts
|
||||
RUN echo "export * from './mock';" > src/lib/api/index.ts
|
||||
|
||||
# Create mock API files
|
||||
RUN cat > src/lib/api/auth.ts << 'EOF'
|
||||
export const authApi = {
|
||||
login: async () => ({ token: 'demo', user: { id: '1', username: 'demo' } }),
|
||||
register: async () => ({ token: 'demo', user: { id: '1', username: 'demo' } }),
|
||||
};
|
||||
EOF
|
||||
# Create mock database files
|
||||
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 cat > src/lib/api/scripts.ts << 'EOF'
|
||||
export const scriptsApi = {
|
||||
getScripts: async () => ({ scripts: [], total: 0 }),
|
||||
getScript: async () => null,
|
||||
createScript: async () => ({}),
|
||||
updateScript: async () => ({}),
|
||||
deleteScript: async () => ({}),
|
||||
moderateScript: async () => ({}),
|
||||
};
|
||||
EOF
|
||||
# Create mock API index
|
||||
RUN echo "export const generateId = () => 'mock-id'; export class ApiError extends Error { constructor(message, status) { super(message); this.status = status; } }" > src/lib/api/index.ts
|
||||
|
||||
RUN cat > src/lib/api/ratings.ts << 'EOF'
|
||||
export const ratingsApi = {
|
||||
submitRating: async () => ({}),
|
||||
getUserRating: async () => null,
|
||||
getScriptRatingStats: async () => ({ averageRating: 0, totalRatings: 0 }),
|
||||
};
|
||||
EOF
|
||||
# Create mock auth API
|
||||
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/analytics.ts << 'EOF'
|
||||
export const analyticsApi = {
|
||||
trackEvent: async () => ({}),
|
||||
getAnalytics: async () => ({ views: [], downloads: [] }),
|
||||
};
|
||||
EOF
|
||||
# Create mock scripts API
|
||||
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/collections.ts << 'EOF'
|
||||
export const collectionsApi = {
|
||||
getCollections: async () => [],
|
||||
createCollection: async () => ({}),
|
||||
updateCollection: async () => ({}),
|
||||
deleteCollection: async () => ({}),
|
||||
};
|
||||
EOF
|
||||
# Create mock ratings API
|
||||
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/users.ts << 'EOF'
|
||||
export const usersApi = {
|
||||
getUser: async () => null,
|
||||
updateUser: async () => ({}),
|
||||
updateUserPermissions: async () => ({}),
|
||||
};
|
||||
EOF
|
||||
# Create mock analytics API
|
||||
RUN echo "export const analyticsApi = { trackEvent: async () => ({}), getAnalytics: async () => ({ views: [], downloads: [], topScripts: [], userGrowth: [] }) };" > src/lib/api/analytics.ts
|
||||
|
||||
# Create mock collections API
|
||||
RUN echo "export const collectionsApi = { getCollections: async () => [], createCollection: async () => ({}), updateCollection: async () => ({}), deleteCollection: async () => ({}), addScriptToCollection: async () => ({}), removeScriptFromCollection: async () => ({}) };" > src/lib/api/collections.ts
|
||||
|
||||
# Create mock users API
|
||||
RUN echo "export const usersApi = { getUser: async () => null, updateUser: async () => ({}), updateUserPermissions: async () => ({}), getAllUsers: async () => ([]), searchUsers: async () => ([]) };" > src/lib/api/users.ts
|
||||
|
||||
# Build the application (frontend only with mocks)
|
||||
RUN npm run build
|
||||
|
Reference in New Issue
Block a user