@mediamonks/canopy-cli 0.0.1 → 0.2.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/dist/api-CyJ-wBZh.mjs +40 -0
- package/dist/config-C-z7st1X.mjs +33 -0
- package/dist/{db-BBcgT1md.mjs → db-CtUG4vfG.mjs} +3 -3
- package/dist/{deploy-BfhAlb91.mjs → deploy-N88l4Kt3.mjs} +7 -6
- package/dist/{dev-BB7CwqoI.mjs → dev-DTGW0lm0.mjs} +6 -5
- package/dist/dev-D_GlUULk.mjs +2 -0
- package/dist/docs/ci.md +48 -0
- package/dist/docs/cli.md +67 -0
- package/dist/docs/data.md +49 -0
- package/dist/docs/deploy.md +50 -0
- package/dist/docs/dev.md +44 -0
- package/dist/docs/getting-started.md +100 -0
- package/dist/docs/troubleshooting.md +61 -0
- package/dist/docs-C3aOAx_A.mjs +179 -0
- package/dist/index.mjs +26 -16
- package/dist/{local-DhufX0eJ.mjs → local-951zc9qJ.mjs} +2 -2
- package/dist/{login-DrXKOEmr.mjs → login-Dif9Y32q.mjs} +38 -10
- package/dist/{open-DFWvrLFc.mjs → open-xLiGUz_W.mjs} +2 -2
- package/dist/package-OcWG7JAW.mjs +4 -0
- package/dist/{project-CrrpLEPs.mjs → project-CpiPLNby.mjs} +1 -1
- package/dist/projects-DJT_mJDR.mjs +228 -0
- package/dist/skill/canopy/SKILL.md +80 -0
- package/dist/skill-jbmERP1X.mjs +84 -0
- package/dist/templates/spa/.github/workflows/canopy-deploy.yml +34 -0
- package/dist/templates/spa/AGENTS.md +43 -0
- package/dist/templates/spa/README.md +14 -0
- package/dist/templates/spa/_gitignore +4 -0
- package/dist/templates/spa/canopy.json +5 -0
- package/dist/templates/spa/index.html +12 -0
- package/dist/templates/spa/package.json +21 -0
- package/dist/templates/spa/src/app.tsx +25 -0
- package/dist/templates/spa/src/canopy.ts +5 -0
- package/dist/templates/spa/src/main.tsx +10 -0
- package/dist/templates/spa/src/style.css +29 -0
- package/dist/templates/spa/tsconfig.json +16 -0
- package/dist/templates/spa/vite.config.ts +7 -0
- package/dist/templates/static/AGENTS.md +41 -0
- package/dist/templates/static/README.md +9 -0
- package/dist/templates/static/_gitignore +2 -0
- package/dist/templates/static/canopy.json +4 -0
- package/dist/templates/static/index.html +21 -0
- package/dist/templates/static/main.js +9 -0
- package/dist/templates/static/style.css +29 -0
- package/dist/templates/worker/.github/workflows/canopy-deploy.yml +34 -0
- package/dist/templates/worker/AGENTS.md +51 -0
- package/dist/templates/worker/README.md +18 -0
- package/dist/templates/worker/_gitignore +4 -0
- package/dist/templates/worker/canopy.json +6 -0
- package/dist/templates/worker/index.html +12 -0
- package/dist/templates/worker/package.json +22 -0
- package/dist/templates/worker/src/app.tsx +25 -0
- package/dist/templates/worker/src/canopy.ts +5 -0
- package/dist/templates/worker/src/main.tsx +10 -0
- package/dist/templates/worker/src/style.css +29 -0
- package/dist/templates/worker/tsconfig.json +16 -0
- package/dist/templates/worker/vite.config.ts +7 -0
- package/dist/templates/worker/worker/index.ts +29 -0
- package/dist/token-rTD9jxPZ.mjs +75 -0
- package/dist/ui-C8VuPzGp.mjs +40 -0
- package/dist/upgrade-Y8ejvoeg.mjs +99 -0
- package/dist/version-check-CoWgQs2h.mjs +128 -0
- package/package.json +2 -2
- package/dist/api-BEY4O4ap.mjs +0 -36
- package/dist/dev-Bvy21srH.mjs +0 -2
- package/dist/projects-f_KocDae.mjs +0 -295
- package/dist/ui-Cl5P_yQ6.mjs +0 -72
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import { i as unwrap, n as reportErrors, r as requireTty } from "./ui-Cl5P_yQ6.mjs";
|
|
2
|
-
import { t as apiRequest } from "./api-BEY4O4ap.mjs";
|
|
3
|
-
import { r as projectUrl } from "./project-CrrpLEPs.mjs";
|
|
4
|
-
import { defineCommand } from "citty";
|
|
5
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
6
|
-
import * as p from "@clack/prompts";
|
|
7
|
-
import { join, resolve } from "node:path";
|
|
8
|
-
//#region src/template.ts
|
|
9
|
-
function templateFiles({ name, slug }) {
|
|
10
|
-
return {
|
|
11
|
-
"canopy.json": `${JSON.stringify({
|
|
12
|
-
slug,
|
|
13
|
-
dist: "."
|
|
14
|
-
}, null, 2)}\n`,
|
|
15
|
-
".gitignore": `.canopy/
|
|
16
|
-
.DS_Store
|
|
17
|
-
`,
|
|
18
|
-
"index.html": `<!doctype html>
|
|
19
|
-
<html lang="en">
|
|
20
|
-
<head>
|
|
21
|
-
<meta charset="UTF-8" />
|
|
22
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
23
|
-
<title>${name}</title>
|
|
24
|
-
<link rel="stylesheet" href="./style.css" />
|
|
25
|
-
</head>
|
|
26
|
-
<body>
|
|
27
|
-
<main>
|
|
28
|
-
<h1>${name}</h1>
|
|
29
|
-
<p class="status" id="status">connecting to Canopy…</p>
|
|
30
|
-
<section id="app">
|
|
31
|
-
<p class="placeholder">Start building — edit <code>main.js</code>, then run <code>canopy deploy</code>.</p>
|
|
32
|
-
</section>
|
|
33
|
-
</main>
|
|
34
|
-
<script type="module" src="./main.js"><\/script>
|
|
35
|
-
</body>
|
|
36
|
-
</html>
|
|
37
|
-
`,
|
|
38
|
-
"main.js": `// The Canopy SDK is served by the platform itself — nothing to install.
|
|
39
|
-
// Auth (auth), data (db), files (blob) and AI (ai) are all live — see
|
|
40
|
-
// CLAUDE.md for the full surface.
|
|
41
|
-
import { createCanopy } from "/_api/v1/sdk.js";
|
|
42
|
-
|
|
43
|
-
const canopy = createCanopy();
|
|
44
|
-
|
|
45
|
-
const user = await canopy.auth.user();
|
|
46
|
-
document.getElementById("status").textContent = \`signed in as \${user.email}\`;
|
|
47
|
-
`,
|
|
48
|
-
"style.css": `:root {
|
|
49
|
-
font-family: system-ui, sans-serif;
|
|
50
|
-
color-scheme: light dark;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
body {
|
|
54
|
-
margin: 0;
|
|
55
|
-
display: grid;
|
|
56
|
-
place-items: center;
|
|
57
|
-
min-height: 100vh;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
main {
|
|
61
|
-
max-width: 40rem;
|
|
62
|
-
padding: 2rem;
|
|
63
|
-
text-align: center;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.status {
|
|
67
|
-
font-size: 0.9rem;
|
|
68
|
-
opacity: 0.7;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.placeholder {
|
|
72
|
-
border: 1px dashed color-mix(in srgb, currentColor 30%, transparent);
|
|
73
|
-
border-radius: 8px;
|
|
74
|
-
padding: 1.5rem;
|
|
75
|
-
opacity: 0.6;
|
|
76
|
-
}
|
|
77
|
-
`,
|
|
78
|
-
"CLAUDE.md": `# ${name} — a Canopy project
|
|
79
|
-
|
|
80
|
-
This is a static web app on Canopy, the managed platform for internal Monks
|
|
81
|
-
projects. Everything is served behind company login; there is no
|
|
82
|
-
infrastructure to manage and none should be added.
|
|
83
|
-
|
|
84
|
-
## The paved road
|
|
85
|
-
|
|
86
|
-
- Frontend only: html/css/js in this directory (add a bundler if you must,
|
|
87
|
-
set \`build\` and \`dist\` in canopy.json accordingly).
|
|
88
|
-
- All backend needs go through the Canopy SDK — never call external APIs with
|
|
89
|
-
secrets from the browser, never add your own server:
|
|
90
|
-
\`\`\`js
|
|
91
|
-
import { createCanopy } from "/_api/v1/sdk.js";
|
|
92
|
-
const canopy = createCanopy();
|
|
93
|
-
const user = await canopy.auth.user(); // { id, email, name, kind }
|
|
94
|
-
|
|
95
|
-
// Data — document collections on the project's own database (no tables, no migrations):
|
|
96
|
-
const todos = canopy.db.collection("todos");
|
|
97
|
-
const doc = await todos.insert({ title: "hi", done: false }); // -> data + { _id, _createdAt, _updatedAt }
|
|
98
|
-
await todos.find({ where: { done: false }, orderBy: "_createdAt", order: "desc", limit: 20 });
|
|
99
|
-
await todos.get(doc._id); // Doc | null
|
|
100
|
-
await todos.update(doc._id, { done: true }); // merge-patch; null removes a key
|
|
101
|
-
await todos.delete(doc._id);
|
|
102
|
-
await todos.search("groceries"); // full-text search over the collection
|
|
103
|
-
await canopy.db.sql("SELECT ... WHERE x = ?", [param]); // raw SQL escape hatch, same database — always parameterize with ?
|
|
104
|
-
|
|
105
|
-
// Files — private storage on the project's own prefix (never public):
|
|
106
|
-
await canopy.blob.put("notes.txt", "hello", { contentType: "text/plain" });
|
|
107
|
-
const blob = await canopy.blob.get("notes.txt"); // Blob | null — .text(), .arrayBuffer(), URL.createObjectURL(...)
|
|
108
|
-
const { url } = await canopy.blob.getUrl("notes.txt"); // short-lived URL for <img src> / links
|
|
109
|
-
await canopy.blob.list("some/prefix/"); // [{ key, size, contentType, uploadedAt }]
|
|
110
|
-
await canopy.blob.delete("notes.txt");
|
|
111
|
-
|
|
112
|
-
// AI — LLM calls through the project's metered, budget-capped gateway:
|
|
113
|
-
const { message } = await canopy.ai.chat({ messages: [{ role: "user", content: "hi" }] });
|
|
114
|
-
// Streaming variant: canopy.ai.chatStream(sameOptions) -> SSE ReadableStream.
|
|
115
|
-
const { baseUrl, models } = await canopy.ai.endpoint(); // OpenAI-compatible base URL for ecosystem clients (same budget)
|
|
116
|
-
\`\`\`
|
|
117
|
-
- AI spend is hard-capped per project; over budget, calls fail with
|
|
118
|
-
\`ai_budget_exceeded\` (429) — handle it, don't retry in a loop.
|
|
119
|
-
- Develop with \`canopy dev\` — a local server on this directory whose
|
|
120
|
-
\`/_api\` proxies to the real platform. That is LIVE project data, the same
|
|
121
|
-
the deployed app uses: read freely, but take a \`canopy db snapshot\` before
|
|
122
|
-
risky data changes.
|
|
123
|
-
- Prefer \`canopy dev --local\` for risky or destructive experiments — a
|
|
124
|
-
local-data sandbox (db/blob in \`.canopy/local/\`, writes never reach the
|
|
125
|
-
platform). Add \`--pull\` to hydrate it from a fresh copy of the live
|
|
126
|
-
database (pull-only; blobs stay empty). \`canopy.ai\` still works there —
|
|
127
|
-
it proxies to the platform and is metered as usual.
|
|
128
|
-
- Deploy with \`canopy deploy\` — the live URL is
|
|
129
|
-
https://${slug}.thanarie.dev (company login required).
|
|
130
|
-
|
|
131
|
-
## Boundaries
|
|
132
|
-
|
|
133
|
-
- Do not add auth — the platform handles it before any request reaches this app.
|
|
134
|
-
- Do not store secrets anywhere in this project.
|
|
135
|
-
- Keep it a static site: no SSR, no custom servers, no databases outside canopy.db.
|
|
136
|
-
`,
|
|
137
|
-
"README.md": `# ${name}
|
|
138
|
-
|
|
139
|
-
A [Canopy](https://dashboard.thanarie.dev) project. Live (behind company
|
|
140
|
-
login) at https://${slug}.thanarie.dev after the first \`canopy deploy\`.
|
|
141
|
-
|
|
142
|
-
- \`canopy dev\` — develop locally against the live platform (real data!)
|
|
143
|
-
- \`canopy dev --local [--pull]\` — offline sandbox with local data instead
|
|
144
|
-
- \`canopy deploy\` — publish the current directory
|
|
145
|
-
- \`CLAUDE.md\` — guardrails and SDK guide for coding agents
|
|
146
|
-
`
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/projects.ts
|
|
151
|
-
/**
|
|
152
|
-
* canopy create | projects | delete — the project registry from the terminal
|
|
153
|
-
* (docs/04-roadmap.md Phase 1 item 2). `create` registers the project, then
|
|
154
|
-
* scaffolds ./<slug>/ from the starter template (--no-scaffold to skip, e.g.
|
|
155
|
-
* for an existing directory).
|
|
156
|
-
*/
|
|
157
|
-
function slugify(input) {
|
|
158
|
-
return input.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/(^-+|-+$)/g, "").slice(0, 40);
|
|
159
|
-
}
|
|
160
|
-
const createCommand = defineCommand({
|
|
161
|
-
meta: {
|
|
162
|
-
name: "create",
|
|
163
|
-
description: "Create a new Canopy project"
|
|
164
|
-
},
|
|
165
|
-
args: {
|
|
166
|
-
name: {
|
|
167
|
-
type: "positional",
|
|
168
|
-
description: "Project name (prompted for when omitted)",
|
|
169
|
-
required: false
|
|
170
|
-
},
|
|
171
|
-
slug: {
|
|
172
|
-
type: "string",
|
|
173
|
-
description: "URL slug (defaults to a slugified name)"
|
|
174
|
-
},
|
|
175
|
-
scaffold: {
|
|
176
|
-
type: "boolean",
|
|
177
|
-
default: true,
|
|
178
|
-
description: "Scaffold ./<slug>/ from the starter template",
|
|
179
|
-
negativeDescription: "Only register — no files written"
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
run: reportErrors("create", async ({ args }) => {
|
|
183
|
-
let name = args._.join(" ").trim();
|
|
184
|
-
p.intro("canopy create");
|
|
185
|
-
if (!name) {
|
|
186
|
-
requireTty("pass the project name as an argument.");
|
|
187
|
-
name = unwrap(await p.text({
|
|
188
|
-
message: "Project name",
|
|
189
|
-
validate: (value) => value?.trim() ? void 0 : "A project name is required."
|
|
190
|
-
})).trim();
|
|
191
|
-
}
|
|
192
|
-
let slug = args.slug;
|
|
193
|
-
if (!slug && process.stdin.isTTY) slug = unwrap(await p.text({
|
|
194
|
-
message: "Slug",
|
|
195
|
-
defaultValue: slugify(name),
|
|
196
|
-
placeholder: slugify(name),
|
|
197
|
-
validate: (value) => !value || /^[a-z0-9][a-z0-9-]*$/.test(value) ? void 0 : "Lowercase letters, digits and dashes only."
|
|
198
|
-
})).trim();
|
|
199
|
-
slug ||= slugify(name);
|
|
200
|
-
const targetDir = resolve(slug);
|
|
201
|
-
if (args.scaffold && existsSync(targetDir)) throw new Error(`Directory ./${slug} already exists — remove it, or use --no-scaffold to only register.`);
|
|
202
|
-
const spin = p.spinner();
|
|
203
|
-
spin.start(`Registering ${slug}…`);
|
|
204
|
-
let project;
|
|
205
|
-
try {
|
|
206
|
-
({project} = await apiRequest("POST", "/projects", {
|
|
207
|
-
slug,
|
|
208
|
-
name
|
|
209
|
-
}));
|
|
210
|
-
} catch (err) {
|
|
211
|
-
spin.error("Create failed.");
|
|
212
|
-
throw err;
|
|
213
|
-
}
|
|
214
|
-
spin.stop(`Created ${project.name} — ${projectUrl(project.slug)}`);
|
|
215
|
-
if (args.scaffold) {
|
|
216
|
-
mkdirSync(targetDir, { recursive: true });
|
|
217
|
-
for (const [path, content] of Object.entries(templateFiles({
|
|
218
|
-
name,
|
|
219
|
-
slug
|
|
220
|
-
}))) writeFileSync(join(targetDir, path), content);
|
|
221
|
-
p.note(`cd ${slug}\ncanopy dev (or deploy right away: canopy deploy)`, `Scaffolded ./${slug}/ — next`);
|
|
222
|
-
p.outro(`Live URL (after first deploy): ${projectUrl(project.slug)}`);
|
|
223
|
-
} else p.outro("Registered without scaffolding — add a canopy.json to deploy an existing app.");
|
|
224
|
-
})
|
|
225
|
-
});
|
|
226
|
-
const projectsCommand = defineCommand({
|
|
227
|
-
meta: {
|
|
228
|
-
name: "projects",
|
|
229
|
-
description: "List your projects"
|
|
230
|
-
},
|
|
231
|
-
args: { all: {
|
|
232
|
-
type: "boolean",
|
|
233
|
-
default: false,
|
|
234
|
-
description: "Include projects you can't edit"
|
|
235
|
-
} },
|
|
236
|
-
run: reportErrors("projects", async ({ args }) => {
|
|
237
|
-
const { projects, is_admin: isAdmin } = await apiRequest("GET", "/projects");
|
|
238
|
-
const mine = args.all || isAdmin ? projects : projects.filter((project) => project.role);
|
|
239
|
-
if (mine.length === 0) {
|
|
240
|
-
console.log(projects.length === 0 ? "No projects yet — run `canopy create`." : `No projects of your own yet — run \`canopy create\`, or --all to list all ${projects.length}.`);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const width = Math.max(...mine.map((project) => project.slug.length));
|
|
244
|
-
for (const project of mine) {
|
|
245
|
-
const role = project.role ?? (isAdmin ? "admin" : `owner: ${project.owner_email}`);
|
|
246
|
-
console.log(`${project.slug.padEnd(width)} ${project.status.padEnd(7)} ${role.padEnd(6)} ${projectUrl(project.slug)} ${project.name}`);
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
});
|
|
250
|
-
const deleteCommand = defineCommand({
|
|
251
|
-
meta: {
|
|
252
|
-
name: "delete",
|
|
253
|
-
description: "Delete a project (full teardown)"
|
|
254
|
-
},
|
|
255
|
-
args: {
|
|
256
|
-
slug: {
|
|
257
|
-
type: "positional",
|
|
258
|
-
description: "Project slug (picked from a list when omitted)",
|
|
259
|
-
required: false
|
|
260
|
-
},
|
|
261
|
-
yes: {
|
|
262
|
-
type: "boolean",
|
|
263
|
-
default: false,
|
|
264
|
-
description: "Skip the type-the-slug confirmation"
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
run: reportErrors("delete", async ({ args }) => {
|
|
268
|
-
let slug = args.slug;
|
|
269
|
-
if (!slug) {
|
|
270
|
-
requireTty("pass the project slug as an argument.");
|
|
271
|
-
const listing = await apiRequest("GET", "/projects");
|
|
272
|
-
const projects = listing.is_admin ? listing.projects : listing.projects.filter((project) => project.role === "owner");
|
|
273
|
-
if (projects.length === 0) throw new Error("No projects to delete.");
|
|
274
|
-
slug = unwrap(await p.select({
|
|
275
|
-
message: "Project to delete",
|
|
276
|
-
options: projects.map((project) => ({
|
|
277
|
-
value: project.slug,
|
|
278
|
-
label: project.slug,
|
|
279
|
-
hint: project.name
|
|
280
|
-
}))
|
|
281
|
-
}));
|
|
282
|
-
}
|
|
283
|
-
if (!args.yes) {
|
|
284
|
-
requireTty("pass --yes to delete without confirmation.");
|
|
285
|
-
if (unwrap(await p.text({ message: `Delete "${slug}" permanently? This tears down its database and files. Type the slug to confirm.` })).trim() !== slug) {
|
|
286
|
-
p.cancel("Aborted.");
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
await apiRequest("DELETE", `/projects/${slug}`);
|
|
291
|
-
p.log.success(`Deleted ${slug}.`);
|
|
292
|
-
})
|
|
293
|
-
});
|
|
294
|
-
//#endregion
|
|
295
|
-
export { createCommand, deleteCommand, projectsCommand };
|
package/dist/ui-Cl5P_yQ6.mjs
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { cancel, isCancel } from "@clack/prompts";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
6
|
-
//#region src/config.ts
|
|
7
|
-
/**
|
|
8
|
-
* CLI config at ~/.canopy/config.json — platform endpoints and the current
|
|
9
|
-
* CLI token. Env overrides: CANOPY_API_URL, CANOPY_OIDC_ISSUER,
|
|
10
|
-
* CANOPY_OIDC_CLIENT_ID.
|
|
11
|
-
*/
|
|
12
|
-
const DEFAULT_API_URL = "https://canopy-api.arjan-van-wijk.workers.dev";
|
|
13
|
-
const DEFAULT_ISSUER = "https://s4capital.onelogin.com/oidc/2";
|
|
14
|
-
const DEFAULT_CLI_CLIENT_ID = "b69755d0-6678-013f-b5ce-09fe44a57aa0180501";
|
|
15
|
-
const configDir = join(homedir(), ".canopy");
|
|
16
|
-
const configPath = join(configDir, "config.json");
|
|
17
|
-
function readConfig() {
|
|
18
|
-
let stored = {};
|
|
19
|
-
try {
|
|
20
|
-
stored = JSON.parse(readFileSync(configPath, "utf8"));
|
|
21
|
-
} catch {}
|
|
22
|
-
return {
|
|
23
|
-
...stored,
|
|
24
|
-
apiUrl: process.env["CANOPY_API_URL"] ?? stored.apiUrl ?? DEFAULT_API_URL,
|
|
25
|
-
issuer: process.env["CANOPY_OIDC_ISSUER"] ?? stored.issuer ?? DEFAULT_ISSUER,
|
|
26
|
-
cliClientId: process.env["CANOPY_OIDC_CLIENT_ID"] ?? stored.cliClientId ?? DEFAULT_CLI_CLIENT_ID
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function writeConfig(config) {
|
|
30
|
-
mkdirSync(configDir, { recursive: true });
|
|
31
|
-
writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
32
|
-
chmodSync(configPath, 384);
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/ui.ts
|
|
36
|
-
/**
|
|
37
|
-
* Shared terminal UX plumbing: clack prompt unwrapping and uniform
|
|
38
|
-
* command error reporting.
|
|
39
|
-
*/
|
|
40
|
-
/** Unwrap a clack prompt result, exiting cleanly when the user cancels (ctrl-c). */
|
|
41
|
-
function unwrap(result) {
|
|
42
|
-
if (isCancel(result)) {
|
|
43
|
-
cancel("Aborted.");
|
|
44
|
-
process.exit(130);
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
/** Wrap a command action so failures print as `canopy <name>: <message>` and exit 1. */
|
|
49
|
-
function reportErrors(name, action) {
|
|
50
|
-
return async (...args) => {
|
|
51
|
-
try {
|
|
52
|
-
await action(...args);
|
|
53
|
-
} catch (err) {
|
|
54
|
-
console.error(`canopy ${name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
55
|
-
process.exit(1);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/** Guard interactive prompts: bail with a actionable message on non-TTY runs. */
|
|
60
|
-
function requireTty(hint) {
|
|
61
|
-
if (!process.stdin.isTTY) throw new Error(`This needs an interactive terminal — ${hint}`);
|
|
62
|
-
}
|
|
63
|
-
/** Open a URL in the default browser, fire-and-forget. */
|
|
64
|
-
function openBrowser(url) {
|
|
65
|
-
spawn(process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open", [url], {
|
|
66
|
-
stdio: "ignore",
|
|
67
|
-
detached: true,
|
|
68
|
-
shell: process.platform === "win32"
|
|
69
|
-
}).on("error", () => {}).unref();
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
export { readConfig as a, unwrap as i, reportErrors as n, writeConfig as o, requireTty as r, openBrowser as t };
|