| 7 | } |
| 8 | |
| 9 | export const runSeed = async (options: SeedOptions): Promise<number> => { |
| 10 | if (options.count !== undefined) { |
| 11 | if (!Number.isSafeInteger(options.count) || options.count <= 0) { |
| 12 | throw new Error('--count must be a positive integer') |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | const spinner = ora('Seeding relay data...').start() |
| 17 | |
| 18 | const code = await runCommand('pnpm', ['run', 'db:seed'], { |
| 19 | env: options.count ? { NOSTREAM_SEED_COUNT: String(options.count) } : undefined, |
| 20 | }) |
| 21 | |
| 22 | if (code === 0) { |
| 23 | if (options.count) { |
| 24 | spinner.succeed(`Seed completed with ${options.count} events requested`) |
| 25 | } else { |
| 26 | spinner.succeed('Seed completed') |
| 27 | } |
| 28 | } else { |
| 29 | spinner.fail('Seed failed') |
| 30 | } |
| 31 | |
| 32 | return code |
| 33 | } |