@puckeditor/cli 0.24.0-canary.8a8fcc94 → 0.24.0-canary.8e792e2d
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/README.md +1 -5
- package/dist/bin.mjs +593 -3054
- package/dist/docs/cli.md +48 -128
- package/dist/docs/getting-started.md +0 -2
- package/dist/templates/manifest.json +1 -4
- package/package.json +1 -2
package/dist/bin.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/bin.ts
|
|
4
4
|
import os from "os";
|
|
5
|
-
import
|
|
5
|
+
import path33 from "path";
|
|
6
6
|
import fs8 from "fs";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
|
|
@@ -49,8 +49,6 @@ var exitCodeByError = {
|
|
|
49
49
|
"PUCK-CLI-CLOUD-UNREACHABLE": EXIT_CODES.cloud,
|
|
50
50
|
"PUCK-CLI-CONNECT-FAILED": EXIT_CODES.cloud,
|
|
51
51
|
"PUCK-CLI-DOC-NOT-FOUND": EXIT_CODES.usage,
|
|
52
|
-
"PUCK-CLI-PAGES-FILE-INVALID": EXIT_CODES.usage,
|
|
53
|
-
"PUCK-CLI-PAGES-IMPORT-FAILED": EXIT_CODES.cloud,
|
|
54
52
|
"PUCK-CLI-CANCELLED": EXIT_CODES.cancelled
|
|
55
53
|
};
|
|
56
54
|
var exitCodeForError = (code) => exitCodeByError[code];
|
|
@@ -76,13 +74,10 @@ var DEFAULT_CLOUD_URL = "https://cloud.puckeditor.com";
|
|
|
76
74
|
var API_KEYS_PATH = "/api-keys";
|
|
77
75
|
var DOCS_URL = "https://puckeditor.com/docs/cli";
|
|
78
76
|
var MANUAL_INTEGRATION_DOCS_URL = "https://puckeditor.com/docs/getting-started";
|
|
79
|
-
var CLI_PACKAGE = "@puckeditor/cli";
|
|
80
77
|
var CORE_PACKAGE = "@puckeditor/core";
|
|
81
78
|
var LEGACY_CORE_PACKAGE = "@measured/puck";
|
|
82
79
|
var CLOUD_CLIENT_PACKAGE = "@puckeditor/cloud-client";
|
|
83
80
|
var PLUGIN_AI_PACKAGE = "@puckeditor/plugin-ai";
|
|
84
|
-
var PLUGIN_PAGES_PACKAGE = "@puckeditor/plugin-pages";
|
|
85
|
-
var PLUGIN_AUTH_PACKAGE = "@puckeditor/plugin-auth";
|
|
86
81
|
var CANONICAL_INVOCATION = "npx @puckeditor/cli";
|
|
87
82
|
|
|
88
83
|
// src/detect/framework.ts
|
|
@@ -215,11 +210,6 @@ var versionOf = (versionOrRange) => {
|
|
|
215
210
|
const match = /(\d+)(?:\.(\d+))?/.exec(cleaned);
|
|
216
211
|
return match ? [Number(match[1]), Number(match[2] ?? 0)] : null;
|
|
217
212
|
};
|
|
218
|
-
var atLeast = (versionOrRange, min) => {
|
|
219
|
-
const [major2, minor] = versionOf(versionOrRange) ?? [0, 0];
|
|
220
|
-
const [minMajor, minMinor] = versionOf(min) ?? [0, 0];
|
|
221
|
-
return major2 > minMajor || major2 === minMajor && minor >= minMinor;
|
|
222
|
-
};
|
|
223
213
|
var majorOf = (versionOrRange) => versionOf(versionOrRange)?.[0] ?? null;
|
|
224
214
|
|
|
225
215
|
// src/detect/server.ts
|
|
@@ -808,18 +798,11 @@ var OPTIONS = {
|
|
|
808
798
|
config: { type: "string" },
|
|
809
799
|
"package-manager": { type: "string" },
|
|
810
800
|
wait: { type: "boolean" },
|
|
811
|
-
login: { type: "boolean" },
|
|
812
801
|
framework: { type: "string" },
|
|
813
802
|
name: { type: "string" },
|
|
814
803
|
offline: { type: "boolean" },
|
|
815
804
|
ai: { type: "boolean" },
|
|
816
805
|
"no-ai": { type: "boolean" },
|
|
817
|
-
pages: { type: "boolean" },
|
|
818
|
-
"no-pages": { type: "boolean" },
|
|
819
|
-
auth: { type: "boolean" },
|
|
820
|
-
"no-auth": { type: "boolean" },
|
|
821
|
-
"editor-only": { type: "boolean" },
|
|
822
|
-
canary: { type: "boolean" },
|
|
823
806
|
backend: { type: "string" },
|
|
824
807
|
"backend-url": { type: "string" }
|
|
825
808
|
};
|
|
@@ -838,33 +821,18 @@ var MUTATING = [
|
|
|
838
821
|
"config",
|
|
839
822
|
"package-manager",
|
|
840
823
|
"wait",
|
|
841
|
-
"login",
|
|
842
824
|
"backend",
|
|
843
825
|
"backend-url"
|
|
844
826
|
];
|
|
845
827
|
var COMMAND_OPTIONS = {
|
|
846
|
-
init: [
|
|
847
|
-
|
|
848
|
-
...MUTATING,
|
|
849
|
-
"framework",
|
|
850
|
-
"name",
|
|
851
|
-
"ai",
|
|
852
|
-
"no-ai",
|
|
853
|
-
"pages",
|
|
854
|
-
"no-pages",
|
|
855
|
-
"auth",
|
|
856
|
-
"no-auth",
|
|
857
|
-
"editor-only",
|
|
858
|
-
"canary"
|
|
859
|
-
],
|
|
860
|
-
add: [...GLOBAL, ...MUTATING, "canary"],
|
|
828
|
+
init: [...GLOBAL, ...MUTATING, "framework", "name", "ai", "no-ai"],
|
|
829
|
+
add: [...GLOBAL, ...MUTATING],
|
|
861
830
|
connect: [...GLOBAL, "api-key", "config", "wait"],
|
|
862
831
|
status: ["json", "help", "version", "cwd", "workspace", "config"],
|
|
863
832
|
doctor: ["json", "help", "version", "cwd", "workspace", "config", "offline"],
|
|
864
833
|
docs: ["json", "help", "version"],
|
|
865
834
|
frameworks: ["json", "help", "version"],
|
|
866
835
|
telemetry: ["json", "help", "version"],
|
|
867
|
-
pages: ["json", "yes", "dry-run", "help", "version", "cwd", "api-key"],
|
|
868
836
|
help: GLOBAL
|
|
869
837
|
};
|
|
870
838
|
var COMMANDS = [
|
|
@@ -876,7 +844,6 @@ var COMMANDS = [
|
|
|
876
844
|
"docs",
|
|
877
845
|
"frameworks",
|
|
878
846
|
"telemetry",
|
|
879
|
-
"pages",
|
|
880
847
|
"help"
|
|
881
848
|
];
|
|
882
849
|
var FRAMEWORKS = FRAMEWORK_IDS;
|
|
@@ -954,19 +921,11 @@ var parseCliArgs = (argv) => {
|
|
|
954
921
|
"--backend-url must be an http(s) URL, e.g. http://localhost:3000."
|
|
955
922
|
);
|
|
956
923
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
);
|
|
963
|
-
}
|
|
964
|
-
if (values[name] && values["editor-only"]) {
|
|
965
|
-
throw new CliError(
|
|
966
|
-
"PUCK-CLI-INVALID-ARGS",
|
|
967
|
-
`--${name} and --editor-only can't be used together.`
|
|
968
|
-
);
|
|
969
|
-
}
|
|
924
|
+
if (values.ai && values["no-ai"]) {
|
|
925
|
+
throw new CliError(
|
|
926
|
+
"PUCK-CLI-INVALID-ARGS",
|
|
927
|
+
"--ai and --no-ai can't be used together."
|
|
928
|
+
);
|
|
970
929
|
}
|
|
971
930
|
return {
|
|
972
931
|
command,
|
|
@@ -984,18 +943,11 @@ var parseCliArgs = (argv) => {
|
|
|
984
943
|
config: values.config,
|
|
985
944
|
packageManager: pm,
|
|
986
945
|
wait: Boolean(values.wait),
|
|
987
|
-
login: Boolean(values.login),
|
|
988
946
|
framework,
|
|
989
947
|
name: values.name,
|
|
990
948
|
offline: Boolean(values.offline),
|
|
991
949
|
ai: Boolean(values.ai),
|
|
992
950
|
noAi: Boolean(values["no-ai"]),
|
|
993
|
-
pages: Boolean(values.pages),
|
|
994
|
-
noPages: Boolean(values["no-pages"]),
|
|
995
|
-
auth: Boolean(values.auth),
|
|
996
|
-
noAuth: Boolean(values["no-auth"]),
|
|
997
|
-
editorOnly: Boolean(values["editor-only"]),
|
|
998
|
-
canary: Boolean(values.canary),
|
|
999
951
|
backend,
|
|
1000
952
|
backendUrl: backendUrl?.replace(/\/+$/, "")
|
|
1001
953
|
}
|
|
@@ -1036,10 +988,6 @@ var createInquirerPrompter = (output) => {
|
|
|
1036
988
|
const { default: select } = await import("@inquirer/select");
|
|
1037
989
|
return select({ message, choices }, context);
|
|
1038
990
|
}),
|
|
1039
|
-
checkbox: (message, choices) => wrap(async () => {
|
|
1040
|
-
const { default: checkbox } = await import("@inquirer/checkbox");
|
|
1041
|
-
return checkbox({ message, choices }, context);
|
|
1042
|
-
}),
|
|
1043
991
|
input: (message, opts = {}) => wrap(async () => {
|
|
1044
992
|
const { default: input } = await import("@inquirer/input");
|
|
1045
993
|
return input(
|
|
@@ -1100,8 +1048,6 @@ var CloudRequestError = class extends Error {
|
|
|
1100
1048
|
kind;
|
|
1101
1049
|
};
|
|
1102
1050
|
var TIMEOUT_MS = 15e3;
|
|
1103
|
-
var IMPORT_TIMEOUT_MS = 6e4;
|
|
1104
|
-
var IMPORT_BATCH_SIZE = 100;
|
|
1105
1051
|
var POLL_ERRORS = {
|
|
1106
1052
|
authorization_pending: "pending",
|
|
1107
1053
|
slow_down: "slow_down",
|
|
@@ -1111,11 +1057,11 @@ var POLL_ERRORS = {
|
|
|
1111
1057
|
};
|
|
1112
1058
|
var createCloudApi = (baseUrl, fetchImpl) => {
|
|
1113
1059
|
const url = (p) => new URL(p, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).toString();
|
|
1114
|
-
const request = async (p, init
|
|
1060
|
+
const request = async (p, init) => {
|
|
1115
1061
|
try {
|
|
1116
1062
|
return await fetchImpl(url(p), {
|
|
1117
1063
|
...init,
|
|
1118
|
-
signal: AbortSignal.timeout(
|
|
1064
|
+
signal: AbortSignal.timeout(TIMEOUT_MS)
|
|
1119
1065
|
});
|
|
1120
1066
|
} catch (err) {
|
|
1121
1067
|
throw new CloudRequestError(
|
|
@@ -1154,22 +1100,6 @@ var createCloudApi = (baseUrl, fetchImpl) => {
|
|
|
1154
1100
|
}
|
|
1155
1101
|
return body;
|
|
1156
1102
|
},
|
|
1157
|
-
async createClaimableProject(client) {
|
|
1158
|
-
const res = await request("api/claimable-projects", {
|
|
1159
|
-
method: "POST",
|
|
1160
|
-
headers: { "content-type": "application/json" },
|
|
1161
|
-
body: JSON.stringify(client)
|
|
1162
|
-
});
|
|
1163
|
-
if (res.status === 404 || res.status === 429) return null;
|
|
1164
|
-
const body = await json(res);
|
|
1165
|
-
if (!res.ok || typeof body.apiKey !== "string" || typeof body.claimUrl !== "string") {
|
|
1166
|
-
throw new CloudRequestError(
|
|
1167
|
-
`Puck Cloud returned an unexpected response (${res.status})`,
|
|
1168
|
-
"bad_response"
|
|
1169
|
-
);
|
|
1170
|
-
}
|
|
1171
|
-
return body;
|
|
1172
|
-
},
|
|
1173
1103
|
async pollConnect(deviceCode) {
|
|
1174
1104
|
const res = await request("api/cli/connect/token", {
|
|
1175
1105
|
method: "POST",
|
|
@@ -1198,44 +1128,10 @@ var createCloudApi = (baseUrl, fetchImpl) => {
|
|
|
1198
1128
|
} catch {
|
|
1199
1129
|
return "unreachable";
|
|
1200
1130
|
}
|
|
1201
|
-
},
|
|
1202
|
-
async importPages(apiKey, pages) {
|
|
1203
|
-
const res = await request(
|
|
1204
|
-
"api/pages/batch",
|
|
1205
|
-
{
|
|
1206
|
-
method: "POST",
|
|
1207
|
-
headers: { "content-type": "application/json", "x-api-key": apiKey },
|
|
1208
|
-
body: JSON.stringify({ pages })
|
|
1209
|
-
},
|
|
1210
|
-
IMPORT_TIMEOUT_MS
|
|
1211
|
-
);
|
|
1212
|
-
const body = await json(res);
|
|
1213
|
-
if (res.status === 401 || res.status === 403) {
|
|
1214
|
-
throw new CloudRequestError(
|
|
1215
|
-
"Puck Cloud rejected the API key",
|
|
1216
|
-
"rejected"
|
|
1217
|
-
);
|
|
1218
|
-
}
|
|
1219
|
-
if (res.status === 429) {
|
|
1220
|
-
throw new CloudRequestError(
|
|
1221
|
-
"Too many requests. Wait a minute and try again.",
|
|
1222
|
-
"rate_limited"
|
|
1223
|
-
);
|
|
1224
|
-
}
|
|
1225
|
-
if (!res.ok || !Array.isArray(body.created) || !Array.isArray(body.skipped)) {
|
|
1226
|
-
throw new CloudRequestError(
|
|
1227
|
-
typeof body.error === "string" ? `Puck Cloud couldn't import the pages: ${body.error}` : `Puck Cloud returned an unexpected response (${res.status})`,
|
|
1228
|
-
"bad_response"
|
|
1229
|
-
);
|
|
1230
|
-
}
|
|
1231
|
-
return { created: body.created, skipped: body.skipped };
|
|
1232
1131
|
}
|
|
1233
1132
|
};
|
|
1234
1133
|
};
|
|
1235
1134
|
|
|
1236
|
-
// src/context.ts
|
|
1237
|
-
import path5 from "path";
|
|
1238
|
-
|
|
1239
1135
|
// src/env/truthy.ts
|
|
1240
1136
|
var isTruthyEnv = (value) => value !== void 0 && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
1241
1137
|
|
|
@@ -1271,17 +1167,7 @@ var rerunCommand = (rc) => {
|
|
|
1271
1167
|
if (arg.startsWith("--api-key=")) continue;
|
|
1272
1168
|
args.push(/[\s"'$`]/.test(arg) ? JSON.stringify(arg) : arg);
|
|
1273
1169
|
}
|
|
1274
|
-
return [
|
|
1275
|
-
};
|
|
1276
|
-
var localInvocation = (binPath, cwd, env2) => {
|
|
1277
|
-
for (let dir = cwd; ; dir = path5.dirname(dir)) {
|
|
1278
|
-
if (binPath.startsWith(path5.join(dir, "node_modules") + path5.sep)) break;
|
|
1279
|
-
if (path5.dirname(dir) === dir) return void 0;
|
|
1280
|
-
}
|
|
1281
|
-
const pm = env2.npm_config_user_agent?.split("/")[0];
|
|
1282
|
-
if (pm === "pnpm") return "pnpm exec puck";
|
|
1283
|
-
if (pm === "yarn") return "yarn puck";
|
|
1284
|
-
return "npm exec --no -- puck";
|
|
1170
|
+
return ["npx", "@puckeditor/cli", ...args].join(" ");
|
|
1285
1171
|
};
|
|
1286
1172
|
|
|
1287
1173
|
// src/result.ts
|
|
@@ -1296,8 +1182,6 @@ var emptyResult = (command, dryRun = false) => ({
|
|
|
1296
1182
|
puck: null,
|
|
1297
1183
|
cloud: null,
|
|
1298
1184
|
ai: null,
|
|
1299
|
-
pages: null,
|
|
1300
|
-
auth: null,
|
|
1301
1185
|
filesModified: [],
|
|
1302
1186
|
filesCreated: [],
|
|
1303
1187
|
packagesInstalled: [],
|
|
@@ -1313,12 +1197,12 @@ var COMMANDS2 = [
|
|
|
1313
1197
|
description: "Set up Puck in this project or create a new app, optionally with Puck AI"
|
|
1314
1198
|
},
|
|
1315
1199
|
{
|
|
1316
|
-
name: "add <editor|cloud|ai
|
|
1317
|
-
description: "Add
|
|
1200
|
+
name: "add <editor|cloud|ai>",
|
|
1201
|
+
description: "Add one capability (ai includes cloud, cloud includes editor)"
|
|
1318
1202
|
},
|
|
1319
1203
|
{
|
|
1320
|
-
name: "connect
|
|
1321
|
-
description: "Log in to Puck Cloud again and replace PUCK_API_KEY
|
|
1204
|
+
name: "connect",
|
|
1205
|
+
description: "Log in to Puck Cloud again and replace PUCK_API_KEY"
|
|
1322
1206
|
},
|
|
1323
1207
|
{ name: "status", description: "Show what's installed and configured" },
|
|
1324
1208
|
{
|
|
@@ -1333,10 +1217,6 @@ var COMMANDS2 = [
|
|
|
1333
1217
|
name: "docs <command>",
|
|
1334
1218
|
description: "Read the docs for this version: ls, cat <page>, find <query>, grep <text>"
|
|
1335
1219
|
},
|
|
1336
|
-
{
|
|
1337
|
-
name: "pages import <file>",
|
|
1338
|
-
description: "Publish pages from a JSON file of Puck data keyed by route to Puck Cloud"
|
|
1339
|
-
},
|
|
1340
1220
|
{
|
|
1341
1221
|
name: "telemetry [status|enable|disable]",
|
|
1342
1222
|
description: "Show or change anonymous usage data collection"
|
|
@@ -1363,18 +1243,12 @@ Flags:
|
|
|
1363
1243
|
--workspace <name|dir> Choose an app when run from a monorepo root
|
|
1364
1244
|
--api-key <key> Use an existing Puck API key (prefer PUCK_API_KEY=\u2026 in the environment)
|
|
1365
1245
|
--no-env-write Don't write PUCK_API_KEY to .env.local
|
|
1366
|
-
--ai
|
|
1367
|
-
--no-ai
|
|
1368
|
-
Include all of them except these (init)
|
|
1369
|
-
--editor-only Include none of them (init)
|
|
1370
|
-
--canary Install the latest canaries of Puck's packages (init, add;
|
|
1371
|
-
or PUCK_CANARY=1)
|
|
1246
|
+
--ai Also set up Puck AI and Puck Cloud (init)
|
|
1247
|
+
--no-ai Set up the editor only, without asking about Puck AI (init)
|
|
1372
1248
|
--backend <add|external|none> Where a Vite or static Astro app gets its server:
|
|
1373
1249
|
add one, use one elsewhere, or none (editor only)
|
|
1374
1250
|
--backend-url <url> The server for --backend external, e.g. http://localhost:3000
|
|
1375
1251
|
--wait Wait for Puck Cloud login approval instead of returning
|
|
1376
|
-
--login Log in to Puck Cloud instead of starting on a project
|
|
1377
|
-
without an account (init, add)
|
|
1378
1252
|
--framework <name> Framework for new apps (init), one of:
|
|
1379
1253
|
${FRAMEWORK_IDS.join(", ")}
|
|
1380
1254
|
--name <name> Directory name for new apps (init)
|
|
@@ -1383,8 +1257,7 @@ Flags:
|
|
|
1383
1257
|
For agents:
|
|
1384
1258
|
Every command prints exactly one JSON document with --json. When "status" is
|
|
1385
1259
|
"action_required", surface each entry in "actions" to the developer (e.g. a
|
|
1386
|
-
browser_login URL and code), then run its "rerun" command.
|
|
1387
|
-
claim_project link to the developer even when "status" is "success". Exit codes:
|
|
1260
|
+
browser_login URL and code), then run its "rerun" command. Exit codes:
|
|
1388
1261
|
0 success, 2 usage, 3 unsupported project, 4 file conflict, 5 package manager,
|
|
1389
1262
|
6 doctor found problems, 7 Puck Cloud unreachable, 10 action required, 11 partial.
|
|
1390
1263
|
|
|
@@ -1426,10 +1299,10 @@ var indentationAt = (code, offset) => {
|
|
|
1426
1299
|
|
|
1427
1300
|
// src/templates/source.ts
|
|
1428
1301
|
import fs from "fs";
|
|
1429
|
-
import
|
|
1302
|
+
import path7 from "path";
|
|
1430
1303
|
|
|
1431
1304
|
// src/env/gitignore.ts
|
|
1432
|
-
import
|
|
1305
|
+
import path5 from "path";
|
|
1433
1306
|
var globToRegex = (glob) => {
|
|
1434
1307
|
let out = "";
|
|
1435
1308
|
for (let i = 0; i < glob.length; i++) {
|
|
@@ -1457,19 +1330,19 @@ var matchesPattern = (pattern, relPath) => {
|
|
|
1457
1330
|
const anchored = p.startsWith("/") || p.slice(0, -1).includes("/");
|
|
1458
1331
|
p = p.replace(/^\//, "");
|
|
1459
1332
|
const regex = globToRegex(p);
|
|
1460
|
-
return anchored ? regex.test(relPath) : regex.test(
|
|
1333
|
+
return anchored ? regex.test(relPath) : regex.test(path5.posix.basename(relPath));
|
|
1461
1334
|
};
|
|
1462
1335
|
var isIgnored = (vfs, file, rootDir) => {
|
|
1463
1336
|
const dirs = [];
|
|
1464
|
-
for (let dir =
|
|
1337
|
+
for (let dir = path5.dirname(file); ; dir = path5.dirname(dir)) {
|
|
1465
1338
|
dirs.unshift(dir);
|
|
1466
|
-
if (dir === rootDir ||
|
|
1339
|
+
if (dir === rootDir || path5.dirname(dir) === dir) break;
|
|
1467
1340
|
}
|
|
1468
1341
|
let ignored = false;
|
|
1469
1342
|
for (const dir of dirs) {
|
|
1470
|
-
const text = vfs.readText(
|
|
1343
|
+
const text = vfs.readText(path5.join(dir, ".gitignore"));
|
|
1471
1344
|
if (text === null) continue;
|
|
1472
|
-
const rel =
|
|
1345
|
+
const rel = path5.relative(dir, file).split(path5.sep).join("/");
|
|
1473
1346
|
for (const raw of text.split(/\r?\n/)) {
|
|
1474
1347
|
const line = raw.trim();
|
|
1475
1348
|
if (!line || line.startsWith("#")) continue;
|
|
@@ -1483,10 +1356,10 @@ var isIgnored = (vfs, file, rootDir) => {
|
|
|
1483
1356
|
return ignored;
|
|
1484
1357
|
};
|
|
1485
1358
|
var planIgnore = (vfs, file, appRoot, gitRoot) => {
|
|
1486
|
-
const appGitignore =
|
|
1487
|
-
const rootGitignore = gitRoot ?
|
|
1359
|
+
const appGitignore = path5.join(appRoot, ".gitignore");
|
|
1360
|
+
const rootGitignore = gitRoot ? path5.join(gitRoot, ".gitignore") : null;
|
|
1488
1361
|
const gitignore = vfs.exists(appGitignore) ? appGitignore : rootGitignore && vfs.exists(rootGitignore) ? rootGitignore : appGitignore;
|
|
1489
|
-
const pattern =
|
|
1362
|
+
const pattern = path5.relative(path5.dirname(gitignore), file).split(path5.sep).join("/");
|
|
1490
1363
|
const existing = vfs.readText(gitignore);
|
|
1491
1364
|
const eol = existing?.includes("\r\n") ? "\r\n" : "\n";
|
|
1492
1365
|
const block = `# Puck Cloud API key${eol}${pattern}${eol}`;
|
|
@@ -1495,7 +1368,7 @@ var planIgnore = (vfs, file, appRoot, gitRoot) => {
|
|
|
1495
1368
|
};
|
|
1496
1369
|
|
|
1497
1370
|
// src/detect/scan.ts
|
|
1498
|
-
import
|
|
1371
|
+
import path6 from "path";
|
|
1499
1372
|
|
|
1500
1373
|
// src/ast/imports.ts
|
|
1501
1374
|
var specifierName = (node) => node.type === "Identifier" ? node.name : node.value;
|
|
@@ -1553,16 +1426,6 @@ var getModuleReferences = (ast, code) => {
|
|
|
1553
1426
|
}
|
|
1554
1427
|
return refs;
|
|
1555
1428
|
};
|
|
1556
|
-
var findImportLocal = (ast, code, source, imported) => {
|
|
1557
|
-
for (const ref of getModuleReferences(ast, code)) {
|
|
1558
|
-
if (ref.kind !== "import" || ref.source !== source) continue;
|
|
1559
|
-
const spec = ref.specifiers.find(
|
|
1560
|
-
(s) => s.imported === imported && !s.typeOnly
|
|
1561
|
-
);
|
|
1562
|
-
if (spec) return spec.local;
|
|
1563
|
-
}
|
|
1564
|
-
return null;
|
|
1565
|
-
};
|
|
1566
1429
|
|
|
1567
1430
|
// src/detect/scan.ts
|
|
1568
1431
|
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
@@ -1587,7 +1450,7 @@ var SOURCE_EXT = /\.(tsx?|jsx?|mjs|cjs|mts|cts)$/;
|
|
|
1587
1450
|
var MAX_FILES = 4e3;
|
|
1588
1451
|
var MAX_DEPTH = 10;
|
|
1589
1452
|
var MAX_BYTES = 512 * 1024;
|
|
1590
|
-
var toPosix = (p) => p.split(
|
|
1453
|
+
var toPosix = (p) => p.split(path6.sep).join("/");
|
|
1591
1454
|
var listSourceFiles = (vfs, root) => {
|
|
1592
1455
|
const files = [];
|
|
1593
1456
|
let truncated = false;
|
|
@@ -1598,12 +1461,12 @@ var listSourceFiles = (vfs, root) => {
|
|
|
1598
1461
|
truncated = true;
|
|
1599
1462
|
return;
|
|
1600
1463
|
}
|
|
1601
|
-
const full =
|
|
1464
|
+
const full = path6.join(dir, entry.name);
|
|
1602
1465
|
if (entry.isDir) {
|
|
1603
1466
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
1604
1467
|
if (entry.name.startsWith(".") && entry.name !== ".server" && entry.name !== ".client")
|
|
1605
1468
|
continue;
|
|
1606
|
-
if (depth > 0 && vfs.exists(
|
|
1469
|
+
if (depth > 0 && vfs.exists(path6.join(full, "package.json"))) continue;
|
|
1607
1470
|
visit(full, depth + 1);
|
|
1608
1471
|
} else if (SOURCE_EXT.test(entry.name) && !entry.name.endsWith(".d.ts")) {
|
|
1609
1472
|
files.push(full);
|
|
@@ -1619,10 +1482,6 @@ var scanSources = (vfs, root) => {
|
|
|
1619
1482
|
renderFiles: [],
|
|
1620
1483
|
cloudHandlerFiles: [],
|
|
1621
1484
|
aiPluginFiles: [],
|
|
1622
|
-
pagesPluginFiles: [],
|
|
1623
|
-
authPluginFiles: [],
|
|
1624
|
-
cloudPageFiles: [],
|
|
1625
|
-
signInFiles: [],
|
|
1626
1485
|
cssImported: false,
|
|
1627
1486
|
truncated: false
|
|
1628
1487
|
};
|
|
@@ -1635,9 +1494,8 @@ var scanSources = (vfs, root) => {
|
|
|
1635
1494
|
if (!code.includes("@puckeditor/")) continue;
|
|
1636
1495
|
const ast = tryParseModule(code, file);
|
|
1637
1496
|
if (!ast) continue;
|
|
1638
|
-
const rel = toPosix(
|
|
1497
|
+
const rel = toPosix(path6.relative(root, file));
|
|
1639
1498
|
for (const ref of getModuleReferences(ast, code)) {
|
|
1640
|
-
const imports = (...names) => ref.kind === "import" && ref.specifiers.some((s) => names.includes(s.imported) && !s.typeOnly);
|
|
1641
1499
|
if (ref.source === CORE_PACKAGE && ref.kind === "import") {
|
|
1642
1500
|
const imported = ref.specifiers.filter((s) => !s.typeOnly).map((s) => s.imported);
|
|
1643
1501
|
if (imported.includes("Puck") || ref.specifiers.some((s) => s.kind === "namespace")) {
|
|
@@ -1653,14 +1511,6 @@ var scanSources = (vfs, root) => {
|
|
|
1653
1511
|
if (ref.source === CLOUD_CLIENT_PACKAGE && ref.specifiers.some((s) => s.imported === "puckHandler" && !s.typeOnly)) {
|
|
1654
1512
|
scan.cloudHandlerFiles.push(rel);
|
|
1655
1513
|
}
|
|
1656
|
-
if (ref.source === PLUGIN_PAGES_PACKAGE && imports("createPagesPlugin"))
|
|
1657
|
-
scan.pagesPluginFiles.push(rel);
|
|
1658
|
-
if (ref.source === PLUGIN_AUTH_PACKAGE && imports("createAuthPlugin"))
|
|
1659
|
-
scan.authPluginFiles.push(rel);
|
|
1660
|
-
if (ref.source === CLOUD_CLIENT_PACKAGE && imports("puckCloud", "PuckCloud", "default") && code.includes(".getPublished("))
|
|
1661
|
-
scan.cloudPageFiles.push(rel);
|
|
1662
|
-
if (ref.source === CLOUD_CLIENT_PACKAGE && imports("getPuckIdentity", "loginUrl"))
|
|
1663
|
-
scan.signInFiles.push(rel);
|
|
1664
1514
|
}
|
|
1665
1515
|
}
|
|
1666
1516
|
const unique = (list) => [...new Set(list)].sort();
|
|
@@ -1668,10 +1518,6 @@ var scanSources = (vfs, root) => {
|
|
|
1668
1518
|
scan.renderFiles = unique(scan.renderFiles);
|
|
1669
1519
|
scan.cloudHandlerFiles = unique(scan.cloudHandlerFiles);
|
|
1670
1520
|
scan.aiPluginFiles = unique(scan.aiPluginFiles);
|
|
1671
|
-
scan.pagesPluginFiles = unique(scan.pagesPluginFiles);
|
|
1672
|
-
scan.authPluginFiles = unique(scan.authPluginFiles);
|
|
1673
|
-
scan.cloudPageFiles = unique(scan.cloudPageFiles);
|
|
1674
|
-
scan.signInFiles = unique(scan.signInFiles);
|
|
1675
1521
|
return scan;
|
|
1676
1522
|
};
|
|
1677
1523
|
|
|
@@ -1711,12 +1557,7 @@ var templates_default = {
|
|
|
1711
1557
|
"eslint.config.mjs",
|
|
1712
1558
|
".env*"
|
|
1713
1559
|
],
|
|
1714
|
-
allowBuilds: ["esbuild"]
|
|
1715
|
-
ranges: {
|
|
1716
|
-
cloudClientPages: "^0.9.0-0",
|
|
1717
|
-
pluginPages: "^0.9.0-0",
|
|
1718
|
-
pluginAuth: "^0.9.0-0"
|
|
1719
|
-
}
|
|
1560
|
+
allowBuilds: ["esbuild"]
|
|
1720
1561
|
};
|
|
1721
1562
|
|
|
1722
1563
|
// src/templates/source.ts
|
|
@@ -1731,8 +1572,8 @@ var excludeMatchers = templates_default.exclude.map((pattern) => {
|
|
|
1731
1572
|
});
|
|
1732
1573
|
var isExcludedTemplateFile = (rel) => excludeMatchers.some((m) => m(rel));
|
|
1733
1574
|
var walk2 = (dir, base = dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
1734
|
-
const full =
|
|
1735
|
-
return entry.isDirectory() ? walk2(full, base) : [toPosix(
|
|
1575
|
+
const full = path7.join(dir, entry.name);
|
|
1576
|
+
return entry.isDirectory() ? walk2(full, base) : [toPosix(path7.relative(base, full))];
|
|
1736
1577
|
});
|
|
1737
1578
|
var DirTemplateSource = class {
|
|
1738
1579
|
#dir;
|
|
@@ -1744,10 +1585,10 @@ var DirTemplateSource = class {
|
|
|
1744
1585
|
this.#manifest = opts.manifest;
|
|
1745
1586
|
}
|
|
1746
1587
|
list(recipe) {
|
|
1747
|
-
return walk2(
|
|
1588
|
+
return walk2(path7.join(this.#dir, recipe)).map((rel) => this.#fromStored(rel)).filter((rel) => !isExcludedTemplateFile(rel)).sort();
|
|
1748
1589
|
}
|
|
1749
1590
|
read(recipe, file) {
|
|
1750
|
-
return fs.readFileSync(
|
|
1591
|
+
return fs.readFileSync(path7.join(this.#dir, recipe, this.#toStored(file)));
|
|
1751
1592
|
}
|
|
1752
1593
|
manifest() {
|
|
1753
1594
|
return this.#manifest();
|
|
@@ -1844,8 +1685,8 @@ var findCloudRoute = (scan, appDir, expected) => {
|
|
|
1844
1685
|
};
|
|
1845
1686
|
|
|
1846
1687
|
// src/templates/relocate.ts
|
|
1847
|
-
import
|
|
1848
|
-
var posix =
|
|
1688
|
+
import path8 from "path";
|
|
1689
|
+
var posix = path8.posix;
|
|
1849
1690
|
var stripExtension = (file) => file.replace(/\.(tsx?|jsx?|mjs|cjs|mts|cts)$/, "");
|
|
1850
1691
|
var relativeSpecifier = (fromFile, toModule) => {
|
|
1851
1692
|
const rel = posix.relative(posix.dirname(fromFile), toModule);
|
|
@@ -1977,505 +1818,100 @@ var relocateModule = (code, opts) => {
|
|
|
1977
1818
|
return { ok: true, code: applyEdits(code, edits) };
|
|
1978
1819
|
};
|
|
1979
1820
|
|
|
1980
|
-
// src/
|
|
1981
|
-
var
|
|
1982
|
-
|
|
1983
|
-
if (
|
|
1984
|
-
|
|
1985
|
-
return null;
|
|
1821
|
+
// src/frameworks/shared.ts
|
|
1822
|
+
var renderTemplate = (p, recipe, from, to, opts) => {
|
|
1823
|
+
const raw = templateText(p.templates, recipe, from);
|
|
1824
|
+
if (!/\.(tsx?|jsx?)$/.test(from)) return { ok: true, code: raw };
|
|
1825
|
+
return relocateModule(raw, { ...opts, from, to });
|
|
1986
1826
|
};
|
|
1987
|
-
var
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
1827
|
+
var configManual = (p, capability, file, reason) => p.manual({
|
|
1828
|
+
id: `${capability}:config-import:${file}`,
|
|
1829
|
+
type: "manual_edit",
|
|
1830
|
+
capability,
|
|
1831
|
+
required: true,
|
|
1832
|
+
file,
|
|
1833
|
+
reason: "unsupported_shape",
|
|
1834
|
+
message: reason,
|
|
1835
|
+
instructions: `Export your Puck config as the default export of ${p.state.puck.configFile}, then re-run the command.`
|
|
1836
|
+
});
|
|
1837
|
+
var copyTemplateFiles = (p, recipe, files, opts, capability = "editor") => {
|
|
1838
|
+
for (const file of files) {
|
|
1839
|
+
const rendered = renderTemplate(p, recipe, file.from, file.to, opts);
|
|
1840
|
+
if (!rendered.ok) {
|
|
1841
|
+
configManual(p, capability, file.to, rendered.reason);
|
|
1842
|
+
continue;
|
|
1843
|
+
}
|
|
1844
|
+
const outcome = p.createFile(file.to, rendered.code, {
|
|
1845
|
+
capability,
|
|
1846
|
+
ifMissing: file.ifMissing
|
|
1847
|
+
});
|
|
1848
|
+
if (outcome === "conflict") {
|
|
1849
|
+
p.manual({
|
|
1850
|
+
id: `${capability}:conflict:${file.to}`,
|
|
1851
|
+
type: "manual_edit",
|
|
1852
|
+
capability,
|
|
1853
|
+
required: true,
|
|
1854
|
+
file: file.to,
|
|
1855
|
+
reason: "conflict",
|
|
1856
|
+
message: `${file.to} already exists with different content, so it was left untouched.`,
|
|
1857
|
+
instructions: `Merge the Puck ${recipe} recipe's ${file.from} into ${file.to}, or move your file and re-run the command.`,
|
|
1858
|
+
snippet: rendered.code
|
|
1859
|
+
});
|
|
2007
1860
|
}
|
|
2008
1861
|
}
|
|
2009
|
-
if (exported.type === "CallExpression" && exported.callee.type === "Identifier" && exported.callee.name === "defineConfig" && exported.arguments.length === 1) {
|
|
2010
|
-
exported = unwrapExpression(exported.arguments[0]);
|
|
2011
|
-
}
|
|
2012
|
-
if (exported.type !== "ObjectExpression") {
|
|
2013
|
-
return {
|
|
2014
|
-
ok: false,
|
|
2015
|
-
detail: "The config is not an object literal (e.g. it's a function)"
|
|
2016
|
-
};
|
|
2017
|
-
}
|
|
2018
|
-
return { ok: true, ast, config: exported };
|
|
2019
1862
|
};
|
|
2020
|
-
var
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2032
|
-
const
|
|
2033
|
-
const
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
return
|
|
2037
|
-
}
|
|
2038
|
-
if (hasTrailingComma) {
|
|
2039
|
-
return {
|
|
2040
|
-
at: last.end + commaIndex + 1,
|
|
2041
|
-
text: `
|
|
2042
|
-
${indent2}${entry(indent2, false)},`
|
|
2043
|
-
};
|
|
1863
|
+
var normalizeEol = (text) => text.replace(/\r\n/g, "\n");
|
|
1864
|
+
var upgradeTemplateFile = (p, {
|
|
1865
|
+
fromRecipe,
|
|
1866
|
+
toRecipe,
|
|
1867
|
+
from,
|
|
1868
|
+
to,
|
|
1869
|
+
opts,
|
|
1870
|
+
capability,
|
|
1871
|
+
summary
|
|
1872
|
+
}) => {
|
|
1873
|
+
const current = p.vfs.readText(p.abs(to));
|
|
1874
|
+
if (current === null) return "missing";
|
|
1875
|
+
const same = (a, b) => normalizeEol(a) === normalizeEol(b);
|
|
1876
|
+
const next = renderTemplate(p, toRecipe, from, to, opts);
|
|
1877
|
+
if (!next.ok) {
|
|
1878
|
+
configManual(p, capability, to, next.reason);
|
|
1879
|
+
return "customized";
|
|
2044
1880
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
1881
|
+
const candidates = [
|
|
1882
|
+
{
|
|
1883
|
+
previous: renderTemplate(p, fromRecipe, from, to, opts),
|
|
1884
|
+
next: next.code
|
|
1885
|
+
},
|
|
1886
|
+
{
|
|
1887
|
+
previous: {
|
|
1888
|
+
ok: true,
|
|
1889
|
+
code: templateText(p.templates, fromRecipe, from)
|
|
1890
|
+
},
|
|
1891
|
+
next: templateText(p.templates, toRecipe, from)
|
|
1892
|
+
}
|
|
1893
|
+
];
|
|
1894
|
+
if (candidates.some((c) => same(current, c.next))) return "already";
|
|
1895
|
+
const match = candidates.find(
|
|
1896
|
+
(c) => c.previous.ok && same(current, c.previous.code)
|
|
1897
|
+
);
|
|
1898
|
+
if (!match) return "customized";
|
|
1899
|
+
p.modifyFile(to, match.next, { capability, summary });
|
|
1900
|
+
return "upgraded";
|
|
2047
1901
|
};
|
|
2048
|
-
var
|
|
2049
|
-
var
|
|
2050
|
-
var
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
var ensureConfigEntry = (code, filename, objectPath, key, value) => {
|
|
2057
|
-
const analysis = analyzeConfig(code, filename);
|
|
2058
|
-
if (!analysis.ok) return { status: "manual", detail: analysis.detail };
|
|
2059
|
-
const q = quoteOf(code);
|
|
2060
|
-
const quote = (s) => `${q}${s.replace(/\\/g, "\\\\").replace(new RegExp(q, "g"), `\\${q}`)}${q}`;
|
|
2061
|
-
const keyText = IDENTIFIER.test(key) ? key : quote(key);
|
|
2062
|
-
const entry = `${keyText}: ${quote(value)}`;
|
|
2063
|
-
let obj = analysis.config;
|
|
2064
|
-
for (let i = 0; i <= objectPath.length; i++) {
|
|
2065
|
-
const segment = objectPath[i];
|
|
2066
|
-
const existing = segment === void 0 ? findProperty(obj, key) : findProperty(obj, segment);
|
|
2067
|
-
if (existing && segment === void 0) return { status: "exists" };
|
|
2068
|
-
if (!existing) {
|
|
2069
|
-
if (obj.properties.some((p) => p.type === "SpreadElement")) {
|
|
2070
|
-
return {
|
|
2071
|
-
status: "manual",
|
|
2072
|
-
detail: `The config spreads another object that may set ${[
|
|
2073
|
-
...objectPath.slice(0, i),
|
|
2074
|
-
segment ?? key
|
|
2075
|
-
].join(".")}`
|
|
2076
|
-
};
|
|
2077
|
-
}
|
|
2078
|
-
const rest = objectPath.slice(i);
|
|
2079
|
-
const multiLine = (indent2) => rest.reduceRight((inner, s, depth) => {
|
|
2080
|
-
const pad = `${indent2}${" ".repeat(depth)}`;
|
|
2081
|
-
return `${s}: {
|
|
2082
|
-
${pad} ${inner},
|
|
2083
|
-
${pad}}`;
|
|
2084
|
-
}, entry);
|
|
2085
|
-
const edit = obj.properties.length === 0 ? (() => {
|
|
2086
|
-
const indent2 = indentationAt(code, obj.start);
|
|
2087
|
-
return {
|
|
2088
|
-
at: obj.start + 1,
|
|
2089
|
-
text: `
|
|
2090
|
-
${indent2} ${multiLine(`${indent2} `)},
|
|
2091
|
-
${indent2}`
|
|
2092
|
-
};
|
|
2093
|
-
})() : insertProperty(
|
|
2094
|
-
code,
|
|
2095
|
-
obj,
|
|
2096
|
-
(indent2, singleLine) => singleLine ? rest.reduceRight((inner, s) => `${s}: { ${inner} }`, entry) : multiLine(indent2)
|
|
2097
|
-
);
|
|
2098
|
-
const next = code.slice(0, edit.at) + edit.text + code.slice(edit.at);
|
|
2099
|
-
return { status: "inserted", code: next, inserted: [edit] };
|
|
2100
|
-
}
|
|
2101
|
-
const value2 = unwrapExpression(existing.value);
|
|
2102
|
-
if (value2.type !== "ObjectExpression") {
|
|
2103
|
-
return {
|
|
2104
|
-
status: "manual",
|
|
2105
|
-
detail: `${objectPath.slice(0, i + 1).join(".")} is not an object literal`
|
|
2106
|
-
};
|
|
2107
|
-
}
|
|
2108
|
-
obj = value2;
|
|
2109
|
-
}
|
|
2110
|
-
return { status: "exists" };
|
|
2111
|
-
};
|
|
2112
|
-
var ensurePlugin = (code, filename, {
|
|
2113
|
-
importName,
|
|
2114
|
-
source,
|
|
2115
|
-
call: callFor
|
|
2116
|
-
}) => {
|
|
2117
|
-
const analysis = analyzeConfig(code, filename);
|
|
2118
|
-
if (!analysis.ok) return { status: "manual", detail: analysis.detail };
|
|
2119
|
-
const { ast, config } = analysis;
|
|
2120
|
-
const q = quoteOf(code);
|
|
2121
|
-
const semi = semicolonsIn(ast, code) ? ";" : "";
|
|
2122
|
-
const call = typeof callFor === "string" ? callFor : callFor(q);
|
|
2123
|
-
const imported = ast.program.body.some(
|
|
2124
|
-
(s) => s.type === "ImportDeclaration" && s.source.value === source && s.specifiers.some((sp) => sp.local.name === importName)
|
|
2125
|
-
);
|
|
2126
|
-
const edits = [];
|
|
2127
|
-
const plugins = findProperty(config, "plugins");
|
|
2128
|
-
if (!plugins) {
|
|
2129
|
-
if (config.properties.some((p) => p.type === "SpreadElement"))
|
|
2130
|
-
return {
|
|
2131
|
-
status: "manual",
|
|
2132
|
-
detail: "The config spreads another object that may set plugins"
|
|
2133
|
-
};
|
|
2134
|
-
edits.push(insertProperty(code, config, () => `plugins: [${call}]`));
|
|
2135
|
-
} else {
|
|
2136
|
-
const list = unwrapExpression(plugins.value);
|
|
2137
|
-
if (list.type !== "ArrayExpression")
|
|
2138
|
-
return { status: "manual", detail: "plugins is not an array literal" };
|
|
2139
|
-
const exists = list.elements.some((e) => {
|
|
2140
|
-
const el = e && unwrapExpression(e);
|
|
2141
|
-
return el?.type === "CallExpression" && el.callee.type === "Identifier" && el.callee.name === importName;
|
|
2142
|
-
});
|
|
2143
|
-
if (exists) return { status: "exists" };
|
|
2144
|
-
const singleLine = lineOf(code, list.start) === lineOf(code, list.end);
|
|
2145
|
-
const items = list.elements.map((e) => code.slice(e.start, e.end));
|
|
2146
|
-
const lineStart = code.lastIndexOf("\n", list.start - 1) + 1;
|
|
2147
|
-
const lineEnd = code.indexOf("\n", list.end);
|
|
2148
|
-
const oneLine = `[${[...items, call].join(", ")}]`;
|
|
2149
|
-
const width = list.start - lineStart + oneLine.length + (lineEnd === -1 ? code.length : lineEnd) - list.end;
|
|
2150
|
-
if (singleLine && width <= 80) {
|
|
2151
|
-
edits.push({ at: list.start, end: list.end, text: oneLine });
|
|
2152
|
-
} else if (singleLine) {
|
|
2153
|
-
const indent2 = indentationAt(code, list.start);
|
|
2154
|
-
edits.push({
|
|
2155
|
-
at: list.start,
|
|
2156
|
-
end: list.end,
|
|
2157
|
-
text: `[
|
|
2158
|
-
${[...items, call].map((item) => `${indent2} ${item},`).join("\n")}
|
|
2159
|
-
${indent2}]`
|
|
2160
|
-
});
|
|
2161
|
-
} else {
|
|
2162
|
-
edits.push(
|
|
2163
|
-
appendAfterLast(code, list, list.elements, () => call)
|
|
2164
|
-
);
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
if (!imported) {
|
|
2168
|
-
const line = `import ${importName} from ${q}${source}${q}${semi}`;
|
|
2169
|
-
const imports = ast.program.body.filter(
|
|
2170
|
-
(s) => s.type === "ImportDeclaration"
|
|
2171
|
-
);
|
|
2172
|
-
const last = imports[imports.length - 1];
|
|
2173
|
-
edits.push(
|
|
2174
|
-
last ? { at: last.end, text: `
|
|
2175
|
-
${line}` } : { at: 0, text: `${line}
|
|
2176
|
-
` }
|
|
2177
|
-
);
|
|
2178
|
-
}
|
|
2179
|
-
let next = code;
|
|
2180
|
-
for (const edit of [...edits].sort((a, b) => b.at - a.at))
|
|
2181
|
-
next = next.slice(0, edit.at) + edit.text + next.slice(edit.end ?? edit.at);
|
|
2182
|
-
return {
|
|
2183
|
-
status: "inserted",
|
|
2184
|
-
code: next,
|
|
2185
|
-
inserted: edits.map(({ at, text }) => ({ at, text }))
|
|
2186
|
-
};
|
|
2187
|
-
};
|
|
2188
|
-
|
|
2189
|
-
// src/templates/auth.ts
|
|
2190
|
-
var SIGN_IN_IMPORT = `import { getPuckIdentity, loginUrl } from "${CLOUD_CLIENT_PACKAGE}";`;
|
|
2191
|
-
var identityOptions = (host) => host ? `, { host: ${JSON.stringify(host)} }` : "";
|
|
2192
|
-
var requiresSignIn = (route) => /\bprovider:\s*["']puck["']/.test(route);
|
|
2193
|
-
var withRouteAuth = (route) => {
|
|
2194
|
-
if (requiresSignIn(route)) return route;
|
|
2195
|
-
if (/\bauth\s*:/.test(route)) return null;
|
|
2196
|
-
const q = quoteOf(route);
|
|
2197
|
-
const property = `auth: { provider: ${q}puck${q} }`;
|
|
2198
|
-
const options = /const options: PuckCloudOptions = \{(\}|\n([ \t]*)| )/;
|
|
2199
|
-
const call = /puckHandler\(request(\)|, \{(\n([ \t]*)| ))/;
|
|
2200
|
-
const entry = (rest, indent2 = "") => rest === "}" ? ` ${property} }` : rest === " " ? ` ${property}, ` : `
|
|
2201
|
-
${indent2}${property},
|
|
2202
|
-
${indent2}`;
|
|
2203
|
-
if (options.test(route))
|
|
2204
|
-
return route.replace(
|
|
2205
|
-
options,
|
|
2206
|
-
(_, rest, indent2) => `const options: PuckCloudOptions = {${entry(rest, indent2)}`
|
|
2207
|
-
);
|
|
2208
|
-
if (call.test(route))
|
|
2209
|
-
return route.replace(
|
|
2210
|
-
call,
|
|
2211
|
-
(_, rest, inner, indent2) => rest === ")" ? `puckHandler(request, {${entry("}")})` : `puckHandler(request, {${entry(inner, indent2)}`
|
|
2212
|
-
);
|
|
2213
|
-
return null;
|
|
2214
|
-
};
|
|
2215
|
-
var nextPuckAuth = (host) => {
|
|
2216
|
-
return `${SIGN_IN_IMPORT}
|
|
2217
|
-
import { headers } from "next/headers";
|
|
2218
|
-
import { redirect } from "next/navigation";
|
|
2219
|
-
|
|
2220
|
-
/** Sends anyone who isn't signed in with Puck to sign in, then back to returnTo */
|
|
2221
|
-
export async function requirePuckSession(returnTo: string) {
|
|
2222
|
-
const session = await getPuckIdentity(await headers()${identityOptions(
|
|
2223
|
-
host
|
|
2224
|
-
)});
|
|
2225
|
-
|
|
2226
|
-
if (!session) {
|
|
2227
|
-
redirect(loginUrl(returnTo));
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
return session;
|
|
2231
|
-
}
|
|
2232
|
-
`;
|
|
2233
|
-
};
|
|
2234
|
-
var withSameRouteAuth = (current, base, next) => {
|
|
2235
|
-
if (current === base) return next;
|
|
2236
|
-
if (current === withRouteAuth(base)) return withRouteAuth(next);
|
|
2237
|
-
return null;
|
|
2238
|
-
};
|
|
2239
|
-
var reactRouterPuckAuth = (host) => {
|
|
2240
|
-
return `import { redirect } from "react-router";
|
|
2241
|
-
${SIGN_IN_IMPORT}
|
|
2242
|
-
|
|
2243
|
-
/** Sends anyone who isn't signed in with Puck to sign in, then back here */
|
|
2244
|
-
export async function requirePuckSession(request: Request) {
|
|
2245
|
-
const session = await getPuckIdentity(request.headers${identityOptions(
|
|
2246
|
-
host
|
|
2247
|
-
)});
|
|
2248
|
-
|
|
2249
|
-
if (!session) {
|
|
2250
|
-
const url = new URL(request.url);
|
|
2251
|
-
throw redirect(loginUrl(\`\${url.pathname}\${url.search}\`));
|
|
2252
|
-
}
|
|
2253
|
-
|
|
2254
|
-
return session;
|
|
2255
|
-
}
|
|
2256
|
-
`;
|
|
2257
|
-
};
|
|
2258
|
-
var tanstackPuckAuth = (host) => {
|
|
2259
|
-
return `import { createServerFn } from "@tanstack/react-start";
|
|
2260
|
-
import { getRequest } from "@tanstack/react-start/server";
|
|
2261
|
-
import { redirect } from "@tanstack/react-router";
|
|
2262
|
-
${SIGN_IN_IMPORT}
|
|
2263
|
-
|
|
2264
|
-
/** Sends anyone who isn't signed in with Puck to sign in, then back to returnTo */
|
|
2265
|
-
export const requirePuckSession = createServerFn({ method: "GET" })
|
|
2266
|
-
.validator((returnTo: string) => returnTo)
|
|
2267
|
-
.handler(async ({ data: returnTo }) => {
|
|
2268
|
-
const session = await getPuckIdentity(getRequest().headers${identityOptions(
|
|
2269
|
-
host
|
|
2270
|
-
)});
|
|
2271
|
-
|
|
2272
|
-
if (!session) {
|
|
2273
|
-
throw redirect({ href: loginUrl(returnTo) });
|
|
2274
|
-
}
|
|
2275
|
-
|
|
2276
|
-
return session;
|
|
2277
|
-
});
|
|
2278
|
-
`;
|
|
2279
|
-
};
|
|
2280
|
-
var REQUIRE_SESSION = `import { useEffect, useState } from "react";
|
|
2281
|
-
import type { ReactNode } from "react";
|
|
2282
|
-
|
|
2283
|
-
/**
|
|
2284
|
-
* Sends anyone who isn't signed in with Puck to sign in, then back here. The
|
|
2285
|
-
* Puck Cloud API route checks the session too, so this only saves signed-out
|
|
2286
|
-
* visitors from an editor they can't use.
|
|
2287
|
-
*/
|
|
2288
|
-
export function RequireSession({ children }: { children: ReactNode }) {
|
|
2289
|
-
const [signedIn, setSignedIn] = useState(false);
|
|
2290
|
-
|
|
2291
|
-
useEffect(() => {
|
|
2292
|
-
fetch("/api/puck/auth/session").then((response) => {
|
|
2293
|
-
if (response.ok) return setSignedIn(true);
|
|
2294
|
-
|
|
2295
|
-
const returnTo = \`\${window.location.pathname}\${window.location.search}\`;
|
|
2296
|
-
window.location.assign(
|
|
2297
|
-
\`/api/puck/auth/login?returnTo=\${encodeURIComponent(returnTo)}\`
|
|
2298
|
-
);
|
|
2299
|
-
});
|
|
2300
|
-
}, []);
|
|
2301
|
-
|
|
2302
|
-
return signedIn ? children : null;
|
|
2303
|
-
}
|
|
2304
|
-
`;
|
|
2305
|
-
var astroPuckAuth = (host) => {
|
|
2306
|
-
return `import fs from "node:fs";
|
|
2307
|
-
${SIGN_IN_IMPORT}
|
|
2308
|
-
|
|
2309
|
-
// Astro doesn't put .env files in process.env, where Sign in with Puck reads
|
|
2310
|
-
// its settings. Production servers read them from their environment.
|
|
2311
|
-
if (import.meta.env.DEV && fs.existsSync(".env.local"))
|
|
2312
|
-
process.loadEnvFile(".env.local");
|
|
2313
|
-
|
|
2314
|
-
/** Where to send visitors who aren't signed in with Puck, or null if they are */
|
|
2315
|
-
export const puckSignInUrl = async (request: Request) => {
|
|
2316
|
-
if (await getPuckIdentity(request.headers${identityOptions(
|
|
2317
|
-
host
|
|
2318
|
-
)})) return null;
|
|
2319
|
-
|
|
2320
|
-
const url = new URL(request.url);
|
|
2321
|
-
return loginUrl(\`\${url.pathname}\${url.search}\`);
|
|
2322
|
-
};
|
|
2323
|
-
`;
|
|
2324
|
-
};
|
|
2325
|
-
|
|
2326
|
-
// src/frameworks/shared.ts
|
|
2327
|
-
var renderCode = (raw, from, to, opts) => {
|
|
2328
|
-
if (!/\.(tsx?|jsx?)$/.test(from)) return { ok: true, code: raw };
|
|
2329
|
-
return relocateModule(raw, { ...opts, from, to });
|
|
2330
|
-
};
|
|
2331
|
-
var renderTemplate = (p, recipe, from, to, opts) => renderCode(templateText(p.templates, recipe, from), from, to, opts);
|
|
2332
|
-
var configManual = (p, capability, file, reason) => p.manual({
|
|
2333
|
-
id: `${capability}:config-import:${file}`,
|
|
2334
|
-
type: "manual_edit",
|
|
2335
|
-
capability,
|
|
2336
|
-
required: true,
|
|
2337
|
-
file,
|
|
2338
|
-
reason: "unsupported_shape",
|
|
2339
|
-
message: reason,
|
|
2340
|
-
instructions: `Export your Puck config as the default export of ${p.state.puck.configFile}, then re-run the command.`
|
|
2341
|
-
});
|
|
2342
|
-
var copyTemplateFiles = (p, recipe, files, opts, capability = "editor") => {
|
|
2343
|
-
for (const file of files) {
|
|
2344
|
-
const rendered = renderTemplate(p, recipe, file.from, file.to, opts);
|
|
2345
|
-
if (!rendered.ok) {
|
|
2346
|
-
configManual(p, capability, file.to, rendered.reason);
|
|
2347
|
-
continue;
|
|
2348
|
-
}
|
|
2349
|
-
const outcome = p.createFile(file.to, rendered.code, {
|
|
2350
|
-
capability,
|
|
2351
|
-
ifMissing: file.ifMissing
|
|
2352
|
-
});
|
|
2353
|
-
if (outcome === "conflict") {
|
|
2354
|
-
p.manual({
|
|
2355
|
-
id: `${capability}:conflict:${file.to}`,
|
|
2356
|
-
type: "manual_edit",
|
|
2357
|
-
capability,
|
|
2358
|
-
required: true,
|
|
2359
|
-
file: file.to,
|
|
2360
|
-
reason: "conflict",
|
|
2361
|
-
message: `${file.to} already exists with different content, so it was left untouched.`,
|
|
2362
|
-
instructions: `Merge the Puck ${recipe} recipe's ${file.from} into ${file.to}, or move your file and re-run the command.`,
|
|
2363
|
-
snippet: rendered.code
|
|
2364
|
-
});
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2367
|
-
};
|
|
2368
|
-
var normalizeEol = (text) => text.replace(/\r\n/g, "\n");
|
|
2369
|
-
var upgradeTemplateFile = (p, {
|
|
2370
|
-
fromRecipe,
|
|
2371
|
-
toRecipe,
|
|
2372
|
-
from,
|
|
2373
|
-
to,
|
|
2374
|
-
opts,
|
|
2375
|
-
capability,
|
|
2376
|
-
summary
|
|
2377
|
-
}) => {
|
|
2378
|
-
const current = p.vfs.readText(p.abs(to));
|
|
2379
|
-
if (current === null) return "missing";
|
|
2380
|
-
const same = (a, b) => normalizeEol(a) === normalizeEol(b);
|
|
2381
|
-
const next = renderTemplate(p, toRecipe, from, to, opts);
|
|
2382
|
-
if (!next.ok) {
|
|
2383
|
-
configManual(p, capability, to, next.reason);
|
|
2384
|
-
return "customized";
|
|
2385
|
-
}
|
|
2386
|
-
const candidates = [
|
|
2387
|
-
{
|
|
2388
|
-
previous: renderTemplate(p, fromRecipe, from, to, opts),
|
|
2389
|
-
next: next.code
|
|
2390
|
-
},
|
|
2391
|
-
{
|
|
2392
|
-
previous: {
|
|
2393
|
-
ok: true,
|
|
2394
|
-
code: templateText(p.templates, fromRecipe, from)
|
|
2395
|
-
},
|
|
2396
|
-
next: templateText(p.templates, toRecipe, from)
|
|
2397
|
-
}
|
|
2398
|
-
];
|
|
2399
|
-
if (candidates.some((c) => same(current, c.next))) return "already";
|
|
2400
|
-
const match = candidates.find(
|
|
2401
|
-
(c) => c.previous.ok && same(current, c.previous.code)
|
|
2402
|
-
);
|
|
2403
|
-
if (!match) return "customized";
|
|
2404
|
-
p.modifyFile(to, match.next, { capability, summary });
|
|
2405
|
-
return "upgraded";
|
|
2406
|
-
};
|
|
2407
|
-
var upgradeVariant = (p, {
|
|
2408
|
-
from,
|
|
2409
|
-
to,
|
|
2410
|
-
opts,
|
|
2411
|
-
combos,
|
|
2412
|
-
source,
|
|
2413
|
-
want,
|
|
2414
|
-
capability,
|
|
2415
|
-
summary,
|
|
2416
|
-
onMatch
|
|
2417
|
-
}) => {
|
|
2418
|
-
const current = p.vfs.readText(p.abs(to));
|
|
2419
|
-
if (current === null) return "missing";
|
|
2420
|
-
const same = (a, b) => normalizeEol(a) === normalizeEol(b);
|
|
2421
|
-
const forms = (flags) => {
|
|
2422
|
-
const raw = source(flags);
|
|
2423
|
-
if (raw === null) return null;
|
|
2424
|
-
const relocated = renderCode(raw, from, to, opts);
|
|
2425
|
-
return { relocated: relocated.ok ? relocated.code : null, verbatim: raw };
|
|
2426
|
-
};
|
|
2427
|
-
for (const combo of combos) {
|
|
2428
|
-
const known = forms(combo);
|
|
2429
|
-
if (!known) continue;
|
|
2430
|
-
const form = [known.relocated, known.verbatim].findIndex(
|
|
2431
|
-
(code2) => code2 !== null && same(current, code2)
|
|
2432
|
-
);
|
|
2433
|
-
if (form === -1) continue;
|
|
2434
|
-
onMatch?.(combo);
|
|
2435
|
-
const wanted = forms({ ...combo, ...want });
|
|
2436
|
-
const code = wanted && [wanted.relocated, wanted.verbatim][form];
|
|
2437
|
-
if (!code) return "customized";
|
|
2438
|
-
if (same(current, code)) return "already";
|
|
2439
|
-
p.modifyFile(to, code, { capability, summary });
|
|
2440
|
-
return "upgraded";
|
|
2441
|
-
}
|
|
2442
|
-
return "customized";
|
|
2443
|
-
};
|
|
2444
|
-
var flagCombos = (...keys) => keys.reduce(
|
|
2445
|
-
(combos, key) => combos.flatMap((c) => [
|
|
2446
|
-
{ ...c, [key]: false },
|
|
2447
|
-
{ ...c, [key]: true }
|
|
2448
|
-
]),
|
|
2449
|
-
[{}]
|
|
2450
|
-
);
|
|
2451
|
-
var configModuleTarget = (p, created = "puck.config.tsx") => stripExtension(p.state.puck.configFile ?? created);
|
|
2452
|
-
var configRelocation = (p) => p.state.puck.configExports ? { module: "puck.config", shape: p.state.puck.configExports } : void 0;
|
|
2453
|
-
var planPuckConfig = (p, recipe, { from = "puck.config.tsx", to = "puck.config.tsx" } = {}) => {
|
|
2454
|
-
if (p.state.puck.configFile) return;
|
|
2455
|
-
p.createFile(to, templateText(p.templates, recipe, from), {
|
|
2456
|
-
capability: "editor",
|
|
2457
|
-
summary: `Create ${to}`
|
|
2458
|
-
});
|
|
1902
|
+
var configModuleTarget = (p, created = "puck.config.tsx") => stripExtension(p.state.puck.configFile ?? created);
|
|
1903
|
+
var configRelocation = (p) => p.state.puck.configExports ? { module: "puck.config", shape: p.state.puck.configExports } : void 0;
|
|
1904
|
+
var planPuckConfig = (p, recipe, { from = "puck.config.tsx", to = "puck.config.tsx" } = {}) => {
|
|
1905
|
+
if (p.state.puck.configFile) return;
|
|
1906
|
+
p.createFile(to, templateText(p.templates, recipe, from), {
|
|
1907
|
+
capability: "editor",
|
|
1908
|
+
summary: `Create ${to}`
|
|
1909
|
+
});
|
|
2459
1910
|
};
|
|
2460
1911
|
var planCoreDependency = (p) => {
|
|
2461
1912
|
if (!p.state.puck.installed)
|
|
2462
1913
|
p.addDependency(CORE_PACKAGE, `^${p.cliVersion}`, "editor");
|
|
2463
1914
|
};
|
|
2464
|
-
var planAiRoute = (p, file, cloudRoute, aiRoute, { warn = true } = {}) => {
|
|
2465
|
-
const current = p.vfs.readText(p.abs(file)) ?? "";
|
|
2466
|
-
const upgraded = withSameRouteAuth(current, cloudRoute, aiRoute);
|
|
2467
|
-
if (upgraded !== null) {
|
|
2468
|
-
p.modifyFile(file, upgraded, {
|
|
2469
|
-
capability: "ai",
|
|
2470
|
-
summary: `Enable Puck AI in ${file}`
|
|
2471
|
-
});
|
|
2472
|
-
} else if (warn && withSameRouteAuth(current, aiRoute, aiRoute) === null) {
|
|
2473
|
-
p.warn(
|
|
2474
|
-
"PUCK-CLI-W-AI-ROUTE",
|
|
2475
|
-
`Make sure the puckHandler in ${file} sets ai.designMode.allowed to true, or Puck AI's design mode will be rejected.`
|
|
2476
|
-
);
|
|
2477
|
-
}
|
|
2478
|
-
};
|
|
2479
1915
|
|
|
2480
1916
|
// src/frameworks/ai.ts
|
|
2481
1917
|
var AI_SNIPPET = `import { Puck, blocksPlugin, outlinePlugin } from "@puckeditor/core";
|
|
@@ -2502,702 +1938,6 @@ var RENDER_AI_SNIPPET = `import { withDynamicConfig } from "@puckeditor/plugin-a
|
|
|
2502
1938
|
<Render config={withDynamicConfig(config, data)} data={data} />
|
|
2503
1939
|
`;
|
|
2504
1940
|
|
|
2505
|
-
// src/templates/pages.ts
|
|
2506
|
-
var publishedData = (host) => `(await puckCloud(${host ? `{ host: ${JSON.stringify(host)} }` : ""}).pages.getPublished(path))?.data ?? null`;
|
|
2507
|
-
var AI_PLUGIN = `const aiPlugin = createAiPlugin({
|
|
2508
|
-
// Allow users to switch between design and assembly mode.
|
|
2509
|
-
// Read more: https://puckeditor.com/docs/ai/design-mode
|
|
2510
|
-
designMode: {
|
|
2511
|
-
visible: true,
|
|
2512
|
-
},
|
|
2513
|
-
// Select design mode by default.
|
|
2514
|
-
defaultMode: "design",
|
|
2515
|
-
});
|
|
2516
|
-
`;
|
|
2517
|
-
var nextPagesEditorClient = ({ ai }) => ai ? `"use client";
|
|
2518
|
-
|
|
2519
|
-
import { Puck, blocksPlugin, outlinePlugin } from "@puckeditor/core";
|
|
2520
|
-
import { createAiPlugin } from "@puckeditor/plugin-ai";
|
|
2521
|
-
import { createPagesPlugin } from "@puckeditor/plugin-pages";
|
|
2522
|
-
|
|
2523
|
-
import config from "../../../puck.config";
|
|
2524
|
-
|
|
2525
|
-
${AI_PLUGIN}
|
|
2526
|
-
// Loads, saves and publishes pages in Puck Cloud
|
|
2527
|
-
const pagesPlugin = createPagesPlugin();
|
|
2528
|
-
|
|
2529
|
-
// Place the ai plugin in the first position in the side nav.
|
|
2530
|
-
const plugins = [aiPlugin, pagesPlugin, blocksPlugin(), outlinePlugin()];
|
|
2531
|
-
|
|
2532
|
-
export function Client() {
|
|
2533
|
-
return <Puck plugins={plugins} data={{}} config={config} />;
|
|
2534
|
-
}
|
|
2535
|
-
` : `"use client";
|
|
2536
|
-
|
|
2537
|
-
import { Puck } from "@puckeditor/core";
|
|
2538
|
-
import { createPagesPlugin } from "@puckeditor/plugin-pages";
|
|
2539
|
-
import config from "../../../puck.config";
|
|
2540
|
-
|
|
2541
|
-
// Loads, saves and publishes pages in Puck Cloud
|
|
2542
|
-
const pagesPlugin = createPagesPlugin();
|
|
2543
|
-
|
|
2544
|
-
export function Client() {
|
|
2545
|
-
return <Puck plugins={[pagesPlugin]} config={config} data={{}} />;
|
|
2546
|
-
}
|
|
2547
|
-
`;
|
|
2548
|
-
var nextPagesEditorPage = ({
|
|
2549
|
-
ai,
|
|
2550
|
-
auth
|
|
2551
|
-
}) => `/**
|
|
2552
|
-
* This file renders the Puck editor at /puck. The Pages plugin opens the page
|
|
2553
|
-
* in the \`path\` query parameter, e.g. /puck?path=/about, and saves it to
|
|
2554
|
-
* Puck Cloud.
|
|
2555
|
-
*
|
|
2556
|
-
* ${auth ? "Editing requires signing in with a Puck Cloud account in your organization." : "NB this route is public, and you will need to add authentication"}
|
|
2557
|
-
*/
|
|
2558
|
-
|
|
2559
|
-
import "@puckeditor/core/puck.css";
|
|
2560
|
-
${ai ? `import "@puckeditor/plugin-ai/styles.css";
|
|
2561
|
-
` : ""}import "@puckeditor/plugin-pages/styles.css";
|
|
2562
|
-
import { Metadata } from "next";
|
|
2563
|
-
import { connection } from "next/server";
|
|
2564
|
-
import { Client } from "./client";${auth ? `
|
|
2565
|
-
import { requirePuckSession } from "../../../lib/puck-auth";` : ""}
|
|
2566
|
-
|
|
2567
|
-
export async function generateMetadata(): Promise<Metadata> {
|
|
2568
|
-
return {
|
|
2569
|
-
title: "Puck",
|
|
2570
|
-
};
|
|
2571
|
-
}
|
|
2572
|
-
|
|
2573
|
-
${auth ? `export default async function Page({
|
|
2574
|
-
searchParams,
|
|
2575
|
-
}: {
|
|
2576
|
-
searchParams: Promise<Record<string, string>>;
|
|
2577
|
-
}) {
|
|
2578
|
-
// Puck renders in the browser, so the editor is rendered on every request
|
|
2579
|
-
await connection();
|
|
2580
|
-
const query = new URLSearchParams(await searchParams).toString();
|
|
2581
|
-
await requirePuckSession(\`/puck\${query ? \`?\${query}\` : ""}\`);
|
|
2582
|
-
|
|
2583
|
-
return <Client />;
|
|
2584
|
-
}` : `export default async function Page() {
|
|
2585
|
-
// Puck renders in the browser, so the editor is rendered on every request
|
|
2586
|
-
await connection();
|
|
2587
|
-
|
|
2588
|
-
return <Client />;
|
|
2589
|
-
}`}
|
|
2590
|
-
`;
|
|
2591
|
-
var nextPagesRenderPage = (host) => `/**
|
|
2592
|
-
* This file implements a catch-all route that renders the pages published in
|
|
2593
|
-
* Puck Cloud. For any route visited (with exception of other hardcoded pages
|
|
2594
|
-
* in /app), it reads the published page with \`getPublished\` and renders it using
|
|
2595
|
-
* <Render>.
|
|
2596
|
-
*/
|
|
2597
|
-
|
|
2598
|
-
import { puckCloud } from "@puckeditor/cloud-client";
|
|
2599
|
-
import { Client } from "./client";
|
|
2600
|
-
import { notFound } from "next/navigation";
|
|
2601
|
-
import { connection } from "next/server";
|
|
2602
|
-
import { Metadata } from "next";
|
|
2603
|
-
import { cache } from "react";
|
|
2604
|
-
|
|
2605
|
-
// Read once per request, by both generateMetadata and the page
|
|
2606
|
-
const getPublishedPage = cache(async (path: string) => {
|
|
2607
|
-
// Pages are published in Puck Cloud, so render them on each request
|
|
2608
|
-
await connection();
|
|
2609
|
-
|
|
2610
|
-
return ${publishedData(host)};
|
|
2611
|
-
});
|
|
2612
|
-
|
|
2613
|
-
export async function generateMetadata({
|
|
2614
|
-
params,
|
|
2615
|
-
}: {
|
|
2616
|
-
params: Promise<{ puckPath: string[] }>;
|
|
2617
|
-
}): Promise<Metadata> {
|
|
2618
|
-
const { puckPath = [] } = await params;
|
|
2619
|
-
const path = \`/\${puckPath.join("/")}\`;
|
|
2620
|
-
|
|
2621
|
-
return {
|
|
2622
|
-
title: (await getPublishedPage(path))?.root.props?.title,
|
|
2623
|
-
};
|
|
2624
|
-
}
|
|
2625
|
-
|
|
2626
|
-
export default async function Page({
|
|
2627
|
-
params,
|
|
2628
|
-
}: {
|
|
2629
|
-
params: Promise<{ puckPath: string[] }>;
|
|
2630
|
-
}) {
|
|
2631
|
-
const { puckPath = [] } = await params;
|
|
2632
|
-
const path = \`/\${puckPath.join("/")}\`;
|
|
2633
|
-
const data = await getPublishedPage(path);
|
|
2634
|
-
|
|
2635
|
-
if (!data) {
|
|
2636
|
-
return notFound();
|
|
2637
|
-
}
|
|
2638
|
-
|
|
2639
|
-
return <Client data={data} />;
|
|
2640
|
-
}
|
|
2641
|
-
`;
|
|
2642
|
-
var NEXT_PAGES_PROXY = `import { NextResponse } from "next/server";
|
|
2643
|
-
|
|
2644
|
-
import type { NextRequest } from "next/server";
|
|
2645
|
-
|
|
2646
|
-
export async function proxy(req: NextRequest) {
|
|
2647
|
-
const res = NextResponse.next({ request: req });
|
|
2648
|
-
|
|
2649
|
-
if (req.method === "GET") {
|
|
2650
|
-
// Redirect routes that match "/[...puckPath]/edit" to "/puck?path=/[...puckPath]"
|
|
2651
|
-
if (req.nextUrl.pathname.endsWith("/edit")) {
|
|
2652
|
-
const url = new URL("/puck", req.url);
|
|
2653
|
-
url.searchParams.set("path", req.nextUrl.pathname.slice(0, -5) || "/");
|
|
2654
|
-
|
|
2655
|
-
return NextResponse.redirect(url);
|
|
2656
|
-
}
|
|
2657
|
-
}
|
|
2658
|
-
|
|
2659
|
-
return res;
|
|
2660
|
-
}
|
|
2661
|
-
`;
|
|
2662
|
-
var cloudPagesServer = (host) => `import { puckCloud } from "@puckeditor/cloud-client";
|
|
2663
|
-
|
|
2664
|
-
// Pages are edited and published in Puck Cloud
|
|
2665
|
-
export async function getPage(path: string) {
|
|
2666
|
-
return ${publishedData(host)};
|
|
2667
|
-
}
|
|
2668
|
-
`;
|
|
2669
|
-
var reactRouterPagesSplat = ({
|
|
2670
|
-
ai
|
|
2671
|
-
}) => `import { redirect } from "react-router";
|
|
2672
|
-
${ai ? `
|
|
2673
|
-
import type { Route } from "./+types/puck-splat";
|
|
2674
|
-
import { resolvePuckPath } from "~/lib/resolve-puck-path.server";
|
|
2675
|
-
import { getPage } from "~/lib/pages.server";
|
|
2676
|
-
import { PuckRender } from "~/components/puck-render";
|
|
2677
|
-
` : `import { Render } from "@puckeditor/core";
|
|
2678
|
-
|
|
2679
|
-
import type { Route } from "./+types/puck-splat";
|
|
2680
|
-
import { config } from "../../puck.config";
|
|
2681
|
-
import { resolvePuckPath } from "~/lib/resolve-puck-path.server";
|
|
2682
|
-
import { getPage } from "~/lib/pages.server";
|
|
2683
|
-
`}
|
|
2684
|
-
export async function loader({ params }: Route.LoaderArgs) {
|
|
2685
|
-
const pathname = params["*"] ?? "/";
|
|
2686
|
-
const { isEditorRoute, path } = resolvePuckPath(pathname);
|
|
2687
|
-
|
|
2688
|
-
// Pages are edited at /puck, which opens the page in the path parameter
|
|
2689
|
-
if (isEditorRoute) {
|
|
2690
|
-
throw redirect(\`/puck?path=\${encodeURIComponent(path)}\`);
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
const page = await getPage(path);
|
|
2694
|
-
|
|
2695
|
-
// Throw a 404 if data for the page does not exist
|
|
2696
|
-
if (!page) {
|
|
2697
|
-
throw new Response("Not Found", { status: 404 });
|
|
2698
|
-
}
|
|
2699
|
-
|
|
2700
|
-
return {
|
|
2701
|
-
path,
|
|
2702
|
-
data: page,
|
|
2703
|
-
};
|
|
2704
|
-
}
|
|
2705
|
-
|
|
2706
|
-
export function meta({ loaderData }: Route.MetaArgs) {
|
|
2707
|
-
return [
|
|
2708
|
-
{
|
|
2709
|
-
title: loaderData.data.root.props?.title ?? "",
|
|
2710
|
-
},
|
|
2711
|
-
];
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
export default function PuckSplatRoute({ loaderData }: Route.ComponentProps) {
|
|
2715
|
-
return (
|
|
2716
|
-
<div>
|
|
2717
|
-
${ai ? "<PuckRender data={loaderData.data} />" : "<Render config={config} data={loaderData.data} />"}
|
|
2718
|
-
</div>
|
|
2719
|
-
);
|
|
2720
|
-
}
|
|
2721
|
-
`;
|
|
2722
|
-
var reactRouterPagesEditor = ({
|
|
2723
|
-
ai,
|
|
2724
|
-
auth
|
|
2725
|
-
}) => `import { Puck${ai ? ", blocksPlugin, outlinePlugin" : ""} } from "@puckeditor/core";
|
|
2726
|
-
${ai ? `import { createAiPlugin } from "@puckeditor/plugin-ai";
|
|
2727
|
-
` : ""}import { createPagesPlugin } from "@puckeditor/plugin-pages";
|
|
2728
|
-
|
|
2729
|
-
import type { Route } from "./+types/puck";
|
|
2730
|
-
import { config } from "../../puck.config";${auth ? `
|
|
2731
|
-
import { requirePuckSession } from "~/lib/puck-auth.server";` : ""}
|
|
2732
|
-
import editorStyles from "@puckeditor/core/puck.css?url";${ai ? `
|
|
2733
|
-
import aiPluginStyles from "@puckeditor/plugin-ai/styles.css?url";` : ""}
|
|
2734
|
-
import pagesPluginStyles from "@puckeditor/plugin-pages/styles.css?url";
|
|
2735
|
-
${auth ? `
|
|
2736
|
-
export async function loader({ request }: Route.LoaderArgs) {
|
|
2737
|
-
await requirePuckSession(request);
|
|
2738
|
-
|
|
2739
|
-
return null;
|
|
2740
|
-
}
|
|
2741
|
-
` : ""}
|
|
2742
|
-
export function meta(_: Route.MetaArgs) {
|
|
2743
|
-
return [{ title: "Puck" }];
|
|
2744
|
-
}
|
|
2745
|
-
${ai ? `
|
|
2746
|
-
${AI_PLUGIN}` : ""}
|
|
2747
|
-
// Loads, saves and publishes pages in Puck Cloud. The page to edit is in the
|
|
2748
|
-
// path parameter, e.g. /puck?path=/about
|
|
2749
|
-
const pagesPlugin = createPagesPlugin();
|
|
2750
|
-
${ai ? `
|
|
2751
|
-
// Place the ai plugin in the first position in the side nav.
|
|
2752
|
-
const plugins = [aiPlugin, pagesPlugin, blocksPlugin(), outlinePlugin()];
|
|
2753
|
-
` : ""}
|
|
2754
|
-
export default function PuckEditorRoute() {
|
|
2755
|
-
return (
|
|
2756
|
-
<>
|
|
2757
|
-
<link rel="stylesheet" href={editorStyles} id="puck-css" />${ai ? `
|
|
2758
|
-
<link rel="stylesheet" href={aiPluginStyles} id="puck-plugin-ai-css" />` : ""}
|
|
2759
|
-
<link
|
|
2760
|
-
rel="stylesheet"
|
|
2761
|
-
href={pagesPluginStyles}
|
|
2762
|
-
id="puck-plugin-pages-css"
|
|
2763
|
-
/>
|
|
2764
|
-
<Puck plugins={${ai ? "plugins" : "[pagesPlugin]"}} config={config} data={{}} />
|
|
2765
|
-
</>
|
|
2766
|
-
);
|
|
2767
|
-
}
|
|
2768
|
-
`;
|
|
2769
|
-
var tanstackPagesLib = `import { createServerFn } from "@tanstack/react-start";
|
|
2770
|
-
import { notFound, redirect } from "@tanstack/react-router";
|
|
2771
|
-
|
|
2772
|
-
import { getPage } from "./pages.server";
|
|
2773
|
-
import { resolvePuckPath } from "./resolve-puck-path";
|
|
2774
|
-
|
|
2775
|
-
// Loads the published page for a URL
|
|
2776
|
-
export const loadPuckPage = createServerFn({ method: "GET" })
|
|
2777
|
-
.validator((pathname: string) => pathname)
|
|
2778
|
-
.handler(async ({ data: pathname }) => {
|
|
2779
|
-
const { isEditorRoute, path } = resolvePuckPath(pathname);
|
|
2780
|
-
|
|
2781
|
-
// Pages are edited at /puck, which opens the page in the path parameter
|
|
2782
|
-
if (isEditorRoute) {
|
|
2783
|
-
throw redirect({ href: \`/puck?path=\${encodeURIComponent(path)}\` });
|
|
2784
|
-
}
|
|
2785
|
-
|
|
2786
|
-
const page = await getPage(path);
|
|
2787
|
-
|
|
2788
|
-
// Throw a 404 if data for the page does not exist
|
|
2789
|
-
if (!page) {
|
|
2790
|
-
throw notFound();
|
|
2791
|
-
}
|
|
2792
|
-
|
|
2793
|
-
return { path, data: page };
|
|
2794
|
-
});
|
|
2795
|
-
`;
|
|
2796
|
-
var TANSTACK_PAGES_SPLAT = `import { createFileRoute } from "@tanstack/react-router";
|
|
2797
|
-
|
|
2798
|
-
import { loadPuckPage } from "../lib/pages";
|
|
2799
|
-
import { PuckRender } from "../components/puck-render";
|
|
2800
|
-
|
|
2801
|
-
export const Route = createFileRoute("/$")({
|
|
2802
|
-
loader: ({ params }) => loadPuckPage({ data: params._splat ?? "" }),
|
|
2803
|
-
head: ({ loaderData }) => ({
|
|
2804
|
-
meta: [{ title: loaderData?.data.root.props?.title ?? "" }],
|
|
2805
|
-
}),
|
|
2806
|
-
component: PuckSplatRoute,
|
|
2807
|
-
});
|
|
2808
|
-
|
|
2809
|
-
function PuckSplatRoute() {
|
|
2810
|
-
const { data } = Route.useLoaderData();
|
|
2811
|
-
|
|
2812
|
-
return <PuckRender data={data} />;
|
|
2813
|
-
}
|
|
2814
|
-
`;
|
|
2815
|
-
var tanstackPagesEditor = ({
|
|
2816
|
-
ai,
|
|
2817
|
-
auth
|
|
2818
|
-
}) => `import { createFileRoute } from "@tanstack/react-router";
|
|
2819
|
-
import { Puck${ai ? ", blocksPlugin, outlinePlugin" : ""} } from "@puckeditor/core";
|
|
2820
|
-
${ai ? `import { createAiPlugin } from "@puckeditor/plugin-ai";
|
|
2821
|
-
` : ""}import { createPagesPlugin } from "@puckeditor/plugin-pages";
|
|
2822
|
-
|
|
2823
|
-
import { config } from "../../puck.config";${auth ? `
|
|
2824
|
-
import { requirePuckSession } from "../lib/puck-auth";` : ""}
|
|
2825
|
-
|
|
2826
|
-
import editorStyles from "@puckeditor/core/puck.css?url";${ai ? `
|
|
2827
|
-
import aiPluginStyles from "@puckeditor/plugin-ai/styles.css?url";` : ""}
|
|
2828
|
-
import pagesPluginStyles from "@puckeditor/plugin-pages/styles.css?url";
|
|
2829
|
-
|
|
2830
|
-
export const Route = createFileRoute("/puck")({${auth ? `
|
|
2831
|
-
beforeLoad: ({ location }) => requirePuckSession({ data: location.href }),` : ""}
|
|
2832
|
-
head: () => ({
|
|
2833
|
-
meta: [{ title: "Puck" }],
|
|
2834
|
-
links: [
|
|
2835
|
-
{ rel: "stylesheet", href: editorStyles },${ai ? `
|
|
2836
|
-
{ rel: "stylesheet", href: aiPluginStyles },` : ""}
|
|
2837
|
-
{ rel: "stylesheet", href: pagesPluginStyles },
|
|
2838
|
-
],
|
|
2839
|
-
}),
|
|
2840
|
-
component: PuckEditorRoute,
|
|
2841
|
-
});
|
|
2842
|
-
${ai ? `
|
|
2843
|
-
${AI_PLUGIN}` : ""}
|
|
2844
|
-
// Loads, saves and publishes pages in Puck Cloud. The page to edit is in the
|
|
2845
|
-
// path parameter, e.g. /puck?path=/about
|
|
2846
|
-
const pagesPlugin = createPagesPlugin();
|
|
2847
|
-
${ai ? `
|
|
2848
|
-
// Place the ai plugin in the first position in the side nav.
|
|
2849
|
-
const plugins = [aiPlugin, pagesPlugin, blocksPlugin(), outlinePlugin()];
|
|
2850
|
-
` : ""}
|
|
2851
|
-
function PuckEditorRoute() {
|
|
2852
|
-
return <Puck plugins={${ai ? "plugins" : "[pagesPlugin]"}} config={config} data={{}} />;
|
|
2853
|
-
}
|
|
2854
|
-
`;
|
|
2855
|
-
var vitePagesRoot = ({
|
|
2856
|
-
auth
|
|
2857
|
-
}) => `import { lazy, Suspense } from "react";
|
|
2858
|
-
import type { ReactNode } from "react";${auth ? `
|
|
2859
|
-
import { RequireSession } from "./require-session";` : ""}
|
|
2860
|
-
|
|
2861
|
-
// Loaded only when editing, so the editor stays out of your app's bundle
|
|
2862
|
-
const Editor = lazy(() => import("./editor"));
|
|
2863
|
-
|
|
2864
|
-
/** The path being edited for URLs ending in /edit, e.g. /about/edit */
|
|
2865
|
-
export const editorPath = (pathname: string) => {
|
|
2866
|
-
const segments = pathname.split("/");
|
|
2867
|
-
if (segments.at(-1) !== "edit") return null;
|
|
2868
|
-
return segments.slice(0, -1).join("/") || "/";
|
|
2869
|
-
};
|
|
2870
|
-
|
|
2871
|
-
/** Renders the Puck editor at /puck, and your app everywhere else */
|
|
2872
|
-
export function PuckRoot({ children }: { children: ReactNode }) {
|
|
2873
|
-
const { pathname } = window.location;
|
|
2874
|
-
const path = editorPath(pathname);
|
|
2875
|
-
|
|
2876
|
-
// Pages are edited at /puck, which opens the page in the path parameter
|
|
2877
|
-
if (path !== null) {
|
|
2878
|
-
window.location.replace(\`/puck?path=\${encodeURIComponent(path)}\`);
|
|
2879
|
-
return null;
|
|
2880
|
-
}
|
|
2881
|
-
if (pathname !== "/puck") return children;
|
|
2882
|
-
|
|
2883
|
-
return (
|
|
2884
|
-
// Fill the window, whatever layout styles your app gives its root
|
|
2885
|
-
<div style={{ position: "fixed", inset: 0, textAlign: "initial" }}>
|
|
2886
|
-
<Suspense>
|
|
2887
|
-
${auth ? "<RequireSession>\n <Editor />\n </RequireSession>" : "<Editor />"}
|
|
2888
|
-
</Suspense>
|
|
2889
|
-
</div>
|
|
2890
|
-
);
|
|
2891
|
-
}
|
|
2892
|
-
`;
|
|
2893
|
-
var vitePagesEditor = ({ ai }) => `import { Puck${ai ? ", blocksPlugin, outlinePlugin" : ""} } from "@puckeditor/core";
|
|
2894
|
-
${ai ? `import { createAiPlugin } from "@puckeditor/plugin-ai";
|
|
2895
|
-
` : ""}import { createPagesPlugin } from "@puckeditor/plugin-pages";
|
|
2896
|
-
import "@puckeditor/core/puck.css";${ai ? `
|
|
2897
|
-
import "@puckeditor/plugin-ai/styles.css";` : ""}
|
|
2898
|
-
import "@puckeditor/plugin-pages/styles.css";
|
|
2899
|
-
|
|
2900
|
-
import { config } from "../puck.config";
|
|
2901
|
-
${ai ? `
|
|
2902
|
-
${AI_PLUGIN}` : ""}
|
|
2903
|
-
// Loads, saves and publishes pages in Puck Cloud. The page to edit is in the
|
|
2904
|
-
// path parameter, e.g. /puck?path=/about
|
|
2905
|
-
const pagesPlugin = createPagesPlugin();
|
|
2906
|
-
${ai ? `
|
|
2907
|
-
// Place the ai plugin in the first position in the side nav.
|
|
2908
|
-
const plugins = [aiPlugin, pagesPlugin, blocksPlugin(), outlinePlugin()];
|
|
2909
|
-
` : ""}
|
|
2910
|
-
export default function Editor() {
|
|
2911
|
-
return <Puck plugins={${ai ? "plugins" : "[pagesPlugin]"}} config={config} data={{}} />;
|
|
2912
|
-
}
|
|
2913
|
-
`;
|
|
2914
|
-
var honoPublishedPages = (host) => `// Serves pages published in Puck Cloud
|
|
2915
|
-
// Learn more: https://puckeditor.com/docs/cli
|
|
2916
|
-
import { Hono } from "hono";
|
|
2917
|
-
import { puckCloud } from "@puckeditor/cloud-client";
|
|
2918
|
-
|
|
2919
|
-
export const puckPages = new Hono().get("/api/pages", async (c) => {
|
|
2920
|
-
const path = c.req.query("path") ?? "/";
|
|
2921
|
-
const page = ${publishedData(host)};
|
|
2922
|
-
|
|
2923
|
-
return page ? c.json(page) : c.json({ error: "Not found" }, 404);
|
|
2924
|
-
});
|
|
2925
|
-
`;
|
|
2926
|
-
var ASTRO_LOAD_ENV = `// Astro doesn't put .env files in process.env, where cloud-client reads
|
|
2927
|
-
// PUCK_API_KEY. Production servers read it from their environment.
|
|
2928
|
-
if (import.meta.env.DEV && fs.existsSync(".env.local"))
|
|
2929
|
-
process.loadEnvFile(".env.local");`;
|
|
2930
|
-
var astroPagesLib = (host) => `import fs from "node:fs";
|
|
2931
|
-
import { puckCloud } from "@puckeditor/cloud-client";
|
|
2932
|
-
|
|
2933
|
-
${ASTRO_LOAD_ENV}
|
|
2934
|
-
|
|
2935
|
-
// Pages are edited and published in Puck Cloud
|
|
2936
|
-
export const getPage = async (path: string) => ${publishedData(host)};
|
|
2937
|
-
`;
|
|
2938
|
-
var ASTRO_PAGES_API = `// Serves pages published in Puck Cloud
|
|
2939
|
-
import type { APIRoute } from "astro";
|
|
2940
|
-
import { getPage } from "../../lib/pages";
|
|
2941
|
-
|
|
2942
|
-
export const prerender = false;
|
|
2943
|
-
|
|
2944
|
-
export const GET: APIRoute = async ({ url }) => {
|
|
2945
|
-
const page = await getPage(url.searchParams.get("path") ?? "/");
|
|
2946
|
-
return page
|
|
2947
|
-
? Response.json(page)
|
|
2948
|
-
: Response.json({ error: "Not found" }, { status: 404 });
|
|
2949
|
-
};
|
|
2950
|
-
`;
|
|
2951
|
-
var ASTRO_PAGES_CATCH_ALL = `---
|
|
2952
|
-
import { getPage } from "../lib/pages";
|
|
2953
|
-
import { resolvePuckPath } from "../lib/resolve-puck-path";
|
|
2954
|
-
import PuckRender from "../puck/render";
|
|
2955
|
-
|
|
2956
|
-
// Pages are loaded when requested, so published changes show up immediately
|
|
2957
|
-
export const prerender = false;
|
|
2958
|
-
|
|
2959
|
-
const { isEditorRoute, path } = resolvePuckPath(Astro.url.pathname);
|
|
2960
|
-
|
|
2961
|
-
// Pages are edited at /puck, which opens the page in the path parameter
|
|
2962
|
-
if (isEditorRoute)
|
|
2963
|
-
return Astro.redirect(\`/puck?path=\${encodeURIComponent(path)}\`);
|
|
2964
|
-
|
|
2965
|
-
const page = await getPage(path);
|
|
2966
|
-
|
|
2967
|
-
if (!page) return new Response(null, { status: 404 });
|
|
2968
|
-
---
|
|
2969
|
-
|
|
2970
|
-
<html lang="en">
|
|
2971
|
-
<head>
|
|
2972
|
-
<meta charset="utf-8" />
|
|
2973
|
-
<meta name="viewport" content="width=device-width" />
|
|
2974
|
-
<title>{page.root.props?.title}</title>
|
|
2975
|
-
</head>
|
|
2976
|
-
<body>
|
|
2977
|
-
<PuckRender data={page} />
|
|
2978
|
-
</body>
|
|
2979
|
-
</html>
|
|
2980
|
-
`;
|
|
2981
|
-
var astroPagesEditorPage = ({
|
|
2982
|
-
server,
|
|
2983
|
-
auth
|
|
2984
|
-
}) => `---
|
|
2985
|
-
// The Puck editor, which opens the page in the path parameter, e.g. /puck?path=/about
|
|
2986
|
-
${auth ? `import { puckSignInUrl } from "../lib/puck-auth";
|
|
2987
|
-
` : ""}import Editor from "../puck/editor";
|
|
2988
|
-
${server ? `
|
|
2989
|
-
export const prerender = false;
|
|
2990
|
-
` : ""}${auth ? `
|
|
2991
|
-
// Editing requires Sign in with Puck
|
|
2992
|
-
const signIn = await puckSignInUrl(Astro.request);
|
|
2993
|
-
if (signIn) return Astro.redirect(signIn);
|
|
2994
|
-
` : ""}---
|
|
2995
|
-
|
|
2996
|
-
<html lang="en">
|
|
2997
|
-
<head>
|
|
2998
|
-
<meta charset="utf-8" />
|
|
2999
|
-
<meta name="viewport" content="width=device-width" />
|
|
3000
|
-
<title>Puck</title>
|
|
3001
|
-
</head>
|
|
3002
|
-
<body style="margin: 0">
|
|
3003
|
-
<Editor client:only="react" />
|
|
3004
|
-
</body>
|
|
3005
|
-
</html>
|
|
3006
|
-
`;
|
|
3007
|
-
var expressPublishedPages = (host) => `// Serves pages published in Puck Cloud
|
|
3008
|
-
// Learn more: https://puckeditor.com/docs/cli
|
|
3009
|
-
import express from "express";
|
|
3010
|
-
import { puckCloud } from "@puckeditor/cloud-client";
|
|
3011
|
-
|
|
3012
|
-
export const puckPages = express.Router();
|
|
3013
|
-
|
|
3014
|
-
puckPages.get("/api/pages", async (req, res, next) => {
|
|
3015
|
-
// Express 4 doesn't pass errors from async handlers to next()
|
|
3016
|
-
try {
|
|
3017
|
-
const path = typeof req.query.path === "string" ? req.query.path : "/";
|
|
3018
|
-
const page = ${publishedData(host)};
|
|
3019
|
-
|
|
3020
|
-
if (page) res.json(page);
|
|
3021
|
-
else res.status(404).json({ error: "Not found" });
|
|
3022
|
-
} catch (error) {
|
|
3023
|
-
next(error);
|
|
3024
|
-
}
|
|
3025
|
-
});
|
|
3026
|
-
`;
|
|
3027
|
-
|
|
3028
|
-
// src/ast/puck-plugins.ts
|
|
3029
|
-
var isPuckElement = (node, puck) => node.type === "JSXOpeningElement" && node.name.type === "JSXIdentifier" && node.name.name === puck;
|
|
3030
|
-
var pluginArray = (ast, value) => {
|
|
3031
|
-
const list = unwrapExpression(value);
|
|
3032
|
-
if (list.type === "ArrayExpression") return list;
|
|
3033
|
-
if (list.type !== "Identifier") return null;
|
|
3034
|
-
for (const statement of ast.program.body) {
|
|
3035
|
-
const decl = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
3036
|
-
if (decl?.type !== "VariableDeclaration") continue;
|
|
3037
|
-
for (const d of decl.declarations) {
|
|
3038
|
-
if (d.id.type !== "Identifier" || d.id.name !== list.name || !d.init)
|
|
3039
|
-
continue;
|
|
3040
|
-
const init = unwrapExpression(d.init);
|
|
3041
|
-
return init.type === "ArrayExpression" ? init : null;
|
|
3042
|
-
}
|
|
3043
|
-
}
|
|
3044
|
-
return null;
|
|
3045
|
-
};
|
|
3046
|
-
var ensurePuckPlugin = (code, filename, plugin) => {
|
|
3047
|
-
const ast = tryParseModule(code, filename);
|
|
3048
|
-
if (!ast) return { status: "manual", detail: `Could not parse ${filename}` };
|
|
3049
|
-
if (findImportLocal(ast, code, plugin.source, plugin.factory))
|
|
3050
|
-
return { status: "exists" };
|
|
3051
|
-
const puck = findImportLocal(ast, code, CORE_PACKAGE, "Puck");
|
|
3052
|
-
const elements = [];
|
|
3053
|
-
if (puck)
|
|
3054
|
-
walk(ast.program, (n) => isPuckElement(n, puck) && elements.push(n));
|
|
3055
|
-
if (elements.length !== 1) {
|
|
3056
|
-
return {
|
|
3057
|
-
status: "manual",
|
|
3058
|
-
detail: puck ? "The file doesn't render exactly one <Puck> editor" : `<Puck> isn't imported from ${CORE_PACKAGE}`
|
|
3059
|
-
};
|
|
3060
|
-
}
|
|
3061
|
-
const element = elements[0];
|
|
3062
|
-
const edits = [];
|
|
3063
|
-
const attr = element.attributes.find(
|
|
3064
|
-
(a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "plugins"
|
|
3065
|
-
);
|
|
3066
|
-
if (!attr) {
|
|
3067
|
-
const name = element.name;
|
|
3068
|
-
const first = element.attributes[0];
|
|
3069
|
-
const multiline = first && lineOf(code, first.start) !== lineOf(code, name.start);
|
|
3070
|
-
edits.push({
|
|
3071
|
-
at: name.end,
|
|
3072
|
-
text: multiline ? `
|
|
3073
|
-
${indentationAt(code, first.start)}plugins={[${plugin.local}]}` : ` plugins={[${plugin.local}]}`
|
|
3074
|
-
});
|
|
3075
|
-
} else {
|
|
3076
|
-
const value = attr.type === "JSXAttribute" && attr.value?.type === "JSXExpressionContainer" && attr.value.expression.type !== "JSXEmptyExpression" ? attr.value.expression : null;
|
|
3077
|
-
const list = value && pluginArray(ast, value);
|
|
3078
|
-
if (!list)
|
|
3079
|
-
return {
|
|
3080
|
-
status: "manual",
|
|
3081
|
-
detail: "plugins isn't an array literal or a constant holding one"
|
|
3082
|
-
};
|
|
3083
|
-
const singleLine = lineOf(code, list.start) === lineOf(code, list.end);
|
|
3084
|
-
const items = list.elements.filter(Boolean);
|
|
3085
|
-
edits.push(
|
|
3086
|
-
singleLine ? items.length ? { at: items[items.length - 1].end, text: `, ${plugin.local}` } : { at: list.start + 1, text: plugin.local } : appendAfterLast(code, list, items, () => plugin.local)
|
|
3087
|
-
);
|
|
3088
|
-
}
|
|
3089
|
-
const q = quoteOf(code);
|
|
3090
|
-
const imports = ast.program.body.filter(
|
|
3091
|
-
(s) => s.type === "ImportDeclaration"
|
|
3092
|
-
);
|
|
3093
|
-
const last = imports[imports.length - 1];
|
|
3094
|
-
const semi = !last || code[last.end - 1] === ";" ? ";" : "";
|
|
3095
|
-
const lines = [
|
|
3096
|
-
`import { ${plugin.factory} } from ${q}${plugin.source}${q}${semi}`,
|
|
3097
|
-
...plugin.css ? [`import ${q}${plugin.css}${q}${semi}`] : []
|
|
3098
|
-
].join("\n");
|
|
3099
|
-
const created = `const ${plugin.local} = ${plugin.factory}()${semi}`;
|
|
3100
|
-
edits.push(
|
|
3101
|
-
last ? { at: last.end, text: `
|
|
3102
|
-
${lines}
|
|
3103
|
-
|
|
3104
|
-
${created}` } : { at: 0, text: `${lines}
|
|
3105
|
-
|
|
3106
|
-
${created}
|
|
3107
|
-
|
|
3108
|
-
` }
|
|
3109
|
-
);
|
|
3110
|
-
let next = code;
|
|
3111
|
-
for (const edit of [...edits].sort((a, b) => b.at - a.at))
|
|
3112
|
-
next = next.slice(0, edit.at) + edit.text + next.slice(edit.end ?? edit.at);
|
|
3113
|
-
return {
|
|
3114
|
-
status: "inserted",
|
|
3115
|
-
code: next,
|
|
3116
|
-
inserted: edits.map(({ at, text }) => ({ at, text }))
|
|
3117
|
-
};
|
|
3118
|
-
};
|
|
3119
|
-
|
|
3120
|
-
// src/frameworks/pages-auth.ts
|
|
3121
|
-
var AUTH_PLUGIN = {
|
|
3122
|
-
factory: "createAuthPlugin",
|
|
3123
|
-
source: PLUGIN_AUTH_PACKAGE,
|
|
3124
|
-
local: "authPlugin",
|
|
3125
|
-
css: `${PLUGIN_AUTH_PACKAGE}/styles.css`
|
|
3126
|
-
};
|
|
3127
|
-
var withAuthPlugin = (code, file) => {
|
|
3128
|
-
const result = ensurePuckPlugin(code, file, AUTH_PLUGIN);
|
|
3129
|
-
return result.status === "inserted" ? result.code : code;
|
|
3130
|
-
};
|
|
3131
|
-
var AUTH_PLUGIN_SNIPPET = `import { createAuthPlugin } from "@puckeditor/plugin-auth";
|
|
3132
|
-
import "@puckeditor/plugin-auth/styles.css";
|
|
3133
|
-
|
|
3134
|
-
const authPlugin = createAuthPlugin();
|
|
3135
|
-
|
|
3136
|
-
<Puck plugins={[authPlugin]} config={config} data={data} />
|
|
3137
|
-
`;
|
|
3138
|
-
var planRouteAuth = (p) => {
|
|
3139
|
-
const file = p.state.cloud.routeFile ?? p.state.cloud.expectedRouteFile;
|
|
3140
|
-
const current = file && p.vfs.readText(p.abs(file));
|
|
3141
|
-
if (!file || current === null) return;
|
|
3142
|
-
const next = withRouteAuth(current);
|
|
3143
|
-
if (next === current) return;
|
|
3144
|
-
if (next !== null) {
|
|
3145
|
-
p.modifyFile(file, next, {
|
|
3146
|
-
capability: "auth",
|
|
3147
|
-
summary: `Require Sign in with Puck in ${file}`
|
|
3148
|
-
});
|
|
3149
|
-
return;
|
|
3150
|
-
}
|
|
3151
|
-
p.manual({
|
|
3152
|
-
id: "auth:route-auth",
|
|
3153
|
-
type: "manual_edit",
|
|
3154
|
-
capability: "auth",
|
|
3155
|
-
required: true,
|
|
3156
|
-
file,
|
|
3157
|
-
reason: "unsupported_shape",
|
|
3158
|
-
message: `${file} was customised, so Sign in with Puck wasn't required automatically.`,
|
|
3159
|
-
instructions: `Pass auth: { provider: "puck" } to puckHandler in ${file}, so it serves Sign in with Puck and only lets signed-in members through.`,
|
|
3160
|
-
snippet: `puckHandler(request, { auth: { provider: "puck" } });
|
|
3161
|
-
`
|
|
3162
|
-
});
|
|
3163
|
-
};
|
|
3164
|
-
var planAuthPlugin = (p, preferred) => {
|
|
3165
|
-
const editors = p.state.scan.editorFiles;
|
|
3166
|
-
const file = p.vfs.exists(p.abs(preferred)) ? preferred : editors.length === 1 ? editors[0] : null;
|
|
3167
|
-
const current = file && p.vfs.readText(p.abs(file));
|
|
3168
|
-
const result = current ? ensurePuckPlugin(current, file, AUTH_PLUGIN) : {
|
|
3169
|
-
status: "manual",
|
|
3170
|
-
detail: "No single Puck editor was found"
|
|
3171
|
-
};
|
|
3172
|
-
if (result.status === "exists") return;
|
|
3173
|
-
if (result.status === "inserted") {
|
|
3174
|
-
p.modifyFile(file, result.code, {
|
|
3175
|
-
capability: "auth",
|
|
3176
|
-
summary: `Add the Puck Auth plugin to ${file}`,
|
|
3177
|
-
inserted: result.inserted
|
|
3178
|
-
});
|
|
3179
|
-
return;
|
|
3180
|
-
}
|
|
3181
|
-
p.manual({
|
|
3182
|
-
id: "auth:editor",
|
|
3183
|
-
type: "manual_edit",
|
|
3184
|
-
capability: "auth",
|
|
3185
|
-
required: true,
|
|
3186
|
-
file: file ?? preferred,
|
|
3187
|
-
reason: "unsupported_shape",
|
|
3188
|
-
message: `Couldn't add the Puck Auth plugin automatically: ${result.detail}.`,
|
|
3189
|
-
instructions: "Add the Puck Auth plugin to your <Puck> editor's plugins, and import its styles.",
|
|
3190
|
-
snippet: AUTH_PLUGIN_SNIPPET
|
|
3191
|
-
});
|
|
3192
|
-
};
|
|
3193
|
-
var warnLocalPages = (p) => {
|
|
3194
|
-
if (!p.vfs.exists(p.abs("database.json"))) return;
|
|
3195
|
-
p.warn(
|
|
3196
|
-
"PUCK-CLI-W-LOCAL-PAGES",
|
|
3197
|
-
"Pages are now stored in Puck Cloud, so database.json and the routes that read and write it are no longer used. Import its pages with `npx @puckeditor/cli pages import database.json`, then delete them."
|
|
3198
|
-
);
|
|
3199
|
-
};
|
|
3200
|
-
|
|
3201
1941
|
// src/frameworks/next.ts
|
|
3202
1942
|
var NEXT_CLOUD_ROUTE_FILE = (appDir) => `${appDir}/api/puck/[...all]/route.ts`;
|
|
3203
1943
|
var PROXY_FILES = ["proxy", "middleware"].flatMap(
|
|
@@ -3239,7 +1979,6 @@ var nextRelocation = (p, info) => {
|
|
|
3239
1979
|
"app/puck/[...puckPath]/client": `${A}/puck/[...puckPath]/client`,
|
|
3240
1980
|
"app/page": `${A}/page`,
|
|
3241
1981
|
"lib/get-page": `${lib}/get-page`,
|
|
3242
|
-
"lib/puck-auth": `${lib}/puck-auth`,
|
|
3243
1982
|
"puck.config": configModuleTarget(p)
|
|
3244
1983
|
},
|
|
3245
1984
|
config: configRelocation(p),
|
|
@@ -3260,7 +1999,8 @@ var conflictingSegments = (p, appDir) => {
|
|
|
3260
1999
|
visit(appDir, 0);
|
|
3261
2000
|
return found;
|
|
3262
2001
|
};
|
|
3263
|
-
var proxySource = (p, info
|
|
2002
|
+
var proxySource = (p, info) => {
|
|
2003
|
+
const code = templateText(p.templates, "next", "proxy.ts");
|
|
3264
2004
|
if (info.proxyKind === "proxy") return code;
|
|
3265
2005
|
const ast = parseModule(code, "proxy.ts");
|
|
3266
2006
|
for (const statement of ast.program.body) {
|
|
@@ -3273,13 +2013,6 @@ var proxySource = (p, info, code = templateText(p.templates, "next", "proxy.ts")
|
|
|
3273
2013
|
}
|
|
3274
2014
|
return code;
|
|
3275
2015
|
};
|
|
3276
|
-
var findProxy = (p) => PROXY_FILES.flatMap((f) => [f, `src/${f}`]).find(
|
|
3277
|
-
(f) => p.vfs.exists(p.abs(f))
|
|
3278
|
-
);
|
|
3279
|
-
var proxyFile = (info) => {
|
|
3280
|
-
const name = `${info.proxyKind}.ts`;
|
|
3281
|
-
return info.baseDir ? `${info.baseDir}/${name}` : name;
|
|
3282
|
-
};
|
|
3283
2016
|
var planNextEditor = (p, info, withAi = false) => {
|
|
3284
2017
|
const A = info.appDir;
|
|
3285
2018
|
const base = info.baseDir ? `${info.baseDir}/` : "";
|
|
@@ -3336,8 +2069,12 @@ var planNextEditor = (p, info, withAi = false) => {
|
|
|
3336
2069
|
}
|
|
3337
2070
|
planPuckConfig(p, recipe);
|
|
3338
2071
|
copyTemplateFiles(p, recipe, files, nextRelocation(p, info));
|
|
3339
|
-
const
|
|
3340
|
-
const
|
|
2072
|
+
const proxyDir = info.baseDir;
|
|
2073
|
+
const existingProxy = PROXY_FILES.flatMap((f) => [f, `src/${f}`]).find(
|
|
2074
|
+
(f) => p.vfs.exists(p.abs(f))
|
|
2075
|
+
);
|
|
2076
|
+
const proxyName = `${info.proxyKind}.ts`;
|
|
2077
|
+
const proxyRel = proxyDir ? `${proxyDir}/${proxyName}` : proxyName;
|
|
3341
2078
|
if (existingProxy) {
|
|
3342
2079
|
p.manual({
|
|
3343
2080
|
id: "editor:next-proxy",
|
|
@@ -3371,7 +2108,18 @@ var planNextCloudRoute = (p, info, withAi = false) => {
|
|
|
3371
2108
|
) : cloudRoute;
|
|
3372
2109
|
const existing = p.state.cloud.routeFile;
|
|
3373
2110
|
if (existing) {
|
|
3374
|
-
|
|
2111
|
+
const current = p.vfs.readText(p.abs(existing));
|
|
2112
|
+
if (withAi && current === cloudRoute) {
|
|
2113
|
+
p.modifyFile(existing, route, {
|
|
2114
|
+
capability: "ai",
|
|
2115
|
+
summary: `Enable Puck AI in ${existing}`
|
|
2116
|
+
});
|
|
2117
|
+
} else if (withAi && current !== route) {
|
|
2118
|
+
p.warn(
|
|
2119
|
+
"PUCK-CLI-W-AI-ROUTE",
|
|
2120
|
+
`Make sure the puckHandler in ${existing} sets ai.designMode.allowed to true, or Puck AI's design mode will be rejected.`
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
3375
2123
|
if (existing !== p.state.cloud.expectedRouteFile) {
|
|
3376
2124
|
p.warn(
|
|
3377
2125
|
"PUCK-CLI-W-CLOUD-ROUTE-PATH",
|
|
@@ -3408,25 +2156,21 @@ var planNextAi = (p, info) => {
|
|
|
3408
2156
|
to: from.replace(/^app\//, `${A}/`),
|
|
3409
2157
|
opts,
|
|
3410
2158
|
capability: "ai",
|
|
3411
|
-
summary
|
|
3412
|
-
});
|
|
3413
|
-
const editor = upgradeEditor(p, info, EDITOR_CLIENT, {
|
|
3414
|
-
want: { ai: true },
|
|
3415
|
-
capability: "ai",
|
|
3416
|
-
summary: `Add the Puck AI plugin to ${A}/puck/[...puckPath]/client.tsx`
|
|
3417
|
-
});
|
|
3418
|
-
upgradeEditor(p, info, EDITOR_PAGE, {
|
|
3419
|
-
want: { ai: true },
|
|
3420
|
-
capability: "ai",
|
|
3421
|
-
summary: `Load Puck AI styles in ${A}/puck/[...puckPath]/page.tsx`
|
|
2159
|
+
summary
|
|
3422
2160
|
});
|
|
2161
|
+
const editor = upgrade(
|
|
2162
|
+
"app/puck/[...puckPath]/client.tsx",
|
|
2163
|
+
`Add the Puck AI plugin to ${A}/puck/[...puckPath]/client.tsx`
|
|
2164
|
+
);
|
|
2165
|
+
upgrade(
|
|
2166
|
+
"app/puck/[...puckPath]/page.tsx",
|
|
2167
|
+
`Load Puck AI styles in ${A}/puck/[...puckPath]/page.tsx`
|
|
2168
|
+
);
|
|
3423
2169
|
const render = upgrade(
|
|
3424
2170
|
"app/[...puckPath]/client.tsx",
|
|
3425
2171
|
`Render AI-designed components in ${A}/[...puckPath]/client.tsx`
|
|
3426
2172
|
);
|
|
3427
|
-
|
|
3428
|
-
if (pages && (editor === "upgraded" || editor === "already")) {
|
|
3429
|
-
} else if (editor === "upgraded" || editor === "already") {
|
|
2173
|
+
if (editor === "upgraded" || editor === "already") {
|
|
3430
2174
|
copyTemplateFiles(
|
|
3431
2175
|
p,
|
|
3432
2176
|
"next-ai",
|
|
@@ -3462,161 +2206,6 @@ var planNextAi = (p, info) => {
|
|
|
3462
2206
|
});
|
|
3463
2207
|
}
|
|
3464
2208
|
};
|
|
3465
|
-
var EDITOR_CLIENT = "app/puck/[...puckPath]/client.tsx";
|
|
3466
|
-
var EDITOR_PAGE = "app/puck/[...puckPath]/page.tsx";
|
|
3467
|
-
var RENDER_PAGE = "app/[...puckPath]/page.tsx";
|
|
3468
|
-
var recipeText = (p, ai, file) => templateText(p.templates, ai ? "next-ai" : "next", file);
|
|
3469
|
-
var GET_PAGE_IMPORT = 'import { getPage } from "../../../lib/get-page";';
|
|
3470
|
-
var gateRecipeEditorPage = (recipe) => {
|
|
3471
|
-
const code = recipe.replace(
|
|
3472
|
-
GET_PAGE_IMPORT,
|
|
3473
|
-
`${GET_PAGE_IMPORT}
|
|
3474
|
-
import { requirePuckSession } from "../../../lib/puck-auth";`
|
|
3475
|
-
).replace(
|
|
3476
|
-
"NB this route is public, and you will need to add authentication",
|
|
3477
|
-
"Editing requires signing in with a Puck Cloud account in your organization."
|
|
3478
|
-
);
|
|
3479
|
-
const path36 = 'const path = `/${puckPath.join("/")}`;';
|
|
3480
|
-
const at = code.indexOf(path36, code.indexOf("export default async function Page")) + path36.length;
|
|
3481
|
-
return `${code.slice(0, at)}
|
|
3482
|
-
await requirePuckSession(\`\${path.replace(/\\/$/, "")}/edit\`);${code.slice(
|
|
3483
|
-
at
|
|
3484
|
-
)}`;
|
|
3485
|
-
};
|
|
3486
|
-
var EDITOR_SOURCES = {
|
|
3487
|
-
[EDITOR_CLIENT]: (p) => ({ ai, pages, auth }) => {
|
|
3488
|
-
const code = pages ? nextPagesEditorClient({ ai }) : recipeText(p, ai, EDITOR_CLIENT);
|
|
3489
|
-
return auth ? withAuthPlugin(code, EDITOR_CLIENT) : code;
|
|
3490
|
-
},
|
|
3491
|
-
[EDITOR_PAGE]: (p) => ({ ai, pages, auth }) => {
|
|
3492
|
-
if (pages) return nextPagesEditorPage({ ai, auth });
|
|
3493
|
-
const code = recipeText(p, ai, EDITOR_PAGE);
|
|
3494
|
-
return auth ? gateRecipeEditorPage(code) : code;
|
|
3495
|
-
}
|
|
3496
|
-
};
|
|
3497
|
-
var upgradeEditor = (p, info, from, {
|
|
3498
|
-
want,
|
|
3499
|
-
capability,
|
|
3500
|
-
summary
|
|
3501
|
-
}) => upgradeVariant(p, {
|
|
3502
|
-
from,
|
|
3503
|
-
to: from.replace(/^app\//, `${info.appDir}/`),
|
|
3504
|
-
opts: nextRelocation(p, info),
|
|
3505
|
-
combos: flagCombos("ai", "pages", "auth"),
|
|
3506
|
-
source: EDITOR_SOURCES[from](p),
|
|
3507
|
-
want,
|
|
3508
|
-
capability,
|
|
3509
|
-
summary
|
|
3510
|
-
});
|
|
3511
|
-
var planNextPages = (p, info) => {
|
|
3512
|
-
const A = info.appDir;
|
|
3513
|
-
const opts = nextRelocation(p, info);
|
|
3514
|
-
const manual = (file, snippet, required = true) => p.manual({
|
|
3515
|
-
id: `pages:${file}`,
|
|
3516
|
-
type: "manual_edit",
|
|
3517
|
-
capability: "pages",
|
|
3518
|
-
required,
|
|
3519
|
-
file,
|
|
3520
|
-
reason: "unsupported_shape",
|
|
3521
|
-
message: `${file} was customised or moved, so it wasn't changed to use Puck Pages.`,
|
|
3522
|
-
instructions: `Update ${file} to match this version, which uses pages stored in Puck Cloud.`,
|
|
3523
|
-
snippet
|
|
3524
|
-
});
|
|
3525
|
-
const client = upgradeEditor(p, info, EDITOR_CLIENT, {
|
|
3526
|
-
want: { pages: true },
|
|
3527
|
-
capability: "pages",
|
|
3528
|
-
summary: `Add the Puck Pages plugin to ${A}/puck/[...puckPath]/client.tsx`
|
|
3529
|
-
});
|
|
3530
|
-
if (client === "customized" || client === "missing")
|
|
3531
|
-
manual(
|
|
3532
|
-
`${A}/puck/[...puckPath]/client.tsx`,
|
|
3533
|
-
nextPagesEditorClient({ ai: false })
|
|
3534
|
-
);
|
|
3535
|
-
const page = upgradeEditor(p, info, EDITOR_PAGE, {
|
|
3536
|
-
want: { pages: true },
|
|
3537
|
-
capability: "pages",
|
|
3538
|
-
summary: `Open pages from Puck Cloud in ${A}/puck/[...puckPath]/page.tsx`
|
|
3539
|
-
});
|
|
3540
|
-
if (page === "customized" || page === "missing")
|
|
3541
|
-
manual(
|
|
3542
|
-
`${A}/puck/[...puckPath]/page.tsx`,
|
|
3543
|
-
nextPagesEditorPage({ ai: false, auth: false })
|
|
3544
|
-
);
|
|
3545
|
-
const render = upgradeVariant(p, {
|
|
3546
|
-
from: RENDER_PAGE,
|
|
3547
|
-
to: `${A}/[...puckPath]/page.tsx`,
|
|
3548
|
-
opts,
|
|
3549
|
-
combos: [{ pages: false }, { pages: true }],
|
|
3550
|
-
source: ({ pages }) => pages ? nextPagesRenderPage(p.cloudHost) : templateText(p.templates, "next", RENDER_PAGE),
|
|
3551
|
-
want: { pages: true },
|
|
3552
|
-
capability: "pages",
|
|
3553
|
-
summary: `Render pages published in Puck Cloud in ${A}/[...puckPath]/page.tsx`
|
|
3554
|
-
});
|
|
3555
|
-
if (render === "customized" || render === "missing")
|
|
3556
|
-
manual(`${A}/[...puckPath]/page.tsx`, nextPagesRenderPage(p.cloudHost));
|
|
3557
|
-
const proxy = findProxy(p) ?? proxyFile(info);
|
|
3558
|
-
const proxyOutcome = p.vfs.exists(p.abs(proxy)) ? upgradeVariant(p, {
|
|
3559
|
-
from: "proxy.ts",
|
|
3560
|
-
to: proxy,
|
|
3561
|
-
opts,
|
|
3562
|
-
combos: [{ pages: false }, { pages: true }],
|
|
3563
|
-
source: ({ pages }) => proxySource(p, info, pages ? NEXT_PAGES_PROXY : void 0),
|
|
3564
|
-
want: { pages: true },
|
|
3565
|
-
capability: "pages",
|
|
3566
|
-
summary: `Redirect /<path>/edit to the Puck Pages editor in ${proxy}`
|
|
3567
|
-
}) : p.createFile(proxy, proxySource(p, info, NEXT_PAGES_PROXY), {
|
|
3568
|
-
capability: "pages",
|
|
3569
|
-
summary: `Create ${proxy} (redirects /<path>/edit to the editor)`
|
|
3570
|
-
});
|
|
3571
|
-
if (proxyOutcome === "customized")
|
|
3572
|
-
manual(proxy, proxySource(p, info, NEXT_PAGES_PROXY), false);
|
|
3573
|
-
warnLocalPages(p);
|
|
3574
|
-
};
|
|
3575
|
-
var planNextAuth = (p, info) => {
|
|
3576
|
-
const A = info.appDir;
|
|
3577
|
-
const lib = `${info.baseDir ? `${info.baseDir}/` : ""}lib`;
|
|
3578
|
-
const helper = `${lib}/puck-auth.ts`;
|
|
3579
|
-
const created = p.createFile(helper, nextPuckAuth(p.cloudHost), {
|
|
3580
|
-
capability: "auth",
|
|
3581
|
-
summary: `Create ${helper} (requires Sign in with Puck)`
|
|
3582
|
-
});
|
|
3583
|
-
if (created === "conflict") {
|
|
3584
|
-
p.manual({
|
|
3585
|
-
id: "auth:helper",
|
|
3586
|
-
type: "manual_edit",
|
|
3587
|
-
capability: "auth",
|
|
3588
|
-
required: true,
|
|
3589
|
-
file: helper,
|
|
3590
|
-
reason: "conflict",
|
|
3591
|
-
message: `${helper} already exists with different content.`,
|
|
3592
|
-
instructions: `Export requirePuckSession from ${helper}, or move your file and re-run the command.`,
|
|
3593
|
-
snippet: nextPuckAuth(p.cloudHost)
|
|
3594
|
-
});
|
|
3595
|
-
}
|
|
3596
|
-
const gate = upgradeEditor(p, info, EDITOR_PAGE, {
|
|
3597
|
-
want: { auth: true },
|
|
3598
|
-
capability: "auth",
|
|
3599
|
-
summary: `Require Sign in with Puck in ${A}/puck/[...puckPath]/page.tsx`
|
|
3600
|
-
});
|
|
3601
|
-
if (gate === "customized" || gate === "missing") {
|
|
3602
|
-
p.manual({
|
|
3603
|
-
id: "auth:editor-gate",
|
|
3604
|
-
type: "manual_edit",
|
|
3605
|
-
capability: "auth",
|
|
3606
|
-
required: false,
|
|
3607
|
-
file: `${A}/puck/[...puckPath]/page.tsx`,
|
|
3608
|
-
reason: "unsupported_shape",
|
|
3609
|
-
message: "Your editor page was customised, so it doesn't send signed-out visitors to sign in.",
|
|
3610
|
-
instructions: "Call requirePuckSession at the start of the page that renders your editor. The Puck Cloud API route already requires Sign in with Puck.",
|
|
3611
|
-
snippet: `import { requirePuckSession } from "${lib}/puck-auth";
|
|
3612
|
-
|
|
3613
|
-
await requirePuckSession("/puck");
|
|
3614
|
-
`
|
|
3615
|
-
});
|
|
3616
|
-
}
|
|
3617
|
-
planAuthPlugin(p, `${A}/puck/[...puckPath]/client.tsx`);
|
|
3618
|
-
planRouteAuth(p);
|
|
3619
|
-
};
|
|
3620
2209
|
var nextAdapter = {
|
|
3621
2210
|
recipe: (withAi) => withAi ? "next-ai" : "next",
|
|
3622
2211
|
recipeCloudRoute: NEXT_CLOUD_ROUTE_FILE("app"),
|
|
@@ -3634,12 +2223,219 @@ var nextAdapter = {
|
|
|
3634
2223
|
planEditor: planNextEditor,
|
|
3635
2224
|
planCloudRoute: planNextCloudRoute,
|
|
3636
2225
|
planAi: planNextAi,
|
|
3637
|
-
planPages: planNextPages,
|
|
3638
|
-
planAuth: planNextAuth,
|
|
3639
2226
|
devUrl: "http://localhost:3000/edit",
|
|
3640
2227
|
deployEnvWarning: "Set PUCK_API_KEY in your hosting provider's environment variables before deploying."
|
|
3641
2228
|
};
|
|
3642
2229
|
|
|
2230
|
+
// src/ast/config-object.ts
|
|
2231
|
+
var keyName = (node) => {
|
|
2232
|
+
if (node.type !== "ObjectProperty" || node.computed) return null;
|
|
2233
|
+
if (node.key.type === "Identifier") return node.key.name;
|
|
2234
|
+
if (node.key.type === "StringLiteral") return node.key.value;
|
|
2235
|
+
return null;
|
|
2236
|
+
};
|
|
2237
|
+
var findProperty = (obj, key) => obj.properties.find((p) => keyName(p) === key);
|
|
2238
|
+
var analyzeConfig = (code, filename) => {
|
|
2239
|
+
const ast = tryParseModule(code, filename);
|
|
2240
|
+
if (!ast) return { ok: false, detail: `Could not parse ${filename}` };
|
|
2241
|
+
const exportDefault = ast.program.body.find(
|
|
2242
|
+
(s) => s.type === "ExportDefaultDeclaration"
|
|
2243
|
+
);
|
|
2244
|
+
if (!exportDefault || exportDefault.type !== "ExportDefaultDeclaration") {
|
|
2245
|
+
return { ok: false, detail: "No default export" };
|
|
2246
|
+
}
|
|
2247
|
+
let exported = unwrapExpression(exportDefault.declaration);
|
|
2248
|
+
if (exported.type === "Identifier") {
|
|
2249
|
+
const name = exported.name;
|
|
2250
|
+
for (const statement of ast.program.body) {
|
|
2251
|
+
if (statement.type !== "VariableDeclaration" || statement.kind !== "const")
|
|
2252
|
+
continue;
|
|
2253
|
+
const declarator = statement.declarations.find(
|
|
2254
|
+
(d) => d.id.type === "Identifier" && d.id.name === name
|
|
2255
|
+
);
|
|
2256
|
+
if (declarator?.init) exported = unwrapExpression(declarator.init);
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
if (exported.type === "CallExpression" && exported.callee.type === "Identifier" && exported.callee.name === "defineConfig" && exported.arguments.length === 1) {
|
|
2260
|
+
exported = unwrapExpression(exported.arguments[0]);
|
|
2261
|
+
}
|
|
2262
|
+
if (exported.type !== "ObjectExpression") {
|
|
2263
|
+
return {
|
|
2264
|
+
ok: false,
|
|
2265
|
+
detail: "The config is not an object literal (e.g. it's a function)"
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
return { ok: true, ast, config: exported };
|
|
2269
|
+
};
|
|
2270
|
+
var appendAfterLast = (code, node, items, entry) => {
|
|
2271
|
+
const singleLine = lineOf(code, node.start) === lineOf(code, node.end);
|
|
2272
|
+
if (items.length === 0) {
|
|
2273
|
+
const indent3 = `${indentationAt(code, node.start)} `;
|
|
2274
|
+
return {
|
|
2275
|
+
at: node.start + 1,
|
|
2276
|
+
text: singleLine ? entry(indent3, true) : `
|
|
2277
|
+
${indent3}${entry(indent3, false)},`
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
const last = items[items.length - 1];
|
|
2281
|
+
const indent2 = indentationAt(code, last.start);
|
|
2282
|
+
const between = code.slice(last.end, node.end - 1);
|
|
2283
|
+
const commaIndex = between.indexOf(",");
|
|
2284
|
+
const hasTrailingComma = commaIndex !== -1 && between.slice(0, commaIndex).trim() === "";
|
|
2285
|
+
if (singleLine) {
|
|
2286
|
+
return { at: last.end, text: `, ${entry(indent2, true)}` };
|
|
2287
|
+
}
|
|
2288
|
+
if (hasTrailingComma) {
|
|
2289
|
+
return {
|
|
2290
|
+
at: last.end + commaIndex + 1,
|
|
2291
|
+
text: `
|
|
2292
|
+
${indent2}${entry(indent2, false)},`
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
return { at: last.end, text: `,
|
|
2296
|
+
${indent2}${entry(indent2, false)}` };
|
|
2297
|
+
};
|
|
2298
|
+
var insertProperty = (code, obj, property) => appendAfterLast(code, obj, obj.properties, property);
|
|
2299
|
+
var quoteOf = (code) => /^\s*import[^'"\n]*'/m.test(code) ? "'" : '"';
|
|
2300
|
+
var semicolonsIn = (ast, code) => {
|
|
2301
|
+
const last = ast.program.body.filter((s) => s.type === "ImportDeclaration");
|
|
2302
|
+
const node = last[last.length - 1] ?? ast.program.body[0];
|
|
2303
|
+
return node ? code[node.end - 1] === ";" : true;
|
|
2304
|
+
};
|
|
2305
|
+
var IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
2306
|
+
var ensureConfigEntry = (code, filename, objectPath, key, value) => {
|
|
2307
|
+
const analysis = analyzeConfig(code, filename);
|
|
2308
|
+
if (!analysis.ok) return { status: "manual", detail: analysis.detail };
|
|
2309
|
+
const q = quoteOf(code);
|
|
2310
|
+
const quote = (s) => `${q}${s.replace(/\\/g, "\\\\").replace(new RegExp(q, "g"), `\\${q}`)}${q}`;
|
|
2311
|
+
const keyText = IDENTIFIER.test(key) ? key : quote(key);
|
|
2312
|
+
const entry = `${keyText}: ${quote(value)}`;
|
|
2313
|
+
let obj = analysis.config;
|
|
2314
|
+
for (let i = 0; i <= objectPath.length; i++) {
|
|
2315
|
+
const segment = objectPath[i];
|
|
2316
|
+
const existing = segment === void 0 ? findProperty(obj, key) : findProperty(obj, segment);
|
|
2317
|
+
if (existing && segment === void 0) return { status: "exists" };
|
|
2318
|
+
if (!existing) {
|
|
2319
|
+
if (obj.properties.some((p) => p.type === "SpreadElement")) {
|
|
2320
|
+
return {
|
|
2321
|
+
status: "manual",
|
|
2322
|
+
detail: `The config spreads another object that may set ${[
|
|
2323
|
+
...objectPath.slice(0, i),
|
|
2324
|
+
segment ?? key
|
|
2325
|
+
].join(".")}`
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
const rest = objectPath.slice(i);
|
|
2329
|
+
const multiLine = (indent2) => rest.reduceRight((inner, s, depth) => {
|
|
2330
|
+
const pad = `${indent2}${" ".repeat(depth)}`;
|
|
2331
|
+
return `${s}: {
|
|
2332
|
+
${pad} ${inner},
|
|
2333
|
+
${pad}}`;
|
|
2334
|
+
}, entry);
|
|
2335
|
+
const edit = obj.properties.length === 0 ? (() => {
|
|
2336
|
+
const indent2 = indentationAt(code, obj.start);
|
|
2337
|
+
return {
|
|
2338
|
+
at: obj.start + 1,
|
|
2339
|
+
text: `
|
|
2340
|
+
${indent2} ${multiLine(`${indent2} `)},
|
|
2341
|
+
${indent2}`
|
|
2342
|
+
};
|
|
2343
|
+
})() : insertProperty(
|
|
2344
|
+
code,
|
|
2345
|
+
obj,
|
|
2346
|
+
(indent2, singleLine) => singleLine ? rest.reduceRight((inner, s) => `${s}: { ${inner} }`, entry) : multiLine(indent2)
|
|
2347
|
+
);
|
|
2348
|
+
const next = code.slice(0, edit.at) + edit.text + code.slice(edit.at);
|
|
2349
|
+
return { status: "inserted", code: next, inserted: [edit] };
|
|
2350
|
+
}
|
|
2351
|
+
const value2 = unwrapExpression(existing.value);
|
|
2352
|
+
if (value2.type !== "ObjectExpression") {
|
|
2353
|
+
return {
|
|
2354
|
+
status: "manual",
|
|
2355
|
+
detail: `${objectPath.slice(0, i + 1).join(".")} is not an object literal`
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
obj = value2;
|
|
2359
|
+
}
|
|
2360
|
+
return { status: "exists" };
|
|
2361
|
+
};
|
|
2362
|
+
var ensurePlugin = (code, filename, {
|
|
2363
|
+
importName,
|
|
2364
|
+
source,
|
|
2365
|
+
call: callFor
|
|
2366
|
+
}) => {
|
|
2367
|
+
const analysis = analyzeConfig(code, filename);
|
|
2368
|
+
if (!analysis.ok) return { status: "manual", detail: analysis.detail };
|
|
2369
|
+
const { ast, config } = analysis;
|
|
2370
|
+
const q = quoteOf(code);
|
|
2371
|
+
const semi = semicolonsIn(ast, code) ? ";" : "";
|
|
2372
|
+
const call = typeof callFor === "string" ? callFor : callFor(q);
|
|
2373
|
+
const imported = ast.program.body.some(
|
|
2374
|
+
(s) => s.type === "ImportDeclaration" && s.source.value === source && s.specifiers.some((sp) => sp.local.name === importName)
|
|
2375
|
+
);
|
|
2376
|
+
const edits = [];
|
|
2377
|
+
const plugins = findProperty(config, "plugins");
|
|
2378
|
+
if (!plugins) {
|
|
2379
|
+
if (config.properties.some((p) => p.type === "SpreadElement"))
|
|
2380
|
+
return {
|
|
2381
|
+
status: "manual",
|
|
2382
|
+
detail: "The config spreads another object that may set plugins"
|
|
2383
|
+
};
|
|
2384
|
+
edits.push(insertProperty(code, config, () => `plugins: [${call}]`));
|
|
2385
|
+
} else {
|
|
2386
|
+
const list = unwrapExpression(plugins.value);
|
|
2387
|
+
if (list.type !== "ArrayExpression")
|
|
2388
|
+
return { status: "manual", detail: "plugins is not an array literal" };
|
|
2389
|
+
const exists = list.elements.some((e) => {
|
|
2390
|
+
const el = e && unwrapExpression(e);
|
|
2391
|
+
return el?.type === "CallExpression" && el.callee.type === "Identifier" && el.callee.name === importName;
|
|
2392
|
+
});
|
|
2393
|
+
if (exists) return { status: "exists" };
|
|
2394
|
+
const singleLine = lineOf(code, list.start) === lineOf(code, list.end);
|
|
2395
|
+
const items = list.elements.map((e) => code.slice(e.start, e.end));
|
|
2396
|
+
const lineStart = code.lastIndexOf("\n", list.start - 1) + 1;
|
|
2397
|
+
const lineEnd = code.indexOf("\n", list.end);
|
|
2398
|
+
const oneLine = `[${[...items, call].join(", ")}]`;
|
|
2399
|
+
const width = list.start - lineStart + oneLine.length + (lineEnd === -1 ? code.length : lineEnd) - list.end;
|
|
2400
|
+
if (singleLine && width <= 80) {
|
|
2401
|
+
edits.push({ at: list.start, end: list.end, text: oneLine });
|
|
2402
|
+
} else if (singleLine) {
|
|
2403
|
+
const indent2 = indentationAt(code, list.start);
|
|
2404
|
+
edits.push({
|
|
2405
|
+
at: list.start,
|
|
2406
|
+
end: list.end,
|
|
2407
|
+
text: `[
|
|
2408
|
+
${[...items, call].map((item) => `${indent2} ${item},`).join("\n")}
|
|
2409
|
+
${indent2}]`
|
|
2410
|
+
});
|
|
2411
|
+
} else {
|
|
2412
|
+
edits.push(
|
|
2413
|
+
appendAfterLast(code, list, list.elements, () => call)
|
|
2414
|
+
);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
if (!imported) {
|
|
2418
|
+
const line = `import ${importName} from ${q}${source}${q}${semi}`;
|
|
2419
|
+
const imports = ast.program.body.filter(
|
|
2420
|
+
(s) => s.type === "ImportDeclaration"
|
|
2421
|
+
);
|
|
2422
|
+
const last = imports[imports.length - 1];
|
|
2423
|
+
edits.push(
|
|
2424
|
+
last ? { at: last.end, text: `
|
|
2425
|
+
${line}` } : { at: 0, text: `${line}
|
|
2426
|
+
` }
|
|
2427
|
+
);
|
|
2428
|
+
}
|
|
2429
|
+
let next = code;
|
|
2430
|
+
for (const edit of [...edits].sort((a, b) => b.at - a.at))
|
|
2431
|
+
next = next.slice(0, edit.at) + edit.text + next.slice(edit.end ?? edit.at);
|
|
2432
|
+
return {
|
|
2433
|
+
status: "inserted",
|
|
2434
|
+
code: next,
|
|
2435
|
+
inserted: edits.map(({ at, text }) => ({ at, text }))
|
|
2436
|
+
};
|
|
2437
|
+
};
|
|
2438
|
+
|
|
3643
2439
|
// src/ast/vite-optimize-deps.ts
|
|
3644
2440
|
var readList = (config, [outer, inner]) => {
|
|
3645
2441
|
const section = findProperty(config, outer);
|
|
@@ -3783,7 +2579,7 @@ var vinextAdapter = {
|
|
|
3783
2579
|
};
|
|
3784
2580
|
|
|
3785
2581
|
// src/frameworks/react-router.ts
|
|
3786
|
-
import
|
|
2582
|
+
import path9 from "path";
|
|
3787
2583
|
|
|
3788
2584
|
// src/ast/react-router-routes.ts
|
|
3789
2585
|
var ROUTES_MODULE = "@react-router/dev/routes";
|
|
@@ -3832,10 +2628,10 @@ var analyzeRoutes = (code, filename) => {
|
|
|
3832
2628
|
const topLevel = new Set(exported.elements.filter(Boolean));
|
|
3833
2629
|
walk(exported, (node) => {
|
|
3834
2630
|
if (!isRouteCall(node, routeLocal)) return;
|
|
3835
|
-
const
|
|
2631
|
+
const path34 = stringArg(node, 0);
|
|
3836
2632
|
const isTop = topLevel.has(node);
|
|
3837
|
-
calls.push({ path:
|
|
3838
|
-
if (
|
|
2633
|
+
calls.push({ path: path34, file: stringArg(node, 1), topLevel: isTop });
|
|
2634
|
+
if (path34 === "*") {
|
|
3839
2635
|
if (isTop) splat = node;
|
|
3840
2636
|
else nestedSplat = true;
|
|
3841
2637
|
}
|
|
@@ -4066,7 +2862,6 @@ var rrRelocation = (p, info) => {
|
|
|
4066
2862
|
"app/lib/pages.server": `${A}/lib/pages.server`,
|
|
4067
2863
|
"app/lib/resolve-puck-path.server": `${A}/lib/resolve-puck-path.server`,
|
|
4068
2864
|
"app/components/puck-render": `${A}/components/puck-render`,
|
|
4069
|
-
"app/lib/puck-auth.server": `${A}/lib/puck-auth.server`,
|
|
4070
2865
|
"puck.config": configModuleTarget(p)
|
|
4071
2866
|
},
|
|
4072
2867
|
aliases: { "~/": "app/" },
|
|
@@ -4167,7 +2962,18 @@ var planReactRouterCloudRoute = (p, info, withAi = false) => {
|
|
|
4167
2962
|
) : cloudRoute;
|
|
4168
2963
|
let routeFile = p.state.cloud.routeFile;
|
|
4169
2964
|
if (routeFile) {
|
|
4170
|
-
|
|
2965
|
+
const current = p.vfs.readText(p.abs(routeFile));
|
|
2966
|
+
if (withAi && current === cloudRoute) {
|
|
2967
|
+
p.modifyFile(routeFile, route, {
|
|
2968
|
+
capability: "ai",
|
|
2969
|
+
summary: `Enable Puck AI in ${routeFile}`
|
|
2970
|
+
});
|
|
2971
|
+
} else if (withAi && current !== route) {
|
|
2972
|
+
p.warn(
|
|
2973
|
+
"PUCK-CLI-W-AI-ROUTE",
|
|
2974
|
+
`Make sure the puckHandler in ${routeFile} sets ai.designMode.allowed to true, or Puck AI's design mode will be rejected.`
|
|
2975
|
+
);
|
|
2976
|
+
}
|
|
4171
2977
|
} else {
|
|
4172
2978
|
routeFile = REACT_ROUTER_CLOUD_ROUTE_FILE(info.appDir);
|
|
4173
2979
|
const outcome = p.createFile(routeFile, route, {
|
|
@@ -4193,7 +2999,7 @@ var planReactRouterCloudRoute = (p, info, withAi = false) => {
|
|
|
4193
2999
|
registerRoute(
|
|
4194
3000
|
p,
|
|
4195
3001
|
info,
|
|
4196
|
-
{ path: entry.path, file:
|
|
3002
|
+
{ path: entry.path, file: path9.posix.relative(info.appDir, routeFile) },
|
|
4197
3003
|
"cloud",
|
|
4198
3004
|
{ position: "before-splat" }
|
|
4199
3005
|
);
|
|
@@ -4219,21 +3025,15 @@ var planReactRouterAi = (p, info) => {
|
|
|
4219
3025
|
}
|
|
4220
3026
|
}
|
|
4221
3027
|
const opts = rrRelocation(p, info);
|
|
4222
|
-
const
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
3028
|
+
const editor = upgradeTemplateFile(p, {
|
|
3029
|
+
fromRecipe: "react-router",
|
|
3030
|
+
toRecipe: "react-router-ai",
|
|
3031
|
+
from: "app/routes/puck-splat.tsx",
|
|
3032
|
+
to: `${A}/routes/puck-splat.tsx`,
|
|
3033
|
+
opts,
|
|
4226
3034
|
capability: "ai",
|
|
4227
|
-
summary:
|
|
3035
|
+
summary: `Add the Puck AI plugin to ${A}/routes/puck-splat.tsx`
|
|
4228
3036
|
});
|
|
4229
|
-
if (pagesEditor) {
|
|
4230
|
-
upgradeVariant(p, {
|
|
4231
|
-
...pagesEditorVariants(p, info),
|
|
4232
|
-
want: { ai: true },
|
|
4233
|
-
capability: "ai",
|
|
4234
|
-
summary: `Add the Puck AI plugin to ${A}/${PAGES_EDITOR}`
|
|
4235
|
-
});
|
|
4236
|
-
}
|
|
4237
3037
|
planOptimizeDeps(p, info, [CORE_PACKAGE, PLUGIN_AI_PACKAGE], "ai");
|
|
4238
3038
|
if (editor === "upgraded" || editor === "already") {
|
|
4239
3039
|
const render = upgradeTemplateFile(p, {
|
|
@@ -4274,164 +3074,6 @@ var planReactRouterAi = (p, info) => {
|
|
|
4274
3074
|
snippet: AI_SNIPPET
|
|
4275
3075
|
});
|
|
4276
3076
|
};
|
|
4277
|
-
var SPLAT = "routes/puck-splat.tsx";
|
|
4278
|
-
var PAGES_EDITOR = "routes/puck.tsx";
|
|
4279
|
-
var PAGES_EDITOR_ROUTE = { path: "puck", file: PAGES_EDITOR };
|
|
4280
|
-
var gateRecipeSplat = (code) => {
|
|
4281
|
-
const resolved = "const { isEditorRoute, path } = resolvePuckPath(pathname);";
|
|
4282
|
-
const loader = code.indexOf("export async function loader");
|
|
4283
|
-
const at = code.indexOf(resolved, loader) + resolved.length;
|
|
4284
|
-
return `${code.slice(0, at)}
|
|
4285
|
-
|
|
4286
|
-
// Editing requires Sign in with Puck
|
|
4287
|
-
if (isEditorRoute) await requirePuckSession(request);${code.slice(at)}`.replace(
|
|
4288
|
-
"export async function loader({ params }: Route.LoaderArgs)",
|
|
4289
|
-
"export async function loader({ params, request }: Route.LoaderArgs)"
|
|
4290
|
-
).replace(
|
|
4291
|
-
'import { getPage, savePage } from "~/lib/pages.server";',
|
|
4292
|
-
'import { getPage, savePage } from "~/lib/pages.server";\nimport { requirePuckSession } from "~/lib/puck-auth.server";'
|
|
4293
|
-
);
|
|
4294
|
-
};
|
|
4295
|
-
var splatVariants = (p, info) => ({
|
|
4296
|
-
from: `app/${SPLAT}`,
|
|
4297
|
-
to: `${info.appDir}/${SPLAT}`,
|
|
4298
|
-
opts: rrRelocation(p, info),
|
|
4299
|
-
combos: flagCombos("ai", "pages", "auth"),
|
|
4300
|
-
source: ({
|
|
4301
|
-
ai,
|
|
4302
|
-
pages,
|
|
4303
|
-
auth
|
|
4304
|
-
}) => {
|
|
4305
|
-
if (pages) return reactRouterPagesSplat({ ai });
|
|
4306
|
-
const code = templateText(
|
|
4307
|
-
p.templates,
|
|
4308
|
-
ai ? "react-router-ai" : "react-router",
|
|
4309
|
-
`app/${SPLAT}`
|
|
4310
|
-
);
|
|
4311
|
-
return auth ? withAuthPlugin(gateRecipeSplat(code), SPLAT) : code;
|
|
4312
|
-
}
|
|
4313
|
-
});
|
|
4314
|
-
var pagesEditorVariants = (p, info) => ({
|
|
4315
|
-
from: `app/${PAGES_EDITOR}`,
|
|
4316
|
-
to: `${info.appDir}/${PAGES_EDITOR}`,
|
|
4317
|
-
opts: rrRelocation(p, info),
|
|
4318
|
-
combos: flagCombos("ai", "auth"),
|
|
4319
|
-
source: ({ ai, auth }) => {
|
|
4320
|
-
const code = reactRouterPagesEditor({ ai, auth });
|
|
4321
|
-
return auth ? withAuthPlugin(code, PAGES_EDITOR) : code;
|
|
4322
|
-
}
|
|
4323
|
-
});
|
|
4324
|
-
var planReactRouterPages = (p, info) => {
|
|
4325
|
-
const A = info.appDir;
|
|
4326
|
-
const opts = rrRelocation(p, info);
|
|
4327
|
-
const manual = (file, snippet) => p.manual({
|
|
4328
|
-
id: `pages:${file}`,
|
|
4329
|
-
type: "manual_edit",
|
|
4330
|
-
capability: "pages",
|
|
4331
|
-
required: true,
|
|
4332
|
-
file,
|
|
4333
|
-
reason: "unsupported_shape",
|
|
4334
|
-
message: `${file} was customised or moved, so it wasn't changed to use Puck Pages.`,
|
|
4335
|
-
instructions: `Update ${file} to match this version, which uses pages stored in Puck Cloud.`,
|
|
4336
|
-
snippet
|
|
4337
|
-
});
|
|
4338
|
-
let flags = { ai: false, auth: false };
|
|
4339
|
-
const splat = upgradeVariant(p, {
|
|
4340
|
-
...splatVariants(p, info),
|
|
4341
|
-
want: { pages: true },
|
|
4342
|
-
capability: "pages",
|
|
4343
|
-
summary: `Render pages published in Puck Cloud in ${A}/${SPLAT}`,
|
|
4344
|
-
onMatch: ({ ai, auth }) => flags = { ai, auth }
|
|
4345
|
-
});
|
|
4346
|
-
if (splat === "customized" || splat === "missing") {
|
|
4347
|
-
manual(`${A}/${SPLAT}`, reactRouterPagesSplat({ ai: false }));
|
|
4348
|
-
} else {
|
|
4349
|
-
const server = upgradeVariant(p, {
|
|
4350
|
-
from: "app/lib/pages.server.ts",
|
|
4351
|
-
to: `${A}/lib/pages.server.ts`,
|
|
4352
|
-
opts,
|
|
4353
|
-
combos: [{ pages: false }, { pages: true }],
|
|
4354
|
-
source: ({ pages }) => pages ? cloudPagesServer(p.cloudHost) : templateText(
|
|
4355
|
-
p.templates,
|
|
4356
|
-
"react-router",
|
|
4357
|
-
"app/lib/pages.server.ts"
|
|
4358
|
-
),
|
|
4359
|
-
want: { pages: true },
|
|
4360
|
-
capability: "pages",
|
|
4361
|
-
summary: `Read published pages from Puck Cloud in ${A}/lib/pages.server.ts`
|
|
4362
|
-
});
|
|
4363
|
-
if (server === "customized" || server === "missing")
|
|
4364
|
-
manual(`${A}/lib/pages.server.ts`, cloudPagesServer(p.cloudHost));
|
|
4365
|
-
}
|
|
4366
|
-
const editor = pagesEditorVariants(p, info);
|
|
4367
|
-
const rendered = renderCode(
|
|
4368
|
-
editor.source(flags),
|
|
4369
|
-
editor.from,
|
|
4370
|
-
editor.to,
|
|
4371
|
-
opts
|
|
4372
|
-
);
|
|
4373
|
-
if (!rendered.ok || p.createFile(editor.to, rendered.code, {
|
|
4374
|
-
capability: "pages",
|
|
4375
|
-
summary: `Create ${editor.to} (the Puck Pages editor)`
|
|
4376
|
-
}) === "conflict") {
|
|
4377
|
-
manual(editor.to, reactRouterPagesEditor({ ai: false, auth: false }));
|
|
4378
|
-
}
|
|
4379
|
-
registerRoute(p, info, PAGES_EDITOR_ROUTE, "pages", {
|
|
4380
|
-
position: "before-splat"
|
|
4381
|
-
});
|
|
4382
|
-
planOptimizeDeps(p, info, [PLUGIN_PAGES_PACKAGE], "pages");
|
|
4383
|
-
warnLocalPages(p);
|
|
4384
|
-
};
|
|
4385
|
-
var planReactRouterAuth = (p, info) => {
|
|
4386
|
-
const A = info.appDir;
|
|
4387
|
-
const helper = `${A}/lib/puck-auth.server.ts`;
|
|
4388
|
-
if (p.createFile(helper, reactRouterPuckAuth(p.cloudHost), {
|
|
4389
|
-
capability: "auth",
|
|
4390
|
-
summary: `Create ${helper} (requires Sign in with Puck)`
|
|
4391
|
-
}) === "conflict") {
|
|
4392
|
-
p.manual({
|
|
4393
|
-
id: "auth:helper",
|
|
4394
|
-
type: "manual_edit",
|
|
4395
|
-
capability: "auth",
|
|
4396
|
-
required: true,
|
|
4397
|
-
file: helper,
|
|
4398
|
-
reason: "conflict",
|
|
4399
|
-
message: `${helper} already exists with different content.`,
|
|
4400
|
-
instructions: `Export requirePuckSession from ${helper}, or move your file and re-run the command.`,
|
|
4401
|
-
snippet: reactRouterPuckAuth(p.cloudHost)
|
|
4402
|
-
});
|
|
4403
|
-
}
|
|
4404
|
-
const pagesEditor = p.vfs.exists(p.abs(`${A}/${PAGES_EDITOR}`));
|
|
4405
|
-
const file = `${A}/${pagesEditor ? PAGES_EDITOR : SPLAT}`;
|
|
4406
|
-
const upgrade = {
|
|
4407
|
-
want: { auth: true },
|
|
4408
|
-
capability: "auth",
|
|
4409
|
-
summary: `Require Sign in with Puck in ${file}`
|
|
4410
|
-
};
|
|
4411
|
-
const gate = pagesEditor ? upgradeVariant(p, { ...pagesEditorVariants(p, info), ...upgrade }) : upgradeVariant(p, { ...splatVariants(p, info), ...upgrade });
|
|
4412
|
-
if (gate === "customized" || gate === "missing") {
|
|
4413
|
-
p.manual({
|
|
4414
|
-
id: "auth:editor-gate",
|
|
4415
|
-
type: "manual_edit",
|
|
4416
|
-
capability: "auth",
|
|
4417
|
-
required: false,
|
|
4418
|
-
file,
|
|
4419
|
-
reason: "unsupported_shape",
|
|
4420
|
-
message: "Your editor route was customised, so it doesn't send signed-out visitors to sign in.",
|
|
4421
|
-
instructions: "Call requirePuckSession in the loader of the route that renders your editor. The Puck Cloud API route already requires Sign in with Puck.",
|
|
4422
|
-
snippet: `import { requirePuckSession } from "~/lib/puck-auth.server";
|
|
4423
|
-
|
|
4424
|
-
export async function loader({ request }: Route.LoaderArgs) {
|
|
4425
|
-
await requirePuckSession(request);
|
|
4426
|
-
return null;
|
|
4427
|
-
}
|
|
4428
|
-
`
|
|
4429
|
-
});
|
|
4430
|
-
}
|
|
4431
|
-
planAuthPlugin(p, file);
|
|
4432
|
-
planOptimizeDeps(p, info, [PLUGIN_AUTH_PACKAGE], "auth");
|
|
4433
|
-
planRouteAuth(p);
|
|
4434
|
-
};
|
|
4435
3077
|
var REACT_ROUTER_7 = "^7.18.0";
|
|
4436
3078
|
var V8_FUTURE_FLAGS = ` future: {
|
|
4437
3079
|
v8_middleware: true,
|
|
@@ -4470,10 +3112,10 @@ var reactRouterAdapter = {
|
|
|
4470
3112
|
const routeFile = findCloudRoute(scan, info.appDir, expectedRouteFile);
|
|
4471
3113
|
let routeRegistered = false;
|
|
4472
3114
|
if (info.routesFile) {
|
|
4473
|
-
const code = vfs.readText(
|
|
3115
|
+
const code = vfs.readText(path9.join(root, info.routesFile)) ?? "";
|
|
4474
3116
|
routeRegistered = hasRoute(code, info.routesFile, {
|
|
4475
3117
|
path: CLOUD_ROUTE_ENTRY.path,
|
|
4476
|
-
file: routeFile ?
|
|
3118
|
+
file: routeFile ? path9.posix.relative(info.appDir, routeFile) : CLOUD_ROUTE_ENTRY.file
|
|
4477
3119
|
});
|
|
4478
3120
|
}
|
|
4479
3121
|
return { expectedRouteFile, routeFile, routeRegistered };
|
|
@@ -4481,14 +3123,12 @@ var reactRouterAdapter = {
|
|
|
4481
3123
|
planEditor: planReactRouterEditor,
|
|
4482
3124
|
planCloudRoute: planReactRouterCloudRoute,
|
|
4483
3125
|
planAi: planReactRouterAi,
|
|
4484
|
-
planPages: planReactRouterPages,
|
|
4485
|
-
planAuth: planReactRouterAuth,
|
|
4486
3126
|
devUrl: "http://localhost:5173/edit",
|
|
4487
3127
|
deployEnvWarning: "react-router-serve doesn't load .env files. Set PUCK_API_KEY in the environment wherever the app runs in production."
|
|
4488
3128
|
};
|
|
4489
3129
|
|
|
4490
3130
|
// src/frameworks/tanstack-start.ts
|
|
4491
|
-
import
|
|
3131
|
+
import path10 from "path";
|
|
4492
3132
|
var TANSTACK_START_CLOUD_ROUTE_FILE = (routesDir) => `${routesDir}/api/puck/$.ts`;
|
|
4493
3133
|
var TANSTACK_START_EDITOR_MAPPED = [
|
|
4494
3134
|
"database.json",
|
|
@@ -4522,7 +3162,6 @@ var tanstackRelocation = (p, info) => {
|
|
|
4522
3162
|
"src/lib/pages.server": moduleId("src/lib/pages.server"),
|
|
4523
3163
|
"src/lib/resolve-puck-path": moduleId("src/lib/resolve-puck-path"),
|
|
4524
3164
|
"src/components/puck-render": moduleId("src/components/puck-render"),
|
|
4525
|
-
"src/lib/puck-auth": moduleId("src/lib/puck-auth"),
|
|
4526
3165
|
"puck.config": configModuleTarget(p)
|
|
4527
3166
|
},
|
|
4528
3167
|
config: configRelocation(p)
|
|
@@ -4545,7 +3184,7 @@ var planTanStackStartEditor = (p, info, withAi = false) => {
|
|
|
4545
3184
|
{ from: "database.json", to: "database.json", ifMissing: true }
|
|
4546
3185
|
];
|
|
4547
3186
|
const homeExists = INDEX_ROUTES.some(
|
|
4548
|
-
(f) => p.vfs.exists(p.abs(
|
|
3187
|
+
(f) => p.vfs.exists(p.abs(path10.posix.join(info.routesDir, f)))
|
|
4549
3188
|
);
|
|
4550
3189
|
if (homeExists) {
|
|
4551
3190
|
p.warn(
|
|
@@ -4578,7 +3217,18 @@ var planTanStackStartCloudRoute = (p, info, withAi = false) => {
|
|
|
4578
3217
|
) : cloudRoute;
|
|
4579
3218
|
const existing = p.state.cloud.routeFile;
|
|
4580
3219
|
if (existing) {
|
|
4581
|
-
|
|
3220
|
+
const current = p.vfs.readText(p.abs(existing));
|
|
3221
|
+
if (withAi && current === cloudRoute) {
|
|
3222
|
+
p.modifyFile(existing, route, {
|
|
3223
|
+
capability: "ai",
|
|
3224
|
+
summary: `Enable Puck AI in ${existing}`
|
|
3225
|
+
});
|
|
3226
|
+
} else if (withAi && current !== route) {
|
|
3227
|
+
p.warn(
|
|
3228
|
+
"PUCK-CLI-W-AI-ROUTE",
|
|
3229
|
+
`Make sure the puckHandler in ${existing} sets ai.designMode.allowed to true, or Puck AI's design mode will be rejected.`
|
|
3230
|
+
);
|
|
3231
|
+
}
|
|
4582
3232
|
if (existing !== p.state.cloud.expectedRouteFile) {
|
|
4583
3233
|
p.warn(
|
|
4584
3234
|
"PUCK-CLI-W-CLOUD-ROUTE-PATH",
|
|
@@ -4617,21 +3267,10 @@ var planTanStackStartAi = (p, info) => {
|
|
|
4617
3267
|
capability: "ai",
|
|
4618
3268
|
summary
|
|
4619
3269
|
});
|
|
4620
|
-
const
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
capability: "ai",
|
|
4625
|
-
summary: `Add the Puck AI plugin to ${to(SPLAT2)}`
|
|
4626
|
-
});
|
|
4627
|
-
if (pagesEditor) {
|
|
4628
|
-
upgradeVariant(p, {
|
|
4629
|
-
...pagesEditorVariants2(p, info),
|
|
4630
|
-
want: { ai: true },
|
|
4631
|
-
capability: "ai",
|
|
4632
|
-
summary: `Add the Puck AI plugin to ${to(PAGES_EDITOR2)}`
|
|
4633
|
-
});
|
|
4634
|
-
}
|
|
3270
|
+
const editor = upgrade(
|
|
3271
|
+
"src/routes/$.tsx",
|
|
3272
|
+
`Add the Puck AI plugin to ${to("src/routes/$.tsx")}`
|
|
3273
|
+
);
|
|
4635
3274
|
planOptimizeDeps(p, info, [CORE_PACKAGE, PLUGIN_AI_PACKAGE], "ai");
|
|
4636
3275
|
if (editor === "upgraded" || editor === "already") {
|
|
4637
3276
|
upgrade(
|
|
@@ -4653,183 +3292,6 @@ var planTanStackStartAi = (p, info) => {
|
|
|
4653
3292
|
snippet: AI_SNIPPET
|
|
4654
3293
|
});
|
|
4655
3294
|
};
|
|
4656
|
-
var SPLAT2 = "src/routes/$.tsx";
|
|
4657
|
-
var PAGES_LIB = "src/lib/pages.ts";
|
|
4658
|
-
var PAGES_SERVER = "src/lib/pages.server.ts";
|
|
4659
|
-
var PAGES_EDITOR2 = "src/routes/puck.tsx";
|
|
4660
|
-
var gateRecipePagesLib = (code) => {
|
|
4661
|
-
const resolved = "const { isEditorRoute, path } = resolvePuckPath(pathname);";
|
|
4662
|
-
const at = code.indexOf(resolved) + resolved.length;
|
|
4663
|
-
return `${code.slice(0, at)}
|
|
4664
|
-
|
|
4665
|
-
// Editing requires Sign in with Puck
|
|
4666
|
-
if (isEditorRoute) await requirePuckSession({ data: pathname });${code.slice(
|
|
4667
|
-
at
|
|
4668
|
-
)}`.replace(
|
|
4669
|
-
'import { resolvePuckPath } from "./resolve-puck-path";',
|
|
4670
|
-
'import { resolvePuckPath } from "./resolve-puck-path";\nimport { requirePuckSession } from "./puck-auth";'
|
|
4671
|
-
);
|
|
4672
|
-
};
|
|
4673
|
-
var splatVariants2 = (p, info) => ({
|
|
4674
|
-
from: SPLAT2,
|
|
4675
|
-
to: locate(info)(SPLAT2),
|
|
4676
|
-
opts: tanstackRelocation(p, info),
|
|
4677
|
-
combos: flagCombos("ai", "pages", "auth"),
|
|
4678
|
-
source: ({ ai, pages, auth }) => {
|
|
4679
|
-
if (pages) return TANSTACK_PAGES_SPLAT;
|
|
4680
|
-
const code = templateText(
|
|
4681
|
-
p.templates,
|
|
4682
|
-
ai ? "tanstack-start-ai" : "tanstack-start",
|
|
4683
|
-
SPLAT2
|
|
4684
|
-
);
|
|
4685
|
-
return auth ? withAuthPlugin(code, SPLAT2) : code;
|
|
4686
|
-
}
|
|
4687
|
-
});
|
|
4688
|
-
var pagesLibVariants = (p, info) => ({
|
|
4689
|
-
from: PAGES_LIB,
|
|
4690
|
-
to: locate(info)(PAGES_LIB),
|
|
4691
|
-
opts: tanstackRelocation(p, info),
|
|
4692
|
-
combos: flagCombos("pages", "auth"),
|
|
4693
|
-
source: ({ pages, auth }) => {
|
|
4694
|
-
if (pages) return tanstackPagesLib;
|
|
4695
|
-
const code = templateText(p.templates, "tanstack-start", PAGES_LIB);
|
|
4696
|
-
return auth ? gateRecipePagesLib(code) : code;
|
|
4697
|
-
}
|
|
4698
|
-
});
|
|
4699
|
-
var pagesEditorVariants2 = (p, info) => ({
|
|
4700
|
-
from: PAGES_EDITOR2,
|
|
4701
|
-
to: locate(info)(PAGES_EDITOR2),
|
|
4702
|
-
opts: tanstackRelocation(p, info),
|
|
4703
|
-
combos: flagCombos("ai", "auth"),
|
|
4704
|
-
source: ({ ai, auth }) => {
|
|
4705
|
-
const code = tanstackPagesEditor({ ai, auth });
|
|
4706
|
-
return auth ? withAuthPlugin(code, PAGES_EDITOR2) : code;
|
|
4707
|
-
}
|
|
4708
|
-
});
|
|
4709
|
-
var planTanStackStartPages = (p, info) => {
|
|
4710
|
-
const to = locate(info);
|
|
4711
|
-
const manual = (file, snippet) => p.manual({
|
|
4712
|
-
id: `pages:${file}`,
|
|
4713
|
-
type: "manual_edit",
|
|
4714
|
-
capability: "pages",
|
|
4715
|
-
required: true,
|
|
4716
|
-
file,
|
|
4717
|
-
reason: "unsupported_shape",
|
|
4718
|
-
message: `${file} was customised or moved, so it wasn't changed to use Puck Pages.`,
|
|
4719
|
-
instructions: `Update ${file} to match this version, which uses pages stored in Puck Cloud.`,
|
|
4720
|
-
snippet
|
|
4721
|
-
});
|
|
4722
|
-
const upgrade = (variants, summary, snippet, onMatch) => {
|
|
4723
|
-
const outcome = upgradeVariant(p, {
|
|
4724
|
-
...variants,
|
|
4725
|
-
want: { pages: true },
|
|
4726
|
-
capability: "pages",
|
|
4727
|
-
summary,
|
|
4728
|
-
onMatch
|
|
4729
|
-
});
|
|
4730
|
-
const ok = outcome === "upgraded" || outcome === "already";
|
|
4731
|
-
if (!ok) manual(variants.to, snippet);
|
|
4732
|
-
return ok;
|
|
4733
|
-
};
|
|
4734
|
-
let flags = { ai: false, auth: false };
|
|
4735
|
-
const splat = upgrade(
|
|
4736
|
-
splatVariants2(p, info),
|
|
4737
|
-
`Render pages published in Puck Cloud in ${to(SPLAT2)}`,
|
|
4738
|
-
TANSTACK_PAGES_SPLAT,
|
|
4739
|
-
({ ai, auth }) => flags = { ai, auth }
|
|
4740
|
-
);
|
|
4741
|
-
if (splat) {
|
|
4742
|
-
upgrade(
|
|
4743
|
-
pagesLibVariants(p, info),
|
|
4744
|
-
`Send /<path>/edit to the Puck Pages editor in ${to(PAGES_LIB)}`,
|
|
4745
|
-
tanstackPagesLib
|
|
4746
|
-
);
|
|
4747
|
-
upgrade(
|
|
4748
|
-
{
|
|
4749
|
-
from: PAGES_SERVER,
|
|
4750
|
-
to: to(PAGES_SERVER),
|
|
4751
|
-
opts: tanstackRelocation(p, info),
|
|
4752
|
-
combos: [{ pages: false }, { pages: true }],
|
|
4753
|
-
source: ({ pages }) => pages ? cloudPagesServer(p.cloudHost) : templateText(p.templates, "tanstack-start", PAGES_SERVER)
|
|
4754
|
-
},
|
|
4755
|
-
`Read published pages from Puck Cloud in ${to(PAGES_SERVER)}`,
|
|
4756
|
-
cloudPagesServer(p.cloudHost)
|
|
4757
|
-
);
|
|
4758
|
-
}
|
|
4759
|
-
const editor = pagesEditorVariants2(p, info);
|
|
4760
|
-
const rendered = renderCode(
|
|
4761
|
-
editor.source(flags),
|
|
4762
|
-
editor.from,
|
|
4763
|
-
editor.to,
|
|
4764
|
-
editor.opts
|
|
4765
|
-
);
|
|
4766
|
-
if (!rendered.ok || p.createFile(editor.to, rendered.code, {
|
|
4767
|
-
capability: "pages",
|
|
4768
|
-
summary: `Create ${editor.to} (the Puck Pages editor)`
|
|
4769
|
-
}) === "conflict") {
|
|
4770
|
-
manual(editor.to, tanstackPagesEditor({ ai: false, auth: false }));
|
|
4771
|
-
}
|
|
4772
|
-
planOptimizeDeps(p, info, [PLUGIN_PAGES_PACKAGE], "pages");
|
|
4773
|
-
warnLocalPages(p);
|
|
4774
|
-
};
|
|
4775
|
-
var planTanStackStartAuth = (p, info) => {
|
|
4776
|
-
const to = locate(info);
|
|
4777
|
-
const helper = to("src/lib/puck-auth.ts");
|
|
4778
|
-
if (p.createFile(helper, tanstackPuckAuth(p.cloudHost), {
|
|
4779
|
-
capability: "auth",
|
|
4780
|
-
summary: `Create ${helper} (requires Sign in with Puck)`
|
|
4781
|
-
}) === "conflict") {
|
|
4782
|
-
p.manual({
|
|
4783
|
-
id: "auth:helper",
|
|
4784
|
-
type: "manual_edit",
|
|
4785
|
-
capability: "auth",
|
|
4786
|
-
required: true,
|
|
4787
|
-
file: helper,
|
|
4788
|
-
reason: "conflict",
|
|
4789
|
-
message: `${helper} already exists with different content.`,
|
|
4790
|
-
instructions: `Export the requirePuckSession server function from ${helper}, or move your file and re-run the command.`,
|
|
4791
|
-
snippet: tanstackPuckAuth(p.cloudHost)
|
|
4792
|
-
});
|
|
4793
|
-
}
|
|
4794
|
-
const pagesEditor = p.vfs.exists(p.abs(to(PAGES_EDITOR2)));
|
|
4795
|
-
const upgrade = (file) => ({
|
|
4796
|
-
want: { auth: true },
|
|
4797
|
-
capability: "auth",
|
|
4798
|
-
summary: `Require Sign in with Puck in ${file}`
|
|
4799
|
-
});
|
|
4800
|
-
const gate = pagesEditor ? upgradeVariant(p, {
|
|
4801
|
-
...pagesEditorVariants2(p, info),
|
|
4802
|
-
...upgrade(to(PAGES_EDITOR2))
|
|
4803
|
-
}) : upgradeVariant(p, {
|
|
4804
|
-
...pagesLibVariants(p, info),
|
|
4805
|
-
...upgrade(to(PAGES_LIB))
|
|
4806
|
-
});
|
|
4807
|
-
if (!pagesEditor) {
|
|
4808
|
-
upgradeVariant(p, {
|
|
4809
|
-
...splatVariants2(p, info),
|
|
4810
|
-
want: { auth: true },
|
|
4811
|
-
capability: "auth",
|
|
4812
|
-
summary: `Add the Puck Auth plugin to ${to(SPLAT2)}`
|
|
4813
|
-
});
|
|
4814
|
-
}
|
|
4815
|
-
if (gate === "customized" || gate === "missing") {
|
|
4816
|
-
p.manual({
|
|
4817
|
-
id: "auth:editor-gate",
|
|
4818
|
-
type: "manual_edit",
|
|
4819
|
-
capability: "auth",
|
|
4820
|
-
required: false,
|
|
4821
|
-
file: to(pagesEditor ? PAGES_EDITOR2 : PAGES_LIB),
|
|
4822
|
-
reason: "unsupported_shape",
|
|
4823
|
-
message: "Your editor was customised, so it doesn't send signed-out visitors to sign in.",
|
|
4824
|
-
instructions: "Call requirePuckSession before loading the route that renders your editor. The Puck Cloud API route already requires Sign in with Puck.",
|
|
4825
|
-
snippet: `beforeLoad: ({ location }) => requirePuckSession({ data: location.href }),
|
|
4826
|
-
`
|
|
4827
|
-
});
|
|
4828
|
-
}
|
|
4829
|
-
planAuthPlugin(p, to(pagesEditor ? PAGES_EDITOR2 : SPLAT2));
|
|
4830
|
-
planOptimizeDeps(p, info, [PLUGIN_AUTH_PACKAGE], "auth");
|
|
4831
|
-
planRouteAuth(p);
|
|
4832
|
-
};
|
|
4833
3295
|
var tanstackStartAdapter = {
|
|
4834
3296
|
recipe: (withAi) => withAi ? "tanstack-start-ai" : "tanstack-start",
|
|
4835
3297
|
recipeCloudRoute: AI_ROUTE2,
|
|
@@ -4848,14 +3310,12 @@ var tanstackStartAdapter = {
|
|
|
4848
3310
|
planEditor: planTanStackStartEditor,
|
|
4849
3311
|
planCloudRoute: planTanStackStartCloudRoute,
|
|
4850
3312
|
planAi: planTanStackStartAi,
|
|
4851
|
-
planPages: planTanStackStartPages,
|
|
4852
|
-
planAuth: planTanStackStartAuth,
|
|
4853
3313
|
devUrl: "http://localhost:3000/edit",
|
|
4854
3314
|
deployEnvWarning: "Set PUCK_API_KEY in your hosting provider's environment variables before deploying."
|
|
4855
3315
|
};
|
|
4856
3316
|
|
|
4857
3317
|
// src/frameworks/server.ts
|
|
4858
|
-
import
|
|
3318
|
+
import path11 from "path";
|
|
4859
3319
|
|
|
4860
3320
|
// src/ast/server-app.ts
|
|
4861
3321
|
var stripExtension2 = (source) => source.replace(/\.(m?[jt]sx?)$/, "");
|
|
@@ -5030,12 +3490,12 @@ var CLOUD = { from: "src/puck/cloud.ts", name: "puckCloud" };
|
|
|
5030
3490
|
var CLOUD_CLIENT_PEER = { name: "react", range: "^19.0.0" };
|
|
5031
3491
|
var puckDir = (vfs, root, info) => {
|
|
5032
3492
|
if (info.entry)
|
|
5033
|
-
return
|
|
5034
|
-
return vfs.isDir(
|
|
3493
|
+
return path11.posix.join(path11.posix.dirname(info.entry), "puck");
|
|
3494
|
+
return vfs.isDir(path11.join(root, "src")) ? "src/puck" : "puck";
|
|
5035
3495
|
};
|
|
5036
3496
|
var importSource = (info, file) => {
|
|
5037
|
-
const from =
|
|
5038
|
-
const rel =
|
|
3497
|
+
const from = path11.posix.dirname(info.entry ?? "index.ts");
|
|
3498
|
+
const rel = path11.posix.relative(from, file).replace(/\.ts$/, "");
|
|
5039
3499
|
return `${rel.startsWith(".") ? "" : "./"}${rel}${info.importExtension}`;
|
|
5040
3500
|
};
|
|
5041
3501
|
var mountSnippet = (info, name, file) => `import { ${name} } from "${importSource(info, file)}";
|
|
@@ -5159,7 +3619,18 @@ var serverPlanner = (id2) => {
|
|
|
5159
3619
|
p.addDependency(CLOUD_CLIENT_PEER.name, CLOUD_CLIENT_PEER.range, "cloud");
|
|
5160
3620
|
}
|
|
5161
3621
|
if (existing) {
|
|
5162
|
-
|
|
3622
|
+
const current = p.vfs.readText(p.abs(existing));
|
|
3623
|
+
if (withAi && current === cloudRoute) {
|
|
3624
|
+
p.modifyFile(existing, route, {
|
|
3625
|
+
capability: "ai",
|
|
3626
|
+
summary: `Enable Puck AI in ${existing}`
|
|
3627
|
+
});
|
|
3628
|
+
} else if (withAi && current !== route) {
|
|
3629
|
+
p.warn(
|
|
3630
|
+
"PUCK-CLI-W-AI-ROUTE",
|
|
3631
|
+
`Make sure the puckHandler in ${existing} sets ai.designMode.allowed to true, or Puck AI's design mode will be rejected.`
|
|
3632
|
+
);
|
|
3633
|
+
}
|
|
5163
3634
|
} else {
|
|
5164
3635
|
const outcome = p.createFile(file, route, {
|
|
5165
3636
|
capability: "cloud",
|
|
@@ -5185,60 +3656,17 @@ var serverPlanner = (id2) => {
|
|
|
5185
3656
|
}
|
|
5186
3657
|
planEnvLoading(p, info);
|
|
5187
3658
|
};
|
|
5188
|
-
const planPages = (p, info) => {
|
|
5189
|
-
const file = `${puckDir(p.vfs, p.ctx.root, info)}/pages.ts`;
|
|
5190
|
-
const published = (host) => id2 === "hono" ? honoPublishedPages(host) : expressPublishedPages(host);
|
|
5191
|
-
const outcome = upgradeVariant(p, {
|
|
5192
|
-
from: PAGES.from,
|
|
5193
|
-
to: file,
|
|
5194
|
-
opts: { moduleMap: {} },
|
|
5195
|
-
combos: [{ pages: false }, { pages: true }],
|
|
5196
|
-
source: ({ pages }) => pages ? published(p.cloudHost) : templateText(p.templates, recipe, PAGES.from),
|
|
5197
|
-
want: { pages: true },
|
|
5198
|
-
capability: "pages",
|
|
5199
|
-
summary: `Serve pages published in Puck Cloud from ${file}`
|
|
5200
|
-
});
|
|
5201
|
-
if (outcome === "customized" || outcome === "missing") {
|
|
5202
|
-
p.manual({
|
|
5203
|
-
id: `pages:${file}`,
|
|
5204
|
-
type: "manual_edit",
|
|
5205
|
-
capability: "pages",
|
|
5206
|
-
required: true,
|
|
5207
|
-
file,
|
|
5208
|
-
reason: "unsupported_shape",
|
|
5209
|
-
message: `${file} was customised or moved, so it wasn't changed to serve pages from Puck Cloud.`,
|
|
5210
|
-
instructions: `Serve published pages from Puck Cloud with puckCloud().pages.getPublished() from @puckeditor/cloud-client.`,
|
|
5211
|
-
snippet: published(p.cloudHost)
|
|
5212
|
-
});
|
|
5213
|
-
} else {
|
|
5214
|
-
p.warnings = p.warnings.filter(
|
|
5215
|
-
(w) => w.code !== "PUCK-CLI-W-PAGES-PUBLIC"
|
|
5216
|
-
);
|
|
5217
|
-
}
|
|
5218
|
-
warnLocalPages(p);
|
|
5219
|
-
p.warn(
|
|
5220
|
-
"PUCK-CLI-W-PAGES-EDITOR",
|
|
5221
|
-
"Pages are edited with the Puck Pages plugin. Run `npx @puckeditor/cli add pages` in the editor's app too."
|
|
5222
|
-
);
|
|
5223
|
-
};
|
|
5224
|
-
const planAuth = (p) => {
|
|
5225
|
-
planRouteAuth(p);
|
|
5226
|
-
p.warn(
|
|
5227
|
-
"PUCK-CLI-W-AUTH-EDITOR",
|
|
5228
|
-
"Puck Cloud requests now require Sign in with Puck. Run `npx @puckeditor/cli add auth` in the editor's app too, so editors can sign in."
|
|
5229
|
-
);
|
|
5230
|
-
};
|
|
5231
3659
|
const adapter = {
|
|
5232
3660
|
kind: "server",
|
|
5233
3661
|
recipe: (withAi) => withAi ? aiRecipe : recipe,
|
|
5234
3662
|
recipeCloudRoute: CLOUD.from,
|
|
5235
|
-
appDir: (info) => info.entry ?
|
|
3663
|
+
appDir: (info) => info.entry ? path11.posix.dirname(info.entry).replace(/^\.$/, "") : "",
|
|
5236
3664
|
configDirs: () => [],
|
|
5237
3665
|
envDir: () => "",
|
|
5238
3666
|
detectCloudRoute: (info, vfs, root, scan) => {
|
|
5239
3667
|
const expectedRouteFile = `${puckDir(vfs, root, info)}/cloud.ts`;
|
|
5240
3668
|
const routeFile = findCloudRoute(scan, "", expectedRouteFile);
|
|
5241
|
-
const code = info.entry ? vfs.readText(
|
|
3669
|
+
const code = info.entry ? vfs.readText(path11.join(root, info.entry)) ?? "" : "";
|
|
5242
3670
|
return {
|
|
5243
3671
|
expectedRouteFile,
|
|
5244
3672
|
routeFile,
|
|
@@ -5247,10 +3675,10 @@ var serverPlanner = (id2) => {
|
|
|
5247
3675
|
})
|
|
5248
3676
|
};
|
|
5249
3677
|
},
|
|
5250
|
-
|
|
3678
|
+
detectPages: (info, vfs, root) => {
|
|
5251
3679
|
const file = `${puckDir(vfs, root, info)}/pages.ts`;
|
|
5252
|
-
if (!vfs.exists(
|
|
5253
|
-
const code = info.entry ? vfs.readText(
|
|
3680
|
+
if (!vfs.exists(path11.join(root, file))) return null;
|
|
3681
|
+
const code = info.entry ? vfs.readText(path11.join(root, info.entry)) ?? "" : "";
|
|
5254
3682
|
return {
|
|
5255
3683
|
file,
|
|
5256
3684
|
mounted: Boolean(info.entry) && isMounted(code, info.entry, info.id, {
|
|
@@ -5264,8 +3692,6 @@ var serverPlanner = (id2) => {
|
|
|
5264
3692
|
// The AI plugin goes in the editor; this server only enables AI in its Cloud route
|
|
5265
3693
|
planAi: () => {
|
|
5266
3694
|
},
|
|
5267
|
-
planPages,
|
|
5268
|
-
planAuth,
|
|
5269
3695
|
devUrl: "http://localhost:3000/api/pages?path=/",
|
|
5270
3696
|
deployEnvWarning: `Node doesn't load .env files in production. Set ${ENV_KEY} in the environment wherever the server runs.`
|
|
5271
3697
|
};
|
|
@@ -5277,7 +3703,7 @@ var expressAdapter = serverPlanner(
|
|
|
5277
3703
|
);
|
|
5278
3704
|
|
|
5279
3705
|
// src/frameworks/vite-app.ts
|
|
5280
|
-
import
|
|
3706
|
+
import path12 from "path";
|
|
5281
3707
|
|
|
5282
3708
|
// src/ast/react-root.ts
|
|
5283
3709
|
var isCreateRoot = (node) => node.type === "CallExpression" && (node.callee.type === "Identifier" && node.callee.name === "createRoot" || node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && node.callee.property.name === "createRoot");
|
|
@@ -5406,7 +3832,7 @@ var SERVER_DEV_PACKAGES = [
|
|
|
5406
3832
|
{ name: "@hono/vite-dev-server", range: "^0.26.1" },
|
|
5407
3833
|
{ name: "tsx", range: "^4.23.0" }
|
|
5408
3834
|
];
|
|
5409
|
-
var locate2 = (info) => (from) => from.startsWith("src/") ?
|
|
3835
|
+
var locate2 = (info) => (from) => from.startsWith("src/") ? path12.posix.join(info.srcDir || ".", from.slice(4)) : from;
|
|
5410
3836
|
var viteRelocation = (p, info) => {
|
|
5411
3837
|
const to = locate2(info);
|
|
5412
3838
|
const moduleId = (id2) => to(`${id2}.ts`).replace(/\.ts$/, "");
|
|
@@ -5414,7 +3840,6 @@ var viteRelocation = (p, info) => {
|
|
|
5414
3840
|
moduleMap: {
|
|
5415
3841
|
"src/puck/pages": moduleId("src/puck/pages"),
|
|
5416
3842
|
"src/puck/editor": moduleId("src/puck/editor"),
|
|
5417
|
-
"src/puck/require-session": moduleId("src/puck/require-session"),
|
|
5418
3843
|
"src/puck.config": configModuleTarget(p, to("src/puck.config.tsx"))
|
|
5419
3844
|
},
|
|
5420
3845
|
config: configRelocation(p)
|
|
@@ -5520,8 +3945,8 @@ var planViteEditor = (p, info, withAi = false) => {
|
|
|
5520
3945
|
);
|
|
5521
3946
|
}
|
|
5522
3947
|
const entry = info.entry;
|
|
5523
|
-
const rootModule =
|
|
5524
|
-
|
|
3948
|
+
const rootModule = path12.posix.relative(
|
|
3949
|
+
path12.posix.dirname(entry ?? "src/main.tsx"),
|
|
5525
3950
|
to("src/puck/root")
|
|
5526
3951
|
);
|
|
5527
3952
|
const source = rootModule.startsWith(".") ? rootModule : `./${rootModule}`;
|
|
@@ -5611,7 +4036,13 @@ var planViteCloudRoute = (p, info, withAi = false) => {
|
|
|
5611
4036
|
const cloudRoute = withCloudHost(withoutAiOptions(aiRoute), p.cloudHost);
|
|
5612
4037
|
const existing = p.state.cloud.routeFile;
|
|
5613
4038
|
if (existing) {
|
|
5614
|
-
|
|
4039
|
+
const current = p.vfs.readText(p.abs(existing));
|
|
4040
|
+
if (withAi && current === cloudRoute) {
|
|
4041
|
+
p.modifyFile(existing, route, {
|
|
4042
|
+
capability: "ai",
|
|
4043
|
+
summary: `Enable Puck AI in ${existing}`
|
|
4044
|
+
});
|
|
4045
|
+
}
|
|
5615
4046
|
} else {
|
|
5616
4047
|
p.createFile(CLOUD_ROUTE, route, {
|
|
5617
4048
|
capability: "cloud",
|
|
@@ -5659,12 +4090,10 @@ var planViteAi = (p, info) => {
|
|
|
5659
4090
|
capability: "ai",
|
|
5660
4091
|
summary
|
|
5661
4092
|
});
|
|
5662
|
-
const editor =
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
summary: `Add the Puck AI plugin to ${to(EDITOR)}`
|
|
5667
|
-
});
|
|
4093
|
+
const editor = upgrade(
|
|
4094
|
+
"src/puck/editor.tsx",
|
|
4095
|
+
`Add the Puck AI plugin to ${to("src/puck/editor.tsx")}`
|
|
4096
|
+
);
|
|
5668
4097
|
planOptimizeDeps(p, info, [CORE_PACKAGE, PLUGIN_AI_PACKAGE], "ai");
|
|
5669
4098
|
if (editor === "upgraded" || editor === "already") {
|
|
5670
4099
|
upgrade(
|
|
@@ -5686,134 +4115,6 @@ var planViteAi = (p, info) => {
|
|
|
5686
4115
|
snippet: AI_SNIPPET
|
|
5687
4116
|
});
|
|
5688
4117
|
};
|
|
5689
|
-
var ROOT = "src/puck/root.tsx";
|
|
5690
|
-
var EDITOR = "src/puck/editor.tsx";
|
|
5691
|
-
var PAGES_API = "server/puck/pages.ts";
|
|
5692
|
-
var gateRecipeRoot = (code) => code.replace(
|
|
5693
|
-
'import type { ReactNode } from "react";',
|
|
5694
|
-
'import type { ReactNode } from "react";\nimport { RequireSession } from "./require-session";'
|
|
5695
|
-
).replace(
|
|
5696
|
-
"<Editor path={path} />",
|
|
5697
|
-
"<RequireSession>\n <Editor path={path} />\n </RequireSession>"
|
|
5698
|
-
);
|
|
5699
|
-
var rootVariants = (p, info) => ({
|
|
5700
|
-
from: ROOT,
|
|
5701
|
-
to: locate2(info)(ROOT),
|
|
5702
|
-
opts: viteRelocation(p, info),
|
|
5703
|
-
combos: flagCombos("pages", "auth"),
|
|
5704
|
-
source: ({ pages, auth }) => {
|
|
5705
|
-
if (pages) return vitePagesRoot({ auth });
|
|
5706
|
-
const code = templateText(p.templates, "vite", ROOT);
|
|
5707
|
-
return auth ? gateRecipeRoot(code) : code;
|
|
5708
|
-
}
|
|
5709
|
-
});
|
|
5710
|
-
var editorVariants = (p, info) => ({
|
|
5711
|
-
from: EDITOR,
|
|
5712
|
-
to: locate2(info)(EDITOR),
|
|
5713
|
-
opts: viteRelocation(p, info),
|
|
5714
|
-
combos: flagCombos("ai", "pages", "auth"),
|
|
5715
|
-
source: ({ ai, pages, auth }) => {
|
|
5716
|
-
const code = pages ? vitePagesEditor({ ai }) : templateText(p.templates, ai ? "vite-ai" : "vite", EDITOR);
|
|
5717
|
-
return auth ? withAuthPlugin(code, EDITOR) : code;
|
|
5718
|
-
}
|
|
5719
|
-
});
|
|
5720
|
-
var planVitePages = (p, info) => {
|
|
5721
|
-
const to = locate2(info);
|
|
5722
|
-
const manual = (file, snippet) => p.manual({
|
|
5723
|
-
id: `pages:${file}`,
|
|
5724
|
-
type: "manual_edit",
|
|
5725
|
-
capability: "pages",
|
|
5726
|
-
required: true,
|
|
5727
|
-
file,
|
|
5728
|
-
reason: "unsupported_shape",
|
|
5729
|
-
message: `${file} was customised or moved, so it wasn't changed to use Puck Pages.`,
|
|
5730
|
-
instructions: `Update ${file} to match this version, which uses pages stored in Puck Cloud.`,
|
|
5731
|
-
snippet
|
|
5732
|
-
});
|
|
5733
|
-
const failed = (outcome) => outcome === "customized" || outcome === "missing";
|
|
5734
|
-
const want = { pages: true };
|
|
5735
|
-
if (failed(
|
|
5736
|
-
upgradeVariant(p, {
|
|
5737
|
-
...editorVariants(p, info),
|
|
5738
|
-
want,
|
|
5739
|
-
capability: "pages",
|
|
5740
|
-
summary: `Add the Puck Pages plugin to ${to(EDITOR)}`
|
|
5741
|
-
})
|
|
5742
|
-
))
|
|
5743
|
-
manual(to(EDITOR), vitePagesEditor({ ai: false }));
|
|
5744
|
-
if (failed(
|
|
5745
|
-
upgradeVariant(p, {
|
|
5746
|
-
...rootVariants(p, info),
|
|
5747
|
-
want,
|
|
5748
|
-
capability: "pages",
|
|
5749
|
-
summary: `Open the Puck Pages editor at /puck in ${to(ROOT)}`
|
|
5750
|
-
})
|
|
5751
|
-
))
|
|
5752
|
-
manual(to(ROOT), vitePagesRoot({ auth: false }));
|
|
5753
|
-
if (modeOf(p, info) === "external") {
|
|
5754
|
-
p.warn(
|
|
5755
|
-
"PUCK-CLI-W-EXTERNAL-PAGES",
|
|
5756
|
-
`Pages are loaded from ${p.backend?.url ?? "the server /api is proxied to"}. Run \`npx @puckeditor/cli add pages\` in that server's project, so /api/pages serves pages published in Puck Cloud.`
|
|
5757
|
-
);
|
|
5758
|
-
} else {
|
|
5759
|
-
const api = upgradeVariant(p, {
|
|
5760
|
-
from: PAGES_API,
|
|
5761
|
-
to: PAGES_API,
|
|
5762
|
-
opts: { moduleMap: {} },
|
|
5763
|
-
combos: [{ pages: false }, { pages: true }],
|
|
5764
|
-
source: ({ pages }) => pages ? honoPublishedPages(p.cloudHost) : templateText(p.templates, "vite", PAGES_API),
|
|
5765
|
-
want,
|
|
5766
|
-
capability: "pages",
|
|
5767
|
-
summary: `Serve pages published in Puck Cloud from ${PAGES_API}`
|
|
5768
|
-
});
|
|
5769
|
-
if (failed(api)) manual(PAGES_API, honoPublishedPages(p.cloudHost));
|
|
5770
|
-
warnLocalPages(p);
|
|
5771
|
-
}
|
|
5772
|
-
planOptimizeDeps(p, info, [PLUGIN_PAGES_PACKAGE], "pages");
|
|
5773
|
-
};
|
|
5774
|
-
var planViteAuth = (p, info) => {
|
|
5775
|
-
const to = locate2(info);
|
|
5776
|
-
p.createFile(to("src/puck/require-session.tsx"), REQUIRE_SESSION, {
|
|
5777
|
-
capability: "auth",
|
|
5778
|
-
summary: `Create ${to(
|
|
5779
|
-
"src/puck/require-session.tsx"
|
|
5780
|
-
)} (sends signed-out visitors to Sign in with Puck)`
|
|
5781
|
-
});
|
|
5782
|
-
const gate = upgradeVariant(p, {
|
|
5783
|
-
...rootVariants(p, info),
|
|
5784
|
-
want: { auth: true },
|
|
5785
|
-
capability: "auth",
|
|
5786
|
-
summary: `Require Sign in with Puck to edit in ${to(ROOT)}`
|
|
5787
|
-
});
|
|
5788
|
-
if (gate === "customized" || gate === "missing") {
|
|
5789
|
-
p.manual({
|
|
5790
|
-
id: "auth:editor-gate",
|
|
5791
|
-
type: "manual_edit",
|
|
5792
|
-
capability: "auth",
|
|
5793
|
-
required: false,
|
|
5794
|
-
file: to(ROOT),
|
|
5795
|
-
reason: "unsupported_shape",
|
|
5796
|
-
message: "Your editor was customised, so it doesn't send signed-out visitors to sign in.",
|
|
5797
|
-
instructions: "Wrap your editor in <RequireSession>. The Puck Cloud API route already requires Sign in with Puck.",
|
|
5798
|
-
snippet: `import { RequireSession } from "./require-session";
|
|
5799
|
-
|
|
5800
|
-
<RequireSession>
|
|
5801
|
-
<Editor />
|
|
5802
|
-
</RequireSession>
|
|
5803
|
-
`
|
|
5804
|
-
});
|
|
5805
|
-
}
|
|
5806
|
-
planAuthPlugin(p, to(EDITOR));
|
|
5807
|
-
planOptimizeDeps(p, info, [PLUGIN_AUTH_PACKAGE], "auth");
|
|
5808
|
-
if (modeOf(p, info) === "external") {
|
|
5809
|
-
p.warn(
|
|
5810
|
-
"PUCK-CLI-W-EXTERNAL-AUTH",
|
|
5811
|
-
`Puck Cloud requests go to ${p.backend?.url ?? "the server /api is proxied to"}. Run \`npx @puckeditor/cli add auth\` in that server's project to require Sign in with Puck there.`
|
|
5812
|
-
);
|
|
5813
|
-
} else {
|
|
5814
|
-
planRouteAuth(p);
|
|
5815
|
-
}
|
|
5816
|
-
};
|
|
5817
4118
|
var viteAdapter = {
|
|
5818
4119
|
recipe: (withAi) => withAi ? "vite-ai" : "vite",
|
|
5819
4120
|
recipeCloudRoute: CLOUD_ROUTE,
|
|
@@ -5827,7 +4128,7 @@ var viteAdapter = {
|
|
|
5827
4128
|
}),
|
|
5828
4129
|
detectCloudRoute: (info, vfs, root, scan) => {
|
|
5829
4130
|
const routeFile = findCloudRoute(scan, "server", CLOUD_ROUTE);
|
|
5830
|
-
const index = vfs.readText(
|
|
4131
|
+
const index = vfs.readText(path12.join(root, SERVER_ENTRY)) ?? "";
|
|
5831
4132
|
return {
|
|
5832
4133
|
expectedRouteFile: CLOUD_ROUTE,
|
|
5833
4134
|
routeFile,
|
|
@@ -5840,21 +4141,19 @@ var viteAdapter = {
|
|
|
5840
4141
|
planEditor: planViteEditor,
|
|
5841
4142
|
planCloudRoute: planViteCloudRoute,
|
|
5842
4143
|
planAi: planViteAi,
|
|
5843
|
-
planPages: planVitePages,
|
|
5844
|
-
planAuth: planViteAuth,
|
|
5845
4144
|
devUrl: "http://localhost:5173/edit",
|
|
5846
4145
|
deployEnvWarning: `npm start runs server/prod.ts. Set ${ENV_KEY} in the environment wherever it runs.`
|
|
5847
4146
|
};
|
|
5848
4147
|
|
|
5849
4148
|
// src/plan/install.ts
|
|
5850
|
-
import
|
|
4149
|
+
import path13 from "path";
|
|
5851
4150
|
var addCommand = (ctx, packages, { dev = false } = {}) => {
|
|
5852
4151
|
const pm = ctx.packageManager.name;
|
|
5853
4152
|
const specs = dev ? [pm === "bun" ? "-d" : "-D", ...packages] : packages;
|
|
5854
4153
|
const ws = ctx.workspace && !ctx.workspace.isRoot ? ctx.workspace : null;
|
|
5855
4154
|
const name = ctx.packageJson?.name;
|
|
5856
4155
|
if (ws) {
|
|
5857
|
-
const relDir = toPosix(
|
|
4156
|
+
const relDir = toPosix(path13.relative(ws.root, ctx.root));
|
|
5858
4157
|
if (pm === "pnpm" && name)
|
|
5859
4158
|
return {
|
|
5860
4159
|
command: "pnpm",
|
|
@@ -6087,7 +4386,12 @@ var planAstroCloudRoute = (p, _info, withAi = false) => {
|
|
|
6087
4386
|
const route = withAi ? withCloudHost(aiRoute, p.cloudHost) : cloudRoute;
|
|
6088
4387
|
const existing = p.state.cloud.routeFile;
|
|
6089
4388
|
if (existing) {
|
|
6090
|
-
if (withAi
|
|
4389
|
+
if (withAi && p.vfs.readText(p.abs(existing)) === cloudRoute) {
|
|
4390
|
+
p.modifyFile(existing, route, {
|
|
4391
|
+
capability: "ai",
|
|
4392
|
+
summary: `Enable Puck AI in ${existing}`
|
|
4393
|
+
});
|
|
4394
|
+
}
|
|
6091
4395
|
return;
|
|
6092
4396
|
}
|
|
6093
4397
|
const outcome = p.createFile(CLOUD_ROUTE2, route, {
|
|
@@ -6119,12 +4423,10 @@ var planAstroAi = (p) => {
|
|
|
6119
4423
|
capability: "ai",
|
|
6120
4424
|
summary
|
|
6121
4425
|
});
|
|
6122
|
-
const editor =
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6126
|
-
summary: `Add the Puck AI plugin to ${EDITOR2}`
|
|
6127
|
-
});
|
|
4426
|
+
const editor = upgrade(
|
|
4427
|
+
"src/puck/editor.tsx",
|
|
4428
|
+
"Add the Puck AI plugin to src/puck/editor.tsx"
|
|
4429
|
+
);
|
|
6128
4430
|
if (editor === "upgraded" || editor === "already") {
|
|
6129
4431
|
upgrade(
|
|
6130
4432
|
"src/puck/render.tsx",
|
|
@@ -6134,193 +4436,16 @@ var planAstroAi = (p) => {
|
|
|
6134
4436
|
}
|
|
6135
4437
|
const file = p.state.scan.editorFiles[0] ?? "src/puck/editor.tsx";
|
|
6136
4438
|
p.manual({
|
|
6137
|
-
id: "ai:editor",
|
|
6138
|
-
type: "manual_edit",
|
|
6139
|
-
capability: "ai",
|
|
6140
|
-
required: true,
|
|
6141
|
-
file,
|
|
6142
|
-
reason: "unsupported_shape",
|
|
6143
|
-
message: `${file} was customised, so the Puck AI plugin wasn't added automatically.`,
|
|
6144
|
-
instructions: `Add the Puck AI plugin to the <Puck> editor in ${file}, import "@puckeditor/plugin-ai/styles.css", and wrap the config with withDynamicConfig wherever you <Render> Puck pages.`,
|
|
6145
|
-
snippet: AI_SNIPPET
|
|
6146
|
-
});
|
|
6147
|
-
};
|
|
6148
|
-
var EDITOR2 = "src/puck/editor.tsx";
|
|
6149
|
-
var CATCH_ALL_PAGE = "src/pages/[...puckPath].astro";
|
|
6150
|
-
var PAGES_EDITOR3 = "src/pages/puck.astro";
|
|
6151
|
-
var PAGES_LIB2 = "src/lib/pages.ts";
|
|
6152
|
-
var PAGES_API2 = "src/pages/api/pages.ts";
|
|
6153
|
-
var editorVariants2 = (p) => ({
|
|
6154
|
-
from: EDITOR2,
|
|
6155
|
-
to: EDITOR2,
|
|
6156
|
-
opts: astroRelocation(p),
|
|
6157
|
-
combos: flagCombos("ai", "pages", "auth"),
|
|
6158
|
-
source: ({ ai, pages, auth }) => {
|
|
6159
|
-
const code = pages ? vitePagesEditor({ ai }) : templateText(p.templates, ai ? "astro-ai" : "astro", EDITOR2);
|
|
6160
|
-
return auth ? withAuthPlugin(code, EDITOR2) : code;
|
|
6161
|
-
}
|
|
6162
|
-
});
|
|
6163
|
-
var gateRecipeCatchAll = (code) => {
|
|
6164
|
-
const resolved = "const { isEditorRoute, path } = resolvePuckPath(Astro.url.pathname);";
|
|
6165
|
-
return code.replace(
|
|
6166
|
-
resolved,
|
|
6167
|
-
`${resolved}
|
|
6168
|
-
|
|
6169
|
-
// Editing requires Sign in with Puck
|
|
6170
|
-
const signIn = isEditorRoute ? await puckSignInUrl(Astro.request) : null;
|
|
6171
|
-
if (signIn) return Astro.redirect(signIn);
|
|
6172
|
-
`
|
|
6173
|
-
).replace(
|
|
6174
|
-
'import { getPage } from "../lib/pages";',
|
|
6175
|
-
'import { getPage } from "../lib/pages";\nimport { puckSignInUrl } from "../lib/puck-auth";'
|
|
6176
|
-
);
|
|
6177
|
-
};
|
|
6178
|
-
var catchAllVariants = (p) => ({
|
|
6179
|
-
from: CATCH_ALL_PAGE,
|
|
6180
|
-
to: CATCH_ALL_PAGE,
|
|
6181
|
-
opts: astroRelocation(p),
|
|
6182
|
-
combos: flagCombos("pages", "auth"),
|
|
6183
|
-
source: ({ pages, auth }) => {
|
|
6184
|
-
if (pages) return ASTRO_PAGES_CATCH_ALL;
|
|
6185
|
-
const code = templateText(p.templates, "astro", CATCH_ALL_PAGE);
|
|
6186
|
-
return auth ? gateRecipeCatchAll(code) : code;
|
|
6187
|
-
}
|
|
6188
|
-
});
|
|
6189
|
-
var pagesEditorVariants3 = (p, server) => ({
|
|
6190
|
-
from: PAGES_EDITOR3,
|
|
6191
|
-
to: PAGES_EDITOR3,
|
|
6192
|
-
opts: astroRelocation(p),
|
|
6193
|
-
combos: flagCombos("auth"),
|
|
6194
|
-
source: ({ auth }) => astroPagesEditorPage({ server, auth })
|
|
6195
|
-
});
|
|
6196
|
-
var planAstroPages = (p, info) => {
|
|
6197
|
-
const mode = modeOf2(p, info);
|
|
6198
|
-
const onServer = mode === "local" || mode === "add";
|
|
6199
|
-
const manual = (file, snippet) => p.manual({
|
|
6200
|
-
id: `pages:${file}`,
|
|
6201
|
-
type: "manual_edit",
|
|
6202
|
-
capability: "pages",
|
|
6203
|
-
required: true,
|
|
6204
|
-
file,
|
|
6205
|
-
reason: "unsupported_shape",
|
|
6206
|
-
message: `${file} was customised or moved, so it wasn't changed to use Puck Pages.`,
|
|
6207
|
-
instructions: `Update ${file} to match this version, which uses pages stored in Puck Cloud.`,
|
|
6208
|
-
snippet
|
|
6209
|
-
});
|
|
6210
|
-
const ok = (outcome) => outcome === "upgraded" || outcome === "already";
|
|
6211
|
-
const want = { pages: true };
|
|
6212
|
-
if (!ok(
|
|
6213
|
-
upgradeVariant(p, {
|
|
6214
|
-
...editorVariants2(p),
|
|
6215
|
-
want,
|
|
6216
|
-
capability: "pages",
|
|
6217
|
-
summary: `Add the Puck Pages plugin to ${EDITOR2}`
|
|
6218
|
-
})
|
|
6219
|
-
))
|
|
6220
|
-
manual(EDITOR2, vitePagesEditor({ ai: false }));
|
|
6221
|
-
let auth = false;
|
|
6222
|
-
if (onServer) {
|
|
6223
|
-
const catchAll = upgradeVariant(p, {
|
|
6224
|
-
...catchAllVariants(p),
|
|
6225
|
-
want,
|
|
6226
|
-
capability: "pages",
|
|
6227
|
-
summary: `Render pages published in Puck Cloud in ${CATCH_ALL_PAGE}`,
|
|
6228
|
-
onMatch: (flags) => auth = flags.auth
|
|
6229
|
-
});
|
|
6230
|
-
if (!ok(catchAll)) manual(CATCH_ALL_PAGE, ASTRO_PAGES_CATCH_ALL);
|
|
6231
|
-
const api = upgradeVariant(p, {
|
|
6232
|
-
from: PAGES_API2,
|
|
6233
|
-
to: PAGES_API2,
|
|
6234
|
-
opts: astroRelocation(p),
|
|
6235
|
-
combos: [{ pages: false }, { pages: true }],
|
|
6236
|
-
source: ({ pages }) => pages ? ASTRO_PAGES_API : templateText(p.templates, "astro", PAGES_API2),
|
|
6237
|
-
want,
|
|
6238
|
-
capability: "pages",
|
|
6239
|
-
summary: `Serve pages published in Puck Cloud from ${PAGES_API2}`
|
|
6240
|
-
});
|
|
6241
|
-
if (ok(api) || api === "missing") {
|
|
6242
|
-
const lib = upgradeVariant(p, {
|
|
6243
|
-
from: PAGES_LIB2,
|
|
6244
|
-
to: PAGES_LIB2,
|
|
6245
|
-
opts: astroRelocation(p),
|
|
6246
|
-
combos: [{ pages: false }, { pages: true }],
|
|
6247
|
-
source: ({ pages }) => pages ? astroPagesLib(p.cloudHost) : templateText(p.templates, "astro", PAGES_LIB2),
|
|
6248
|
-
want,
|
|
6249
|
-
capability: "pages",
|
|
6250
|
-
summary: `Read published pages from Puck Cloud in ${PAGES_LIB2}`
|
|
6251
|
-
});
|
|
6252
|
-
if (!ok(lib)) manual(PAGES_LIB2, astroPagesLib(p.cloudHost));
|
|
6253
|
-
} else {
|
|
6254
|
-
manual(PAGES_API2, ASTRO_PAGES_API);
|
|
6255
|
-
manual(PAGES_LIB2, astroPagesLib(p.cloudHost));
|
|
6256
|
-
}
|
|
6257
|
-
warnLocalPages(p);
|
|
6258
|
-
} else {
|
|
6259
|
-
p.warn(
|
|
6260
|
-
"PUCK-CLI-W-EXTERNAL-PAGES",
|
|
6261
|
-
`Pages are loaded from ${p.backend?.url ?? "the server /api is proxied to"}. Run \`npx @puckeditor/cli add pages\` in that server's project, so /api/pages serves pages published in Puck Cloud.`
|
|
6262
|
-
);
|
|
6263
|
-
}
|
|
6264
|
-
const page = astroPagesEditorPage({ server: onServer, auth });
|
|
6265
|
-
if (p.createFile(PAGES_EDITOR3, page, {
|
|
6266
|
-
capability: "pages",
|
|
6267
|
-
summary: `Create ${PAGES_EDITOR3} (the Puck Pages editor)`
|
|
6268
|
-
}) === "conflict")
|
|
6269
|
-
manual(PAGES_EDITOR3, page);
|
|
6270
|
-
};
|
|
6271
|
-
var planAstroAuth = (p, info) => {
|
|
6272
|
-
const mode = modeOf2(p, info);
|
|
6273
|
-
const onServer = mode === "local" || mode === "add";
|
|
6274
|
-
if (onServer) {
|
|
6275
|
-
const helper = "src/lib/puck-auth.ts";
|
|
6276
|
-
if (p.createFile(helper, astroPuckAuth(p.cloudHost), {
|
|
6277
|
-
capability: "auth",
|
|
6278
|
-
summary: `Create ${helper} (requires Sign in with Puck)`
|
|
6279
|
-
}) === "conflict") {
|
|
6280
|
-
p.manual({
|
|
6281
|
-
id: "auth:helper",
|
|
6282
|
-
type: "manual_edit",
|
|
6283
|
-
capability: "auth",
|
|
6284
|
-
required: true,
|
|
6285
|
-
file: helper,
|
|
6286
|
-
reason: "conflict",
|
|
6287
|
-
message: `${helper} already exists with different content.`,
|
|
6288
|
-
instructions: `Export puckSignInUrl from ${helper}, or move your file and re-run the command.`,
|
|
6289
|
-
snippet: astroPuckAuth(p.cloudHost)
|
|
6290
|
-
});
|
|
6291
|
-
}
|
|
6292
|
-
const pagesEditor = p.vfs.exists(p.abs(PAGES_EDITOR3));
|
|
6293
|
-
const upgrade = {
|
|
6294
|
-
want: { auth: true },
|
|
6295
|
-
capability: "auth",
|
|
6296
|
-
summary: `Require Sign in with Puck in ${pagesEditor ? PAGES_EDITOR3 : CATCH_ALL_PAGE}`
|
|
6297
|
-
};
|
|
6298
|
-
const gate = pagesEditor ? upgradeVariant(p, { ...pagesEditorVariants3(p, true), ...upgrade }) : upgradeVariant(p, { ...catchAllVariants(p), ...upgrade });
|
|
6299
|
-
if (gate === "customized" || gate === "missing") {
|
|
6300
|
-
p.manual({
|
|
6301
|
-
id: "auth:editor-gate",
|
|
6302
|
-
type: "manual_edit",
|
|
6303
|
-
capability: "auth",
|
|
6304
|
-
required: false,
|
|
6305
|
-
file: pagesEditor ? PAGES_EDITOR3 : CATCH_ALL_PAGE,
|
|
6306
|
-
reason: "unsupported_shape",
|
|
6307
|
-
message: "Your editor page was customised, so it doesn't send signed-out visitors to sign in.",
|
|
6308
|
-
instructions: "Redirect to puckSignInUrl in the frontmatter of the page that renders your editor. The Puck Cloud API route already requires Sign in with Puck.",
|
|
6309
|
-
snippet: `import { puckSignInUrl } from "../lib/puck-auth";
|
|
6310
|
-
|
|
6311
|
-
const signIn = await puckSignInUrl(Astro.request);
|
|
6312
|
-
if (signIn) return Astro.redirect(signIn);
|
|
6313
|
-
`
|
|
6314
|
-
});
|
|
6315
|
-
}
|
|
6316
|
-
planRouteAuth(p);
|
|
6317
|
-
} else {
|
|
6318
|
-
p.warn(
|
|
6319
|
-
"PUCK-CLI-W-EXTERNAL-AUTH",
|
|
6320
|
-
`Puck Cloud requests go to ${p.backend?.url ?? "the server /api is proxied to"}. Run \`npx @puckeditor/cli add auth\` in that server's project to require Sign in with Puck there.`
|
|
6321
|
-
);
|
|
6322
|
-
}
|
|
6323
|
-
planAuthPlugin(p, EDITOR2);
|
|
4439
|
+
id: "ai:editor",
|
|
4440
|
+
type: "manual_edit",
|
|
4441
|
+
capability: "ai",
|
|
4442
|
+
required: true,
|
|
4443
|
+
file,
|
|
4444
|
+
reason: "unsupported_shape",
|
|
4445
|
+
message: `${file} was customised, so the Puck AI plugin wasn't added automatically.`,
|
|
4446
|
+
instructions: `Add the Puck AI plugin to the <Puck> editor in ${file}, import "@puckeditor/plugin-ai/styles.css", and wrap the config with withDynamicConfig wherever you <Render> Puck pages.`,
|
|
4447
|
+
snippet: AI_SNIPPET
|
|
4448
|
+
});
|
|
6324
4449
|
};
|
|
6325
4450
|
var astroAdapter = {
|
|
6326
4451
|
recipe: (withAi) => withAi ? "astro-ai" : "astro",
|
|
@@ -6341,8 +4466,6 @@ var astroAdapter = {
|
|
|
6341
4466
|
planEditor: planAstroEditor,
|
|
6342
4467
|
planCloudRoute: planAstroCloudRoute,
|
|
6343
4468
|
planAi: (p) => planAstroAi(p),
|
|
6344
|
-
planPages: planAstroPages,
|
|
6345
|
-
planAuth: planAstroAuth,
|
|
6346
4469
|
devUrl: "http://localhost:4321/edit",
|
|
6347
4470
|
deployEnvWarning: `.env.local is only loaded in development. Set ${ENV_KEY} in the environment wherever the Astro server runs.`
|
|
6348
4471
|
};
|
|
@@ -6361,13 +4484,13 @@ var ADAPTERS = {
|
|
|
6361
4484
|
var adapterFor = (info) => ADAPTERS[info.id];
|
|
6362
4485
|
|
|
6363
4486
|
// src/output/summary.ts
|
|
6364
|
-
import
|
|
4487
|
+
import path16 from "path";
|
|
6365
4488
|
|
|
6366
4489
|
// src/detect/state.ts
|
|
6367
|
-
import
|
|
4490
|
+
import path15 from "path";
|
|
6368
4491
|
|
|
6369
4492
|
// src/env/files.ts
|
|
6370
|
-
import
|
|
4493
|
+
import path14 from "path";
|
|
6371
4494
|
|
|
6372
4495
|
// src/env/dotenv.ts
|
|
6373
4496
|
var LINE = /^(\s*)(export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=\s*(.*)$/;
|
|
@@ -6431,7 +4554,7 @@ var findApiKey = (vfs, envDir, processEnv) => {
|
|
|
6431
4554
|
};
|
|
6432
4555
|
}
|
|
6433
4556
|
for (const name of DEV_ENV_FILES) {
|
|
6434
|
-
const file =
|
|
4557
|
+
const file = path14.join(envDir, name);
|
|
6435
4558
|
const text = vfs.readText(file);
|
|
6436
4559
|
if (text === null) continue;
|
|
6437
4560
|
const value = parseEnv(text)[ENV_KEY];
|
|
@@ -6448,25 +4571,25 @@ var CONFIG_CANDIDATES = ["tsx", "ts", "jsx", "js"].map(
|
|
|
6448
4571
|
);
|
|
6449
4572
|
var findConfig = (vfs, ctx, configFlag) => {
|
|
6450
4573
|
if (configFlag) {
|
|
6451
|
-
const abs =
|
|
6452
|
-
return vfs.exists(abs) ? toPosix(
|
|
4574
|
+
const abs = path15.resolve(ctx.cwd, configFlag);
|
|
4575
|
+
return vfs.exists(abs) ? toPosix(path15.relative(ctx.root, abs)) : null;
|
|
6453
4576
|
}
|
|
6454
4577
|
const dirs = ctx.framework ? adapterFor(ctx.framework).configDirs(ctx.framework) : ["", "src"];
|
|
6455
4578
|
for (const dir of dirs) {
|
|
6456
4579
|
for (const candidate of CONFIG_CANDIDATES) {
|
|
6457
4580
|
const rel = dir ? `${dir}/${candidate}` : candidate;
|
|
6458
|
-
if (vfs.exists(
|
|
4581
|
+
if (vfs.exists(path15.join(ctx.root, rel))) return rel;
|
|
6459
4582
|
}
|
|
6460
4583
|
}
|
|
6461
4584
|
return null;
|
|
6462
4585
|
};
|
|
6463
|
-
var envDirFor = (ctx) => ctx.framework ?
|
|
4586
|
+
var envDirFor = (ctx) => ctx.framework ? path15.join(ctx.root, adapterFor(ctx.framework).envDir(ctx.framework)) : ctx.root;
|
|
6464
4587
|
var detectState = (vfs, ctx, env2, opts = {}) => {
|
|
6465
4588
|
const scan = scanSources(vfs, ctx.root);
|
|
6466
4589
|
const configFile = findConfig(vfs, ctx, opts.configFlag);
|
|
6467
4590
|
let configExports = null;
|
|
6468
4591
|
if (configFile) {
|
|
6469
|
-
const code = vfs.readText(
|
|
4592
|
+
const code = vfs.readText(path15.join(ctx.root, configFile));
|
|
6470
4593
|
const ast = code ? tryParseModule(code, configFile) : null;
|
|
6471
4594
|
configExports = ast ? getExportShape(ast) : null;
|
|
6472
4595
|
}
|
|
@@ -6477,13 +4600,12 @@ var detectState = (vfs, ctx, env2, opts = {}) => {
|
|
|
6477
4600
|
ctx.root,
|
|
6478
4601
|
scan
|
|
6479
4602
|
) : null;
|
|
6480
|
-
const routeCode = route?.routeFile ? vfs.readText(path16.join(ctx.root, route.routeFile)) : null;
|
|
6481
4603
|
const envDir = envDirFor(ctx);
|
|
6482
4604
|
const apiKey = findApiKey(vfs, envDir, env2);
|
|
6483
4605
|
const gitignoreRoot2 = ctx.gitRoot ?? ctx.workspace?.root ?? ctx.root;
|
|
6484
4606
|
return {
|
|
6485
4607
|
target: adapter?.kind === "server" ? "server" : "app",
|
|
6486
|
-
|
|
4608
|
+
pages: ctx.framework && adapter?.detectPages ? adapter.detectPages(ctx.framework, vfs, ctx.root) : null,
|
|
6487
4609
|
scan,
|
|
6488
4610
|
puck: {
|
|
6489
4611
|
installed: CORE_PACKAGE in ctx.deps,
|
|
@@ -6507,24 +4629,15 @@ var detectState = (vfs, ctx, env2, opts = {}) => {
|
|
|
6507
4629
|
ai: {
|
|
6508
4630
|
installed: PLUGIN_AI_PACKAGE in ctx.deps,
|
|
6509
4631
|
declaredRange: ctx.deps[PLUGIN_AI_PACKAGE] ?? null
|
|
6510
|
-
},
|
|
6511
|
-
pages: {
|
|
6512
|
-
pluginInstalled: PLUGIN_PAGES_PACKAGE in ctx.deps,
|
|
6513
|
-
declaredRange: ctx.deps[PLUGIN_PAGES_PACKAGE] ?? null
|
|
6514
|
-
},
|
|
6515
|
-
auth: {
|
|
6516
|
-
pluginInstalled: PLUGIN_AUTH_PACKAGE in ctx.deps,
|
|
6517
|
-
declaredRange: ctx.deps[PLUGIN_AUTH_PACKAGE] ?? null,
|
|
6518
|
-
routeAuthenticated: Boolean(routeCode && requiresSignIn(routeCode))
|
|
6519
4632
|
}
|
|
6520
4633
|
};
|
|
6521
4634
|
};
|
|
6522
4635
|
var capabilityStatus = (state) => {
|
|
6523
4636
|
const editorMissing = [];
|
|
6524
4637
|
if (state.target === "server") {
|
|
6525
|
-
if (!state.
|
|
6526
|
-
else if (!state.
|
|
6527
|
-
editorMissing.push(`${state.
|
|
4638
|
+
if (!state.pages) editorMissing.push("No Puck pages API found");
|
|
4639
|
+
else if (!state.pages.mounted)
|
|
4640
|
+
editorMissing.push(`${state.pages.file} isn't mounted on the app`);
|
|
6528
4641
|
} else {
|
|
6529
4642
|
if (!state.puck.installed)
|
|
6530
4643
|
editorMissing.push(`${CORE_PACKAGE} is not installed`);
|
|
@@ -6551,44 +4664,22 @@ var capabilityStatus = (state) => {
|
|
|
6551
4664
|
if (state.scan.aiPluginFiles.length === 0)
|
|
6552
4665
|
aiMissing.push("The Puck AI plugin isn't added to the editor");
|
|
6553
4666
|
}
|
|
6554
|
-
const pagesMissing = state.target === "server" ? [...cloudMissing] : [];
|
|
6555
|
-
if (state.target === "app") {
|
|
6556
|
-
if (!state.pages.pluginInstalled)
|
|
6557
|
-
pagesMissing.push(`${PLUGIN_PAGES_PACKAGE} is not installed`);
|
|
6558
|
-
if (state.scan.pagesPluginFiles.length === 0)
|
|
6559
|
-
pagesMissing.push("The Puck Pages plugin isn't added to the editor");
|
|
6560
|
-
}
|
|
6561
|
-
if (!state.cloud.external && state.scan.cloudPageFiles.length === 0)
|
|
6562
|
-
pagesMissing.push("Nothing renders published pages from Puck Cloud");
|
|
6563
|
-
const authMissing = state.target === "server" ? [...cloudMissing] : [];
|
|
6564
|
-
if (state.target === "app") {
|
|
6565
|
-
if (!state.auth.pluginInstalled)
|
|
6566
|
-
authMissing.push(`${PLUGIN_AUTH_PACKAGE} is not installed`);
|
|
6567
|
-
if (state.scan.authPluginFiles.length === 0)
|
|
6568
|
-
authMissing.push("The Puck Auth plugin isn't added to the editor");
|
|
6569
|
-
}
|
|
6570
|
-
if (!state.cloud.external && !state.auth.routeAuthenticated)
|
|
6571
|
-
authMissing.push("The Puck Cloud API route doesn't use Sign in with Puck");
|
|
6572
4667
|
return {
|
|
6573
4668
|
editor: { satisfied: editorMissing.length === 0, missing: editorMissing },
|
|
6574
4669
|
cloud: { satisfied: cloudMissing.length === 0, missing: cloudMissing },
|
|
6575
|
-
ai: { satisfied: aiMissing.length === 0, missing: aiMissing }
|
|
6576
|
-
pages: { satisfied: pagesMissing.length === 0, missing: pagesMissing },
|
|
6577
|
-
auth: { satisfied: authMissing.length === 0, missing: authMissing }
|
|
4670
|
+
ai: { satisfied: aiMissing.length === 0, missing: aiMissing }
|
|
6578
4671
|
};
|
|
6579
4672
|
};
|
|
6580
4673
|
|
|
6581
4674
|
// src/output/summary.ts
|
|
6582
4675
|
var displayPath = (base, abs) => {
|
|
6583
|
-
const rel = toPosix(
|
|
4676
|
+
const rel = toPosix(path16.relative(base, abs));
|
|
6584
4677
|
return rel === "" ? "." : rel;
|
|
6585
4678
|
};
|
|
6586
4679
|
var capabilityLabels = (server) => ({
|
|
6587
4680
|
editor: server ? "Puck pages API" : "Puck Editor",
|
|
6588
4681
|
cloud: "Puck Cloud",
|
|
6589
|
-
ai: "Puck AI"
|
|
6590
|
-
pages: "Puck Pages",
|
|
6591
|
-
auth: "Puck Auth"
|
|
4682
|
+
ai: "Puck AI"
|
|
6592
4683
|
});
|
|
6593
4684
|
var projectSummary = (ctx, workspace = null) => ({
|
|
6594
4685
|
root: ctx.root,
|
|
@@ -6620,14 +4711,6 @@ var aiSummary = (state) => ({
|
|
|
6620
4711
|
installed: state.ai.installed,
|
|
6621
4712
|
configured: capabilityStatus(state).ai.satisfied
|
|
6622
4713
|
});
|
|
6623
|
-
var pagesSummary = (state) => ({
|
|
6624
|
-
installed: state.target === "server" ? state.scan.cloudPageFiles.length > 0 : state.pages.pluginInstalled,
|
|
6625
|
-
configured: capabilityStatus(state).pages.satisfied
|
|
6626
|
-
});
|
|
6627
|
-
var authSummary = (state) => ({
|
|
6628
|
-
installed: state.target === "server" ? state.auth.routeAuthenticated : state.auth.pluginInstalled,
|
|
6629
|
-
configured: capabilityStatus(state).auth.satisfied
|
|
6630
|
-
});
|
|
6631
4714
|
|
|
6632
4715
|
// src/output/present.ts
|
|
6633
4716
|
var presentJson = (out, result, secrets) => {
|
|
@@ -6645,12 +4728,6 @@ var actionLines = (action) => {
|
|
|
6645
4728
|
` and confirm the code ${pc.bold(action.userCode)}`
|
|
6646
4729
|
);
|
|
6647
4730
|
break;
|
|
6648
|
-
case "claim_project":
|
|
6649
|
-
lines.push(
|
|
6650
|
-
` Open ${pc.cyan(action.url)}`,
|
|
6651
|
-
` before ${new Date(action.expiresAt).toLocaleString()}`
|
|
6652
|
-
);
|
|
6653
|
-
break;
|
|
6654
4731
|
case "provide_api_key":
|
|
6655
4732
|
lines.push(` ${action.instructions}`);
|
|
6656
4733
|
break;
|
|
@@ -6669,18 +4746,13 @@ var actionLines = (action) => {
|
|
|
6669
4746
|
case "provide_app_name":
|
|
6670
4747
|
lines.push(` ${action.flag} ${action.suggested}`);
|
|
6671
4748
|
break;
|
|
6672
|
-
case "
|
|
6673
|
-
const width = Math.max(...action.choices.map((c) => c.label.length));
|
|
4749
|
+
case "choose_ai":
|
|
6674
4750
|
lines.push(
|
|
6675
4751
|
...action.choices.map(
|
|
6676
|
-
(c) => ` ${c.value.padEnd(8)} ${c.label
|
|
6677
|
-
|
|
6678
|
-
)}`
|
|
6679
|
-
),
|
|
6680
|
-
` ${action.none.padEnd(8)} ${pc.dim("None of them")}`
|
|
4752
|
+
(c) => ` ${c.value.padEnd(8)} ${pc.dim(c.label)}`
|
|
4753
|
+
)
|
|
6681
4754
|
);
|
|
6682
4755
|
break;
|
|
6683
|
-
}
|
|
6684
4756
|
case "choose_backend":
|
|
6685
4757
|
lines.push(
|
|
6686
4758
|
...action.choices.map(
|
|
@@ -6734,18 +4806,6 @@ var statusTable = (result) => {
|
|
|
6734
4806
|
result.ai.configured ? pc.green("configured") : result.ai.installed ? pc.yellow("installed, not added to the editor") : pc.dim("not installed")
|
|
6735
4807
|
]);
|
|
6736
4808
|
}
|
|
6737
|
-
if (result.pages?.installed) {
|
|
6738
|
-
rows.push([
|
|
6739
|
-
"Puck Pages",
|
|
6740
|
-
result.pages.configured ? pc.green("configured") : pc.yellow("installed, not set up")
|
|
6741
|
-
]);
|
|
6742
|
-
}
|
|
6743
|
-
if (result.auth?.installed) {
|
|
6744
|
-
rows.push([
|
|
6745
|
-
"Puck Auth",
|
|
6746
|
-
result.auth.configured ? pc.green("configured") : pc.yellow("installed, not set up")
|
|
6747
|
-
]);
|
|
6748
|
-
}
|
|
6749
4809
|
const width = Math.max(...rows.map(([k]) => k.length), 0) + 2;
|
|
6750
4810
|
return rows.map(([k, v]) => `${k.padEnd(width)}${v}`);
|
|
6751
4811
|
};
|
|
@@ -6888,11 +4948,11 @@ var presentHuman = (out, result, secrets) => {
|
|
|
6888
4948
|
};
|
|
6889
4949
|
|
|
6890
4950
|
// src/commands/init.ts
|
|
6891
|
-
import
|
|
4951
|
+
import path28 from "path";
|
|
6892
4952
|
|
|
6893
4953
|
// src/io/vfs.ts
|
|
6894
4954
|
import fs2 from "fs";
|
|
6895
|
-
import
|
|
4955
|
+
import path17 from "path";
|
|
6896
4956
|
import { createHash } from "crypto";
|
|
6897
4957
|
var hashContent = (content) => createHash("sha256").update(content).digest("hex");
|
|
6898
4958
|
var readDisk = (p) => {
|
|
@@ -6942,10 +5002,10 @@ var Vfs = class {
|
|
|
6942
5002
|
}
|
|
6943
5003
|
} catch {
|
|
6944
5004
|
}
|
|
6945
|
-
const prefix = dir.endsWith(
|
|
5005
|
+
const prefix = dir.endsWith(path17.sep) ? dir : dir + path17.sep;
|
|
6946
5006
|
for (const p of this.#overlay.keys()) {
|
|
6947
5007
|
if (!p.startsWith(prefix)) continue;
|
|
6948
|
-
const [first, ...rest] = p.slice(prefix.length).split(
|
|
5008
|
+
const [first, ...rest] = p.slice(prefix.length).split(path17.sep);
|
|
6949
5009
|
entries.set(first, rest.length > 0 || entries.get(first) === true);
|
|
6950
5010
|
}
|
|
6951
5011
|
return [...entries.entries()].map(([name, isDir]) => ({ name, isDir })).sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -6976,7 +5036,7 @@ var Vfs = class {
|
|
|
6976
5036
|
);
|
|
6977
5037
|
}
|
|
6978
5038
|
#overlayHasDescendant(p) {
|
|
6979
|
-
const prefix = p.endsWith(
|
|
5039
|
+
const prefix = p.endsWith(path17.sep) ? p : p + path17.sep;
|
|
6980
5040
|
for (const key of this.#overlay.keys()) {
|
|
6981
5041
|
if (key.startsWith(prefix)) return true;
|
|
6982
5042
|
}
|
|
@@ -6985,14 +5045,14 @@ var Vfs = class {
|
|
|
6985
5045
|
};
|
|
6986
5046
|
|
|
6987
5047
|
// src/detect/project.ts
|
|
6988
|
-
import
|
|
5048
|
+
import path19 from "path";
|
|
6989
5049
|
|
|
6990
5050
|
// src/detect/workspace.ts
|
|
6991
|
-
import
|
|
5051
|
+
import path18 from "path";
|
|
6992
5052
|
import { globSync } from "tinyglobby";
|
|
6993
5053
|
import { parse as parseYaml } from "yaml";
|
|
6994
5054
|
var readGlobs = (vfs, dir) => {
|
|
6995
|
-
const yamlText = vfs.readText(
|
|
5055
|
+
const yamlText = vfs.readText(path18.join(dir, "pnpm-workspace.yaml"));
|
|
6996
5056
|
if (yamlText !== null) {
|
|
6997
5057
|
try {
|
|
6998
5058
|
const parsed = parseYaml(yamlText);
|
|
@@ -7027,7 +5087,7 @@ var expandWorkspace = (vfs, root, globs) => {
|
|
|
7027
5087
|
absolute: false
|
|
7028
5088
|
}
|
|
7029
5089
|
);
|
|
7030
|
-
return files.map((file) =>
|
|
5090
|
+
return files.map((file) => path18.join(root, path18.dirname(file))).filter((dir) => dir !== root).sort().map((dir) => {
|
|
7031
5091
|
const read = readPackageJson(vfs, dir);
|
|
7032
5092
|
return { dir, name: read.status === "ok" ? read.pkg.name ?? null : null };
|
|
7033
5093
|
});
|
|
@@ -7042,7 +5102,7 @@ var findWorkspace = (vfs, startDir, stopAt) => {
|
|
|
7042
5102
|
packages: expandWorkspace(vfs, dir, globs.globs)
|
|
7043
5103
|
};
|
|
7044
5104
|
}
|
|
7045
|
-
const parent =
|
|
5105
|
+
const parent = path18.dirname(dir);
|
|
7046
5106
|
if (dir === stopAt || parent === dir) return null;
|
|
7047
5107
|
dir = parent;
|
|
7048
5108
|
}
|
|
@@ -7062,8 +5122,8 @@ var IGNORABLE_ENTRIES = /* @__PURE__ */ new Set([
|
|
|
7062
5122
|
]);
|
|
7063
5123
|
var findGitRoot = (vfs, start) => {
|
|
7064
5124
|
for (let dir = start; ; ) {
|
|
7065
|
-
if (vfs.exists(
|
|
7066
|
-
const parent =
|
|
5125
|
+
if (vfs.exists(path19.join(dir, ".git"))) return dir;
|
|
5126
|
+
const parent = path19.dirname(dir);
|
|
7067
5127
|
if (parent === dir) return null;
|
|
7068
5128
|
dir = parent;
|
|
7069
5129
|
}
|
|
@@ -7121,7 +5181,7 @@ var detectProject = ({
|
|
|
7121
5181
|
packageManager,
|
|
7122
5182
|
framework,
|
|
7123
5183
|
frameworkError,
|
|
7124
|
-
typescript: vfs.exists(
|
|
5184
|
+
typescript: vfs.exists(path19.join(root, "tsconfig.json")),
|
|
7125
5185
|
gitRoot,
|
|
7126
5186
|
isEmptyDir: vfs.isDir(root) ? isEmptyDir(vfs, root) : true,
|
|
7127
5187
|
workspace,
|
|
@@ -7130,36 +5190,30 @@ var detectProject = ({
|
|
|
7130
5190
|
};
|
|
7131
5191
|
|
|
7132
5192
|
// src/plan/bootstrap.ts
|
|
7133
|
-
import
|
|
5193
|
+
import path20 from "path";
|
|
7134
5194
|
|
|
7135
5195
|
// src/templates/transform.ts
|
|
7136
5196
|
var WORKSPACE_PROTOCOL = /^workspace:/;
|
|
7137
5197
|
var transformPackageJson = (text, {
|
|
7138
5198
|
appName,
|
|
7139
5199
|
cliVersion,
|
|
7140
|
-
legacy
|
|
7141
|
-
canary = {}
|
|
5200
|
+
legacy
|
|
7142
5201
|
}) => {
|
|
7143
5202
|
const pkg = JSON.parse(text);
|
|
7144
5203
|
pkg.name = appName;
|
|
7145
5204
|
const pinned = [];
|
|
7146
|
-
let prerelease = false;
|
|
7147
5205
|
for (const field of ["dependencies", "devDependencies"]) {
|
|
7148
5206
|
const deps = pkg[field];
|
|
7149
5207
|
if (!deps) continue;
|
|
7150
5208
|
delete deps["eslint-config-custom"];
|
|
7151
5209
|
for (const [name, range] of Object.entries(deps)) {
|
|
7152
5210
|
if (legacy?.dependencies[name]) deps[name] = legacy.dependencies[name];
|
|
7153
|
-
if (WORKSPACE_PROTOCOL.test(range))
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
prerelease ||= deps[name].includes("-");
|
|
7157
|
-
} else if (canary[name]) {
|
|
7158
|
-
deps[name] = canary[name];
|
|
7159
|
-
}
|
|
5211
|
+
if (!WORKSPACE_PROTOCOL.test(range)) continue;
|
|
5212
|
+
deps[name] = `^${cliVersion}`;
|
|
5213
|
+
pinned.push(name);
|
|
7160
5214
|
}
|
|
7161
5215
|
}
|
|
7162
|
-
if (
|
|
5216
|
+
if (cliVersion.includes("-") && pinned.length > 0) {
|
|
7163
5217
|
pkg.overrides = {
|
|
7164
5218
|
...pkg.overrides,
|
|
7165
5219
|
...Object.fromEntries(pinned.map((name) => [name, `$${name}`]))
|
|
@@ -7209,12 +5263,11 @@ var scaffoldApp = (vfs, templates2, {
|
|
|
7209
5263
|
appName,
|
|
7210
5264
|
cliVersion,
|
|
7211
5265
|
cloudHost,
|
|
7212
|
-
legacy
|
|
7213
|
-
canary
|
|
5266
|
+
legacy
|
|
7214
5267
|
}) => {
|
|
7215
5268
|
const files = templates2.list(recipe);
|
|
7216
5269
|
for (const rel of files) {
|
|
7217
|
-
const target =
|
|
5270
|
+
const target = path20.join(dir, ...rel.split("/"));
|
|
7218
5271
|
const raw = templates2.read(recipe, rel);
|
|
7219
5272
|
const legacyFile = legacy?.files[rel];
|
|
7220
5273
|
if (legacyFile) {
|
|
@@ -7225,8 +5278,7 @@ var scaffoldApp = (vfs, templates2, {
|
|
|
7225
5278
|
transformPackageJson(raw.toString("utf8"), {
|
|
7226
5279
|
appName,
|
|
7227
5280
|
cliVersion,
|
|
7228
|
-
legacy
|
|
7229
|
-
canary
|
|
5281
|
+
legacy
|
|
7230
5282
|
})
|
|
7231
5283
|
);
|
|
7232
5284
|
} else if (rel === "tsconfig.json") {
|
|
@@ -7242,9 +5294,9 @@ var scaffoldApp = (vfs, templates2, {
|
|
|
7242
5294
|
|
|
7243
5295
|
// src/commands/target.ts
|
|
7244
5296
|
import fs3 from "fs";
|
|
7245
|
-
import
|
|
5297
|
+
import path21 from "path";
|
|
7246
5298
|
var baseDir = (rc) => {
|
|
7247
|
-
const dir =
|
|
5299
|
+
const dir = path21.resolve(rc.deps.cwd, rc.flags.cwd ?? ".");
|
|
7248
5300
|
if (!fs3.existsSync(dir) || !fs3.statSync(dir).isDirectory()) {
|
|
7249
5301
|
throw new CliError("PUCK-CLI-CWD-NOT-FOUND", `Directory not found: ${dir}`);
|
|
7250
5302
|
}
|
|
@@ -7303,7 +5355,7 @@ var resolveTarget = async (rc, opts = {}) => {
|
|
|
7303
5355
|
const wanted = rc.flags.workspace.replace(/\/+$/, "");
|
|
7304
5356
|
const apps2 = listWorkspaceApps(vfs, workspace);
|
|
7305
5357
|
const match = apps2.find(
|
|
7306
|
-
(a) => a.name === wanted || a.dir ===
|
|
5358
|
+
(a) => a.name === wanted || a.dir === path21.resolve(base, wanted) || a.dir === path21.resolve(workspace.root, wanted)
|
|
7307
5359
|
);
|
|
7308
5360
|
if (!match) {
|
|
7309
5361
|
throw new CliError(
|
|
@@ -7389,10 +5441,10 @@ var resolveTarget = async (rc, opts = {}) => {
|
|
|
7389
5441
|
};
|
|
7390
5442
|
|
|
7391
5443
|
// src/commands/mutate.ts
|
|
7392
|
-
import
|
|
5444
|
+
import path27 from "path";
|
|
7393
5445
|
|
|
7394
5446
|
// src/plan/planner.ts
|
|
7395
|
-
import
|
|
5447
|
+
import path22 from "path";
|
|
7396
5448
|
var normalizeEol2 = (text) => text.replace(/\r\n/g, "\n");
|
|
7397
5449
|
var Planner = class {
|
|
7398
5450
|
constructor(vfs, ctx, state, templates2, cliVersion) {
|
|
@@ -7417,13 +5469,11 @@ var Planner = class {
|
|
|
7417
5469
|
backend;
|
|
7418
5470
|
/** Puck Cloud API host for puckHandler, when not the default */
|
|
7419
5471
|
cloudHost;
|
|
7420
|
-
/** Exact versions to install instead, with --canary */
|
|
7421
|
-
canary = {};
|
|
7422
5472
|
abs(rel) {
|
|
7423
|
-
return
|
|
5473
|
+
return path22.join(this.ctx.root, rel);
|
|
7424
5474
|
}
|
|
7425
5475
|
rel(abs) {
|
|
7426
|
-
return toPosix(
|
|
5476
|
+
return toPosix(path22.relative(this.ctx.root, abs));
|
|
7427
5477
|
}
|
|
7428
5478
|
createFile(rel, content, opts) {
|
|
7429
5479
|
const abs = this.abs(rel);
|
|
@@ -7448,8 +5498,6 @@ var Planner = class {
|
|
|
7448
5498
|
modifyFile(rel, content, opts) {
|
|
7449
5499
|
const abs = this.abs(rel);
|
|
7450
5500
|
this.vfs.write(abs, content);
|
|
7451
|
-
if (this.steps.some((s) => s.kind === "create_file" && s.path === abs))
|
|
7452
|
-
return;
|
|
7453
5501
|
const id2 = `${opts.capability}:modify:${rel}`;
|
|
7454
5502
|
const edits = (opts.inserted ?? []).map((e) => ({
|
|
7455
5503
|
line: lineOf(content, e.at),
|
|
@@ -7479,12 +5527,7 @@ var Planner = class {
|
|
|
7479
5527
|
}
|
|
7480
5528
|
addDependency(name, range, capability, opts = {}) {
|
|
7481
5529
|
if (!this.#dependencies.some((d) => d.name === name)) {
|
|
7482
|
-
this.#dependencies.push({
|
|
7483
|
-
name,
|
|
7484
|
-
range: this.canary[name] ?? range,
|
|
7485
|
-
capability,
|
|
7486
|
-
dev: opts.dev
|
|
7487
|
-
});
|
|
5530
|
+
this.#dependencies.push({ name, range, capability, dev: opts.dev });
|
|
7488
5531
|
}
|
|
7489
5532
|
}
|
|
7490
5533
|
/** Runs a framework's own setup command, e.g. `astro add react` */
|
|
@@ -7500,12 +5543,6 @@ var Planner = class {
|
|
|
7500
5543
|
/** Turns collected dependencies into one install, or folds them into a scaffolded or edited package.json */
|
|
7501
5544
|
finalize() {
|
|
7502
5545
|
if (this.#dependencies.length === 0) return;
|
|
7503
|
-
if (!(CLI_PACKAGE in this.ctx.deps)) {
|
|
7504
|
-
const range = this.cliVersion.includes("-") ? this.cliVersion : `^${this.cliVersion}`;
|
|
7505
|
-
this.addDependency(CLI_PACKAGE, range, this.#dependencies[0].capability, {
|
|
7506
|
-
dev: true
|
|
7507
|
-
});
|
|
7508
|
-
}
|
|
7509
5546
|
const specs = this.#dependencies.map((d) => `${d.name}@${d.range}`);
|
|
7510
5547
|
const pkgPath = this.abs("package.json");
|
|
7511
5548
|
if (this.scaffolded) {
|
|
@@ -7543,109 +5580,29 @@ var Planner = class {
|
|
|
7543
5580
|
}
|
|
7544
5581
|
};
|
|
7545
5582
|
|
|
7546
|
-
// src/plan/canary.ts
|
|
7547
|
-
var CANARY_PACKAGES = [
|
|
7548
|
-
CORE_PACKAGE,
|
|
7549
|
-
CLOUD_CLIENT_PACKAGE,
|
|
7550
|
-
PLUGIN_AI_PACKAGE,
|
|
7551
|
-
PLUGIN_PAGES_PACKAGE,
|
|
7552
|
-
PLUGIN_AUTH_PACKAGE
|
|
7553
|
-
];
|
|
7554
|
-
var DEFAULT_REGISTRY = "https://registry.npmjs.org";
|
|
7555
|
-
var TIMEOUT_MS2 = 15e3;
|
|
7556
|
-
var latestCanary = async (fetchImpl, registry, name, token) => {
|
|
7557
|
-
let packument;
|
|
7558
|
-
try {
|
|
7559
|
-
const res = await fetchImpl(
|
|
7560
|
-
`${registry.replace(/\/+$/, "")}/${name.replace("/", "%2f")}`,
|
|
7561
|
-
{
|
|
7562
|
-
headers: {
|
|
7563
|
-
accept: "application/json",
|
|
7564
|
-
// Private packages, e.g. plugins before their release
|
|
7565
|
-
...token ? { authorization: `Bearer ${token}` } : {}
|
|
7566
|
-
},
|
|
7567
|
-
signal: AbortSignal.timeout(TIMEOUT_MS2)
|
|
7568
|
-
}
|
|
7569
|
-
);
|
|
7570
|
-
if (!res.ok) return null;
|
|
7571
|
-
packument = await res.json();
|
|
7572
|
-
} catch {
|
|
7573
|
-
return null;
|
|
7574
|
-
}
|
|
7575
|
-
const tagged = packument["dist-tags"]?.canary;
|
|
7576
|
-
if (tagged) return tagged;
|
|
7577
|
-
const [newest] = Object.entries(packument.time ?? {}).filter(([version]) => /^\d+\.\d+\.\d+-/.test(version)).sort(([, a], [, b]) => b.localeCompare(a));
|
|
7578
|
-
return newest?.[0] ?? null;
|
|
7579
|
-
};
|
|
7580
|
-
var registryToken = (registry, npmrcs, env2) => {
|
|
7581
|
-
const url = new URL(registry);
|
|
7582
|
-
const key = `//${url.host}${url.pathname.replace(/\/*$/, "/")}:_authToken`;
|
|
7583
|
-
for (const npmrc of npmrcs) {
|
|
7584
|
-
for (const line of npmrc?.split(/\r?\n/) ?? []) {
|
|
7585
|
-
const match = /^\s*([^=#;\s]+)\s*=\s*(.*?)\s*$/.exec(line);
|
|
7586
|
-
if (match?.[1] !== key) continue;
|
|
7587
|
-
const token = match[2].replace(
|
|
7588
|
-
/\$\{([^}]+)\}/g,
|
|
7589
|
-
(_, name) => env2[name] ?? ""
|
|
7590
|
-
);
|
|
7591
|
-
if (token) return token;
|
|
7592
|
-
}
|
|
7593
|
-
}
|
|
7594
|
-
return null;
|
|
7595
|
-
};
|
|
7596
|
-
var resolveCanaries = async (fetchImpl, registry = DEFAULT_REGISTRY, token = null) => {
|
|
7597
|
-
const found = await Promise.all(
|
|
7598
|
-
CANARY_PACKAGES.map(
|
|
7599
|
-
async (name) => [name, await latestCanary(fetchImpl, registry, name, token)]
|
|
7600
|
-
)
|
|
7601
|
-
);
|
|
7602
|
-
return {
|
|
7603
|
-
versions: Object.fromEntries(
|
|
7604
|
-
found.filter(([, version]) => version !== null)
|
|
7605
|
-
),
|
|
7606
|
-
missing: found.filter(([, version]) => version === null).map(([n]) => n)
|
|
7607
|
-
};
|
|
7608
|
-
};
|
|
7609
|
-
|
|
7610
5583
|
// src/plan/capabilities.ts
|
|
7611
|
-
var CAPABILITY_IDS = [
|
|
7612
|
-
"editor",
|
|
7613
|
-
"cloud",
|
|
7614
|
-
"ai",
|
|
7615
|
-
"pages",
|
|
7616
|
-
"auth"
|
|
7617
|
-
];
|
|
5584
|
+
var CAPABILITY_IDS = ["editor", "cloud", "ai"];
|
|
7618
5585
|
var DEPENDS_ON = {
|
|
7619
5586
|
editor: [],
|
|
7620
5587
|
cloud: ["editor"],
|
|
7621
5588
|
// Puck Cloud is the backend; Puck AI is the editor plugin that uses it
|
|
7622
|
-
ai: ["cloud"]
|
|
7623
|
-
// Pages are stored in Puck Cloud, and Sign in with Puck is served by it
|
|
7624
|
-
pages: ["cloud"],
|
|
7625
|
-
auth: ["cloud"]
|
|
5589
|
+
ai: ["cloud"]
|
|
7626
5590
|
};
|
|
7627
|
-
var AUTH_RESOLVES = ["PUCK-CLI-W-PUBLIC-ROUTE", "PUCK-CLI-W-EDITOR-PUBLIC"];
|
|
7628
5591
|
var resolveCapabilities = (requested) => {
|
|
7629
|
-
const
|
|
5592
|
+
const ordered = [];
|
|
7630
5593
|
const visit = (id2) => {
|
|
7631
|
-
if (
|
|
7632
|
-
resolved.add(id2);
|
|
5594
|
+
if (ordered.includes(id2)) return;
|
|
7633
5595
|
DEPENDS_ON[id2].forEach(visit);
|
|
5596
|
+
ordered.push(id2);
|
|
7634
5597
|
};
|
|
7635
5598
|
requested.forEach(visit);
|
|
7636
|
-
return
|
|
7637
|
-
};
|
|
7638
|
-
var planCloudClientUpgrade = (p, capability) => {
|
|
7639
|
-
const range = p.templates.manifest().cloudClientPagesRange;
|
|
7640
|
-
if (atLeast(p.state.cloud.declaredRange, range)) return;
|
|
7641
|
-
p.addDependency(CLOUD_CLIENT_PACKAGE, range, capability);
|
|
5599
|
+
return ordered;
|
|
7642
5600
|
};
|
|
7643
5601
|
var planCapabilities = (p, capabilities) => {
|
|
7644
5602
|
const framework = p.ctx.framework;
|
|
7645
5603
|
const adapter = adapterFor(framework);
|
|
7646
5604
|
const status = capabilityStatus(p.state);
|
|
7647
5605
|
const withAi = capabilities.includes("ai");
|
|
7648
|
-
const withAuth = capabilities.includes("auth") || status.auth.satisfied;
|
|
7649
5606
|
let editorPlanned = false;
|
|
7650
5607
|
for (const id2 of capabilities) {
|
|
7651
5608
|
if (id2 === "editor") {
|
|
@@ -7661,8 +5618,7 @@ var planCapabilities = (p, capabilities) => {
|
|
|
7661
5618
|
);
|
|
7662
5619
|
continue;
|
|
7663
5620
|
}
|
|
7664
|
-
|
|
7665
|
-
if (!p.state.cloud.clientInstalled && !pagesOrAuth) {
|
|
5621
|
+
if (!p.state.cloud.clientInstalled) {
|
|
7666
5622
|
p.addDependency(
|
|
7667
5623
|
CLOUD_CLIENT_PACKAGE,
|
|
7668
5624
|
p.templates.manifest().cloudClientRange,
|
|
@@ -7688,49 +5644,11 @@ var planCapabilities = (p, capabilities) => {
|
|
|
7688
5644
|
if (editorPlanned || p.state.scan.aiPluginFiles.length > 0) continue;
|
|
7689
5645
|
adapter.planAi(p, framework);
|
|
7690
5646
|
}
|
|
7691
|
-
if (id2 === "pages") {
|
|
7692
|
-
if (status.pages.satisfied) continue;
|
|
7693
|
-
planCloudClientUpgrade(p, "pages");
|
|
7694
|
-
if (adapter.kind !== "server" && !p.state.pages.pluginInstalled) {
|
|
7695
|
-
p.addDependency(
|
|
7696
|
-
PLUGIN_PAGES_PACKAGE,
|
|
7697
|
-
p.templates.manifest().pluginPagesRange,
|
|
7698
|
-
"pages"
|
|
7699
|
-
);
|
|
7700
|
-
}
|
|
7701
|
-
adapter.planPages(p, framework);
|
|
7702
|
-
if (!withAuth) {
|
|
7703
|
-
p.warn(
|
|
7704
|
-
"PUCK-CLI-W-PAGES-UNAUTHENTICATED",
|
|
7705
|
-
`Anyone who can reach /api/puck can edit, publish and delete pages using your API key. Add Sign in with Puck with \`${CANONICAL_INVOCATION} add auth\` before deploying.`
|
|
7706
|
-
);
|
|
7707
|
-
}
|
|
7708
|
-
}
|
|
7709
|
-
if (id2 === "auth") {
|
|
7710
|
-
if (status.auth.satisfied) continue;
|
|
7711
|
-
planCloudClientUpgrade(p, "auth");
|
|
7712
|
-
if (adapter.kind !== "server" && !p.state.auth.pluginInstalled) {
|
|
7713
|
-
p.addDependency(
|
|
7714
|
-
PLUGIN_AUTH_PACKAGE,
|
|
7715
|
-
p.templates.manifest().pluginAuthRange,
|
|
7716
|
-
"auth"
|
|
7717
|
-
);
|
|
7718
|
-
}
|
|
7719
|
-
adapter.planAuth(p, framework);
|
|
7720
|
-
if (!capabilities.includes("pages") && !status.pages.satisfied) {
|
|
7721
|
-
p.warn(
|
|
7722
|
-
"PUCK-CLI-W-LOCAL-SAVE-PUBLIC",
|
|
7723
|
-
`Sign in with Puck protects the editor and Puck Cloud, but the editor still saves pages through your own route, which anyone can call. Store pages in Puck Cloud with \`${CANONICAL_INVOCATION} add pages\`, or protect that route.`
|
|
7724
|
-
);
|
|
7725
|
-
}
|
|
7726
|
-
}
|
|
7727
5647
|
}
|
|
7728
|
-
if (withAuth)
|
|
7729
|
-
p.warnings = p.warnings.filter((w) => !AUTH_RESOLVES.includes(w.code));
|
|
7730
5648
|
};
|
|
7731
5649
|
|
|
7732
5650
|
// src/plan/env.ts
|
|
7733
|
-
import
|
|
5651
|
+
import path23 from "path";
|
|
7734
5652
|
var gitignoreRoot = (p) => p.ctx.gitRoot ?? p.ctx.workspace?.root ?? p.ctx.root;
|
|
7735
5653
|
var planGitignore = (p, envFile) => {
|
|
7736
5654
|
if (isIgnored(p.vfs, envFile, gitignoreRoot(p))) return;
|
|
@@ -7740,7 +5658,7 @@ var planGitignore = (p, envFile) => {
|
|
|
7740
5658
|
p.ctx.root,
|
|
7741
5659
|
p.ctx.gitRoot
|
|
7742
5660
|
);
|
|
7743
|
-
const pattern =
|
|
5661
|
+
const pattern = path23.relative(path23.dirname(gitignore), envFile).split(path23.sep).join("/");
|
|
7744
5662
|
p.vfs.write(gitignore, content);
|
|
7745
5663
|
p.steps.push({
|
|
7746
5664
|
id: `cloud:gitignore:${p.rel(gitignore)}`,
|
|
@@ -7755,7 +5673,7 @@ var planEnvWrite = (p, secret) => {
|
|
|
7755
5673
|
const location = p.state.cloud.apiKey;
|
|
7756
5674
|
const envDir = p.state.cloud.envDir;
|
|
7757
5675
|
const root = gitignoreRoot(p);
|
|
7758
|
-
const target = location.file && isLocalEnvFile(location.source) && isIgnored(p.vfs, location.file, root) ? location.file :
|
|
5676
|
+
const target = location.file && isLocalEnvFile(location.source) && isIgnored(p.vfs, location.file, root) ? location.file : path23.join(envDir, ".env.local");
|
|
7759
5677
|
if (isSharedEnvFile(location.source)) {
|
|
7760
5678
|
p.warn(
|
|
7761
5679
|
"PUCK-CLI-W-KEY-IN-SHARED-ENV",
|
|
@@ -7782,7 +5700,7 @@ var planEnvWrite = (p, secret) => {
|
|
|
7782
5700
|
};
|
|
7783
5701
|
|
|
7784
5702
|
// src/plan/pnpm-builds.ts
|
|
7785
|
-
import
|
|
5703
|
+
import path24 from "path";
|
|
7786
5704
|
import { Document, isMap, isSeq, parseDocument } from "yaml";
|
|
7787
5705
|
var LEGACY_LISTS = [
|
|
7788
5706
|
"onlyBuiltDependencies",
|
|
@@ -7824,7 +5742,7 @@ var planAllowedBuilds = (planner) => {
|
|
|
7824
5742
|
if (ctx.packageManager.name !== "pnpm") return;
|
|
7825
5743
|
const ws = ctx.workspace;
|
|
7826
5744
|
if (ws && ws.source !== "pnpm-workspace.yaml") return;
|
|
7827
|
-
const file =
|
|
5745
|
+
const file = path24.join(ws?.root ?? ctx.root, "pnpm-workspace.yaml");
|
|
7828
5746
|
const names = templates_default.allowBuilds;
|
|
7829
5747
|
const list = names.join(", ");
|
|
7830
5748
|
const next = withAllowedBuilds(vfs.readText(file), names);
|
|
@@ -7910,14 +5828,14 @@ var resolveBackend = async (rc, options, capabilities, planned) => {
|
|
|
7910
5828
|
|
|
7911
5829
|
// src/auth/session-store.ts
|
|
7912
5830
|
import fs4 from "fs";
|
|
7913
|
-
import
|
|
5831
|
+
import path25 from "path";
|
|
7914
5832
|
import { createHash as createHash2 } from "crypto";
|
|
7915
5833
|
var SessionStore = class {
|
|
7916
5834
|
#file;
|
|
7917
5835
|
constructor(cacheDir, projectRoot, baseUrl) {
|
|
7918
5836
|
const key = createHash2("sha256").update(`${projectRoot}
|
|
7919
5837
|
${baseUrl}`).digest("hex").slice(0, 32);
|
|
7920
|
-
this.#file =
|
|
5838
|
+
this.#file = path25.join(cacheDir, "puck", "connect", `${key}.json`);
|
|
7921
5839
|
}
|
|
7922
5840
|
get path() {
|
|
7923
5841
|
return this.#file;
|
|
@@ -7931,14 +5849,14 @@ ${baseUrl}`).digest("hex").slice(0, 32);
|
|
|
7931
5849
|
}
|
|
7932
5850
|
}
|
|
7933
5851
|
save(session) {
|
|
7934
|
-
fs4.mkdirSync(
|
|
5852
|
+
fs4.mkdirSync(path25.dirname(this.#file), { recursive: true, mode: 448 });
|
|
7935
5853
|
fs4.writeFileSync(this.#file, JSON.stringify(session), { mode: 384 });
|
|
7936
5854
|
}
|
|
7937
5855
|
clear() {
|
|
7938
5856
|
fs4.rmSync(this.#file, { force: true });
|
|
7939
5857
|
}
|
|
7940
5858
|
};
|
|
7941
|
-
var cacheDirFor = (env2, homedir) => env2.XDG_CACHE_HOME ||
|
|
5859
|
+
var cacheDirFor = (env2, homedir) => env2.XDG_CACHE_HOME || path25.join(homedir, ".cache");
|
|
7942
5860
|
|
|
7943
5861
|
// src/auth/credentials.ts
|
|
7944
5862
|
var apiKeysUrl = (rc) => new URL(API_KEYS_PATH, rc.cloud.baseUrl).toString();
|
|
@@ -7972,7 +5890,6 @@ var clientPayload = (rc, info) => ({
|
|
|
7972
5890
|
hostname: rc.deps.hostname.slice(0, 100),
|
|
7973
5891
|
projectName: info.projectName?.slice(0, 100),
|
|
7974
5892
|
framework: info.framework,
|
|
7975
|
-
branch: info.branch,
|
|
7976
5893
|
anonymousId: rc.telemetry?.anonymousId ?? void 0
|
|
7977
5894
|
});
|
|
7978
5895
|
var onApproved = (rc, approved) => {
|
|
@@ -8014,28 +5931,6 @@ var connectFallback = (rc, err) => {
|
|
|
8014
5931
|
warnings: []
|
|
8015
5932
|
};
|
|
8016
5933
|
};
|
|
8017
|
-
var startUnclaimed = async (rc, info) => {
|
|
8018
|
-
let created;
|
|
8019
|
-
try {
|
|
8020
|
-
created = await rc.cloud.createClaimableProject(clientPayload(rc, info));
|
|
8021
|
-
} catch (err) {
|
|
8022
|
-
return connectFallback(rc, err);
|
|
8023
|
-
}
|
|
8024
|
-
if (!created) return null;
|
|
8025
|
-
const secret = secretFrom(rc, created.apiKey, "Puck Cloud");
|
|
8026
|
-
rc.log(
|
|
8027
|
-
`\u2713 Created the Puck Cloud project "${created.project.name}" without an account (key "${created.keyName}")`
|
|
8028
|
-
);
|
|
8029
|
-
return {
|
|
8030
|
-
kind: "resolved",
|
|
8031
|
-
secret,
|
|
8032
|
-
source: "connect",
|
|
8033
|
-
needsWrite: true,
|
|
8034
|
-
verified: "valid",
|
|
8035
|
-
warnings: [],
|
|
8036
|
-
claim: { url: created.claimUrl, expiresAt: created.expiresAt }
|
|
8037
|
-
};
|
|
8038
|
-
};
|
|
8039
5934
|
var connectNonInteractive = async (rc, info, attempt = 0) => {
|
|
8040
5935
|
const store = new SessionStore(
|
|
8041
5936
|
cacheDirFor(rc.deps.env, rc.deps.homedir),
|
|
@@ -8043,10 +5938,6 @@ var connectNonInteractive = async (rc, info, attempt = 0) => {
|
|
|
8043
5938
|
rc.cloud.baseUrl
|
|
8044
5939
|
);
|
|
8045
5940
|
let session = store.load();
|
|
8046
|
-
if (session && session.branch !== info.branch) {
|
|
8047
|
-
store.clear();
|
|
8048
|
-
session = null;
|
|
8049
|
-
}
|
|
8050
5941
|
if (session && session.expiresAt <= rc.deps.now()) {
|
|
8051
5942
|
store.clear();
|
|
8052
5943
|
session = null;
|
|
@@ -8060,8 +5951,7 @@ var connectNonInteractive = async (rc, info, attempt = 0) => {
|
|
|
8060
5951
|
userCode: started.userCode,
|
|
8061
5952
|
verificationUriComplete: started.verificationUriComplete,
|
|
8062
5953
|
expiresAt: rc.deps.now() + started.expiresIn * 1e3,
|
|
8063
|
-
interval: started.interval
|
|
8064
|
-
branch: info.branch
|
|
5954
|
+
interval: started.interval
|
|
8065
5955
|
};
|
|
8066
5956
|
store.save(session);
|
|
8067
5957
|
if (!rc.flags.wait)
|
|
@@ -8254,22 +6144,10 @@ var resolveCredential = async (rc, state, info, { fresh = false } = {}) => {
|
|
|
8254
6144
|
"How do you want to connect to Puck Cloud?",
|
|
8255
6145
|
[
|
|
8256
6146
|
{ value: "login", name: "Log in with the browser (recommended)" },
|
|
8257
|
-
// `connect` replaces the key, often for a branch, so it always logs in
|
|
8258
|
-
...fresh ? [] : [
|
|
8259
|
-
{
|
|
8260
|
-
value: "unclaimed",
|
|
8261
|
-
name: "Start without an account (claim it within 72 hours)"
|
|
8262
|
-
}
|
|
8263
|
-
],
|
|
8264
6147
|
{ value: "paste", name: "Paste an existing API key" }
|
|
8265
6148
|
]
|
|
8266
6149
|
);
|
|
8267
|
-
if (method === "
|
|
8268
|
-
const started = await startUnclaimed(rc, info);
|
|
8269
|
-
if (started?.kind === "resolved") return { ...started, warnings };
|
|
8270
|
-
rc.log("Couldn't start without an account. Log in instead.");
|
|
8271
|
-
}
|
|
8272
|
-
if (method === "login" || method === "unclaimed") {
|
|
6150
|
+
if (method === "login") {
|
|
8273
6151
|
const connected = await connectInteractive(rc, info);
|
|
8274
6152
|
if (connected) return { ...connected, warnings };
|
|
8275
6153
|
rc.log("Falling back to pasting an API key.");
|
|
@@ -8291,18 +6169,13 @@ var resolveCredential = async (rc, state, info, { fresh = false } = {}) => {
|
|
|
8291
6169
|
}
|
|
8292
6170
|
};
|
|
8293
6171
|
}
|
|
8294
|
-
if (!fresh && !rc.flags.login) {
|
|
8295
|
-
const started = await startUnclaimed(rc, info);
|
|
8296
|
-
if (started)
|
|
8297
|
-
return { ...started, warnings: [...warnings, ...started.warnings] };
|
|
8298
|
-
}
|
|
8299
6172
|
const resolution = await connectNonInteractive(rc, info);
|
|
8300
6173
|
return { ...resolution, warnings: [...warnings, ...resolution.warnings] };
|
|
8301
6174
|
};
|
|
8302
6175
|
|
|
8303
6176
|
// src/apply/applier.ts
|
|
8304
6177
|
import fs5 from "fs";
|
|
8305
|
-
import
|
|
6178
|
+
import path26 from "path";
|
|
8306
6179
|
var tail = (text, lines = 20) => text.trim().split("\n").slice(-lines).join("\n");
|
|
8307
6180
|
var run = async (rc, spec) => {
|
|
8308
6181
|
rc.log(`$ ${formatCommand(spec)}`);
|
|
@@ -8332,14 +6205,14 @@ ${result.stderr}`))
|
|
|
8332
6205
|
}
|
|
8333
6206
|
};
|
|
8334
6207
|
var writeFile = (file, content, mode) => {
|
|
8335
|
-
fs5.mkdirSync(
|
|
6208
|
+
fs5.mkdirSync(path26.dirname(file), { recursive: true });
|
|
8336
6209
|
if (mode === void 0) {
|
|
8337
6210
|
fs5.writeFileSync(file, content);
|
|
8338
6211
|
return;
|
|
8339
6212
|
}
|
|
8340
|
-
const temp =
|
|
8341
|
-
|
|
8342
|
-
`.${
|
|
6213
|
+
const temp = path26.join(
|
|
6214
|
+
path26.dirname(file),
|
|
6215
|
+
`.${path26.basename(file)}.${process.pid}.tmp`
|
|
8343
6216
|
);
|
|
8344
6217
|
fs5.writeFileSync(temp, content, { mode });
|
|
8345
6218
|
fs5.chmodSync(temp, mode);
|
|
@@ -8466,18 +6339,6 @@ var runMutation = async (rc, input) => {
|
|
|
8466
6339
|
const bootstrap = input.bootstrap;
|
|
8467
6340
|
const root = bootstrap?.dir ?? input.root;
|
|
8468
6341
|
const cloudHost = deps.env.PUCK_CLOUD_URL ? `${deps.env.PUCK_CLOUD_URL.replace(/\/+$/, "")}/api` : void 0;
|
|
8469
|
-
const registry = deps.env.npm_config_registry || DEFAULT_REGISTRY;
|
|
8470
|
-
const canary = flags.canary || isTruthyEnv(deps.env.PUCK_CANARY) ? await resolveCanaries(
|
|
8471
|
-
deps.fetch,
|
|
8472
|
-
registry,
|
|
8473
|
-
registryToken(
|
|
8474
|
-
registry,
|
|
8475
|
-
[base, deps.homedir].map(
|
|
8476
|
-
(dir) => vfs.readText(path28.join(dir, ".npmrc"))
|
|
8477
|
-
),
|
|
8478
|
-
deps.env
|
|
8479
|
-
)
|
|
8480
|
-
) : null;
|
|
8481
6342
|
let scaffoldStep = null;
|
|
8482
6343
|
let legacy = null;
|
|
8483
6344
|
if (bootstrap) {
|
|
@@ -8490,8 +6351,7 @@ var runMutation = async (rc, input) => {
|
|
|
8490
6351
|
appName: bootstrap.appName,
|
|
8491
6352
|
cliVersion: deps.cliVersion,
|
|
8492
6353
|
cloudHost,
|
|
8493
|
-
legacy
|
|
8494
|
-
canary: canary?.versions
|
|
6354
|
+
legacy
|
|
8495
6355
|
});
|
|
8496
6356
|
scaffoldStep = {
|
|
8497
6357
|
id: "bootstrap:scaffold",
|
|
@@ -8517,15 +6377,6 @@ var runMutation = async (rc, input) => {
|
|
|
8517
6377
|
const planner = new Planner(vfs, ctx, state, deps.templates, deps.cliVersion);
|
|
8518
6378
|
planner.scaffolded = Boolean(bootstrap);
|
|
8519
6379
|
planner.cloudHost = cloudHost;
|
|
8520
|
-
if (canary) {
|
|
8521
|
-
planner.canary = canary.versions;
|
|
8522
|
-
if (canary.missing.length) {
|
|
8523
|
-
planner.warn(
|
|
8524
|
-
"PUCK-CLI-W-NO-CANARY",
|
|
8525
|
-
`No canary of ${canary.missing.join(", ")} was found, so ${canary.missing.length === 1 ? "its" : "their"} usual version is installed.`
|
|
8526
|
-
);
|
|
8527
|
-
}
|
|
8528
|
-
}
|
|
8529
6380
|
if (legacy) planner.warn("PUCK-CLI-W-NODE-VERSION", legacy.warning);
|
|
8530
6381
|
for (const warning of ctx.warnings)
|
|
8531
6382
|
planner.warn("PUCK-CLI-W-DETECTION", warning);
|
|
@@ -8534,8 +6385,6 @@ var runMutation = async (rc, input) => {
|
|
|
8534
6385
|
result.puck = puckSummary(state);
|
|
8535
6386
|
result.cloud = cloudSummary(state, "none");
|
|
8536
6387
|
result.ai = aiSummary(state);
|
|
8537
|
-
result.pages = pagesSummary(state);
|
|
8538
|
-
result.auth = authSummary(state);
|
|
8539
6388
|
};
|
|
8540
6389
|
const finishWithoutChanges = (status2, message, actions2) => {
|
|
8541
6390
|
summaries();
|
|
@@ -8606,7 +6455,7 @@ var runMutation = async (rc, input) => {
|
|
|
8606
6455
|
if (wantsCloud) {
|
|
8607
6456
|
credential = await resolveCredential(rc, state, {
|
|
8608
6457
|
projectRoot: root,
|
|
8609
|
-
projectName: bootstrap?.appName ?? ctx.packageJson?.name ??
|
|
6458
|
+
projectName: bootstrap?.appName ?? ctx.packageJson?.name ?? path27.basename(root),
|
|
8610
6459
|
framework: ctx.framework.id
|
|
8611
6460
|
});
|
|
8612
6461
|
for (const w of credential.warnings) planner.warn(w.code, w.message);
|
|
@@ -8617,24 +6466,6 @@ var runMutation = async (rc, input) => {
|
|
|
8617
6466
|
[credential.action]
|
|
8618
6467
|
);
|
|
8619
6468
|
}
|
|
8620
|
-
if (credential.kind === "resolved" && credential.claim) {
|
|
8621
|
-
const { url, expiresAt } = credential.claim;
|
|
8622
|
-
planner.manual({
|
|
8623
|
-
id: "cloud:claim",
|
|
8624
|
-
type: "claim_project",
|
|
8625
|
-
required: false,
|
|
8626
|
-
message: "Ask the developer to claim this Puck Cloud project before it expires, or it's deleted with its pages.",
|
|
8627
|
-
url,
|
|
8628
|
-
expiresAt,
|
|
8629
|
-
instructions: `Open ${url} and sign up or log in before ${expiresAt}. ${ENV_KEY} keeps working once it's claimed.`
|
|
8630
|
-
});
|
|
8631
|
-
if (capabilities.includes("ai") || state.ai.installed) {
|
|
8632
|
-
planner.warn(
|
|
8633
|
-
"PUCK-CLI-W-AI-UNCLAIMED",
|
|
8634
|
-
`Puck AI works once the project is claimed. Open ${url} to claim it.`
|
|
8635
|
-
);
|
|
8636
|
-
}
|
|
8637
|
-
}
|
|
8638
6469
|
if (credential.kind === "resolved" && credential.needsWrite) {
|
|
8639
6470
|
planEnvWrite(planner, credential.secret);
|
|
8640
6471
|
} else if (credential.kind === "resolved" && state.cloud.apiKey.file) {
|
|
@@ -8701,8 +6532,6 @@ var runMutation = async (rc, input) => {
|
|
|
8701
6532
|
result.puck = puckSummary(verifiedState);
|
|
8702
6533
|
result.cloud = cloudSummary(verifiedState, verified);
|
|
8703
6534
|
result.ai = aiSummary(verifiedState);
|
|
8704
|
-
result.pages = pagesSummary(verifiedState);
|
|
8705
|
-
result.auth = authSummary(verifiedState);
|
|
8706
6535
|
result.plan = { steps: serializeSteps(base, planner.steps) };
|
|
8707
6536
|
result.changed = planner.steps.length > 0;
|
|
8708
6537
|
result.filesCreated = outcome.created.map((f) => displayPath(base, f)).sort();
|
|
@@ -8727,10 +6556,7 @@ var runMutation = async (rc, input) => {
|
|
|
8727
6556
|
...rc.deps.platform === "win32" ? devSteps : [devSteps.join(" && ")],
|
|
8728
6557
|
`# then open ${adapterFor(verifiedCtx.framework ?? ctx.framework).devUrl}`
|
|
8729
6558
|
];
|
|
8730
|
-
|
|
8731
|
-
(c) => capabilities.includes(c) || status[c].satisfied
|
|
8732
|
-
);
|
|
8733
|
-
if (wantsCloud && !usesCloud) {
|
|
6559
|
+
if (wantsCloud && !capabilities.includes("ai") && !status.ai.satisfied) {
|
|
8734
6560
|
result.warnings.push({
|
|
8735
6561
|
code: "PUCK-CLI-W-NO-CLIENT-PLUGIN",
|
|
8736
6562
|
message: "Puck Cloud is set up, but nothing in the editor uses it yet. Add Puck AI with `npx @puckeditor/cli add ai`."
|
|
@@ -8774,79 +6600,30 @@ var validateName = (name) => {
|
|
|
8774
6600
|
);
|
|
8775
6601
|
}
|
|
8776
6602
|
};
|
|
8777
|
-
var EXTRAS = {
|
|
8778
|
-
app: [
|
|
8779
|
-
{
|
|
8780
|
-
value: "ai",
|
|
8781
|
-
name: "Puck AI",
|
|
8782
|
-
description: "Generate and edit pages with AI"
|
|
8783
|
-
},
|
|
8784
|
-
{
|
|
8785
|
-
value: "pages",
|
|
8786
|
-
name: "Puck Pages",
|
|
8787
|
-
description: "Store, publish and version pages in Puck Cloud"
|
|
8788
|
-
},
|
|
8789
|
-
{
|
|
8790
|
-
value: "auth",
|
|
8791
|
-
name: "Puck Auth",
|
|
8792
|
-
description: "Require Sign in with Puck to edit"
|
|
8793
|
-
}
|
|
8794
|
-
],
|
|
8795
|
-
server: [
|
|
8796
|
-
{
|
|
8797
|
-
value: "ai",
|
|
8798
|
-
name: "Puck AI",
|
|
8799
|
-
description: "Serve Puck AI for your editor"
|
|
8800
|
-
},
|
|
8801
|
-
{
|
|
8802
|
-
value: "pages",
|
|
8803
|
-
name: "Puck Pages",
|
|
8804
|
-
description: "Serve pages published in Puck Cloud"
|
|
8805
|
-
},
|
|
8806
|
-
{
|
|
8807
|
-
value: "auth",
|
|
8808
|
-
name: "Puck Auth",
|
|
8809
|
-
description: "Require Sign in with Puck for Puck Cloud requests"
|
|
8810
|
-
}
|
|
8811
|
-
]
|
|
8812
|
-
};
|
|
8813
|
-
var EXTRA_IDS = ["ai", "pages", "auth"];
|
|
8814
|
-
var chosenByFlags = ({ flags }) => {
|
|
8815
|
-
const on = { ai: flags.ai, pages: flags.pages, auth: flags.auth };
|
|
8816
|
-
const off = { ai: flags.noAi, pages: flags.noPages, auth: flags.noAuth };
|
|
8817
|
-
if (flags.editorOnly) return [];
|
|
8818
|
-
if (EXTRA_IDS.some((id2) => on[id2])) return EXTRA_IDS.filter((id2) => on[id2]);
|
|
8819
|
-
if (EXTRA_IDS.some((id2) => off[id2]))
|
|
8820
|
-
return EXTRA_IDS.filter((id2) => !off[id2]);
|
|
8821
|
-
return null;
|
|
8822
|
-
};
|
|
8823
6603
|
var chooseCapabilities = async (rc, alreadySetUp, server) => {
|
|
8824
|
-
|
|
8825
|
-
if (
|
|
6604
|
+
if (rc.flags.ai) return ["editor", "ai"];
|
|
6605
|
+
if (rc.flags.noAi) return ["editor"];
|
|
8826
6606
|
if (alreadySetUp) return ["editor", "ai"];
|
|
8827
6607
|
if (!rc.interactive) return null;
|
|
8828
|
-
const
|
|
8829
|
-
"
|
|
8830
|
-
|
|
8831
|
-
...extra,
|
|
8832
|
-
checked: true
|
|
8833
|
-
}))
|
|
6608
|
+
const withAi = await rc.prompter.confirm(
|
|
6609
|
+
server ? "Serve Puck AI from this server? (sets up Puck Cloud, requires a Puck Cloud account)" : "Add Puck AI? (includes Puck Cloud, requires a Puck Cloud account)",
|
|
6610
|
+
false
|
|
8834
6611
|
);
|
|
8835
|
-
return ["editor",
|
|
6612
|
+
return withAi ? ["editor", "ai"] : ["editor"];
|
|
8836
6613
|
};
|
|
8837
|
-
var
|
|
8838
|
-
var
|
|
8839
|
-
id: "init:
|
|
8840
|
-
type: "
|
|
6614
|
+
var AI_CHOICE_FLAGS = "<--ai|--no-ai>";
|
|
6615
|
+
var aiChoiceAction = (server = false) => ({
|
|
6616
|
+
id: "init:ai",
|
|
6617
|
+
type: "choose_ai",
|
|
8841
6618
|
required: true,
|
|
8842
|
-
message:
|
|
8843
|
-
choices:
|
|
8844
|
-
value:
|
|
8845
|
-
label:
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
6619
|
+
message: server ? "Choose whether this server should serve Puck AI for your editor. It sets up Puck Cloud and requires a Puck Cloud account." : "Choose whether to add Puck AI. It includes Puck Cloud and requires a Puck Cloud account.",
|
|
6620
|
+
choices: server ? [
|
|
6621
|
+
{ value: "--ai", label: "Pages API, Puck Cloud and Puck AI" },
|
|
6622
|
+
{ value: "--no-ai", label: "Pages API only" }
|
|
6623
|
+
] : [
|
|
6624
|
+
{ value: "--ai", label: "Add Puck AI and Puck Cloud" },
|
|
6625
|
+
{ value: "--no-ai", label: "Editor only" }
|
|
6626
|
+
]
|
|
8850
6627
|
});
|
|
8851
6628
|
var runInit = async (rc) => {
|
|
8852
6629
|
const base = baseDir(rc);
|
|
@@ -8873,14 +6650,14 @@ var runInit = async (rc) => {
|
|
|
8873
6650
|
{ globs: target.workspace.globs }
|
|
8874
6651
|
);
|
|
8875
6652
|
}
|
|
8876
|
-
parentDir =
|
|
6653
|
+
parentDir = path28.join(target.workspace.root, appsDir);
|
|
8877
6654
|
workspaceRoot = target.workspace.root;
|
|
8878
6655
|
for (const pkg of target.workspace.packages) {
|
|
8879
6656
|
if (pkg.name) existingNames.add(pkg.name);
|
|
8880
|
-
existingNames.add(
|
|
6657
|
+
existingNames.add(path28.basename(pkg.dir));
|
|
8881
6658
|
}
|
|
8882
6659
|
} else {
|
|
8883
|
-
if (vfs.exists(
|
|
6660
|
+
if (vfs.exists(path28.join(target.root, "package.json"))) {
|
|
8884
6661
|
const read = readPackageJson(vfs, target.root);
|
|
8885
6662
|
const deps = depsOf(read.status === "ok" ? read.pkg : null);
|
|
8886
6663
|
const detection = detectFramework(vfs, target.root, deps);
|
|
@@ -8891,11 +6668,11 @@ var runInit = async (rc) => {
|
|
|
8891
6668
|
server
|
|
8892
6669
|
);
|
|
8893
6670
|
if (!requested) {
|
|
8894
|
-
const action =
|
|
8895
|
-
action.rerun = `${rerunCommand(rc)} ${
|
|
6671
|
+
const action = aiChoiceAction(server);
|
|
6672
|
+
action.rerun = `${rerunCommand(rc)} ${AI_CHOICE_FLAGS}`;
|
|
8896
6673
|
const result = emptyResult("init", rc.flags.dryRun);
|
|
8897
6674
|
result.status = "action_required";
|
|
8898
|
-
result.message = "Choose
|
|
6675
|
+
result.message = "Choose whether to add Puck AI; no changes have been made.";
|
|
8899
6676
|
result.actions = [action];
|
|
8900
6677
|
return result;
|
|
8901
6678
|
}
|
|
@@ -8948,16 +6725,12 @@ var runInit = async (rc) => {
|
|
|
8948
6725
|
});
|
|
8949
6726
|
}
|
|
8950
6727
|
}
|
|
8951
|
-
if (!rc.interactive && !
|
|
8952
|
-
missing.push(
|
|
8953
|
-
capabilitiesAction(
|
|
8954
|
-
Boolean(framework) && ADAPTERS[framework].kind === "server"
|
|
8955
|
-
)
|
|
8956
|
-
);
|
|
6728
|
+
if (!rc.interactive && !rc.flags.ai && !rc.flags.noAi) {
|
|
6729
|
+
missing.push(aiChoiceAction());
|
|
8957
6730
|
}
|
|
8958
6731
|
if (missing.length > 0) {
|
|
8959
6732
|
const flags = missing.map(
|
|
8960
|
-
(a) => a.type === "choose_framework" ? `--framework <${FRAMEWORK_IDS.join("|")}>` : a.type === "
|
|
6733
|
+
(a) => a.type === "choose_framework" ? `--framework <${FRAMEWORK_IDS.join("|")}>` : a.type === "choose_ai" ? AI_CHOICE_FLAGS : "--name <name>"
|
|
8961
6734
|
);
|
|
8962
6735
|
for (const action of missing)
|
|
8963
6736
|
action.rerun = `${rerunCommand(rc)} ${flags.join(" ")}`;
|
|
@@ -8974,7 +6747,7 @@ var runInit = async (rc) => {
|
|
|
8974
6747
|
`A workspace package named "${name}" already exists.`
|
|
8975
6748
|
);
|
|
8976
6749
|
}
|
|
8977
|
-
const dir = inPlace ? parentDir :
|
|
6750
|
+
const dir = inPlace ? parentDir : path28.join(parentDir, name);
|
|
8978
6751
|
if (!inPlace && vfs.exists(dir) && !isEmptyDir(vfs, dir)) {
|
|
8979
6752
|
throw new CliError(
|
|
8980
6753
|
"PUCK-CLI-TARGET-DIR-NOT-EMPTY",
|
|
@@ -8993,7 +6766,7 @@ var runInit = async (rc) => {
|
|
|
8993
6766
|
bootstrap: {
|
|
8994
6767
|
framework,
|
|
8995
6768
|
dir,
|
|
8996
|
-
appName: name ?? sanitizeAppName(
|
|
6769
|
+
appName: name ?? sanitizeAppName(path28.basename(dir)),
|
|
8997
6770
|
workspaceRoot
|
|
8998
6771
|
},
|
|
8999
6772
|
workspace: target.kind === "workspace-empty" ? target.summary : null
|
|
@@ -9046,18 +6819,9 @@ var runAdd = async (rc, positionals) => {
|
|
|
9046
6819
|
};
|
|
9047
6820
|
|
|
9048
6821
|
// src/commands/connect.ts
|
|
9049
|
-
import
|
|
9050
|
-
var
|
|
9051
|
-
var isValidBranchName = (name) => name.length <= 255 && BRANCH_NAME.test(name) && !name.includes("..") && !name.includes("//") && !name.endsWith("/") && !name.endsWith(".");
|
|
9052
|
-
var runConnect = async (rc, positionals = []) => {
|
|
6822
|
+
import path29 from "path";
|
|
6823
|
+
var runConnect = async (rc) => {
|
|
9053
6824
|
const { deps, flags } = rc;
|
|
9054
|
-
const [branch, ...rest] = positionals;
|
|
9055
|
-
if (rest.length > 0 || branch !== void 0 && !isValidBranchName(branch)) {
|
|
9056
|
-
throw new CliError(
|
|
9057
|
-
"PUCK-CLI-INVALID-ARGS",
|
|
9058
|
-
`Usage: \`${CANONICAL_INVOCATION} connect [branch]\`, where branch is a Puck Cloud branch name like feature/new-hero.`
|
|
9059
|
-
);
|
|
9060
|
-
}
|
|
9061
6825
|
const result = emptyResult("connect", flags.dryRun);
|
|
9062
6826
|
const target = await resolveTarget(rc);
|
|
9063
6827
|
if (target.kind === "action") {
|
|
@@ -9132,9 +6896,8 @@ var runConnect = async (rc, positionals = []) => {
|
|
|
9132
6896
|
state,
|
|
9133
6897
|
{
|
|
9134
6898
|
projectRoot: root,
|
|
9135
|
-
projectName: ctx.packageJson?.name ??
|
|
9136
|
-
framework: ctx.framework.id
|
|
9137
|
-
branch
|
|
6899
|
+
projectName: ctx.packageJson?.name ?? path29.basename(root),
|
|
6900
|
+
framework: ctx.framework.id
|
|
9138
6901
|
},
|
|
9139
6902
|
{ fresh: true }
|
|
9140
6903
|
);
|
|
@@ -9246,8 +7009,6 @@ var runStatus = async (rc) => {
|
|
|
9246
7009
|
result.puck = puckSummary(state);
|
|
9247
7010
|
result.cloud = cloudSummary(state);
|
|
9248
7011
|
result.ai = aiSummary(state);
|
|
9249
|
-
result.pages = pagesSummary(state);
|
|
9250
|
-
result.auth = authSummary(state);
|
|
9251
7012
|
result.warnings = ctx.warnings.map((message) => ({
|
|
9252
7013
|
code: "PUCK-CLI-W-DETECTION",
|
|
9253
7014
|
message
|
|
@@ -9267,14 +7028,12 @@ var runStatus = async (rc) => {
|
|
|
9267
7028
|
result.message = `${label2.editor}, Puck Cloud and Puck AI are set up.`;
|
|
9268
7029
|
result.nextSteps = [`${CANONICAL_INVOCATION} doctor${where}`];
|
|
9269
7030
|
}
|
|
9270
|
-
if (status.pages.satisfied && !status.auth.satisfied)
|
|
9271
|
-
result.nextSteps.push(`${CANONICAL_INVOCATION} add auth${where}`);
|
|
9272
7031
|
if (target.note) result.nextSteps.unshift(`# ${target.note}`);
|
|
9273
7032
|
return result;
|
|
9274
7033
|
};
|
|
9275
7034
|
|
|
9276
7035
|
// src/commands/doctor.ts
|
|
9277
|
-
import
|
|
7036
|
+
import path30 from "path";
|
|
9278
7037
|
var finding = (check, status, evidence, fix = null) => ({ check, status, evidence, fix });
|
|
9279
7038
|
var runDoctor = async (rc) => {
|
|
9280
7039
|
const base = baseDir(rc);
|
|
@@ -9359,7 +7118,7 @@ var runDoctor = async (rc) => {
|
|
|
9359
7118
|
finding(
|
|
9360
7119
|
"project.package_json",
|
|
9361
7120
|
"ok",
|
|
9362
|
-
displayPath(base,
|
|
7121
|
+
displayPath(base, path30.join(ctx.root, "package.json"))
|
|
9363
7122
|
)
|
|
9364
7123
|
);
|
|
9365
7124
|
result.project = projectSummary(ctx, target.workspace);
|
|
@@ -9420,10 +7179,10 @@ var runDoctor = async (rc) => {
|
|
|
9420
7179
|
const pm = ctx.packageManager.name;
|
|
9421
7180
|
if (state.target === "server") {
|
|
9422
7181
|
findings.push(
|
|
9423
|
-
state.
|
|
7182
|
+
state.pages?.mounted ? finding("puck.pages_api", "ok", state.pages.file) : finding(
|
|
9424
7183
|
"puck.pages_api",
|
|
9425
7184
|
"fail",
|
|
9426
|
-
state.
|
|
7185
|
+
state.pages ? `${state.pages.file} isn't mounted on the app` : "No Puck pages API found",
|
|
9427
7186
|
`${CANONICAL_INVOCATION} add editor${where}`
|
|
9428
7187
|
)
|
|
9429
7188
|
);
|
|
@@ -9577,74 +7336,6 @@ var runDoctor = async (rc) => {
|
|
|
9577
7336
|
);
|
|
9578
7337
|
}
|
|
9579
7338
|
}
|
|
9580
|
-
const usesPages = state.pages.pluginInstalled || state.scan.cloudPageFiles.length > 0;
|
|
9581
|
-
const usesAuth = state.auth.pluginInstalled || state.scan.signInFiles.length > 0;
|
|
9582
|
-
const plugin = (capability, pkg, factory, files) => {
|
|
9583
|
-
if (state.target !== "app") return;
|
|
9584
|
-
findings.push(
|
|
9585
|
-
files.length ? finding(`${capability}.plugin_configured`, "ok", files.join(", ")) : finding(
|
|
9586
|
-
`${capability}.plugin_configured`,
|
|
9587
|
-
"fail",
|
|
9588
|
-
`${factory} from ${pkg} isn't used in the editor`,
|
|
9589
|
-
`${CANONICAL_INVOCATION} add ${capability}${where}`
|
|
9590
|
-
)
|
|
9591
|
-
);
|
|
9592
|
-
};
|
|
9593
|
-
if (usesPages) {
|
|
9594
|
-
plugin(
|
|
9595
|
-
"pages",
|
|
9596
|
-
PLUGIN_PAGES_PACKAGE,
|
|
9597
|
-
"createPagesPlugin",
|
|
9598
|
-
state.scan.pagesPluginFiles
|
|
9599
|
-
);
|
|
9600
|
-
if (!state.cloud.external) {
|
|
9601
|
-
findings.push(
|
|
9602
|
-
state.scan.cloudPageFiles.length ? finding("pages.render", "ok", state.scan.cloudPageFiles.join(", ")) : finding(
|
|
9603
|
-
"pages.render",
|
|
9604
|
-
"warn",
|
|
9605
|
-
"Nothing reads published pages from Puck Cloud with puckCloud().pages.getPublished()",
|
|
9606
|
-
`${CANONICAL_INVOCATION} add pages${where}`
|
|
9607
|
-
)
|
|
9608
|
-
);
|
|
9609
|
-
}
|
|
9610
|
-
}
|
|
9611
|
-
if (usesAuth) {
|
|
9612
|
-
plugin(
|
|
9613
|
-
"auth",
|
|
9614
|
-
PLUGIN_AUTH_PACKAGE,
|
|
9615
|
-
"createAuthPlugin",
|
|
9616
|
-
state.scan.authPluginFiles
|
|
9617
|
-
);
|
|
9618
|
-
if (!state.cloud.external) {
|
|
9619
|
-
findings.push(
|
|
9620
|
-
state.auth.routeAuthenticated ? finding(
|
|
9621
|
-
"auth.route",
|
|
9622
|
-
"ok",
|
|
9623
|
-
`${state.cloud.routeFile} requires Sign in with Puck`
|
|
9624
|
-
) : finding(
|
|
9625
|
-
"auth.route",
|
|
9626
|
-
"fail",
|
|
9627
|
-
"The Puck Cloud API route doesn't use Sign in with Puck",
|
|
9628
|
-
`${CANONICAL_INVOCATION} add auth${where}`
|
|
9629
|
-
)
|
|
9630
|
-
);
|
|
9631
|
-
}
|
|
9632
|
-
}
|
|
9633
|
-
if ((usesPages || usesAuth) && state.cloud.clientInstalled) {
|
|
9634
|
-
const min = rc.deps.templates.manifest().cloudClientPagesRange;
|
|
9635
|
-
findings.push(
|
|
9636
|
-
atLeast(state.cloud.declaredRange, min) ? finding(
|
|
9637
|
-
"cloud.client_version",
|
|
9638
|
-
"ok",
|
|
9639
|
-
`${CLOUD_CLIENT_PACKAGE} ${state.cloud.declaredRange}`
|
|
9640
|
-
) : finding(
|
|
9641
|
-
"cloud.client_version",
|
|
9642
|
-
"fail",
|
|
9643
|
-
`${CLOUD_CLIENT_PACKAGE} ${state.cloud.declaredRange} doesn't have Puck Pages or Sign in with Puck`,
|
|
9644
|
-
`npm install ${CLOUD_CLIENT_PACKAGE}@${min}`
|
|
9645
|
-
)
|
|
9646
|
-
);
|
|
9647
|
-
}
|
|
9648
7339
|
let verified = status.cloud.satisfied ? "local" : "none";
|
|
9649
7340
|
if (!key.present || !key.value) {
|
|
9650
7341
|
findings.push(finding("cloud.connection", "skip", "No API key to check"));
|
|
@@ -9686,8 +7377,6 @@ var runDoctor = async (rc) => {
|
|
|
9686
7377
|
result.puck = puckSummary(state);
|
|
9687
7378
|
result.cloud = cloudSummary(state, verified);
|
|
9688
7379
|
result.ai = aiSummary(state);
|
|
9689
|
-
result.pages = pagesSummary(state);
|
|
9690
|
-
result.auth = authSummary(state);
|
|
9691
7380
|
return finish();
|
|
9692
7381
|
};
|
|
9693
7382
|
|
|
@@ -9845,160 +7534,16 @@ var runFrameworks = async (_rc, positionals) => {
|
|
|
9845
7534
|
return result;
|
|
9846
7535
|
};
|
|
9847
7536
|
|
|
9848
|
-
// src/commands/pages.ts
|
|
9849
|
-
import path32 from "path";
|
|
9850
|
-
var USAGE = `Usage: \`${CANONICAL_INVOCATION} pages import <file.json>\`.`;
|
|
9851
|
-
var runPages = async (rc, positionals) => {
|
|
9852
|
-
const [sub, ...rest] = positionals;
|
|
9853
|
-
if (sub !== "import" || rest.length !== 1)
|
|
9854
|
-
throw new CliError("PUCK-CLI-INVALID-ARGS", USAGE);
|
|
9855
|
-
return runPagesImport(rc, rest[0]);
|
|
9856
|
-
};
|
|
9857
|
-
var invalid = (message, details) => new CliError("PUCK-CLI-PAGES-FILE-INVALID", message, details);
|
|
9858
|
-
var readPages = (vfs, file, shown) => {
|
|
9859
|
-
const text = vfs.readText(file);
|
|
9860
|
-
if (text === null) throw invalid(`${shown} doesn't exist.`);
|
|
9861
|
-
let pages;
|
|
9862
|
-
try {
|
|
9863
|
-
pages = JSON.parse(text);
|
|
9864
|
-
} catch (err) {
|
|
9865
|
-
throw invalid(`${shown} isn't valid JSON: ${err.message}`);
|
|
9866
|
-
}
|
|
9867
|
-
if (!pages || typeof pages !== "object" || Array.isArray(pages))
|
|
9868
|
-
throw invalid(
|
|
9869
|
-
`${shown} must be an object of Puck data keyed by route, e.g. { "/about": { "content": [], "root": {} } }.`
|
|
9870
|
-
);
|
|
9871
|
-
for (const [route, data] of Object.entries(pages)) {
|
|
9872
|
-
if (!route.startsWith("/"))
|
|
9873
|
-
throw invalid(`"${route}" in ${shown} isn't a route starting with /.`, {
|
|
9874
|
-
route
|
|
9875
|
-
});
|
|
9876
|
-
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
9877
|
-
throw invalid(`The page for "${route}" in ${shown} isn't Puck data.`, {
|
|
9878
|
-
route
|
|
9879
|
-
});
|
|
9880
|
-
}
|
|
9881
|
-
return pages;
|
|
9882
|
-
};
|
|
9883
|
-
var runPagesImport = async (rc, arg) => {
|
|
9884
|
-
const { deps, flags } = rc;
|
|
9885
|
-
const base = baseDir(rc);
|
|
9886
|
-
const vfs = new Vfs();
|
|
9887
|
-
const file = path32.resolve(base, arg);
|
|
9888
|
-
const shown = displayPath(base, file);
|
|
9889
|
-
const pages = readPages(vfs, file, shown);
|
|
9890
|
-
const routes = Object.keys(pages);
|
|
9891
|
-
const result = emptyResult("pages", flags.dryRun);
|
|
9892
|
-
const pagesImport = {
|
|
9893
|
-
file: shown,
|
|
9894
|
-
total: routes.length,
|
|
9895
|
-
created: [],
|
|
9896
|
-
skipped: [],
|
|
9897
|
-
notImported: []
|
|
9898
|
-
};
|
|
9899
|
-
result.pagesImport = pagesImport;
|
|
9900
|
-
const key = flags.apiKey ?? findApiKey(vfs, base, deps.env).value;
|
|
9901
|
-
if (!key) {
|
|
9902
|
-
result.status = "action_required";
|
|
9903
|
-
result.message = `A Puck API key is required to import pages. No pages have been imported.`;
|
|
9904
|
-
result.actions = [
|
|
9905
|
-
{
|
|
9906
|
-
id: "pages:api-key",
|
|
9907
|
-
type: "provide_api_key",
|
|
9908
|
-
required: true,
|
|
9909
|
-
message: `Pass a Puck API key with --api-key, set ${ENV_KEY}, or run this from the app with ${ENV_KEY} in its env file.`,
|
|
9910
|
-
url: new URL(API_KEYS_PATH, rc.cloud.baseUrl).toString(),
|
|
9911
|
-
instructions: `Create a key in Puck Cloud, then re-run with --api-key <key>.`,
|
|
9912
|
-
flag: "--api-key",
|
|
9913
|
-
env: ENV_KEY,
|
|
9914
|
-
rerun: `${rerunCommand(rc)} --api-key <key>`
|
|
9915
|
-
}
|
|
9916
|
-
];
|
|
9917
|
-
result.nextSteps = [`${CANONICAL_INVOCATION} connect`];
|
|
9918
|
-
return result;
|
|
9919
|
-
}
|
|
9920
|
-
if (!isValidApiKeyFormat(key.trim())) {
|
|
9921
|
-
throw new CliError(
|
|
9922
|
-
"PUCK-CLI-INVALID-API-KEY",
|
|
9923
|
-
"The API key isn't a valid Puck API key."
|
|
9924
|
-
);
|
|
9925
|
-
}
|
|
9926
|
-
rc.secrets.add(key.trim());
|
|
9927
|
-
const summary = `Import and publish ${routes.length} page${routes.length === 1 ? "" : "s"} from ${shown} to Puck Cloud`;
|
|
9928
|
-
if (flags.dryRun) {
|
|
9929
|
-
result.message = `Dry run: would ${summary[0].toLowerCase()}${summary.slice(
|
|
9930
|
-
1
|
|
9931
|
-
)}.`;
|
|
9932
|
-
return result;
|
|
9933
|
-
}
|
|
9934
|
-
if (!rc.interactive && !flags.yes) {
|
|
9935
|
-
result.status = "action_required";
|
|
9936
|
-
result.message = `Re-run with --yes to ${summary[0].toLowerCase()}${summary.slice(
|
|
9937
|
-
1
|
|
9938
|
-
)}.`;
|
|
9939
|
-
result.actions = [
|
|
9940
|
-
{
|
|
9941
|
-
id: "confirm",
|
|
9942
|
-
type: "confirm_plan",
|
|
9943
|
-
required: true,
|
|
9944
|
-
flag: "--yes",
|
|
9945
|
-
message: "Re-run with --yes to import the pages.",
|
|
9946
|
-
rerun: `${rerunCommand(rc)} --yes`
|
|
9947
|
-
}
|
|
9948
|
-
];
|
|
9949
|
-
return result;
|
|
9950
|
-
}
|
|
9951
|
-
if (rc.interactive && !await rc.prompter.confirm(`${summary}? Existing pages are kept.`, true)) {
|
|
9952
|
-
throw new CliError(
|
|
9953
|
-
"PUCK-CLI-CANCELLED",
|
|
9954
|
-
"Cancelled. No pages were imported."
|
|
9955
|
-
);
|
|
9956
|
-
}
|
|
9957
|
-
for (let i = 0; i < routes.length; i += IMPORT_BATCH_SIZE) {
|
|
9958
|
-
const batch = routes.slice(i, i + IMPORT_BATCH_SIZE);
|
|
9959
|
-
try {
|
|
9960
|
-
const imported = await rc.cloud.importPages(
|
|
9961
|
-
key.trim(),
|
|
9962
|
-
Object.fromEntries(batch.map((route) => [route, pages[route]]))
|
|
9963
|
-
);
|
|
9964
|
-
pagesImport.created.push(...imported.created);
|
|
9965
|
-
pagesImport.skipped.push(...imported.skipped);
|
|
9966
|
-
rc.log(
|
|
9967
|
-
`Imported ${Math.min(i + IMPORT_BATCH_SIZE, routes.length)} of ${routes.length} pages`
|
|
9968
|
-
);
|
|
9969
|
-
} catch (err) {
|
|
9970
|
-
if (!(err instanceof CloudRequestError)) throw err;
|
|
9971
|
-
const fix = err.kind === "rejected" ? `${CANONICAL_INVOCATION} connect` : void 0;
|
|
9972
|
-
if (i === 0) {
|
|
9973
|
-
throw new CliError(
|
|
9974
|
-
err.kind === "unreachable" ? "PUCK-CLI-CLOUD-UNREACHABLE" : err.kind === "rejected" ? "PUCK-CLI-API-KEY-REJECTED" : "PUCK-CLI-PAGES-IMPORT-FAILED",
|
|
9975
|
-
`${err.message}. No pages were imported.`,
|
|
9976
|
-
fix ? { fix } : void 0
|
|
9977
|
-
);
|
|
9978
|
-
}
|
|
9979
|
-
pagesImport.notImported = routes.slice(i);
|
|
9980
|
-
result.status = "partial";
|
|
9981
|
-
result.changed = pagesImport.created.length > 0;
|
|
9982
|
-
result.message = `Imported ${i} of ${routes.length} pages before Puck Cloud failed: ${err.message}. Re-run the command to import the rest.`;
|
|
9983
|
-
result.nextSteps = [rerunCommand(rc)];
|
|
9984
|
-
return result;
|
|
9985
|
-
}
|
|
9986
|
-
}
|
|
9987
|
-
result.changed = pagesImport.created.length > 0;
|
|
9988
|
-
result.message = `Published ${pagesImport.created.length} page${pagesImport.created.length === 1 ? "" : "s"} to Puck Cloud${pagesImport.skipped.length ? `, and skipped ${pagesImport.skipped.length} that already exist${pagesImport.skipped.length === 1 ? "s" : ""}` : ""}.`;
|
|
9989
|
-
return result;
|
|
9990
|
-
};
|
|
9991
|
-
|
|
9992
7537
|
// src/telemetry/consent.ts
|
|
9993
7538
|
import { randomUUID } from "crypto";
|
|
9994
7539
|
|
|
9995
7540
|
// src/telemetry/config.ts
|
|
9996
7541
|
import fs6 from "fs";
|
|
9997
|
-
import
|
|
7542
|
+
import path31 from "path";
|
|
9998
7543
|
var TelemetryConfigStore = class {
|
|
9999
7544
|
#file;
|
|
10000
7545
|
constructor(configDir) {
|
|
10001
|
-
this.#file =
|
|
7546
|
+
this.#file = path31.join(configDir, "puck", "telemetry.json");
|
|
10002
7547
|
}
|
|
10003
7548
|
get path() {
|
|
10004
7549
|
return this.#file;
|
|
@@ -10013,13 +7558,13 @@ var TelemetryConfigStore = class {
|
|
|
10013
7558
|
}
|
|
10014
7559
|
/** Throws if the config directory isn't writable */
|
|
10015
7560
|
save(config) {
|
|
10016
|
-
fs6.mkdirSync(
|
|
7561
|
+
fs6.mkdirSync(path31.dirname(this.#file), { recursive: true, mode: 448 });
|
|
10017
7562
|
fs6.writeFileSync(this.#file, JSON.stringify(config, null, 2) + "\n", {
|
|
10018
7563
|
mode: 384
|
|
10019
7564
|
});
|
|
10020
7565
|
}
|
|
10021
7566
|
};
|
|
10022
|
-
var configDirFor = (env2, homedir) => env2.XDG_CONFIG_HOME ||
|
|
7567
|
+
var configDirFor = (env2, homedir) => env2.XDG_CONFIG_HOME || path31.join(homedir, ".config");
|
|
10023
7568
|
|
|
10024
7569
|
// src/telemetry/consent.ts
|
|
10025
7570
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -10157,7 +7702,7 @@ var buildEvent = (input) => {
|
|
|
10157
7702
|
};
|
|
10158
7703
|
|
|
10159
7704
|
// src/telemetry/client.ts
|
|
10160
|
-
var
|
|
7705
|
+
var TIMEOUT_MS2 = 1e3;
|
|
10161
7706
|
var sendTelemetry = async (deps, baseUrl, telemetry, events) => {
|
|
10162
7707
|
if (!telemetry.enabled || !telemetry.anonymousId) return;
|
|
10163
7708
|
const body = JSON.stringify({ anonymousId: telemetry.anonymousId, events });
|
|
@@ -10176,7 +7721,7 @@ var sendTelemetry = async (deps, baseUrl, telemetry, events) => {
|
|
|
10176
7721
|
method: "POST",
|
|
10177
7722
|
headers: { "content-type": "application/json" },
|
|
10178
7723
|
body,
|
|
10179
|
-
signal: AbortSignal.timeout(
|
|
7724
|
+
signal: AbortSignal.timeout(TIMEOUT_MS2)
|
|
10180
7725
|
}
|
|
10181
7726
|
);
|
|
10182
7727
|
} catch {
|
|
@@ -10281,14 +7826,13 @@ var runCli = async (argv, deps) => {
|
|
|
10281
7826
|
try {
|
|
10282
7827
|
if (command === "init") result = await runInit(rc);
|
|
10283
7828
|
else if (command === "add") result = await runAdd(rc, positionals);
|
|
10284
|
-
else if (command === "connect") result = await runConnect(rc
|
|
7829
|
+
else if (command === "connect") result = await runConnect(rc);
|
|
10285
7830
|
else if (command === "status") result = await runStatus(rc);
|
|
10286
7831
|
else if (command === "docs") result = await runDocs(rc, positionals);
|
|
10287
7832
|
else if (command === "frameworks")
|
|
10288
7833
|
result = await runFrameworks(rc, positionals);
|
|
10289
7834
|
else if (command === "telemetry")
|
|
10290
7835
|
result = await runTelemetry(rc, positionals);
|
|
10291
|
-
else if (command === "pages") result = await runPages(rc, positionals);
|
|
10292
7836
|
else result = await runDoctor(rc);
|
|
10293
7837
|
} catch (err) {
|
|
10294
7838
|
result = errorResult(command, err, flags.dryRun);
|
|
@@ -10407,7 +7951,7 @@ var runDevServer = (spec, onReady) => new Promise((resolve) => {
|
|
|
10407
7951
|
|
|
10408
7952
|
// src/docs/source.ts
|
|
10409
7953
|
import fs7 from "fs";
|
|
10410
|
-
import
|
|
7954
|
+
import path32 from "path";
|
|
10411
7955
|
var DirDocsSource = class {
|
|
10412
7956
|
#dir;
|
|
10413
7957
|
constructor(dir) {
|
|
@@ -10415,21 +7959,21 @@ var DirDocsSource = class {
|
|
|
10415
7959
|
}
|
|
10416
7960
|
list() {
|
|
10417
7961
|
return JSON.parse(
|
|
10418
|
-
fs7.readFileSync(
|
|
7962
|
+
fs7.readFileSync(path32.join(this.#dir, "index.json"), "utf8")
|
|
10419
7963
|
);
|
|
10420
7964
|
}
|
|
10421
7965
|
read(page) {
|
|
10422
|
-
return fs7.readFileSync(
|
|
7966
|
+
return fs7.readFileSync(path32.join(this.#dir, `${page}.md`), "utf8");
|
|
10423
7967
|
}
|
|
10424
7968
|
};
|
|
10425
7969
|
|
|
10426
7970
|
// src/bin.ts
|
|
10427
|
-
var distDir =
|
|
10428
|
-
var templatesDir =
|
|
7971
|
+
var distDir = path33.dirname(fileURLToPath(import.meta.url));
|
|
7972
|
+
var templatesDir = path33.join(distDir, "templates");
|
|
10429
7973
|
var templates = new DirTemplateSource(templatesDir, {
|
|
10430
7974
|
gitignoreName: "_gitignore",
|
|
10431
7975
|
manifest: () => JSON.parse(
|
|
10432
|
-
fs8.readFileSync(
|
|
7976
|
+
fs8.readFileSync(path33.join(templatesDir, "manifest.json"), "utf8")
|
|
10433
7977
|
)
|
|
10434
7978
|
});
|
|
10435
7979
|
var env = { ...process.env };
|
|
@@ -10439,19 +7983,14 @@ runCli(process.argv.slice(2), {
|
|
|
10439
7983
|
stdout: process.stdout,
|
|
10440
7984
|
stderr: process.stderr,
|
|
10441
7985
|
stdinIsTTY: Boolean(process.stdin.isTTY),
|
|
10442
|
-
cliVersion: "0.24.0-canary.
|
|
10443
|
-
invocation: localInvocation(
|
|
10444
|
-
fs8.realpathSync(fileURLToPath(import.meta.url)),
|
|
10445
|
-
fs8.realpathSync(process.cwd()),
|
|
10446
|
-
env
|
|
10447
|
-
),
|
|
7986
|
+
cliVersion: "0.24.0-canary.8e792e2d",
|
|
10448
7987
|
runner: createRunner(env),
|
|
10449
7988
|
fetch: globalThis.fetch,
|
|
10450
7989
|
openUrl,
|
|
10451
7990
|
runDevServer,
|
|
10452
7991
|
createPrompter: () => createInquirerPrompter(process.stderr),
|
|
10453
7992
|
templates,
|
|
10454
|
-
docs: new DirDocsSource(
|
|
7993
|
+
docs: new DirDocsSource(path33.join(distDir, "docs")),
|
|
10455
7994
|
homedir: os.homedir(),
|
|
10456
7995
|
hostname: os.hostname(),
|
|
10457
7996
|
platform: process.platform,
|