@cmssy/cli 11.2.0 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +132 -6
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1008,7 +1008,7 @@ async function runLink(options, deps) {
|
|
|
1008
1008
|
}
|
|
1009
1009
|
|
|
1010
1010
|
// src/types-command.ts
|
|
1011
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
1011
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, readdirSync, writeFileSync as writeFileSync4 } from "fs";
|
|
1012
1012
|
import { dirname as dirname3, relative, resolve as resolvePath } from "path";
|
|
1013
1013
|
import { DEFAULT_CMSSY_API_URL } from "@cmssy/core";
|
|
1014
1014
|
|
|
@@ -1178,6 +1178,42 @@ function generateModelTypes(models, options) {
|
|
|
1178
1178
|
return blocks.join("\n");
|
|
1179
1179
|
}
|
|
1180
1180
|
|
|
1181
|
+
// src/operations-file.ts
|
|
1182
|
+
import { CMSSY_DELIVERY_OPERATIONS } from "@cmssy/core/internal";
|
|
1183
|
+
var DEFAULT_OPERATIONS_OUT = "cmssy/operations.graphql";
|
|
1184
|
+
var OPERATION_NAME = /^\s*(?:query|mutation|subscription)\s+([A-Za-z_]\w*)/m;
|
|
1185
|
+
function operationNames() {
|
|
1186
|
+
return CMSSY_DELIVERY_OPERATIONS.map((operation) => {
|
|
1187
|
+
const match = OPERATION_NAME.exec(operation.document);
|
|
1188
|
+
if (!match?.[1]) {
|
|
1189
|
+
throw new Error(
|
|
1190
|
+
"cmssy: a delivery operation has no name - anonymous documents cannot be vendored"
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
return match[1];
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
function generateOperationsFile() {
|
|
1197
|
+
const header = [
|
|
1198
|
+
"# Generated by `cmssy types`. Do not edit - it is rewritten on every run.",
|
|
1199
|
+
"#",
|
|
1200
|
+
"# The delivery reads the SDK itself performs, vendored so your codegen",
|
|
1201
|
+
"# types them like any other document. Point `documents` in codegen.ts at",
|
|
1202
|
+
"# this file. Need a different selection set? Write your own query, under",
|
|
1203
|
+
"# your own operation name - two documents cannot share one.",
|
|
1204
|
+
""
|
|
1205
|
+
].join("\n");
|
|
1206
|
+
const documents = CMSSY_DELIVERY_OPERATIONS.map(
|
|
1207
|
+
// A newline in `purpose` would emit bare prose into the document and break
|
|
1208
|
+
// parsing for every consumer.
|
|
1209
|
+
(operation) => `# ${operation.purpose.replace(/\s+/g, " ").trim()}
|
|
1210
|
+
${operation.document}`
|
|
1211
|
+
).join("\n\n");
|
|
1212
|
+
return `${header}
|
|
1213
|
+
${documents}
|
|
1214
|
+
`;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1181
1217
|
// src/types-command.ts
|
|
1182
1218
|
var DEFAULT_OUT = "cmssy/models.ts";
|
|
1183
1219
|
var SITE_CONFIG_QUERY = `query CliSiteConfig($workspaceSlug: String!) {
|
|
@@ -1272,9 +1308,96 @@ function resolve3(value, fromEnv, variable) {
|
|
|
1272
1308
|
}
|
|
1273
1309
|
return resolved;
|
|
1274
1310
|
}
|
|
1311
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
1312
|
+
"node_modules",
|
|
1313
|
+
"dist",
|
|
1314
|
+
"build",
|
|
1315
|
+
".next",
|
|
1316
|
+
".git",
|
|
1317
|
+
".turbo",
|
|
1318
|
+
".vercel"
|
|
1319
|
+
]);
|
|
1320
|
+
var ANY_OPERATION_NAME = /^\s*(?:query|mutation|subscription)\s+([A-Za-z_]\w*)/gm;
|
|
1321
|
+
function existingOperationNames(cwd, skipPath) {
|
|
1322
|
+
const found = /* @__PURE__ */ new Map();
|
|
1323
|
+
let entries;
|
|
1324
|
+
try {
|
|
1325
|
+
entries = readdirSync(cwd, { recursive: true });
|
|
1326
|
+
} catch {
|
|
1327
|
+
return found;
|
|
1328
|
+
}
|
|
1329
|
+
for (const entry of entries) {
|
|
1330
|
+
if (typeof entry !== "string" || !entry.endsWith(".graphql")) continue;
|
|
1331
|
+
if (entry.split(/[\\/]/).some((part) => SKIP_DIRS.has(part))) continue;
|
|
1332
|
+
const full = resolvePath(cwd, entry);
|
|
1333
|
+
if (full === skipPath) continue;
|
|
1334
|
+
let source;
|
|
1335
|
+
try {
|
|
1336
|
+
source = readFileSync6(full, "utf8");
|
|
1337
|
+
} catch {
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
for (const match of source.matchAll(ANY_OPERATION_NAME)) {
|
|
1341
|
+
const name = match[1];
|
|
1342
|
+
if (name && !found.has(name)) found.set(name, entry);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
return found;
|
|
1346
|
+
}
|
|
1347
|
+
function syncOperations(options, deps) {
|
|
1348
|
+
if (options.noOperations) return 0;
|
|
1349
|
+
const requested = options.operationsOut?.trim() || DEFAULT_OPERATIONS_OUT;
|
|
1350
|
+
const outPath = resolvePath(deps.cwd, requested);
|
|
1351
|
+
const inside = relative(deps.cwd, outPath);
|
|
1352
|
+
const shown = inside && !inside.startsWith("..") ? inside : outPath;
|
|
1353
|
+
const source = generateOperationsFile();
|
|
1354
|
+
let previous = null;
|
|
1355
|
+
try {
|
|
1356
|
+
previous = readFileSync6(outPath, "utf8");
|
|
1357
|
+
} catch {
|
|
1358
|
+
previous = null;
|
|
1359
|
+
}
|
|
1360
|
+
const existing = existingOperationNames(deps.cwd, outPath);
|
|
1361
|
+
const clashes = operationNames().map((name) => ({ name, file: existing.get(name) })).filter((clash) => !!clash.file);
|
|
1362
|
+
if (clashes.length > 0) {
|
|
1363
|
+
deps.log(
|
|
1364
|
+
`cmssy: ${shown} would collide with operations this app already declares`
|
|
1365
|
+
);
|
|
1366
|
+
for (const clash of clashes) {
|
|
1367
|
+
deps.log(` ${clash.name} - already in ${clash.file}`);
|
|
1368
|
+
}
|
|
1369
|
+
deps.log(
|
|
1370
|
+
" delete those documents to use the vendored ones, or pass --no-operations to keep yours"
|
|
1371
|
+
);
|
|
1372
|
+
return 1;
|
|
1373
|
+
}
|
|
1374
|
+
if (previous === source) return 0;
|
|
1375
|
+
if (options.check) {
|
|
1376
|
+
deps.log(
|
|
1377
|
+
previous === null ? `cmssy: ${shown} is missing - run \`cmssy types\` and commit it` : `cmssy: ${shown} is out of date with this CLI's delivery operations`
|
|
1378
|
+
);
|
|
1379
|
+
deps.log(" run `cmssy types` and commit the result");
|
|
1380
|
+
return 1;
|
|
1381
|
+
}
|
|
1382
|
+
try {
|
|
1383
|
+
mkdirSync3(dirname3(outPath), { recursive: true });
|
|
1384
|
+
writeFileSync4(outPath, source);
|
|
1385
|
+
} catch (error) {
|
|
1386
|
+
throw new CliError(
|
|
1387
|
+
`could not write ${shown}: ${error.message}`,
|
|
1388
|
+
"check the path is writable, or pass --operations-out"
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
1391
|
+
const names = operationNames();
|
|
1392
|
+
deps.log(`cmssy: wrote ${shown} - ${names.length} operations`);
|
|
1393
|
+
deps.log(` ${names.join(", ")}`);
|
|
1394
|
+
return 0;
|
|
1395
|
+
}
|
|
1275
1396
|
async function runTypes(options, deps) {
|
|
1397
|
+
let operationsStatus = 0;
|
|
1276
1398
|
try {
|
|
1277
1399
|
loadEnvFiles(deps.cwd, deps.env);
|
|
1400
|
+
operationsStatus = syncOperations(options, deps);
|
|
1278
1401
|
const org = resolve3(options.org, deps.env.CMSSY_ORG_SLUG, "CMSSY_ORG_SLUG");
|
|
1279
1402
|
const workspace = resolve3(
|
|
1280
1403
|
options.workspace,
|
|
@@ -1296,7 +1419,7 @@ async function runTypes(options, deps) {
|
|
|
1296
1419
|
deps.log(
|
|
1297
1420
|
`cmssy: the "${workspace}" workspace has no models yet - nothing to generate`
|
|
1298
1421
|
);
|
|
1299
|
-
return
|
|
1422
|
+
return operationsStatus;
|
|
1300
1423
|
}
|
|
1301
1424
|
const requested = options.out?.trim() || DEFAULT_OUT;
|
|
1302
1425
|
const outPath = resolvePath(deps.cwd, requested);
|
|
@@ -1311,7 +1434,7 @@ async function runTypes(options, deps) {
|
|
|
1311
1434
|
}
|
|
1312
1435
|
if (previous === source) {
|
|
1313
1436
|
deps.log(`cmssy: ${shown} is up to date`);
|
|
1314
|
-
return
|
|
1437
|
+
return operationsStatus;
|
|
1315
1438
|
}
|
|
1316
1439
|
if (options.check) {
|
|
1317
1440
|
deps.log(
|
|
@@ -1335,7 +1458,7 @@ async function runTypes(options, deps) {
|
|
|
1335
1458
|
deps.log(
|
|
1336
1459
|
` ${models.map((model) => model.slug).join(", ")}`
|
|
1337
1460
|
);
|
|
1338
|
-
return
|
|
1461
|
+
return operationsStatus;
|
|
1339
1462
|
} catch (error) {
|
|
1340
1463
|
if (error instanceof CliError) {
|
|
1341
1464
|
deps.log(`cmssy: ${error.message}`);
|
|
@@ -1352,7 +1475,8 @@ var USAGE = [
|
|
|
1352
1475
|
" cmssy init [--dir <path>] [--force]",
|
|
1353
1476
|
" cmssy add block <name> [--dir <path>]",
|
|
1354
1477
|
" cmssy link [--token <cs_...>] [--workspace <slug>] [--preview-url <url>]",
|
|
1355
|
-
" cmssy types [--out <path>] [--
|
|
1478
|
+
" cmssy types [--out <path>] [--operations-out <path>] [--no-operations]",
|
|
1479
|
+
" [--check] [--org <slug>] [--workspace <slug>]"
|
|
1356
1480
|
].join("\n");
|
|
1357
1481
|
function flagValue(args, name) {
|
|
1358
1482
|
const index = args.findIndex((arg) => arg === name);
|
|
@@ -1416,7 +1540,9 @@ async function main() {
|
|
|
1416
1540
|
out: flagValue(args, "--out"),
|
|
1417
1541
|
org: flagValue(args, "--org"),
|
|
1418
1542
|
workspace: flagValue(args, "--workspace"),
|
|
1419
|
-
check: hasFlag(args, "--check")
|
|
1543
|
+
check: hasFlag(args, "--check"),
|
|
1544
|
+
operationsOut: flagValue(args, "--operations-out"),
|
|
1545
|
+
noOperations: hasFlag(args, "--no-operations")
|
|
1420
1546
|
},
|
|
1421
1547
|
{
|
|
1422
1548
|
cwd: process.cwd(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/cli",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.3.0",
|
|
4
4
|
"description": "The cmssy CLI: `cmssy init` wires cmssy into an existing Next.js, Astro or React Router app; `cmssy link` connects it to a workspace and verifies the editor wiring.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -27,13 +27,14 @@
|
|
|
27
27
|
"assets"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@cmssy/core": "11.
|
|
30
|
+
"@cmssy/core": "11.3.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^20.0.0",
|
|
34
34
|
"tsup": "^8.3.0",
|
|
35
35
|
"typescript": "^5.6.0",
|
|
36
|
-
"vitest": "^2.1.0"
|
|
36
|
+
"vitest": "^2.1.0",
|
|
37
|
+
"graphql": "^16.10.0"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"build": "tsup",
|