cg / hackerproducts

63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.

Quick jump: page.tsx / page.tsx / globals.css / schema.sql / package.json

root / src / db / seed.ts

src/db/seed.ts · 200 lines · 6.5 KB← back to folder
1import fs from "node:fs";
2import path from "node:path";
3import crypto from "node:crypto";
4import { getPool, ensureSchema } from "./index";
5
6const envPath = path.join(process.cwd(), ".env.local");
7if (fs.existsSync(envPath)) {
8 const lines = fs.readFileSync(envPath, "utf8").split("\n");
9 for (const line of lines) {
10 const trimmed = line.trim();
11 if (!trimmed || trimmed.startsWith("#")) continue;
12 const eq = trimmed.indexOf("=");
13 if (eq === -1) continue;
14 const key = trimmed.slice(0, eq).trim();
15 const val = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
16 if (!process.env[key]) process.env[key] = val;
17 }
18}
19
20if (process.env.NODE_ENV === "production" || process.env.VERCEL_ENV === "production") {
21 console.error("Refusing to seed fabricated example data in production.");
22 process.exit(1);
23}
24
25async function main() {
26 await ensureSchema();
27 const pool = getPool();
28
29 const makers = [
30 {
31 id: "dev_arden",
32 username: "arden",
33 email: "arden@example.com",
34 name: "Arden",
35 bio: "Building small developer tools and terminal software.",
36 website_url: "https://vessel.sh",
37 is_admin: true,
38 },
39 {
40 id: "dev_mira",
41 username: "mira",
42 email: "mira@example.com",
43 name: "Mira Chen",
44 bio: "Independent maker working on local-first utilities and writing tools.",
45 website_url: "https://notate.app",
46 is_admin: false,
47 },
48 {
49 id: "dev_kyle",
50 username: "kyle",
51 email: "kyle@example.com",
52 name: "Kyle",
53 bio: "Systems engineer who likes fast software with zero fluff.",
54 website_url: "https://trace.dev",
55 is_admin: false,
56 },
57 ];
58
59 for (const m of makers) {
60 await pool.query(
61 `INSERT INTO users (id, username, email, name, bio, website_url, provider, provider_account_id, is_admin)
62 VALUES ($1, $2, $3, $4, $5, $6, 'dev', $1, $7)
63 ON CONFLICT (username) DO NOTHING`,
64 [m.id, m.username, m.email, m.name, m.bio, m.website_url, m.is_admin]
65 );
66 }
67
68 const products = [
69 {
70 owner_id: "dev_arden",
71 name: "Vessel",
72 slug: "vessel",
73 website_url: "https://vessel.sh",
74 description: "A fast, scriptable terminal workspace for running and managing tools.",
75 published_at: "2026-12-02T14:00:00Z",
76 readme_md: `Vessel gives you a single, scriptable workspace for the tools you use every day.
77
78Define processes in a simple config, start them together, and keep them running in a clean, minimal interface. It's designed to get out of your way and make local development feel a bit more sane.
79
80## Why I built it
81
82I was tired of juggling multiple terminals and ad-hoc scripts for every project. I wanted something minimal, fast, and easy to automate, so I built Vessel.
83
84## Features
85
86- Run and manage multiple processes from one config
87- Simple, scriptable configuration in TOML
88- Clean and fast terminal UI with zero Electron bloat
89- Works on macOS, Linux, and Windows
90
91## Quick start
92
93\`\`\`bash
94brew install vessel
95vessel init
96vessel up
97\`\`\``,
98 },
99 {
100 owner_id: "dev_kyle",
101 name: "Stacklet",
102 slug: "stacklet",
103 website_url: "https://stacklet.dev",
104 description: "Disposable cloud environments in seconds.",
105 published_at: "2026-12-02T11:30:00Z",
106 readme_md: `Stacklet spins up isolated Linux environments on demand and tears them down automatically when you close your terminal.
107
108## About
109
110No YAML pyramids or 15-minute container rebuilds. Point Stacklet at a repository and get a fresh machine with your dotfiles and tools ready in under 5 seconds.
111
112## Features
113
114- Cold start in under 5 seconds
115- Automatic idle shutdown so you never pay for forgotten VMs
116- SSH directly from your local terminal or editor`,
117 },
118 {
119 owner_id: "dev_kyle",
120 name: "Trace",
121 slug: "trace",
122 website_url: "https://trace.dev",
123 description: "Record, search and replay application behavior.",
124 published_at: "2026-12-02T09:15:00Z",
125 readme_md: `Trace captures structured execution logs locally so you can inspect and replay bugs without guessing what happened in production.
126
127## Why I built it
128
129Reproducing intermittent bugs across distributed workers wasted half my week. Trace records deterministic inputs and lets you step back through any request.`,
130 },
131 {
132 owner_id: "dev_mira",
133 name: "Screenie",
134 slug: "screenie",
135 website_url: "https://screenie.app",
136 description: "Lightweight screen recording for quick demos.",
137 published_at: "2026-12-01T16:00:00Z",
138 readme_md: `Screenie is a tiny screen recorder that starts in 100ms, records crisp 60fps video, and copies a shareable link to your clipboard.
139
140## Features
141
142- Record screen, window, or region
143- Instant trim and crop
144- Exports clean MP4 or GIF locally`,
145 },
146 {
147 owner_id: "dev_mira",
148 name: "Notate",
149 slug: "notate",
150 website_url: "https://notate.app",
151 description: "Minimal note-taking for technical work.",
152 published_at: "2026-12-01T10:00:00Z",
153 readme_md: `Notate stores plain Markdown files in a local folder with instant full-text search, keyboard navigation, and zero sync lock-in.
154
155## Why I built it
156
157Every note app eventually becomes a slow workspace platform. Notate is just fast plain-text notes with great code blocks and backlinks.`,
158 },
159 ];
160
161 for (const p of products) {
162 const id = crypto.randomUUID();
163 await pool.query(
164 `INSERT INTO products (id, owner_id, name, slug, website_url, description, readme_md, status, published_at)
165 VALUES ($1, $2, $3, $4, $5, $6, $7, 'published', $8)
166 ON CONFLICT (slug) DO NOTHING`,
167 [id, p.owner_id, p.name, p.slug, p.website_url, p.description, p.readme_md, p.published_at]
168 );
169 }
170
171 // Add a few realistic dev stars
172 const prodRows = await pool.query<{ id: string; slug: string }>(`SELECT id, slug FROM products`);
173 for (const row of prodRows.rows) {
174 await pool.query(
175 `INSERT INTO stars (user_id, product_id) VALUES ($1, $2) ON CONFLICT DO NOTHING`,
176 ["dev_arden", row.id]
177 );
178 if (row.slug === "vessel" || row.slug === "screenie") {
179 await pool.query(
180 `INSERT INTO stars (user_id, product_id) VALUES ($1, $2) ON CONFLICT DO NOTHING`,
181 ["dev_mira", row.id]
182 );
183 }
184 if (row.slug === "vessel") {
185 await pool.query(
186 `INSERT INTO stars (user_id, product_id) VALUES ($1, $2) ON CONFLICT DO NOTHING`,
187 ["dev_kyle", row.id]
188 );
189 }
190 }
191
192 console.log("Dev seed data inserted.");
193 await pool.end();
194}
195
196main().catch((err) => {
197 console.error("Seed failed:", err);
198 process.exit(1);
199});
200
cg / hackerproducts — hacker products