@jonandev/longbeard 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +19 -0
- package/README.md +14 -14
- package/beard.json +1 -1
- package/bin/long-beard.js +68 -7
- package/package.json +1 -1
- package/skills/design-md/SKILL.md +28 -15
- package/skills/design-reference-hunt/SKILL.md +220 -64
- package/skills/design-reference-hunt/references/quality.md +34 -4
- package/skills/design-reference-hunt/references/shots.md +27 -7
- package/skills/design-reference-hunt/scripts/capture.mjs +190 -11
- package/skills/design-reference-hunt/scripts/contact-sheet.mjs +247 -0
- package/skills/design-reference-hunt/scripts/contrast.mjs +27 -0
- package/skills/design-reference-hunt/scripts/dribbble-cards.mjs +311 -0
- package/skills/design-reference-hunt/scripts/moodboard.mjs +520 -0
- package/skills/design-reference-hunt/scripts/proof.mjs +301 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// List Dribbble search/popular cards from a listing URL.
|
|
3
|
+
// Headless Chrome; prints TSV: id-slug\tlikes\tviews\timageURL\ttitle
|
|
4
|
+
// Counts come from the card's own stat elements. A column it cannot read
|
|
5
|
+
// stays empty. It never guesses a count from the title.
|
|
6
|
+
//
|
|
7
|
+
// Off-topic cards (merch, resumes, worksheets, posters) are dropped by slug
|
|
8
|
+
// and title before anything is fetched, and the noise rate goes to stderr.
|
|
9
|
+
//
|
|
10
|
+
// node dribbble-cards.mjs "https://dribbble.com/search/shots/popular/product-design?q=writing+app&timeframe=year" --scrolls 4
|
|
11
|
+
// node dribbble-cards.mjs "<url>" --drop "mood,habit" --keep "font,illustration"
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
const flag = (name, def) => {
|
|
19
|
+
const i = args.indexOf(`--${name}`);
|
|
20
|
+
if (i === -1) return def;
|
|
21
|
+
const v = args[i + 1];
|
|
22
|
+
args.splice(i, 2);
|
|
23
|
+
return v;
|
|
24
|
+
};
|
|
25
|
+
const has = (name) => {
|
|
26
|
+
const i = args.indexOf(`--${name}`);
|
|
27
|
+
if (i === -1) return false;
|
|
28
|
+
args.splice(i, 1);
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
31
|
+
const url = args[0];
|
|
32
|
+
const scrolls = Math.max(0, Number(flag("scrolls", "3")) || 3);
|
|
33
|
+
const noFilter = has("no-filter");
|
|
34
|
+
const words = (s) =>
|
|
35
|
+
String(s || "")
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.split(",")
|
|
38
|
+
.map((w) => w.trim())
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
// The shared negative list. These sell the word, not the form: a search for
|
|
41
|
+
// "writing app" returns tees, CV services and tracing worksheets.
|
|
42
|
+
const OFF_TOPIC = [
|
|
43
|
+
"t-shirt", "tshirt", "tee", "merch", "apparel", "hoodie",
|
|
44
|
+
"resume", "cv", "cover letter", "essay",
|
|
45
|
+
"worksheet", "tracing", "handwriting practice", "alphabet",
|
|
46
|
+
"halloween", "christmas", "valentine",
|
|
47
|
+
"logo", "logotype", "branding", "brand identity", "packaging",
|
|
48
|
+
"poster", "book cover", "sticker", "mockup",
|
|
49
|
+
"chatbot", "mood tracker", "habit tracker",
|
|
50
|
+
];
|
|
51
|
+
const keep = words(flag("keep", ""));
|
|
52
|
+
const dropWords = [...OFF_TOPIC.filter((w) => !keep.includes(w)), ...words(flag("drop", ""))];
|
|
53
|
+
if (!url || !/^https?:\/\/(www\.)?dribbble\.com\//i.test(url)) {
|
|
54
|
+
console.error(
|
|
55
|
+
'usage: node dribbble-cards.mjs "https://dribbble.com/search/..." [--scrolls 4] [--drop "a,b"] [--keep "a,b"] [--no-filter]',
|
|
56
|
+
);
|
|
57
|
+
process.exit(2);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Whole words only, so "ai" does not swallow "detail" and "cv" does not
|
|
61
|
+
// swallow "cvs". A hyphen in a slug counts as a space.
|
|
62
|
+
function offTopic(text) {
|
|
63
|
+
const hay = ` ${String(text).toLowerCase().replace(/[^a-z0-9]+/g, " ").trim()} `;
|
|
64
|
+
return dropWords.find((word) => hay.includes(` ${word.replace(/[^a-z0-9]+/g, " ")} `)) || "";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function findChrome() {
|
|
68
|
+
const env = process.env.CHROME_PATH;
|
|
69
|
+
if (env && existsSync(env)) return env;
|
|
70
|
+
const home = process.env.HOME || process.env.USERPROFILE || "";
|
|
71
|
+
const local = process.env.LOCALAPPDATA || "";
|
|
72
|
+
const pf = process.env.PROGRAMFILES || "C:\\Program Files";
|
|
73
|
+
const pf86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
|
|
74
|
+
const candidates = [
|
|
75
|
+
join(pf, "Google/Chrome/Application/chrome.exe"),
|
|
76
|
+
join(pf86, "Google/Chrome/Application/chrome.exe"),
|
|
77
|
+
join(local, "Google/Chrome/Application/chrome.exe"),
|
|
78
|
+
join(pf, "Microsoft/Edge/Application/msedge.exe"),
|
|
79
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
80
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
81
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
|
82
|
+
join(home, "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
|
|
83
|
+
"/usr/bin/google-chrome",
|
|
84
|
+
"/usr/bin/google-chrome-stable",
|
|
85
|
+
"/usr/bin/chromium",
|
|
86
|
+
"/usr/bin/chromium-browser",
|
|
87
|
+
];
|
|
88
|
+
return candidates.find((path) => path && existsSync(path)) || null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
92
|
+
const exe = findChrome();
|
|
93
|
+
if (!exe) {
|
|
94
|
+
console.error("No Chrome/Edge/Chromium found. Install one or set CHROME_PATH.");
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
if (typeof WebSocket === "undefined") {
|
|
98
|
+
console.error("Node 22+ is required.");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const dir = mkdtempSync(join(tmpdir(), "hunt-dribbble-"));
|
|
103
|
+
let proc;
|
|
104
|
+
const drop = () => {
|
|
105
|
+
try {
|
|
106
|
+
if (proc?.pid) process.kill(proc.pid, "SIGKILL");
|
|
107
|
+
} catch {}
|
|
108
|
+
try {
|
|
109
|
+
rmSync(dir, { recursive: true, force: true });
|
|
110
|
+
} catch {}
|
|
111
|
+
};
|
|
112
|
+
process.once("exit", drop);
|
|
113
|
+
|
|
114
|
+
proc = spawn(
|
|
115
|
+
exe,
|
|
116
|
+
[
|
|
117
|
+
"--headless=new",
|
|
118
|
+
"--remote-debugging-port=0",
|
|
119
|
+
`--user-data-dir=${dir}`,
|
|
120
|
+
"--no-first-run",
|
|
121
|
+
"--hide-scrollbars",
|
|
122
|
+
"--mute-audio",
|
|
123
|
+
"--force-color-profile=srgb",
|
|
124
|
+
"--window-size=1440,900",
|
|
125
|
+
"about:blank",
|
|
126
|
+
],
|
|
127
|
+
{ stdio: ["ignore", "ignore", "pipe"] },
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
let buf = "";
|
|
131
|
+
const wsUrl = await new Promise((resolveWs, reject) => {
|
|
132
|
+
const t = setTimeout(() => reject(new Error("Chrome did not start")), 20000);
|
|
133
|
+
proc.stderr.on("data", (d) => {
|
|
134
|
+
buf += d.toString();
|
|
135
|
+
const m = buf.match(/DevTools listening on (ws:\/\/[^\s]+)/);
|
|
136
|
+
if (m) {
|
|
137
|
+
clearTimeout(t);
|
|
138
|
+
resolveWs(m[1]);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
proc.on("exit", (code) => {
|
|
142
|
+
clearTimeout(t);
|
|
143
|
+
reject(new Error(`Chrome exited ${code}`));
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const ws = new WebSocket(wsUrl);
|
|
148
|
+
await new Promise((res, rej) => {
|
|
149
|
+
ws.onopen = res;
|
|
150
|
+
ws.onerror = () => rej(new Error("CDP socket failed"));
|
|
151
|
+
});
|
|
152
|
+
let nextId = 1;
|
|
153
|
+
const pending = new Map();
|
|
154
|
+
ws.onmessage = (ev) => {
|
|
155
|
+
const msg = JSON.parse(typeof ev.data === "string" ? ev.data : Buffer.from(ev.data).toString());
|
|
156
|
+
if (msg.id && pending.has(msg.id)) {
|
|
157
|
+
const { resolve: ok, reject: bad } = pending.get(msg.id);
|
|
158
|
+
pending.delete(msg.id);
|
|
159
|
+
if (msg.error) bad(new Error(msg.error.message));
|
|
160
|
+
else ok(msg.result);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const send = (method, params = {}, sessionId, timeoutMs = 30000) => {
|
|
164
|
+
const id = nextId++;
|
|
165
|
+
return new Promise((resolveSend, reject) => {
|
|
166
|
+
const timer = setTimeout(() => {
|
|
167
|
+
pending.delete(id);
|
|
168
|
+
reject(new Error(`CDP timeout: ${method}`));
|
|
169
|
+
}, timeoutMs);
|
|
170
|
+
pending.set(id, {
|
|
171
|
+
resolve: (v) => {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
resolveSend(v);
|
|
174
|
+
},
|
|
175
|
+
reject: (e) => {
|
|
176
|
+
clearTimeout(timer);
|
|
177
|
+
reject(e);
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
ws.send(JSON.stringify(sessionId ? { id, method, params, sessionId } : { id, method, params }));
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const { targetId } = await send("Target.createTarget", { url: "about:blank" });
|
|
185
|
+
const { sessionId } = await send("Target.attachToTarget", { targetId, flatten: true });
|
|
186
|
+
const page = (method, params, timeoutMs) => send(method, params, sessionId, timeoutMs);
|
|
187
|
+
|
|
188
|
+
await page("Page.enable");
|
|
189
|
+
await page("Runtime.enable");
|
|
190
|
+
await page("Emulation.setDeviceMetricsOverride", {
|
|
191
|
+
width: 1440,
|
|
192
|
+
height: 900,
|
|
193
|
+
deviceScaleFactor: 1,
|
|
194
|
+
mobile: false,
|
|
195
|
+
});
|
|
196
|
+
await page("Page.navigate", { url }, 40000);
|
|
197
|
+
await sleep(3000);
|
|
198
|
+
|
|
199
|
+
for (let i = 0; i < scrolls; i++) {
|
|
200
|
+
await page("Runtime.evaluate", {
|
|
201
|
+
expression: "window.scrollBy(0, Math.round(window.innerHeight * 0.9))",
|
|
202
|
+
returnByValue: true,
|
|
203
|
+
});
|
|
204
|
+
await sleep(900);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const { result } = await page("Runtime.evaluate", {
|
|
208
|
+
expression: `(() => {
|
|
209
|
+
const rows = [];
|
|
210
|
+
const seen = new Set();
|
|
211
|
+
const tidy = (t) => (t || "").replace(/\\s+/g, "");
|
|
212
|
+
const isCount = (t) => /^[\\d][\\d.,]*[kKmM]?$/.test(t);
|
|
213
|
+
const hints = (el) =>
|
|
214
|
+
["aria-label", "title", "class", "data-type", "data-test"]
|
|
215
|
+
.map((name) => el.getAttribute(name) || "")
|
|
216
|
+
.join(" ");
|
|
217
|
+
// A counter labelled as likes or views: its own text, or the one
|
|
218
|
+
// descendant that is nothing but a count.
|
|
219
|
+
const labelled = (li, word) => {
|
|
220
|
+
const re = new RegExp(word, "i");
|
|
221
|
+
for (const el of li.querySelectorAll("*")) {
|
|
222
|
+
if (!re.test(hints(el))) continue;
|
|
223
|
+
const own = tidy(el.textContent);
|
|
224
|
+
if (isCount(own)) return own;
|
|
225
|
+
for (const kid of el.querySelectorAll("*")) {
|
|
226
|
+
const t = tidy(kid.textContent);
|
|
227
|
+
if (isCount(t)) return t;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return "";
|
|
231
|
+
};
|
|
232
|
+
// Fallback: leaf elements whose whole text is a count, in DOM order.
|
|
233
|
+
// Dribbble prints likes first, then views. Free text is never read.
|
|
234
|
+
const leafCounts = (li) => {
|
|
235
|
+
const out = [];
|
|
236
|
+
for (const el of li.querySelectorAll("*")) {
|
|
237
|
+
if (el.children.length) continue;
|
|
238
|
+
const t = tidy(el.textContent);
|
|
239
|
+
if (isCount(t)) out.push(t);
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
};
|
|
243
|
+
for (const li of document.querySelectorAll("li")) {
|
|
244
|
+
const a = li.querySelector('a[href*="/shots/"]');
|
|
245
|
+
if (!a) continue;
|
|
246
|
+
const m = (a.getAttribute("href") || "").match(/\\/shots\\/([^/?#]+)/);
|
|
247
|
+
if (!m) continue;
|
|
248
|
+
const idSlug = m[1];
|
|
249
|
+
if (seen.has(idSlug)) continue;
|
|
250
|
+
const img = li.querySelector("img");
|
|
251
|
+
if (!img) continue;
|
|
252
|
+
const raw = img.getAttribute("data-src") || img.currentSrc || img.src || "";
|
|
253
|
+
const imageURL = raw.replace(/\\?.*$/, "");
|
|
254
|
+
if (!imageURL) continue;
|
|
255
|
+
seen.add(idSlug);
|
|
256
|
+
let likes = labelled(li, "like");
|
|
257
|
+
let views = labelled(li, "view");
|
|
258
|
+
if (!likes && !views) {
|
|
259
|
+
const counts = leafCounts(li);
|
|
260
|
+
likes = counts[0] || "";
|
|
261
|
+
views = counts[1] || "";
|
|
262
|
+
}
|
|
263
|
+
const title = (img.getAttribute("alt") || a.getAttribute("title") || idSlug).replace(/\\t/g, " ").trim();
|
|
264
|
+
rows.push([idSlug, likes, views, imageURL, title].join("\\t"));
|
|
265
|
+
}
|
|
266
|
+
return rows.join("\\n");
|
|
267
|
+
})()`,
|
|
268
|
+
returnByValue: true,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const tsv = result?.value || "";
|
|
272
|
+
if (!tsv.trim()) {
|
|
273
|
+
console.error(
|
|
274
|
+
"0 cards (empty listing or rate limit — retry after 8s, then after 30s; if it is still 0, record it under the board's drops as `<query>: 0 cards (rate limit?)`)",
|
|
275
|
+
);
|
|
276
|
+
drop();
|
|
277
|
+
process.exit(1);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const all = tsv.split("\n").filter(Boolean);
|
|
281
|
+
const reasons = new Map();
|
|
282
|
+
const kept = noFilter
|
|
283
|
+
? all
|
|
284
|
+
: all.filter((row) => {
|
|
285
|
+
const [idSlug, , , , title = ""] = row.split("\t");
|
|
286
|
+
const word = offTopic(`${idSlug} ${title}`);
|
|
287
|
+
if (!word) return true;
|
|
288
|
+
reasons.set(word, (reasons.get(word) ?? 0) + 1);
|
|
289
|
+
return false;
|
|
290
|
+
});
|
|
291
|
+
const cut = all.length - kept.length;
|
|
292
|
+
if (cut > 0) {
|
|
293
|
+
const top = [...reasons.entries()]
|
|
294
|
+
.sort((a, b) => b[1] - a[1])
|
|
295
|
+
.slice(0, 6)
|
|
296
|
+
.map(([word, n]) => `${word} ${n}`)
|
|
297
|
+
.join(", ");
|
|
298
|
+
// The noise rate belongs under the board's drops. A high one means the
|
|
299
|
+
// query is wrong, not that there is more scrolling to do.
|
|
300
|
+
console.error(
|
|
301
|
+
`${kept.length} of ${all.length} cards kept, ${Math.round((cut / all.length) * 100)}% off-topic (${top})`,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
if (!kept.length) {
|
|
305
|
+
console.error("every card was off-topic — query the form, not the word (add \"ui\", \"screen\", or a category path)");
|
|
306
|
+
drop();
|
|
307
|
+
process.exit(1);
|
|
308
|
+
}
|
|
309
|
+
console.log(kept.join("\n"));
|
|
310
|
+
drop();
|
|
311
|
+
process.exit(0);
|