@realiizlabs/admin 0.15.8 → 0.16.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.
@@ -416,6 +416,10 @@ function makeReaders(config, registry, pending) {
416
416
  const entries = await listDirectory(repo(), e.folder);
417
417
  return entries.find((x) => registry.slugOf(e, x.name) === slug)?.path ?? null;
418
418
  };
419
+ const listSlugs = async (typeId) => {
420
+ const items = await listItems(typeId);
421
+ return items.filter((i) => !i.isNew).map((i) => i.slug).sort();
422
+ };
419
423
  const listItems = async (typeId) => {
420
424
  const e = need(typeId);
421
425
  const ctx = repo();
@@ -491,7 +495,7 @@ function makeReaders(config, registry, pending) {
491
495
  }
492
496
  };
493
497
  const prStatus = (number) => getPullRequestStatus(repo(), number);
494
- return { pathOf, listItems, countItems, readItem, lastAuthor, getPullRequest: getPullRequest2, prStatus };
498
+ return { pathOf, listItems, listSlugs, countItems, readItem, lastAuthor, getPullRequest: getPullRequest2, prStatus };
495
499
  }
496
500
 
497
501
  // src/git/branch.ts
@@ -512,11 +516,10 @@ async function createBranch(ctx, branch) {
512
516
  return { branch, baseSha };
513
517
  }
514
518
  async function deleteBranch(ctx, branch) {
515
- await ghFetchOrThrow(
516
- ctx,
517
- "DELETE",
518
- `${repoPath(ctx)}/git/refs/heads/${encodeURIComponent(branch)}`
519
- );
519
+ const path = `${repoPath(ctx)}/git/refs/heads/${encodeURIComponent(branch)}`;
520
+ const res = await ghFetch(ctx, "DELETE", path);
521
+ if (res.ok || res.status === 404 || res.status === 422) return;
522
+ throw toError(res, path);
520
523
  }
521
524
 
522
525
  // src/git/files.ts
@@ -614,18 +617,22 @@ ${input.body.trim()}
614
617
  if (!pictures.ok) return { ok: false, error: pictures.error };
615
618
  const files = [{ path, content }, ...pictures.files];
616
619
  const repo = config.env().repo;
620
+ const oldPath = input.replaces ? await readers.pathOf(entry.id, input.replaces).catch(() => null) : null;
621
+ const remove = oldPath && oldPath !== path ? [oldPath] : [];
622
+ const renamed = remove.length ? `
623
+ Renamed from \`${oldPath}\` to \`${path}\`` : "";
617
624
  if (input.existing && await stillOpen(input.existing.number)) {
618
- await writeFiles(repo, input.existing.branch, files, `Update: ${title}`);
625
+ await writeFiles(repo, input.existing.branch, files, `Update: ${title}`, { remove });
619
626
  navigation.redirect(`/admin/pr/${input.existing.number}`);
620
627
  }
621
628
  const branch = `admin/${entry.id}/${fileName.replace(/\.mdx$/, "")}-${stamp()}`;
622
629
  await createBranch(repo, branch);
623
- await writeFiles(repo, branch, files, `Publish: ${title}`);
630
+ await writeFiles(repo, branch, files, `Publish: ${title}`, { remove });
624
631
  const pr = await openPullRequest(repo, branch, {
625
632
  title: `Publish: ${title}`,
626
633
  body: `Published from the dashboard by ${user.email ?? user.id}.
627
634
 
628
- File: \`${path}\``
635
+ File: \`${path}\`${renamed}`
629
636
  });
630
637
  navigation.redirect(`/admin/pr/${pr.number}`);
631
638
  };
@@ -1116,7 +1123,7 @@ function makeHandlers(ctx) {
1116
1123
  }
1117
1124
 
1118
1125
  // src/version.ts
1119
- var ADMIN_VERSION = "0.15.8" ;
1126
+ var ADMIN_VERSION = "0.16.0" ;
1120
1127
 
1121
1128
  // src/studio/update.ts
1122
1129
  var PACKAGE_NAME = "@realiizlabs/admin";