@fluid-app/fluid-cli-theme-dev 0.1.911 → 0.1.913

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.
@@ -1,5 +1,5 @@
1
1
  import { j as r } from "./account-screen-runtime-B9i-9CLs.js";
2
- import { M as e } from "./MemberShareablesScreen-Cjiwm4hS.js";
2
+ import { M as e } from "./MemberShareablesScreen-kHnOtPBS.js";
3
3
  function a() {
4
4
  return /* @__PURE__ */ r.jsx(e, { curation: "always" });
5
5
  }
@@ -18,14 +18,14 @@ const p = {
18
18
  },
19
19
  media: async () => {
20
20
  const [t, e] = await Promise.all([
21
- import("./MediaScreen-BeW7cyF3.js"),
21
+ import("./MediaScreen-CdR-A1zJ.js"),
22
22
  import("./media-7vUjJ3C6.js")
23
23
  ]);
24
24
  return { Component: t.MediaScreen, styles: e.default };
25
25
  },
26
26
  playlists: async () => {
27
27
  const [t, e] = await Promise.all([
28
- import("./PlaylistsScreen-C-g9E_Fb.js"),
28
+ import("./PlaylistsScreen-69uNeW45.js"),
29
29
  import("./playlists-7vUjJ3C6.js")
30
30
  ]);
31
31
  return { Component: t.PlaylistsScreen, styles: e.default };
@@ -39,7 +39,7 @@ const p = {
39
39
  },
40
40
  messaging: async () => {
41
41
  const [t, e] = await Promise.all([
42
- import("./MessagingScreen-BTVg7cag.js"),
42
+ import("./MessagingScreen-7dW84pg4.js"),
43
43
  import("./messaging-BTJiMVy5.js")
44
44
  ]);
45
45
  return { Component: t.default, styles: e.default };
@@ -132,7 +132,7 @@ function h(t = "fluid-account-screen", e, s = !1) {
132
132
  this.status(!1);
133
133
  try {
134
134
  const [a, i] = await Promise.all([
135
- import("./mount-account-screen-ClGhNo9j.js"),
135
+ import("./mount-account-screen-lvuh2o8K.js"),
136
136
  w(r)
137
137
  ]);
138
138
  if (!this.isConnected || this.generation !== n) return;
@@ -18,8 +18,8 @@ import { u as cr, S as sr } from "./sidebar-SmEnwFoV.js";
18
18
  import { S as or } from "./store-api-context-TW7uud2C.js";
19
19
  import { s as dr, a as mr, b as vr, c as hr } from "./hey-api-client-EAWr0fT_.js";
20
20
  import { M as yr } from "./use-mobile-BChC77Fq.js";
21
- import { i as zv, n as rr } from "./navigate-account-screen-AGarxy-u.js";
22
- import { a as gr } from "./cli-preview-CmXcVR8O.js";
21
+ import { i as zv, n as rr } from "./navigate-account-screen-CUajuBVm.js";
22
+ import { a as gr } from "./cli-preview-6Q0W6jz6.js";
23
23
  import { A as Sr } from "./arrow-left-Ds5JkG8w.js";
24
24
  /**
25
25
  * @license lucide-react v0.575.0 - ISC
@@ -1,4 +1,4 @@
1
- import { i as o } from "./cli-preview-CmXcVR8O.js";
1
+ import { i as o } from "./cli-preview-6Q0W6jz6.js";
2
2
  function i(n) {
3
3
  if (!s(n)) return;
4
4
  const e = new URL(`/${n}`, window.location.origin), r = new URL(window.location.href);
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { Command, InvalidArgumentError, Option } from "commander";
3
- import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
4
4
  import { execFileSync, spawn } from "node:child_process";
5
5
  import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
6
6
  import * as core from "@fluid-app/fluid-cli";
@@ -7352,6 +7352,7 @@ function hasGeneratedConflictMarkers(content) {
7352
7352
  const text = content.toString("utf8");
7353
7353
  return /^<<<<<<< local\r?$/m.test(text) && /^=======\r?$/m.test(text) && /^>>>>>>> remote\r?$/m.test(text);
7354
7354
  }
7355
+ /** A remote resource's bytes: binary files downloaded, text as sent. */
7355
7356
  async function materialize(resource, fetchBinary) {
7356
7357
  if (resource.resource_type === "FileResource" && resource.url) return fetchBinary(resource.url);
7357
7358
  if (resource.content == null) return null;
@@ -13984,7 +13985,7 @@ function planPublication(root) {
13984
13985
  });
13985
13986
  continue;
13986
13987
  }
13987
- const bytes = file.isText ? Buffer.from(publishedText(file), "utf-8") : file.readBinary();
13988
+ const bytes = publishedBytes(file);
13988
13989
  const sha256 = createHash("sha256").update(bytes).digest("hex");
13989
13990
  entries.push({
13990
13991
  path,
@@ -14000,6 +14001,10 @@ function planPublication(root) {
14000
14001
  skipped
14001
14002
  };
14002
14003
  }
14004
+ /** The bytes a publish sends for a file, which its digest is taken from. */
14005
+ function publishedBytes(file) {
14006
+ return file.isText ? Buffer.from(publishedText(file), "utf-8") : file.readBinary();
14007
+ }
14003
14008
  /**
14004
14009
  * The text staging receives for a file. Account and member pages are not
14005
14010
  * published, and the server refuses a member configuration that still
@@ -14224,6 +14229,203 @@ async function undoStagingPromotion(api, themeId) {
14224
14229
  return undoPromotion(api, themeId, latest.id);
14225
14230
  }
14226
14231
  //#endregion
14232
+ //#region src/theme/staging-pull.ts
14233
+ /**
14234
+ * Take into this folder the files someone else published to the theme's
14235
+ * staging branch, so a later publish carries their work instead of being
14236
+ * refused for replacing it (see publishToStaging).
14237
+ *
14238
+ * Only files that changed on staging since this folder was last in step with
14239
+ * it (its staging baseline) are candidates, and only those this folder still
14240
+ * has as they were then are written: a file edited here too is kept and
14241
+ * named, never overwritten. Without a baseline nothing tells whose change a
14242
+ * difference is, so only files this folder does not have are taken.
14243
+ *
14244
+ * Staging navigates with its own copies of the live theme's menus, so its
14245
+ * files name those copies. A file taken from staging has each staging menu
14246
+ * put back to the menu this folder names at the same place (matched through
14247
+ * the two member configurations' menu references); a file that would still
14248
+ * name a staging menu is kept instead, so a later push never points the live
14249
+ * theme at staging's menus. The member configuration itself is never taken.
14250
+ */
14251
+ async function pullFromStaging(api, themeId, root, onProgress = () => {}, fetchBinary = downloadBinaryWithRetry) {
14252
+ const branch = (await readStagingStatus(api, themeId)).branch;
14253
+ if (branch?.state !== "ready" || branch.theme_id == null) throw new Error("Staging is not ready. Run `fluid theme staging request` and wait for it first.");
14254
+ onProgress("Checking what changed on staging…");
14255
+ const declared = comparisonDeclaration(planPublication(root));
14256
+ const local = await compareDeclaration(api, themeId, branch.slug, root, declared);
14257
+ const baseline = readStagingBaseline(root.root, themeId);
14258
+ const theirs = baseline ? await compareDeclaration(api, themeId, branch.slug, root, baseline) : null;
14259
+ const changedThere = new Set([...theirs?.changed ?? [], ...theirs?.branchOnly ?? []].map(resourceIdentity));
14260
+ const atBaseline = new Map((baseline?.entries ?? []).map((entry) => [resourceIdentity(entry.path), entry.sha256]));
14261
+ const here = new Map(declared.entries.map((entry) => [resourceIdentity(entry.path), entry.sha256]));
14262
+ const keptRemote = keptRemoteAssets(root);
14263
+ const toTake = [];
14264
+ const kept = [];
14265
+ for (const path of [...local.changed, ...local.branchOnly]) {
14266
+ const identity = resourceIdentity(path);
14267
+ const missingHere = !here.has(identity);
14268
+ if (identity === resourceIdentity("members_sites.json")) kept.push({
14269
+ path,
14270
+ reason: "the member configuration is not taken from staging"
14271
+ });
14272
+ else if (keptRemote.has(path)) kept.push({
14273
+ path,
14274
+ reason: "kept remote in .fluid-assets.json"
14275
+ });
14276
+ else if (baseline && !changedThere.has(identity)) kept.push({
14277
+ path,
14278
+ reason: "changed here, not on staging"
14279
+ });
14280
+ else if (missingHere || here.get(identity) === atBaseline.get(identity)) toTake.push(path);
14281
+ else kept.push({
14282
+ path,
14283
+ reason: baseline ? "changed here too since you last published" : "no record of your last publish here, so it may be your change"
14284
+ });
14285
+ }
14286
+ const taken = [];
14287
+ if (toTake.length > 0) {
14288
+ onProgress(`Reading ${toTake.length} ${toTake.length === 1 ? "file" : "files"} from staging…`);
14289
+ const served = await stagingResources(api, branch.theme_id);
14290
+ const menus = stagingMenus(served.get(resourceIdentity(MEMBER_CONFIGURATION_KEY)), root);
14291
+ for (const path of toTake) {
14292
+ const resource = served.get(resourceIdentity(path));
14293
+ const fetched = resource && await materialize(resource, fetchBinary);
14294
+ if (!fetched) {
14295
+ kept.push({
14296
+ path,
14297
+ reason: "staging did not return its content"
14298
+ });
14299
+ continue;
14300
+ }
14301
+ const content = resource.resource_type === "FileResource" ? fetched : withOwnMenus(fetched.toString("utf-8"), menus);
14302
+ if (content === null) {
14303
+ kept.push({
14304
+ path,
14305
+ reason: "it names a staging menu this folder doesn't have"
14306
+ });
14307
+ continue;
14308
+ }
14309
+ const file = root.file(path);
14310
+ if (!writableInside(root.root, file.absolutePath)) {
14311
+ kept.push({
14312
+ path,
14313
+ reason: "path is outside this folder"
14314
+ });
14315
+ continue;
14316
+ }
14317
+ if (digestNow(file) !== here.get(resourceIdentity(path))) {
14318
+ kept.push({
14319
+ path,
14320
+ reason: "changed here while getting their changes"
14321
+ });
14322
+ continue;
14323
+ }
14324
+ try {
14325
+ file.write(content);
14326
+ } catch (error) {
14327
+ kept.push({
14328
+ path,
14329
+ reason: `couldn't be written: ${error instanceof Error ? error.message : String(error)}`
14330
+ });
14331
+ continue;
14332
+ }
14333
+ taken.push(path);
14334
+ }
14335
+ }
14336
+ const after = await compareWithStaging(api, themeId, root).catch(() => null);
14337
+ return {
14338
+ revision: after?.revision ?? local.revision,
14339
+ taken: taken.sort(),
14340
+ kept: kept.sort((a, b) => a.path.localeCompare(b.path)),
14341
+ matches: after?.matches ?? false
14342
+ };
14343
+ }
14344
+ /** The file's digest as a publish would declare it, or undefined if absent. */
14345
+ function digestNow(file) {
14346
+ if (!existsSync(file.absolutePath)) return void 0;
14347
+ return createHash("sha256").update(publishedBytes(file)).digest("hex");
14348
+ }
14349
+ /**
14350
+ * Whether writing `absolutePath` stays inside the theme folder, following
14351
+ * symlinks: the path is under the folder, is not itself a symlink, and its
14352
+ * nearest existing directory resolves inside the folder's real path.
14353
+ */
14354
+ function writableInside(themeRoot, absolutePath) {
14355
+ if (!absolutePath.startsWith(themeRoot + sep)) return false;
14356
+ try {
14357
+ if (lstatSync(absolutePath).isSymbolicLink()) return false;
14358
+ } catch {}
14359
+ let directory = dirname(absolutePath);
14360
+ while (!existsSync(directory)) directory = dirname(directory);
14361
+ const realRoot = realpathSync(themeRoot);
14362
+ const realDirectory = realpathSync(directory);
14363
+ return realDirectory === realRoot || realDirectory.startsWith(realRoot + sep);
14364
+ }
14365
+ /** Every resource the staging copy serves, by resource identity. */
14366
+ async function stagingResources(api, stagingThemeId) {
14367
+ const body = await listThemeResources(api, stagingThemeId);
14368
+ return new Map((body.application_theme_resources ?? []).map((resource) => [resourceIdentity(resource.key), resource]));
14369
+ }
14370
+ /**
14371
+ * Staging's menus, each with the menu this folder names in its place: a
14372
+ * staging menu reference maps to the local one at the same location, path
14373
+ * and pointer. A staging menu with no local counterpart maps to null.
14374
+ */
14375
+ function stagingMenus(configuration, root) {
14376
+ const staging = memberDocument(configuration?.content);
14377
+ const ownConfiguration = root.file(MEMBER_CONFIGURATION_KEY);
14378
+ const local = memberDocument(ownConfiguration.exists ? ownConfiguration.read() : null);
14379
+ const place = (reference) => JSON.stringify([
14380
+ reference.location,
14381
+ reference.path,
14382
+ reference.pointer
14383
+ ]);
14384
+ const localKeys = new Map(references(local).map((reference) => [place(reference), reference.menu_key]));
14385
+ const ownKeys = new Set(menuKeys(local));
14386
+ const menus = /* @__PURE__ */ new Map();
14387
+ for (const key of menuKeys(staging)) if (!ownKeys.has(key)) menus.set(key, null);
14388
+ for (const reference of references(staging)) {
14389
+ const key = reference.menu_key;
14390
+ const own = localKeys.get(place(reference));
14391
+ if (typeof key !== "string" || ownKeys.has(key)) continue;
14392
+ if (typeof own === "string") menus.set(key, own);
14393
+ else if (!menus.has(key)) menus.set(key, null);
14394
+ }
14395
+ return menus;
14396
+ }
14397
+ /**
14398
+ * The text with staging's menus put back to this folder's, or null when it
14399
+ * would still name a staging menu.
14400
+ */
14401
+ function withOwnMenus(text, menus) {
14402
+ let translated = text;
14403
+ for (const [stagingKey, own] of menus) if (own !== null) translated = translated.replaceAll(`"${stagingKey}"`, `"${own}"`);
14404
+ for (const stagingKey of menus.keys()) if (translated.includes(stagingKey)) return null;
14405
+ return Buffer.from(translated, "utf-8");
14406
+ }
14407
+ function memberDocument(content) {
14408
+ let parsed = content;
14409
+ if (typeof content === "string") try {
14410
+ parsed = JSON.parse(content);
14411
+ } catch {
14412
+ return null;
14413
+ }
14414
+ return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
14415
+ }
14416
+ function references(document) {
14417
+ const listed = document?.["menu_references"];
14418
+ return Array.isArray(listed) ? listed.filter((reference) => reference !== null && typeof reference === "object") : [];
14419
+ }
14420
+ function menuKeys(document) {
14421
+ const listed = document?.["menus"];
14422
+ if (!Array.isArray(listed)) return [];
14423
+ return listed.flatMap((menu) => {
14424
+ const fields = menu;
14425
+ return [fields?.key, fields?.handle].filter((key) => typeof key === "string");
14426
+ });
14427
+ }
14428
+ //#endregion
14227
14429
  //#region src/commands/staging.ts
14228
14430
  /**
14229
14431
  * The production theme staging belongs to: --theme, else the theme this
@@ -14397,6 +14599,24 @@ function createStagingCommand() {
14397
14599
  for (const path of compared.localOnly) console.log(chalk.green(` local only ${path}`));
14398
14600
  for (const path of compared.branchOnly) console.log(chalk.red(` staging only ${path}`));
14399
14601
  }));
14602
+ const pull = withThemeOptions$1(new Command("pull").description("Take the files others published to staging into this directory; files you changed too are kept")).action((opts) => run$1(opts, async () => {
14603
+ requireToken();
14604
+ const root = new ThemeRoot(resolveRoot(opts.root));
14605
+ if (!root.isValid()) throw new Error(`'${root.root}' does not look like a theme directory.`);
14606
+ const outcome = await pullFromStaging(createApiClient(), resolveThemeId(opts), root, opts.json ? void 0 : (message) => console.error(chalk.dim(message)));
14607
+ if (opts.json) {
14608
+ console.log(JSON.stringify(outcome));
14609
+ return;
14610
+ }
14611
+ if (outcome.taken.length === 0) console.log(`Nothing to take from staging (revision ${outcome.revision}).`);
14612
+ else console.log(`Took ${outcome.taken.length} ${outcome.taken.length === 1 ? "file" : "files"} from staging (revision ${outcome.revision}):`);
14613
+ for (const path of outcome.taken) console.log(chalk.green(` ${path}`));
14614
+ if (outcome.kept.length > 0) {
14615
+ console.log("Kept as they are here:");
14616
+ for (const { path, reason } of outcome.kept) console.log(chalk.yellow(` ${path}: ${reason}`));
14617
+ }
14618
+ console.log(outcome.matches ? "This directory now matches staging." : "This directory still differs from staging; publishing sends your copies of the files kept above.");
14619
+ }));
14400
14620
  const promote = withThemeOptions$1(new Command("promote").description("Copy what staging serves onto the live theme, all at once, if the live theme hasn't changed since staging was based on it")).option("-y, --yes", "Promote without asking").option("--dry-run", "Show what promoting would change and the latest promotion; nothing is changed").option("--snapshot <id>", "Promote only this staging snapshot (a preview's snapshot_id); refuse if staging has changed since").action((opts) => run$1(opts, async () => {
14401
14621
  requireToken();
14402
14622
  const api = createApiClient();
@@ -14451,9 +14671,10 @@ function createStagingCommand() {
14451
14671
  }));
14452
14672
  declareInputs(request, themeBindingInputs);
14453
14673
  declareInputs(publish, stagingPublishInputs);
14674
+ declareInputs(pull, stagingPublishInputs);
14454
14675
  declareInputs(promote, themeBindingInputs);
14455
14676
  declareInputs(undoPromote, themeBindingInputs);
14456
- 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(promote).addCommand(undoPromote).addCommand(compare);
14677
+ 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(pull).addCommand(promote).addCommand(undoPromote).addCommand(compare);
14457
14678
  }
14458
14679
  //#endregion
14459
14680
  //#region src/commands/widget.ts