Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions epicshop/post-set-playground.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { existsSync } from 'node:fs'
import { unlink } from 'node:fs/promises'
import { join } from 'node:path'
import { execa } from 'execa'

const seedPath = join(
process.env.EPICSHOP_PLAYGROUND_DEST_DIR,
'src',
'db',
'seed.ts',
)
const playgroundDir = process.env.EPICSHOP_PLAYGROUND_DEST_DIR
const seedPath = join(playgroundDir, 'src', 'db', 'seed.ts')

// Delete the database file if it exists to prevent EBUSY errors when switching playgrounds
const dbPath = join(playgroundDir, 'db.sqlite')
if (existsSync(dbPath)) {
console.log('Deleting existing database file...')
try {
await unlink(dbPath)
console.log('Database file deleted successfully')
} catch (error) {
console.warn('Failed to delete database file:', error.message)
// Continue anyway - the seed script will also try to delete it
}
}

if (existsSync(seedPath)) {
console.log('Running seed script...')
try {
await execa('npx', ['tsx', seedPath], {
cwd: process.env.EPICSHOP_PLAYGROUND_DEST_DIR,
cwd: playgroundDir,
stdio: 'inherit',
})
console.log('Seed script completed successfully')
Expand Down
Loading