@cmssy/cli 10.6.1 → 10.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +29 -2
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1244,6 +1244,22 @@ async function request(deps, endpoint, query, variables) {
1244
1244
  if (!body.data) throw new CliError("the delivery API returned no data");
1245
1245
  return body.data;
1246
1246
  }
1247
+ function describeDrift(previous, next) {
1248
+ const declared = (source, pattern) => new Set([...source.matchAll(pattern)].map((match) => match[1] ?? ""));
1249
+ const body = (source) => source.split("/** Every model in the")[0] ?? source;
1250
+ const models = /export interface (\w+)Data/g;
1251
+ const fields = /^\s{2}(\w+)\??:/gm;
1252
+ const lines = [];
1253
+ const report = (label, before, after) => {
1254
+ const added = [...after].filter((name) => !before.has(name));
1255
+ const removed = [...before].filter((name) => !after.has(name));
1256
+ if (added.length) lines.push(`+ ${label}: ${added.join(", ")}`);
1257
+ if (removed.length) lines.push(`- ${label}: ${removed.join(", ")}`);
1258
+ };
1259
+ report("models", declared(previous, models), declared(next, models));
1260
+ report("fields", declared(body(previous), fields), declared(body(next), fields));
1261
+ return lines.length ? lines : ["the generated output differs"];
1262
+ }
1247
1263
  function resolve3(value, fromEnv, variable) {
1248
1264
  const resolved = value?.trim() || fromEnv?.trim();
1249
1265
  if (!resolved) {
@@ -1295,6 +1311,16 @@ async function runTypes(options, deps) {
1295
1311
  deps.log(`cmssy: ${shown} is up to date`);
1296
1312
  return 0;
1297
1313
  }
1314
+ if (options.check) {
1315
+ deps.log(
1316
+ previous === null ? `cmssy: ${shown} is missing - run \`cmssy types\` and commit it` : `cmssy: ${shown} is out of date with the "${workspace}" workspace`
1317
+ );
1318
+ if (previous !== null) {
1319
+ for (const line of describeDrift(previous, source)) deps.log(` ${line}`);
1320
+ }
1321
+ deps.log(" run `cmssy types` and commit the result");
1322
+ return 1;
1323
+ }
1298
1324
  mkdirSync3(dirname3(outPath), { recursive: true });
1299
1325
  writeFileSync4(outPath, source);
1300
1326
  const fieldCount = models.reduce(
@@ -1324,7 +1350,7 @@ var USAGE = [
1324
1350
  " cmssy init [--dir <path>] [--force]",
1325
1351
  " cmssy add block <name> [--dir <path>]",
1326
1352
  " cmssy link [--token <cs_...>] [--workspace <slug>] [--preview-url <url>]",
1327
- " cmssy types [--out <path>] [--org <slug>] [--workspace <slug>]"
1353
+ " cmssy types [--out <path>] [--check] [--org <slug>] [--workspace <slug>]"
1328
1354
  ].join("\n");
1329
1355
  function flagValue(args, name) {
1330
1356
  const index = args.findIndex((arg) => arg === name);
@@ -1387,7 +1413,8 @@ async function main() {
1387
1413
  {
1388
1414
  out: flagValue(args, "--out"),
1389
1415
  org: flagValue(args, "--org"),
1390
- workspace: flagValue(args, "--workspace")
1416
+ workspace: flagValue(args, "--workspace"),
1417
+ check: hasFlag(args, "--check")
1391
1418
  },
1392
1419
  {
1393
1420
  cwd: process.cwd(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/cli",
3
- "version": "10.6.1",
3
+ "version": "10.7.0",
4
4
  "description": "The cmssy CLI: `cmssy init` wires cmssy into an existing Next.js, Astro or React Router app; `cmssy link` connects it to a workspace and verifies the editor wiring.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -27,7 +27,7 @@
27
27
  "assets"
28
28
  ],
29
29
  "dependencies": {
30
- "@cmssy/core": "10.6.1"
30
+ "@cmssy/core": "10.7.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^20.0.0",