@calo-design/cli 0.13.2 → 0.13.4
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/bin/backend.js +42 -3
- package/package.json +1 -1
package/bin/backend.js
CHANGED
|
@@ -104,6 +104,30 @@ function recipesDir(root) {
|
|
|
104
104
|
|
|
105
105
|
const listRecipes = (dir) => fs.readdirSync(dir).filter((r) => fs.existsSync(path.join(dir, r, "recipe.json")));
|
|
106
106
|
|
|
107
|
+
// Which resources a worker/ dir needs, inferred from the bindings its code references
|
|
108
|
+
// (env.DB → d1, env.KV → kv, env.BUCKET → r2). Used on the reconnect/fork path where
|
|
109
|
+
// there's no recipe.json to read — a fork of ANY recipe provisions the right resources,
|
|
110
|
+
// not just d1. Scans worker source (skips migrations/); migrations also imply d1.
|
|
111
|
+
function inferResources(workerDir) {
|
|
112
|
+
const kinds = new Set();
|
|
113
|
+
const scan = (d) => {
|
|
114
|
+
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
|
|
115
|
+
const p = path.join(d, e.name);
|
|
116
|
+
if (e.isDirectory()) {
|
|
117
|
+
if (e.name === "migrations") kinds.add("d1");
|
|
118
|
+
else scan(p);
|
|
119
|
+
} else if (/\.(js|ts|mjs)$/.test(e.name)) {
|
|
120
|
+
const src = fs.readFileSync(p, "utf8");
|
|
121
|
+
if (/\benv\.DB\b/.test(src)) kinds.add("d1");
|
|
122
|
+
if (/\benv\.KV\b/.test(src)) kinds.add("kv");
|
|
123
|
+
if (/\benv\.BUCKET\b/.test(src)) kinds.add("r2");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
try { scan(workerDir); } catch {}
|
|
128
|
+
return [...kinds];
|
|
129
|
+
}
|
|
130
|
+
|
|
107
131
|
// --- verbs ----------------------------------------------------------------------------
|
|
108
132
|
|
|
109
133
|
// Scaffold (recipe → worker/) + provision + write backend.json + glue. One command in
|
|
@@ -137,8 +161,10 @@ async function cmdInit(args) {
|
|
|
137
161
|
} else {
|
|
138
162
|
log(c.dim(`worker/ already exists — ${existing ? "re-checking provisioning" : "reconnecting it to a provisioned backend"}`));
|
|
139
163
|
recipe = recipe || (existing && existing.recipe) || undefined;
|
|
140
|
-
// Infer
|
|
141
|
-
|
|
164
|
+
// Infer resource needs from what the worker code actually BINDS — env.DB (d1),
|
|
165
|
+
// env.KV (kv), env.BUCKET (r2) — so a fork of any recipe (or a hand-written worker)
|
|
166
|
+
// provisions the right resources. (Migrations imply d1 too, as a belt.)
|
|
167
|
+
recipeResources = inferResources(workerDir);
|
|
142
168
|
}
|
|
143
169
|
|
|
144
170
|
// Provision. When we hold no backend.json we always ask for a key: for a brand-new
|
|
@@ -380,10 +406,23 @@ async function cmdRotateKey(args) {
|
|
|
380
406
|
warn("published web shares still carry the OLD key baked into their bundle — re-run `calo-design share` to fix them");
|
|
381
407
|
}
|
|
382
408
|
|
|
409
|
+
// Org-wide backend list for the Design Kitchen dashboard (machine-facing; --json).
|
|
410
|
+
async function cmdAll(args) {
|
|
411
|
+
const text = await call("GET", "/v1/backend/all", { raw: true });
|
|
412
|
+
if (has(args, "json")) return emitJson(text);
|
|
413
|
+
const { backends } = JSON.parse(text);
|
|
414
|
+
if (!backends.length) return log(c.dim("no prototype backends yet"));
|
|
415
|
+
for (const b of backends) {
|
|
416
|
+
const who = (b.owner || "").split("@")[0];
|
|
417
|
+
log(`${c.b(b.slug)} ${c.dim(who)} ${b.resources.join("+") || c.dim("worker")}${b.deployed ? "" : c.dim(" (not deployed)")}`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
383
421
|
async function cmdBackend(args) {
|
|
384
422
|
const sub = args[0] && !args[0].startsWith("--") ? args[0] : "";
|
|
385
423
|
const rest = args.slice(1);
|
|
386
424
|
if (sub === "init") return cmdInit(rest);
|
|
425
|
+
if (sub === "all") return cmdAll(rest);
|
|
387
426
|
if (sub === "add") return cmdAdd(rest);
|
|
388
427
|
if (sub === "deploy") return cmdDeploy(rest);
|
|
389
428
|
if (sub === "status") return cmdStatus(rest);
|
|
@@ -393,7 +432,7 @@ async function cmdBackend(args) {
|
|
|
393
432
|
if (sub === "secrets") return cmdSecrets(rest);
|
|
394
433
|
if (sub === "rotate-key") return cmdRotateKey(rest);
|
|
395
434
|
throw new Error(
|
|
396
|
-
"unknown backend command — one of: init, add <d1|kv|r2>, deploy, status, logs, sql, check, secrets set, rotate-key"
|
|
435
|
+
"unknown backend command — one of: init, add <d1|kv|r2>, deploy, status, logs, sql, check, secrets set, rotate-key, all"
|
|
397
436
|
);
|
|
398
437
|
}
|
|
399
438
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calo-design/cli",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.4",
|
|
4
4
|
"description": "One-line setup for Calo design tooling: logs in with your Calo email and installs the calo-design skill + design-system packages. No GitHub account needed.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"calo-design": "bin/cli.js"
|