@camox/cli 0.2.0-alpha.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/LICENSE.md ADDED
@@ -0,0 +1,110 @@
1
+ # Functional Source License, Version 1.1, MIT Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-MIT
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Rémi de Juvigny
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the MIT license that is effective on the second anniversary of the date we make
91
+ the Software available. On or after that date, you may use the Software under
92
+ the MIT license, in which case the following will apply:
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
95
+ this software and associated documentation files (the "Software"), to deal in
96
+ the Software without restriction, including without limitation the rights to
97
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98
+ of the Software, and to permit persons to whom the Software is furnished to do
99
+ so, subject to the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be included in all
102
+ copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createOrganization,
4
+ createProject,
5
+ listOrganizations,
6
+ setActiveOrganization,
7
+ verifySession
8
+ } from "./chunk-KYDY3NNE.js";
9
+ export {
10
+ createOrganization,
11
+ createProject,
12
+ listOrganizations,
13
+ setActiveOrganization,
14
+ verifySession
15
+ };
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+
8
+ // src/lib/api.ts
9
+ import { createORPCClient } from "@orpc/client";
10
+ import { RPCLink } from "@orpc/client/fetch";
11
+ var CAMOX_API_URL = process.env.CAMOX_API_URL || "https://api.camox.ai";
12
+ function authHeaders(token) {
13
+ return {
14
+ Authorization: `Bearer ${token}`,
15
+ "Content-Type": "application/json"
16
+ };
17
+ }
18
+ function createRpcClient(token) {
19
+ const link = new RPCLink({
20
+ url: `${CAMOX_API_URL}/rpc`,
21
+ headers: { Authorization: `Bearer ${token}` }
22
+ });
23
+ return createORPCClient(link);
24
+ }
25
+ async function verifySession(token) {
26
+ const res = await fetch(`${CAMOX_API_URL}/api/auth/get-session`, {
27
+ method: "GET",
28
+ headers: authHeaders(token)
29
+ });
30
+ return res.ok;
31
+ }
32
+ async function listOrganizations(token) {
33
+ const res = await fetch(`${CAMOX_API_URL}/api/auth/organization/list`, {
34
+ method: "GET",
35
+ headers: authHeaders(token)
36
+ });
37
+ if (!res.ok) {
38
+ throw new Error(`Failed to list organizations: ${res.status}`);
39
+ }
40
+ return res.json();
41
+ }
42
+ async function createOrganization(token, name, slug) {
43
+ const res = await fetch(`${CAMOX_API_URL}/api/auth/organization/create`, {
44
+ method: "POST",
45
+ headers: authHeaders(token),
46
+ body: JSON.stringify({ name, slug })
47
+ });
48
+ if (!res.ok) {
49
+ const text = await res.text();
50
+ throw new Error(`Failed to create organization: ${res.status} ${text}`);
51
+ }
52
+ return res.json();
53
+ }
54
+ async function setActiveOrganization(token, organizationId) {
55
+ const res = await fetch(`${CAMOX_API_URL}/api/auth/organization/set-active`, {
56
+ method: "POST",
57
+ headers: authHeaders(token),
58
+ body: JSON.stringify({ organizationId })
59
+ });
60
+ if (!res.ok) {
61
+ throw new Error(`Failed to set active organization: ${res.status}`);
62
+ }
63
+ }
64
+ async function createProject(token, name, organizationSlug) {
65
+ const client = createRpcClient(token);
66
+ const result = await client.projects.create({ name, organizationSlug });
67
+ return result;
68
+ }
69
+
70
+ export {
71
+ __export,
72
+ verifySession,
73
+ listOrganizations,
74
+ createOrganization,
75
+ setActiveOrganization,
76
+ createProject
77
+ };
package/dist/index.js ADDED
@@ -0,0 +1,501 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ __export,
4
+ createOrganization,
5
+ createProject,
6
+ listOrganizations,
7
+ setActiveOrganization
8
+ } from "./chunk-KYDY3NNE.js";
9
+
10
+ // src/index.ts
11
+ import { or } from "@optique/core/constructs";
12
+ import { message } from "@optique/core/message";
13
+ import { defineProgram } from "@optique/core/program";
14
+ import { run } from "@optique/run";
15
+
16
+ // src/commands/init.ts
17
+ var init_exports = {};
18
+ __export(init_exports, {
19
+ handler: () => handler,
20
+ init: () => init,
21
+ parser: () => parser
22
+ });
23
+ import { execSync as execSync3, spawn, spawnSync } from "child_process";
24
+ import fs3 from "fs";
25
+ import path3 from "path";
26
+ import { fileURLToPath } from "url";
27
+ import * as p2 from "@clack/prompts";
28
+ import { object } from "@optique/core/constructs";
29
+ import { command, constant } from "@optique/core/primitives";
30
+
31
+ // src/lib/auth.ts
32
+ import { execSync } from "child_process";
33
+ import fs from "fs";
34
+ import http from "http";
35
+ import os from "os";
36
+ import path from "path";
37
+ import * as p from "@clack/prompts";
38
+ var CAMOX_URL = process.env.CAMOX_URL || "https://camox.ai";
39
+ var CAMOX_API_URL = process.env.CAMOX_API_URL || "https://api.camox.ai";
40
+ var AUTH_TIMEOUT_MS = 12e4;
41
+ var AUTH_DIR = path.join(os.homedir(), ".camox");
42
+ var AUTH_FILE = path.join(AUTH_DIR, "auth.json");
43
+ function readAuthToken() {
44
+ try {
45
+ const data = JSON.parse(fs.readFileSync(AUTH_FILE, "utf-8"));
46
+ if (data?.token && data?.name) return data;
47
+ return null;
48
+ } catch {
49
+ return null;
50
+ }
51
+ }
52
+ function writeAuthToken(token) {
53
+ fs.mkdirSync(AUTH_DIR, { recursive: true });
54
+ fs.writeFileSync(AUTH_FILE, JSON.stringify(token, null, 2), { mode: 384 });
55
+ }
56
+ function removeAuthToken() {
57
+ try {
58
+ fs.unlinkSync(AUTH_FILE);
59
+ } catch {
60
+ }
61
+ }
62
+ function openBrowser(url) {
63
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
64
+ try {
65
+ execSync(`${cmd} ${JSON.stringify(url)}`, { stdio: "ignore" });
66
+ } catch {
67
+ }
68
+ }
69
+ function startCallbackServer() {
70
+ return new Promise((resolve, reject) => {
71
+ let resolveOtt;
72
+ const ottPromise = new Promise((res) => {
73
+ resolveOtt = res;
74
+ });
75
+ const server = http.createServer((req, res) => {
76
+ const url = new URL(req.url ?? "/", `http://localhost`);
77
+ if (url.pathname !== "/callback") {
78
+ res.writeHead(404);
79
+ res.end();
80
+ return;
81
+ }
82
+ const ott = url.searchParams.get("ott");
83
+ if (!ott) {
84
+ res.writeHead(400, { "Content-Type": "text/html" });
85
+ res.end("<html><body><h2>Missing token. Please try again.</h2></body></html>");
86
+ return;
87
+ }
88
+ res.writeHead(302, { Location: `${CAMOX_URL}/cli-authorized` });
89
+ res.end();
90
+ resolveOtt(ott);
91
+ });
92
+ server.listen(0, () => {
93
+ const addr = server.address();
94
+ if (!addr || typeof addr === "string") {
95
+ reject(new Error("Failed to start callback server"));
96
+ return;
97
+ }
98
+ resolve({
99
+ port: addr.port,
100
+ ottPromise,
101
+ close: () => server.close()
102
+ });
103
+ });
104
+ server.on("error", reject);
105
+ });
106
+ }
107
+ async function verifyOtt(token) {
108
+ const res = await fetch(`${CAMOX_API_URL}/api/auth/one-time-token/verify`, {
109
+ method: "POST",
110
+ headers: { "Content-Type": "application/json" },
111
+ body: JSON.stringify({ token })
112
+ });
113
+ if (!res.ok) {
114
+ throw new Error(`OTT verification failed: ${res.status}`);
115
+ }
116
+ const data = await res.json();
117
+ const user = data.user;
118
+ if (!user?.name) {
119
+ throw new Error("No user info in verification response");
120
+ }
121
+ const sessionToken = data.session?.token;
122
+ if (!sessionToken) {
123
+ throw new Error("No session token in verification response");
124
+ }
125
+ return { name: user.name, email: user.email ?? "", sessionToken };
126
+ }
127
+ async function authenticateUser() {
128
+ const { port, ottPromise, close } = await startCallbackServer();
129
+ const loginUrl = `${CAMOX_URL}/cli-authorize?callback=${encodeURIComponent(`http://localhost:${port}/callback`)}`;
130
+ const action = await p.select({
131
+ message: "Log in to Camox",
132
+ options: [
133
+ { value: "open", label: "Open browser" },
134
+ { value: "copy", label: "Copy URL" }
135
+ ]
136
+ });
137
+ if (p.isCancel(action)) {
138
+ close();
139
+ throw new Error("Authentication cancelled");
140
+ }
141
+ if (action === "open") {
142
+ openBrowser(loginUrl);
143
+ } else {
144
+ p.log.info(loginUrl);
145
+ }
146
+ const s = p.spinner();
147
+ s.start("Waiting for authentication...");
148
+ try {
149
+ const ott = await Promise.race([
150
+ ottPromise,
151
+ new Promise(
152
+ (_, reject) => setTimeout(() => reject(new Error("Authentication timed out")), AUTH_TIMEOUT_MS)
153
+ )
154
+ ]);
155
+ s.message("Verifying...");
156
+ const result2 = await verifyOtt(ott);
157
+ const authToken = {
158
+ token: result2.sessionToken,
159
+ name: result2.name,
160
+ email: result2.email
161
+ };
162
+ writeAuthToken(authToken);
163
+ s.stop(`Authenticated as ${result2.name}`);
164
+ return authToken;
165
+ } catch (err) {
166
+ s.stop("Authentication failed.");
167
+ throw err;
168
+ } finally {
169
+ close();
170
+ }
171
+ }
172
+ async function getOrAuthenticate() {
173
+ const stored = readAuthToken();
174
+ if (stored) {
175
+ const { verifySession } = await import("./api-4OWBCL7B.js");
176
+ const valid = await verifySession(stored.token);
177
+ if (valid) {
178
+ p.log.info(`Authenticated as ${stored.name}`);
179
+ return stored;
180
+ }
181
+ removeAuthToken();
182
+ p.log.warn("Session expired. Please log in again.");
183
+ } else {
184
+ p.log.info("Please authenticate to create a Camox project.");
185
+ }
186
+ return authenticateUser();
187
+ }
188
+
189
+ // src/lib/utils.ts
190
+ import { execSync as execSync2 } from "child_process";
191
+ import fs2 from "fs";
192
+ import path2 from "path";
193
+ var pmCommands = {
194
+ pnpm: { install: "pnpm install", dev: "pnpm dev" },
195
+ bun: { install: "bun install", dev: "bun dev" },
196
+ npm: { install: "npm install", dev: "npm run dev" },
197
+ yarn: { install: "yarn install", dev: "yarn dev" }
198
+ };
199
+ function slugify(name) {
200
+ return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
201
+ }
202
+ function detectPackageManager() {
203
+ const userAgent = process.env.npm_config_user_agent;
204
+ if (userAgent) {
205
+ const name = userAgent.split("/")[0];
206
+ if (name === "pnpm") return "pnpm";
207
+ if (name === "bun") return "bun";
208
+ if (name === "npm" || name === "npx") return "npm";
209
+ if (name === "yarn") return "yarn";
210
+ }
211
+ let dir = process.cwd();
212
+ const root = path2.parse(dir).root;
213
+ while (true) {
214
+ if (fs2.existsSync(path2.join(dir, "pnpm-lock.yaml")) || fs2.existsSync(path2.join(dir, "pnpm-workspace.yaml")))
215
+ return "pnpm";
216
+ if (fs2.existsSync(path2.join(dir, "bun.lockb")) || fs2.existsSync(path2.join(dir, "bun.lock")))
217
+ return "bun";
218
+ if (fs2.existsSync(path2.join(dir, "package-lock.json"))) return "npm";
219
+ if (fs2.existsSync(path2.join(dir, "yarn.lock"))) return "yarn";
220
+ if (dir === root) break;
221
+ dir = path2.dirname(dir);
222
+ }
223
+ return null;
224
+ }
225
+ function isInsideGitRepo() {
226
+ try {
227
+ execSync2("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
228
+ return true;
229
+ } catch {
230
+ return false;
231
+ }
232
+ }
233
+ function copyDir(src, dest, replacements) {
234
+ fs2.mkdirSync(dest, { recursive: true });
235
+ for (const entry of fs2.readdirSync(src, { withFileTypes: true })) {
236
+ const srcPath = path2.join(src, entry.name);
237
+ const destPath = path2.join(dest, entry.name);
238
+ if (entry.isDirectory()) {
239
+ copyDir(srcPath, destPath, replacements);
240
+ continue;
241
+ }
242
+ let content = fs2.readFileSync(srcPath, "utf-8");
243
+ for (const [key, value] of Object.entries(replacements)) {
244
+ content = content.replaceAll(key, value);
245
+ }
246
+ fs2.writeFileSync(destPath, content);
247
+ }
248
+ }
249
+
250
+ // src/commands/init.ts
251
+ var parser = command(
252
+ "init",
253
+ object({
254
+ command: constant("init")
255
+ })
256
+ );
257
+ var handler = init;
258
+ var __dirname = path3.dirname(fileURLToPath(import.meta.url));
259
+ var ownPkg = JSON.parse(fs3.readFileSync(path3.resolve(__dirname, "..", "package.json"), "utf-8"));
260
+ function onCancel() {
261
+ p2.cancel("Cancelled.");
262
+ process.exit(0);
263
+ }
264
+ var CREATE_NEW_ORG = "__create_new__";
265
+ async function selectOrCreateOrganization(token) {
266
+ const orgs = await listOrganizations(token);
267
+ if (orgs.length === 0) {
268
+ p2.log.info("You don't have any organizations yet. Let's create one.");
269
+ return promptCreateOrganization(token);
270
+ }
271
+ const selected = await p2.select({
272
+ message: "Select an organization for your new project",
273
+ options: [
274
+ ...orgs.map((org2) => ({ value: org2.id, label: `${org2.name} (${org2.slug})` })),
275
+ { value: CREATE_NEW_ORG, label: "Create a new organization" }
276
+ ]
277
+ });
278
+ if (p2.isCancel(selected)) return onCancel();
279
+ if (selected === CREATE_NEW_ORG) {
280
+ return promptCreateOrganization(token);
281
+ }
282
+ const org = orgs.find((o) => o.id === selected);
283
+ await setActiveOrganization(token, org.id);
284
+ return org.slug;
285
+ }
286
+ async function promptCreateOrganization(token) {
287
+ const orgName = await p2.text({
288
+ message: "Organization name",
289
+ placeholder: "My Company",
290
+ validate: (value) => {
291
+ if (!value.trim()) return "Organization name is required";
292
+ }
293
+ });
294
+ if (p2.isCancel(orgName)) return onCancel();
295
+ const orgSlug = slugify(orgName);
296
+ const org = await createOrganization(token, orgName, orgSlug);
297
+ p2.log.success(`Created organization: ${org.name}`);
298
+ return org.slug;
299
+ }
300
+ async function init() {
301
+ p2.intro("camox init");
302
+ const result2 = await p2.group(
303
+ {
304
+ name: () => p2.text({
305
+ message: "Project display name",
306
+ placeholder: "My Website",
307
+ validate: (value) => {
308
+ if (!value.trim()) return "Project name is required";
309
+ }
310
+ }),
311
+ path: ({ results }) => p2.text({
312
+ message: "Project path",
313
+ initialValue: `./${slugify(results.name ?? "") || "my-site"}`,
314
+ validate: (value) => {
315
+ if (!value.trim()) return "Path is required";
316
+ }
317
+ })
318
+ },
319
+ { onCancel }
320
+ );
321
+ const targetDir = path3.resolve(result2.path);
322
+ const auth = await getOrAuthenticate();
323
+ const orgSlug = await selectOrCreateOrganization(auth.token);
324
+ const s0 = p2.spinner();
325
+ s0.start("Creating project...");
326
+ let project;
327
+ try {
328
+ project = await createProject(auth.token, result2.name, orgSlug);
329
+ s0.stop(`Project created with slug: ${project.slug}`);
330
+ } catch (err) {
331
+ s0.stop("Failed to create project.");
332
+ p2.log.error(err instanceof Error ? err.message : "Unknown error");
333
+ process.exit(1);
334
+ }
335
+ if (fs3.existsSync(targetDir) && fs3.readdirSync(targetDir).length > 0) {
336
+ p2.cancel(`Directory ${targetDir} is not empty.`);
337
+ process.exit(1);
338
+ }
339
+ const alreadyInRepo = isInsideGitRepo();
340
+ let initGit = false;
341
+ if (!alreadyInRepo) {
342
+ const answer = await p2.confirm({
343
+ message: "Initialize a git repository?",
344
+ initialValue: true
345
+ });
346
+ if (p2.isCancel(answer)) return onCancel();
347
+ initGit = answer;
348
+ }
349
+ const detected = detectPackageManager();
350
+ let pm;
351
+ if (detected) {
352
+ pm = detected;
353
+ p2.log.info(`Detected package manager: ${detected}`);
354
+ } else {
355
+ const selected = await p2.select({
356
+ message: "Which package manager?",
357
+ options: [
358
+ { value: "pnpm", label: "pnpm" },
359
+ { value: "bun", label: "bun" },
360
+ { value: "npm", label: "npm" },
361
+ { value: "yarn", label: "yarn" }
362
+ ]
363
+ });
364
+ if (p2.isCancel(selected)) return onCancel();
365
+ pm = selected;
366
+ }
367
+ const s = p2.spinner();
368
+ s.start("Scaffolding project...");
369
+ const templateDir = path3.resolve(__dirname, "..", "template");
370
+ copyDir(templateDir, targetDir, {
371
+ "{{projectName}}": result2.name,
372
+ "{{projectSlug}}": project.slug,
373
+ "{{syncSecret}}": project.syncSecret,
374
+ "{{camoxVersion}}": ownPkg.version
375
+ });
376
+ s.stop("Project scaffolded!");
377
+ function dropIntoProject() {
378
+ const shell = process.env.SHELL || "/bin/bash";
379
+ p2.log.info(`Dropping you into ${result2.path}`);
380
+ spawnSync(shell, [], { cwd: targetDir, stdio: "inherit" });
381
+ process.exit(0);
382
+ }
383
+ if (initGit) {
384
+ try {
385
+ execSync3("git init", { cwd: targetDir, stdio: "ignore" });
386
+ p2.log.success("Initialized git repository.");
387
+ } catch {
388
+ p2.log.warn("Could not initialize git repository.");
389
+ }
390
+ }
391
+ const { install: installCmd, dev: devCmd } = pmCommands[pm];
392
+ const [installBin, ...installArgs] = installCmd.split(" ");
393
+ const s2 = p2.spinner();
394
+ s2.start(`Running ${installCmd}...`);
395
+ try {
396
+ await new Promise((resolve, reject) => {
397
+ const child2 = spawn(installBin, installArgs, {
398
+ cwd: targetDir,
399
+ stdio: "ignore"
400
+ });
401
+ child2.on("close", (code) => {
402
+ if (code === 0) resolve();
403
+ else reject(new Error(`Exit code ${code}`));
404
+ });
405
+ child2.on("error", reject);
406
+ });
407
+ s2.stop("Dependencies installed!");
408
+ } catch {
409
+ s2.stop("Install failed.");
410
+ p2.log.error(`Failed to install dependencies. Run "${installCmd}" manually.`);
411
+ dropIntoProject();
412
+ }
413
+ if (initGit) {
414
+ try {
415
+ execSync3("git add -A", { cwd: targetDir, stdio: "ignore" });
416
+ execSync3('git commit -m "Initial commit from camox init"', {
417
+ cwd: targetDir,
418
+ stdio: "ignore"
419
+ });
420
+ p2.log.success("Created initial commit.");
421
+ } catch {
422
+ p2.log.warn("Could not create initial commit.");
423
+ }
424
+ }
425
+ p2.outro(`Starting dev server...`);
426
+ const [cmd, ...args] = devCmd.split(" ");
427
+ const child = spawn(cmd, args, {
428
+ cwd: targetDir,
429
+ stdio: "inherit"
430
+ });
431
+ child.on("close", () => {
432
+ dropIntoProject();
433
+ });
434
+ }
435
+
436
+ // src/commands/login.ts
437
+ var login_exports = {};
438
+ __export(login_exports, {
439
+ handler: () => handler2,
440
+ login: () => login,
441
+ parser: () => parser2
442
+ });
443
+ import * as p3 from "@clack/prompts";
444
+ import { object as object2 } from "@optique/core/constructs";
445
+ import { command as command2, constant as constant2 } from "@optique/core/primitives";
446
+ var parser2 = command2(
447
+ "login",
448
+ object2({
449
+ command: constant2("login")
450
+ })
451
+ );
452
+ var handler2 = login;
453
+ async function login() {
454
+ p3.intro("camox login");
455
+ try {
456
+ await getOrAuthenticate();
457
+ } catch {
458
+ p3.log.error("Authentication failed.");
459
+ process.exit(1);
460
+ }
461
+ p3.outro("You're all set!");
462
+ process.exit(0);
463
+ }
464
+
465
+ // src/commands/logout.ts
466
+ var logout_exports = {};
467
+ __export(logout_exports, {
468
+ handler: () => handler3,
469
+ logout: () => logout,
470
+ parser: () => parser3
471
+ });
472
+ import { object as object3 } from "@optique/core/constructs";
473
+ import { command as command3, constant as constant3 } from "@optique/core/primitives";
474
+ var parser3 = command3(
475
+ "logout",
476
+ object3({
477
+ command: constant3("logout")
478
+ })
479
+ );
480
+ var handler3 = logout;
481
+ function logout() {
482
+ const token = readAuthToken();
483
+ if (!token) {
484
+ console.log("Not logged in.");
485
+ return;
486
+ }
487
+ removeAuthToken();
488
+ console.log(`Logged out from ${token.name}.`);
489
+ }
490
+
491
+ // src/index.ts
492
+ var commands = { init: init_exports, login: login_exports, logout: logout_exports };
493
+ var program = defineProgram({
494
+ parser: or(parser, parser2, parser3),
495
+ metadata: {
496
+ name: "camox",
497
+ brief: message`Camox CLI`
498
+ }
499
+ });
500
+ var result = run(program, { help: "both" });
501
+ await commands[result.command].handler();