@fluid-app/fluid-cli-theme-dev 0.1.550 → 0.1.552

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 CHANGED
@@ -482,10 +482,25 @@ replace the widget.
482
482
  uploaded. On push, references to them are removed from `templates` and
483
483
  `menu_references` (with any menu left unused) and the local manifest is
484
484
  rewritten to match.
485
- - **`fluid theme staging publish` skips `members_sites.json`** and lists it
486
- as skipped. Member configuration is not published to staging branches yet.
487
- Retired template folders aren't theme files, so staging publish never sees
488
- them: they are neither uploaded nor listed.
485
+ - **`fluid theme staging publish` sends `members_sites.json`** with the rest
486
+ of the theme, without references to retired pages, so staging gets the
487
+ theme's member sites, pages and menus. Retired template folders aren't theme
488
+ files, so staging publish never sees them: they are neither uploaded nor
489
+ listed.
490
+ - **`fluid theme staging compare` compares `members_sites.json` by its JSON
491
+ document**, not its bytes, because staging stores the configuration it
492
+ imported in its own layout. A manifest you wrote by hand may still differ
493
+ after publishing, since Fluid may rewrite keys; pull to take staging's
494
+ version.
495
+
496
+ ### Comparing with staging
497
+
498
+ `fluid theme staging compare` reports how this directory's files differ from
499
+ what the theme's staging branch serves: files whose content changed, files
500
+ only you have, and files only staging has. It sends each file's SHA-256, never
501
+ its content, and changes nothing. Publishing to production (`fluid theme push`)
502
+ always sends your local files, so compare first when staging may hold work
503
+ that isn't in this checkout, such as a teammate's staging publish.
489
504
 
490
505
  ## Development
491
506
 
package/dist/index.mjs CHANGED
@@ -13277,6 +13277,16 @@ function declarePublication(api, themeId, slug, key, expectedRevision, entries)
13277
13277
  }));
13278
13278
  }
13279
13279
  /**
13280
+ * Compare local files, declared by the digest a publish would send, with
13281
+ * what the branch serves. Nothing is uploaded or changed.
13282
+ */
13283
+ async function compareBranch(api, themeId, slug, entries) {
13284
+ return (await call(api.request(`${base(themeId)}/branches/${slug}/comparison`, {
13285
+ method: "POST",
13286
+ body: { entries }
13287
+ }))).comparison;
13288
+ }
13289
+ /**
13280
13290
  * Upload one declared content as raw bytes. The shared client always sends
13281
13291
  * JSON, so this goes through fetch with the same base URL and token.
13282
13292
  */
@@ -13459,6 +13469,70 @@ async function publishToStaging(api, themeId, root, onProgress = () => {}) {
13459
13469
  };
13460
13470
  }
13461
13471
  //#endregion
13472
+ //#region src/theme/staging-compare.ts
13473
+ /**
13474
+ * Compare local theme files with what the theme's staging branch serves, so
13475
+ * a caller can say when publishing to production would send something other
13476
+ * than what staging shows.
13477
+ *
13478
+ * Each file is declared by the SHA-256 a staging publish would send for it
13479
+ * (see planPublication), never its content. The member configuration is the
13480
+ * exception: the server stores the document it imported, re-encoded with
13481
+ * its own keys and layout, so `members_sites.json` is declared by the digest
13482
+ * of its JSON document instead (jsonDigest), which the server computes the
13483
+ * same way. Staging-only paths a publish never sends (account pages,
13484
+ * numbered duplicates, files attached to a template) are left out, so they
13485
+ * do not read as a difference on every comparison.
13486
+ */
13487
+ /**
13488
+ * The SHA-256 of a JSON document independent of key order and layout: keys
13489
+ * sorted at every level, encoded without whitespace. Null when the text is
13490
+ * not JSON. Matches Themes::BranchDifferenceResolver.json_digest.
13491
+ */
13492
+ function jsonDigest(text) {
13493
+ let parsed;
13494
+ try {
13495
+ parsed = JSON.parse(text);
13496
+ } catch {
13497
+ return null;
13498
+ }
13499
+ return createHash("sha256").update(JSON.stringify(sorted(parsed))).digest("hex");
13500
+ }
13501
+ function sorted(value) {
13502
+ if (Array.isArray(value)) return value.map(sorted);
13503
+ if (value === null || typeof value !== "object") return value;
13504
+ const object = value;
13505
+ return Object.fromEntries(Object.keys(object).sort().map((key) => [key, sorted(object[key])]));
13506
+ }
13507
+ async function compareWithStaging(api, themeId, root) {
13508
+ const branch = (await readStagingStatus(api, themeId)).branch;
13509
+ if (branch?.state !== "ready") throw new Error("Staging is not ready. Run `fluid theme staging request` and wait for it first.");
13510
+ const plan = planPublication(root);
13511
+ const entries = plan.entries.flatMap((entry) => {
13512
+ if (!("sha256" in entry)) return [];
13513
+ if (entry.path !== "members_sites.json") return [{
13514
+ path: entry.path,
13515
+ sha256: entry.sha256
13516
+ }];
13517
+ const sent = plan.contents.get(entry.sha256);
13518
+ const digest = sent && jsonDigest(Buffer.from(sent).toString("utf-8"));
13519
+ return [{
13520
+ path: entry.path,
13521
+ sha256: digest ?? entry.sha256
13522
+ }];
13523
+ });
13524
+ if (entries.length === 0) throw new Error("No theme files to compare.");
13525
+ const compared = await compareBranch(api, themeId, branch.slug, entries);
13526
+ const branchOnly = compared.branch_only.filter((path) => unpublishableReason(path) === null);
13527
+ return {
13528
+ revision: compared.branch_revision,
13529
+ matches: compared.changed.length === 0 && compared.local_only.length === 0 && branchOnly.length === 0,
13530
+ changed: compared.changed,
13531
+ localOnly: compared.local_only,
13532
+ branchOnly
13533
+ };
13534
+ }
13535
+ //#endregion
13462
13536
  //#region src/commands/staging.ts
13463
13537
  /**
13464
13538
  * The production theme staging belongs to: --theme, else the theme this
@@ -13559,7 +13633,25 @@ function createStagingCommand() {
13559
13633
  for (const { path, reason } of outcome.skipped) console.log(chalk.yellow(` skipped ${path}: ${reason}`));
13560
13634
  if (outcome.branch.preview_url) console.log(`Preview: ${chalk.cyan(outcome.branch.preview_url)}`);
13561
13635
  }));
13562
- return new Command("staging").description("Use the theme's staging branch, previewed by a signed link (needs branch environments)").addCommand(status).addCommand(request).addCommand(wait).addCommand(publish);
13636
+ const compare = withThemeOptions$1(new Command("compare").description("Show how this directory's theme files differ from what staging serves; nothing is changed")).action((opts) => run$1(opts, async () => {
13637
+ requireToken();
13638
+ const root = new ThemeRoot(resolveRoot(opts.root));
13639
+ if (!root.isValid()) throw new Error(`'${root.root}' does not look like a theme directory.`);
13640
+ const compared = await compareWithStaging(createApiClient(), resolveThemeId(opts), root);
13641
+ if (opts.json) {
13642
+ console.log(JSON.stringify(compared));
13643
+ return;
13644
+ }
13645
+ if (compared.matches) {
13646
+ console.log(`These files match staging (revision ${compared.revision}).`);
13647
+ return;
13648
+ }
13649
+ console.log(`These files differ from staging (revision ${compared.revision}). Publishing to production sends these local files, not staging's.`);
13650
+ for (const path of compared.changed) console.log(chalk.yellow(` changed ${path}`));
13651
+ for (const path of compared.localOnly) console.log(chalk.green(` local only ${path}`));
13652
+ for (const path of compared.branchOnly) console.log(chalk.red(` staging only ${path}`));
13653
+ }));
13654
+ return new Command("staging").description("Use the theme's staging branch, previewed by a signed link (needs branch environments)").addCommand(status).addCommand(request).addCommand(wait).addCommand(publish).addCommand(compare);
13563
13655
  }
13564
13656
  //#endregion
13565
13657
  //#region src/commands/widget.ts