Download scripts/start-space.js from moustafa7/gymco: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/moustafa7/gymco/resolve/main/scripts/start-space.js
- Command line
-
hf download hf://spaces/moustafa7/gymco/scripts/start-space.js
-
curl -L -o start-space.js https://huggingface.co/spaces/moustafa7/gymco/resolve/main/scripts/start-space.js
1.3 kB
| import { spawnSync } from 'node:child_process'; | |
| import { PrismaClient } from '@prisma/client'; | |
| import { defaultExercises } from '../src/common/constants/defaultExercises.js'; | |
| process.env.DATABASE_URL ||= 'file:./dev.db'; | |
| process.env.JWT_ACCESS_SECRET ||= 'huggingface-demo-access-secret-change-me'; | |
| process.env.JWT_REFRESH_SECRET ||= 'huggingface-demo-refresh-secret-change-me'; | |
| const run = (command, args) => { | |
| const result = spawnSync(command, args, { | |
| env: process.env, | |
| shell: process.platform === 'win32', | |
| stdio: 'inherit', | |
| }); | |
| if (result.status !== 0) { | |
| process.exit(result.status || 1); | |
| } | |
| }; | |
| run('npx', ['prisma', 'db', 'push', '--skip-generate', '--accept-data-loss']); | |
| const prisma = new PrismaClient(); | |
| try { | |
| const users = await prisma.user.count(); | |
| if (users === 0) { | |
| run('node', ['prisma/seed.js']); | |
| } | |
| const globalExercises = await prisma.exercise.count({ where: { isGlobal: true } }); | |
| if (globalExercises === 0) { | |
| await prisma.exercise.createMany({ | |
| data: defaultExercises.map((exercise) => ({ | |
| ...exercise, | |
| gymId: null, | |
| isGlobal: true, | |
| })), | |
| }); | |
| console.log(`Seeded ${defaultExercises.length} global exercises.`); | |
| } | |
| } finally { | |
| await prisma.$disconnect(); | |
| } | |
| await import('../src/server.js'); | |