@cmssy/cli 9.9.0 → 9.10.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/index.js +60 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -775,6 +775,54 @@ function buildDraftPreviewUrls(previewUrl, draftSecret) {
|
|
|
775
775
|
exitUrl: `${base}?disable=1`
|
|
776
776
|
};
|
|
777
777
|
}
|
|
778
|
+
function draftRouteFix(cwd) {
|
|
779
|
+
const path = `${nextSrcPrefix(cwd)}app/api/draft/route.ts`;
|
|
780
|
+
return [
|
|
781
|
+
`add ${path} so Preview can enter draft mode:`,
|
|
782
|
+
' import { createDraftRoute } from "@cmssy/next/server";',
|
|
783
|
+
' import { cmssy } from "@/cmssy.config";',
|
|
784
|
+
" export const GET = createDraftRoute(cmssy);"
|
|
785
|
+
].join("\n");
|
|
786
|
+
}
|
|
787
|
+
async function checkDraftRouteMounted(previewUrl, fetchImpl, cwd) {
|
|
788
|
+
const base = draftRouteBase(previewUrl);
|
|
789
|
+
if (!base) {
|
|
790
|
+
return {
|
|
791
|
+
status: "fail",
|
|
792
|
+
message: `the workspace preview URL ${previewUrl} is not a valid URL`,
|
|
793
|
+
fix: "set a valid deployed origin as the preview URL: cmssy link --preview-url https://your-site.com"
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
let status;
|
|
797
|
+
try {
|
|
798
|
+
status = (await fetchImpl(base, {
|
|
799
|
+
method: "HEAD",
|
|
800
|
+
signal: AbortSignal.timeout(5e3)
|
|
801
|
+
})).status;
|
|
802
|
+
} catch {
|
|
803
|
+
return {
|
|
804
|
+
status: "unknown",
|
|
805
|
+
message: `could not reach ${base} to check the /api/draft route`
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
if (status === 404) {
|
|
809
|
+
return {
|
|
810
|
+
status: "fail",
|
|
811
|
+
message: `the /api/draft route is not mounted at ${previewUrl} - Preview will 404`,
|
|
812
|
+
fix: draftRouteFix(cwd)
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
if (status === 500) {
|
|
816
|
+
return {
|
|
817
|
+
status: "fail",
|
|
818
|
+
message: `the /api/draft route is mounted but misconfigured at ${previewUrl} - the draft secret must be at least 16 characters`
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
return {
|
|
822
|
+
status: "ok",
|
|
823
|
+
message: `the /api/draft route is mounted at ${previewUrl}`
|
|
824
|
+
};
|
|
825
|
+
}
|
|
778
826
|
async function selectWorkspace(workspaces, options, deps) {
|
|
779
827
|
if (workspaces.length === 0) {
|
|
780
828
|
throw new CliError(
|
|
@@ -914,8 +962,17 @@ async function runLink(options, deps) {
|
|
|
914
962
|
log(formatResult(reachable));
|
|
915
963
|
const secretResult = await checkDraftSecret(preflight);
|
|
916
964
|
log(formatResult(secretResult));
|
|
965
|
+
let draftRouteResult = null;
|
|
966
|
+
if (reachable.previewUrl) {
|
|
967
|
+
draftRouteResult = await checkDraftRouteMounted(
|
|
968
|
+
reachable.previewUrl,
|
|
969
|
+
deps.fetch,
|
|
970
|
+
cwd
|
|
971
|
+
);
|
|
972
|
+
log(formatResult(draftRouteResult));
|
|
973
|
+
}
|
|
917
974
|
log(formatEditorLink(buildEditorUrl(preflight)));
|
|
918
|
-
if (reachable.previewUrl && secretResult.status !== "fail") {
|
|
975
|
+
if (reachable.previewUrl && secretResult.status !== "fail" && draftRouteResult?.status !== "fail") {
|
|
919
976
|
const draftUrls = buildDraftPreviewUrls(
|
|
920
977
|
reachable.previewUrl,
|
|
921
978
|
draftSecret
|
|
@@ -924,7 +981,8 @@ async function runLink(options, deps) {
|
|
|
924
981
|
log(formatDraftPreviewLink(draftUrls.draftUrl, draftUrls.exitUrl));
|
|
925
982
|
}
|
|
926
983
|
}
|
|
927
|
-
|
|
984
|
+
const failed = reachable.status === "fail" || secretResult.status === "fail" || draftRouteResult?.status === "fail";
|
|
985
|
+
return failed ? 1 : 0;
|
|
928
986
|
} catch (error) {
|
|
929
987
|
if (error instanceof CliError) {
|
|
930
988
|
log(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/cli",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.10.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.
|
|
30
|
+
"@cmssy/core": "9.10.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^20.0.0",
|