@cmssy/cli 9.7.1 → 9.8.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.
Files changed (2) hide show
  1. package/dist/index.js +34 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -151,6 +151,13 @@ Edit this site visually:
151
151
  ${paint(url, CYAN, colored)}
152
152
  `;
153
153
  }
154
+ function formatDraftPreviewLink(draftUrl, exitUrl, colored = useColor()) {
155
+ return `
156
+ Preview drafts without the editor (the /api/draft path also works on your local dev server):
157
+ ${paint(draftUrl, CYAN, colored)}
158
+ exit draft mode: ${paint(exitUrl, CYAN, colored)}
159
+ `;
160
+ }
154
161
 
155
162
  // src/init.ts
156
163
  var ASSETS_DIR = fileURLToPath(new URL("../assets/init", import.meta.url));
@@ -496,6 +503,24 @@ function describeWorkspace(workspace) {
496
503
  const org = workspace.organizationSlug ?? "?";
497
504
  return `${workspace.name} (${org}/${workspace.slug})`;
498
505
  }
506
+ function draftRouteBase(previewUrl) {
507
+ try {
508
+ const base = new URL(previewUrl);
509
+ const basePath = base.pathname.replace(/\/+$/, "");
510
+ return `${base.origin}${basePath}/api/draft`;
511
+ } catch {
512
+ return null;
513
+ }
514
+ }
515
+ function buildDraftPreviewUrls(previewUrl, draftSecret) {
516
+ const base = draftRouteBase(previewUrl);
517
+ if (!base) return null;
518
+ const params = new URLSearchParams({ secret: draftSecret, redirect: "/" });
519
+ return {
520
+ draftUrl: `${base}?${params.toString()}`,
521
+ exitUrl: `${base}?disable=1`
522
+ };
523
+ }
499
524
  async function selectWorkspace(workspaces, options, deps) {
500
525
  if (workspaces.length === 0) {
501
526
  throw new CliError(
@@ -636,6 +661,15 @@ async function runLink(options, deps) {
636
661
  const secretResult = await checkDraftSecret(preflight);
637
662
  log(formatResult(secretResult));
638
663
  log(formatEditorLink(buildEditorUrl(preflight)));
664
+ if (reachable.previewUrl && secretResult.status !== "fail") {
665
+ const draftUrls = buildDraftPreviewUrls(
666
+ reachable.previewUrl,
667
+ draftSecret
668
+ );
669
+ if (draftUrls) {
670
+ log(formatDraftPreviewLink(draftUrls.draftUrl, draftUrls.exitUrl));
671
+ }
672
+ }
639
673
  return reachable.status === "fail" || secretResult.status === "fail" ? 1 : 0;
640
674
  } catch (error) {
641
675
  if (error instanceof CliError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/cli",
3
- "version": "9.7.1",
3
+ "version": "9.8.0",
4
4
  "description": "The cmssy CLI: `cmssy init` wires cmssy into an existing Next.js, Astro or React Router app; `cmssy link` connects it to a workspace and verifies the editor wiring.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -27,7 +27,7 @@
27
27
  "assets"
28
28
  ],
29
29
  "dependencies": {
30
- "@cmssy/core": "9.7.1"
30
+ "@cmssy/core": "9.8.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^20.0.0",