Skip to content
Source
Sign inSign up
samwillis/neon-glow-demo
Open History to see the last commit

challenge.ts

14 lines1.1 KB

1import { config } from 'dotenv';
2import { randomUUID } from 'node:crypto';
3config({ path: '.env.local', quiet: true });
4const { database } = await import('../services/api/src/database.ts');
5​
6// Starts a remix challenge shown at the top of Discover. Entries are public remixes of the seed app.
7// Usage: pnpm exec tsx scripts/challenge.ts "<title>" "<description>" <seed-app-id> [days]
8const [title, description, seedAppId, days = '7'] = process.argv.slice(2);
9if (!title || !description || !seedAppId) throw new Error('Usage: scripts/challenge.ts "<title>" "<description>" <seed-app-id> [days]');
10const seed = await database().query(`SELECT data->>'title' AS title FROM glow_apps WHERE id=$1 AND data->>'visibility'='public'`, [seedAppId]);
11if (!seed.rows[0]) throw new Error('The seed app must be posted to the feed (public).');
12await database().query(`INSERT INTO glow_challenges(id,title,description,seed_app_id,ends_at) VALUES($1,$2,$3,$4,now()+make_interval(days => $5::int))`, [randomUUID(), title, description, seedAppId, Number(days)]);
13console.log(`Started "${title}" for ${days} days, seeded with ${seed.rows[0].title}.`);
14await database().end();