tobogganSe connecter

library

Prebuilt pebble components: drop-in custom elements, no compiler needed

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

Dernier runAucun
0Étoiles
0Forks
2Issues
75 lignes · 3039 octetsBrut · Historique
1/**
2 * Prepares the pebble dev dependency: `bun run sync-pebble`.
3 *
4 * pebble is the library's only dependency and it is a local one:
5 * "@pebble/pebble": "file:../pebble/dist" — pebble's dist is its published face.
6 * This script makes that work from any checkout layout:
7 *
8 * 1. Finds the pebble checkout: $PEBBLE_REPO, else ../pebble (the canonical
9 * layout: ~/Projects/library next to ~/Projects/pebble), else
10 * ../../../pebble (an OpenCode worktree under .worktrees/).
11 * 2. If ../pebble does not exist but pebble was found elsewhere (the
12 * worktree case), symlinks ../pebble → the checkout, so the file:
13 * dependency resolves. In a fresh worktree, run this BEFORE `bun install`.
14 * 3. Rebuilds pebble's dist (`bun run build:lib` in the pebble checkout)
15 * when it is missing or older than pebble's sources.
16 *
17 * Needs no node_modules — safe to run before `bun install`.
18 */
19import { existsSync, lstatSync, readdirSync, statSync, symlinkSync } from "node:fs";
20import { join, resolve } from "node:path";
21
22const ROOT = `${import.meta.dir}/..`;
23const LINK_PATH = `${ROOT}/../pebble`;
24
25function findPebble(): string | undefined {
26 const candidates = [process.env.PEBBLE_REPO, LINK_PATH, `${ROOT}/../../../pebble`].filter((c): c is string => Boolean(c));
27 for (const candidate of candidates) {
28 if (existsSync(join(candidate, "package.json")) && existsSync(join(candidate, "scripts/build-lib.ts"))) {
29 return resolve(candidate);
30 }
31 }
32 return undefined;
33}
34
35/** Latest mtime across pebble's sources (src/, packages/, plugins/). */
36function newestSource(pebble: string): number {
37 let newest = 0;
38 const walk = (dir: string) => {
39 for (const entry of readdirSync(dir, { withFileTypes: true })) {
40 const path = join(dir, entry.name);
41 if (entry.isDirectory()) {
42 if (entry.name !== "node_modules" && entry.name !== "dist") walk(path);
43 } else if (/\.[cm]?[jt]sx?$|\.css$/.test(entry.name)) {
44 newest = Math.max(newest, statSync(path).mtimeMs);
45 }
46 }
47 };
48 for (const dir of ["src", "packages", "plugins"]) walk(join(pebble, dir));
49 return newest;
50}
51
52const pebble = findPebble();
53if (!pebble) {
54 throw new Error("pebble checkout not found (tried $PEBBLE_REPO, ../pebble, ../../../pebble); set PEBBLE_REPO=/path/to/pebble");
55}
56
57let linkExists = false;
58try {
59 lstatSync(LINK_PATH);
60 linkExists = true;
61} catch {}
62if (!linkExists) {
63 symlinkSync(pebble, LINK_PATH, "dir");
64 console.log(`linked ../pebble → ${pebble}`);
65}
66
67const distIndex = join(pebble, "dist/index.js");
68const stale = !existsSync(distIndex) || !existsSync(join(pebble, "dist/package.json")) || newestSource(pebble) > statSync(distIndex).mtimeMs;
69if (!stale) {
70 console.log(`pebble dist is fresh (${pebble})`);
71} else {
72 console.log(`building pebble dist (${pebble})…`);
73 const proc = Bun.spawnSync(["bun", "--cwd", pebble, "run", "build:lib"], { stdio: ["inherit", "inherit", "inherit"] });
74 if (proc.exitCode !== 0) throw new Error("pebble build:lib failed");
75}