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
109 lignes · 4848 octetsBrut · Historique
1/**
2 * Publish the components to toboggan's npm registry (@pebble/<name>).
3 *
4 * 1. bun run build — fresh dist/.
5 * 2. bun test — the full board, size budgets included; nothing ships red.
6 * 3. Assemble dist/publish/<name>/: the PREBUILT package (bundle + the
7 * declarations its index reaches, scripts/declarations.ts + css), never
8 * the TS source — the library's promise is "no
9 * compiler needed". The package.json is generated here from
10 * packages/<name>/package.json (name/version/description are the source
11 * of truth) with exports aimed at the built files.
12 * 4. Pre-check each packument: a 200 already carrying the version aborts
13 * (versions are immutable; bump the package's version first).
14 * 5. bun publish each, from inside its publish dir so its .npmrc applies
15 * (bun 1.4: bun publish <dir> from elsewhere did not authenticate).
16 *
17 * `bun run publish tablet toaster` publishes only the packages named; with no
18 * names, every package. A named package whose version is already published
19 * still aborts: the guard catches a forgotten bump.
20 *
21 * Token: $TOBOGGAN_TOKEN, a Packages: pull and push token (settings → Personal
22 * tokens). The trailing slash on the registry URL is load-bearing.
23 */
24import { Glob } from "bun";
25import { shipped } from "./declarations";
26
27const ROOT = `${import.meta.dir}/..`;
28const REGISTRY = "https://toboggan.cloud/npm/";
29
30const run = (cmd: string[], cwd: string = ROOT): void => {
31 const proc = Bun.spawnSync(cmd, { cwd, stdout: "inherit", stderr: "inherit" });
32 if (proc.exitCode !== 0) throw new Error(`${cmd.join(" ")} failed (${proc.exitCode})`);
33};
34
35const token = process.env.TOBOGGAN_TOKEN;
36if (!token) throw new Error("TOBOGGAN_TOKEN is not set — publish needs a Packages: pull and push token (settings → Personal tokens).");
37
38run(["bun", "run", "build"]);
39run(["bun", "test"]);
40
41const npmrc = `@pebble:registry=${REGISTRY}\n//toboggan.cloud/npm/:_authToken=${token}\n`;
42
43const only = process.argv.slice(2);
44for (const pkgPath of new Glob("packages/*/package.json").scanSync(ROOT)) {
45 const name = pkgPath.split("/")[1];
46 if (only.length > 0 && !only.includes(name)) continue;
47 const meta = (await Bun.file(`${ROOT}/${pkgPath}`).json()) as {
48 name: string;
49 version: string;
50 description?: string;
51 dependencies?: Record<string, string>;
52 peerDependencies?: Record<string, string>;
53 };
54 const declared = Object.keys({ ...meta.dependencies, ...meta.peerDependencies });
55 const declarations = shipped(`${ROOT}/dist/types`, name, declared);
56 const out = `${ROOT}/dist/publish/${name}`;
57
58 // The publishable face: built files only.
59 run(["rm", "-rf", out]);
60 run(["mkdir", "-p", out]);
61 run(["cp", `${ROOT}/dist/${name}.js`, `${ROOT}/dist/${name}.js.map`, `${ROOT}/dist/${name}.css`, out]);
62 for (const file of declarations) {
63 run(["mkdir", "-p", `${out}/types/${name}/${file.split("/").slice(0, -1).join("/")}`]);
64 run(["cp", `${ROOT}/dist/types/${name}/${file}`, `${out}/types/${name}/${file}`]);
65 }
66 await Bun.write(`${out}/index.d.ts`, `export * from "./types/${name}/index";\n`);
67 await Bun.write(
68 `${out}/package.json`,
69 `${JSON.stringify(
70 {
71 name: meta.name,
72 version: meta.version,
73 description: meta.description,
74 type: "module",
75 dependencies: meta.dependencies,
76 peerDependencies: meta.peerDependencies,
77 exports: {
78 ".": { types: "./index.d.ts", default: `./${name}.js` },
79 [`./${name}.css`]: `./${name}.css`,
80 },
81 files: [`${name}.js`, `${name}.js.map`, `${name}.css`, "index.d.ts", `types/${name}/**`],
82 publishConfig: { access: "public" },
83 },
84 null,
85 2,
86 )}\n`,
87 );
88 await Bun.write(`${out}/.npmrc`, npmrc);
89
90 try {
91 const res = await fetch(`${REGISTRY}${meta.name}`, { headers: { authorization: `Bearer ${token}` } });
92 if (res.status === 200) {
93 const packument = (await res.json()) as { versions?: Record<string, unknown> };
94 if (packument.versions?.[meta.version] !== undefined)
95 throw new Error(`${meta.name}@${meta.version} is already published — versions are immutable. Bump "version" in ${pkgPath}, then publish again.`);
96 } else if (res.status === 404) {
97 console.log(`${meta.name}: new package — publishing ${meta.version}`);
98 } else if (res.status === 401 || res.status === 403) {
99 throw new Error(`packument pre-check: ${res.status} — the token cannot read ${meta.name}; a publish needs a Packages: pull and push token.`);
100 }
101
102 run(["bun", "publish"], out);
103 console.log(`published ${meta.name}@${meta.version}`);
104 } finally {
105 // The token never outlives the publish.
106 const { rm } = await import("node:fs/promises");
107 await rm(`${out}/.npmrc`, { force: true }).catch(() => {});
108 }
109}