@camox/cli 0.59.0 → 0.60.2

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.
Files changed (2) hide show
  1. package/dist/index.mjs +37 -4
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -7,17 +7,18 @@ import { message } from "@optique/core/message";
7
7
  import { defineProgram } from "@optique/core/program";
8
8
  import { runSync } from "@optique/run";
9
9
  import { execSync, spawnSync } from "node:child_process";
10
- import path, { join, resolve } from "node:path";
10
+ import path, { dirname, join, resolve } from "node:path";
11
11
  import * as p from "@clack/prompts";
12
12
  import { log } from "@clack/prompts";
13
13
  import { optional } from "@optique/core/modifiers";
14
14
  import { argument, command, constant, option } from "@optique/core/primitives";
15
15
  import { string } from "@optique/core/valueparser";
16
16
  import http from "node:http";
17
- import fs, { mkdtempSync, readFileSync, rmSync } from "node:fs";
17
+ import fs, { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
18
18
  import { tmpdir } from "node:os";
19
19
  import { text } from "node:stream/consumers";
20
20
  import { ZodError, z } from "zod";
21
+ import { pathToFileURL } from "node:url";
21
22
  //#region src/lib/auth.ts
22
23
  const CAMOX_URL = process.env.CAMOX_URL || "https://app.camox.ai";
23
24
  const CAMOX_API_URL = process.env.CAMOX_API_URL || "https://api.camox.ai";
@@ -513,7 +514,7 @@ const parser = command("release", object({
513
514
  command: constant("release"),
514
515
  dryRun: option("--dry-run", { description: message`Build the website as a release would, without logging in or syncing its definitions to Live.` })
515
516
  }));
516
- function handler(args) {
517
+ async function handler(args) {
517
518
  p.intro(args.dryRun ? "camox release --dry-run" : "camox release");
518
519
  if (!args.dryRun && !process.env.CAMOX_DEPLOY_TOKEN) {
519
520
  p.log.error("CAMOX_DEPLOY_TOKEN is required to release to Live.");
@@ -536,9 +537,41 @@ function handler(args) {
536
537
  p.log.error(args.dryRun ? "Dry run failed." : "Release failed.");
537
538
  process.exit(result.status ?? 1);
538
539
  }
540
+ try {
541
+ const names = await addSdkBundle(process.cwd());
542
+ if (names) p.log.info(`Added the SDK Bundle ${names.browser} (browser) and ${names.workerd} (workerd).`);
543
+ } catch (error) {
544
+ p.log.error(`Could not add the SDK Bundle: ${error instanceof Error ? error.message : String(error)}`);
545
+ process.exit(1);
546
+ }
539
547
  p.outro(args.dryRun ? "Dry run built successfully." : "Release prepared successfully.");
540
548
  process.exit(0);
541
549
  }
550
+ /**
551
+ * Adds the SDK Bundle the build names to its output, so it deploys on its own, with the website's
552
+ * own camox. A camox without SDK Bundles builds whole-app, so there's nothing to add.
553
+ */
554
+ async function addSdkBundle(root) {
555
+ const module = websiteModule(root, "camox", "./_internal/sdkBundle");
556
+ if (!module) return null;
557
+ const { addSdkBundleToBuild } = await import(pathToFileURL(module).href);
558
+ return addSdkBundleToBuild ? addSdkBundleToBuild({ root }) : null;
559
+ }
560
+ /**
561
+ * The file a package's export resolves to for `import`, from the website in `root`, or null when
562
+ * it isn't installed or doesn't export it.
563
+ */
564
+ function websiteModule(root, name, subpath) {
565
+ for (let dir = resolve(root);; dir = dirname(dir)) {
566
+ const manifestPath = join(dir, "node_modules", name, "package.json");
567
+ if (existsSync(manifestPath)) {
568
+ let target = JSON.parse(readFileSync(manifestPath, "utf8")).exports?.[subpath];
569
+ while (target && typeof target === "object") target = target.import ?? target.default;
570
+ return typeof target === "string" ? join(dirname(manifestPath), target) : null;
571
+ }
572
+ if (dirname(dir) === dir) return null;
573
+ }
574
+ }
542
575
  //#endregion
543
576
  //#region src/index.ts
544
577
  const program = defineProgram({
@@ -557,7 +590,7 @@ switch (result.command) {
557
590
  handler$2(result);
558
591
  break;
559
592
  case "release":
560
- handler(result);
593
+ await handler(result);
561
594
  break;
562
595
  case "clone":
563
596
  await handler$5(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camox/cli",
3
- "version": "0.59.0",
3
+ "version": "0.60.2",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "camox": "./dist/index.mjs"
@@ -28,7 +28,7 @@
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.12.4",
30
30
  "vite-plus": "1.3.0",
31
- "@camox/api-contract": "0.59.0"
31
+ "@camox/api-contract": "0.60.2"
32
32
  },
33
33
  "nx": {
34
34
  "tags": [