frameboard 0.25.0 → 0.26.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/cli.js +667 -207
- package/dist/client/assets/index-DevfxYLc.js +114 -0
- package/dist/client/assets/index-DqicY-g0.css +2 -0
- package/dist/client/index.html +2 -2
- package/package.json +10 -2
- package/dist/client/assets/index-BL6hzziB.css +0 -2
- package/dist/client/assets/index-BPHCKLmi.js +0 -114
package/dist/cli.js
CHANGED
|
@@ -7,14 +7,14 @@ import path, { basename, delimiter, dirname, extname, isAbsolute, join, relative
|
|
|
7
7
|
import fs, { copyFileSync, createReadStream, existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
8
8
|
import process$1, { versions } from "node:process";
|
|
9
9
|
import { isDeepStrictEqual, promisify, stripVTControlCharacters } from "node:util";
|
|
10
|
-
import { constants, copyFile, cp, link, lstat, mkdir, open, readFile, readdir, readlink, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
10
|
+
import { constants, copyFile, cp, link, lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, utimes, writeFile } from "node:fs/promises";
|
|
11
11
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
12
12
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
13
|
-
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
14
14
|
import { STATUS_CODES, ServerResponse, createServer } from "node:http";
|
|
15
15
|
import { Http2ServerRequest, constants as constants$1 } from "node:http2";
|
|
16
16
|
import { Readable } from "node:stream";
|
|
17
|
-
import { homedir, release, type } from "node:os";
|
|
17
|
+
import { homedir, release, tmpdir, type } from "node:os";
|
|
18
18
|
// \0rolldown/runtime.js
|
|
19
19
|
var __create = Object.create;
|
|
20
20
|
var __defProp = Object.defineProperty;
|
|
@@ -3049,7 +3049,12 @@ const EXIT_CODES = {
|
|
|
3049
3049
|
"dispatch-failed": 13,
|
|
3050
3050
|
"section-not-found": 3,
|
|
3051
3051
|
"reanchors-descendant": 7,
|
|
3052
|
-
"clipboard-unsupported": 3
|
|
3052
|
+
"clipboard-unsupported": 3,
|
|
3053
|
+
"frame-map-invalid": 5,
|
|
3054
|
+
"format-refused": 10,
|
|
3055
|
+
"formatter-not-found": 9,
|
|
3056
|
+
"references-stale": 14,
|
|
3057
|
+
"page-file-load": 10
|
|
3053
3058
|
};
|
|
3054
3059
|
var FrameboardError = class extends Error {
|
|
3055
3060
|
code;
|
|
@@ -9158,7 +9163,9 @@ const projectFileSchema = looseObject({
|
|
|
9158
9163
|
version: literal(1),
|
|
9159
9164
|
pages: array$1(string$1()),
|
|
9160
9165
|
createdAt: union([datetime(), unknown()]).optional(),
|
|
9161
|
-
checks: union([projectChecksSchema, unknown()]).optional()
|
|
9166
|
+
checks: union([projectChecksSchema, unknown()]).optional(),
|
|
9167
|
+
group: union([string$1(), unknown()]).optional(),
|
|
9168
|
+
archived: union([boolean$1(), unknown()]).optional()
|
|
9162
9169
|
});
|
|
9163
9170
|
const layoutEntrySchema = looseObject({
|
|
9164
9171
|
x: int$1(),
|
|
@@ -9232,7 +9239,8 @@ async function listFrames(pageDir) {
|
|
|
9232
9239
|
/**
|
|
9233
9240
|
* The page order a reader shows: listed pages that exist in that order, then
|
|
9234
9241
|
* unlisted ones by name. A file that fails to read orders every page by name.
|
|
9235
|
-
* The creation time
|
|
9242
|
+
* The creation time, folder, and archive flag come from the same read, each
|
|
9243
|
+
* read as absent when the file holds none or holds one of another type.
|
|
9236
9244
|
*/
|
|
9237
9245
|
async function readPageOrder(projectDir) {
|
|
9238
9246
|
const folders = await listPageFolders(projectDir);
|
|
@@ -9248,6 +9256,8 @@ async function readPageOrder(projectDir) {
|
|
|
9248
9256
|
return {
|
|
9249
9257
|
pages: folders,
|
|
9250
9258
|
createdAt: null,
|
|
9259
|
+
group: null,
|
|
9260
|
+
archived: false,
|
|
9251
9261
|
error: {
|
|
9252
9262
|
path,
|
|
9253
9263
|
message: error.message
|
|
@@ -9257,9 +9267,17 @@ async function readPageOrder(projectDir) {
|
|
|
9257
9267
|
return {
|
|
9258
9268
|
pages: orderPages(file.pages, folders),
|
|
9259
9269
|
createdAt: isTime(file.createdAt) ? file.createdAt : null,
|
|
9270
|
+
group: groupOf$1(file.group),
|
|
9271
|
+
archived: file.archived === true,
|
|
9260
9272
|
error: null
|
|
9261
9273
|
};
|
|
9262
9274
|
}
|
|
9275
|
+
/** A folder name as home shows it, trimmed, null for a blank or a non-string. */
|
|
9276
|
+
function groupOf$1(value) {
|
|
9277
|
+
if (typeof value !== "string") return null;
|
|
9278
|
+
const trimmed = value.trim();
|
|
9279
|
+
return trimmed === "" ? null : trimmed;
|
|
9280
|
+
}
|
|
9263
9281
|
function isTime(value) {
|
|
9264
9282
|
return datetime().safeParse(value).success;
|
|
9265
9283
|
}
|
|
@@ -9347,7 +9365,7 @@ async function scanBoard(root, { project } = {}) {
|
|
|
9347
9365
|
}
|
|
9348
9366
|
async function scanProject(root, name) {
|
|
9349
9367
|
const path = join(root, name);
|
|
9350
|
-
const { pages: order, createdAt, error } = await readPageOrder(path);
|
|
9368
|
+
const { pages: order, createdAt, group, archived, error } = await readPageOrder(path);
|
|
9351
9369
|
const pages = await Promise.all(order.map((page, index) => scanPage(root, name, page, index)));
|
|
9352
9370
|
const times = await Promise.all([
|
|
9353
9371
|
mtimeOf$1(join(path, PROJECT_FILE)),
|
|
@@ -9359,6 +9377,8 @@ async function scanProject(root, name) {
|
|
|
9359
9377
|
path,
|
|
9360
9378
|
modifiedAt: new Date(Math.max(...times)).toISOString(),
|
|
9361
9379
|
createdAt,
|
|
9380
|
+
group,
|
|
9381
|
+
archived,
|
|
9362
9382
|
projectFileError: error,
|
|
9363
9383
|
pages
|
|
9364
9384
|
};
|
|
@@ -9497,8 +9517,9 @@ async function isDirectory(path) {
|
|
|
9497
9517
|
}
|
|
9498
9518
|
}
|
|
9499
9519
|
// package.json
|
|
9500
|
-
var version$1 = "0.
|
|
9520
|
+
var version$1 = "0.26.0";
|
|
9501
9521
|
var dependencies = { "playwright-core": "1.64.1" };
|
|
9522
|
+
var peerDependencies = { "oxfmt": "0.75.0" };
|
|
9502
9523
|
// src/shared/version.ts
|
|
9503
9524
|
const version = version$1;
|
|
9504
9525
|
// src/cli/client-dir.ts
|
|
@@ -36589,6 +36610,286 @@ const listenerSchema = object$1({
|
|
|
36589
36610
|
tag: string$1(),
|
|
36590
36611
|
since: string$1()
|
|
36591
36612
|
});
|
|
36613
|
+
// src/server/board/pages.ts
|
|
36614
|
+
/** Notes and their images belong to the page they were pinned on, so a copy starts without them. */
|
|
36615
|
+
const NOT_COPIED = /* @__PURE__ */ new Set(["notes.json", ".notes"]);
|
|
36616
|
+
async function addPage(root, ref, { index, ...options }) {
|
|
36617
|
+
const page = await resolvePageRef(root, ref, {
|
|
36618
|
+
...options,
|
|
36619
|
+
allowMissing: true
|
|
36620
|
+
});
|
|
36621
|
+
if (existsSync(page.path)) throw taken(page, page.name);
|
|
36622
|
+
return recordOf(root, page, await reorder(root, page, async (order) => {
|
|
36623
|
+
await mkdir(page.path);
|
|
36624
|
+
await options.journal?.created(page.path);
|
|
36625
|
+
return insert(order, page.name, index ?? order.length);
|
|
36626
|
+
}, options.journal));
|
|
36627
|
+
}
|
|
36628
|
+
async function duplicatePage(root, ref, { name, ...options }) {
|
|
36629
|
+
const source = await resolvePageRef(root, ref, options);
|
|
36630
|
+
const projectDir = join(root, source.project);
|
|
36631
|
+
return recordOf(root, source, await reorder(root, source, async (order) => {
|
|
36632
|
+
const copy = await freeName(source, projectDir, name, false);
|
|
36633
|
+
const copyPath = join(projectDir, copy);
|
|
36634
|
+
await cp(source.path, copyPath, {
|
|
36635
|
+
recursive: true,
|
|
36636
|
+
errorOnExist: true,
|
|
36637
|
+
force: false,
|
|
36638
|
+
filter: (path) => isCopied(basename(path))
|
|
36639
|
+
});
|
|
36640
|
+
await options.journal?.created(copyPath);
|
|
36641
|
+
return {
|
|
36642
|
+
name: copy,
|
|
36643
|
+
order: insert(order, copy, order.indexOf(source.name) + 1)
|
|
36644
|
+
};
|
|
36645
|
+
}, options.journal));
|
|
36646
|
+
}
|
|
36647
|
+
async function renamePage(root, ref, newName, { journal, ...options }) {
|
|
36648
|
+
const page = await resolvePageRef(root, ref, options);
|
|
36649
|
+
const projectDir = join(root, page.project);
|
|
36650
|
+
return recordOf(root, page, await reorder(root, page, async (order) => {
|
|
36651
|
+
const renamed = await freeName(page, projectDir, newName, true);
|
|
36652
|
+
const renamedPath = join(projectDir, renamed);
|
|
36653
|
+
if (journal) await journal.moved(page.path, renamedPath);
|
|
36654
|
+
else await rename(page.path, renamedPath);
|
|
36655
|
+
return {
|
|
36656
|
+
name: renamed,
|
|
36657
|
+
order: order.map((name) => name === page.name ? renamed : name)
|
|
36658
|
+
};
|
|
36659
|
+
}, journal));
|
|
36660
|
+
}
|
|
36661
|
+
async function movePage(root, ref, { index, ...options }) {
|
|
36662
|
+
const page = await resolvePageRef(root, ref, options);
|
|
36663
|
+
return recordOf(root, page, await reorder(root, page, async (order) => insert(order.filter((name) => name !== page.name), page.name, index), options.journal));
|
|
36664
|
+
}
|
|
36665
|
+
async function deletePage(root, ref, { journal, ...options }) {
|
|
36666
|
+
const page = await resolvePageRef(root, ref, options);
|
|
36667
|
+
await reorder(root, page, async (order) => {
|
|
36668
|
+
if (journal) await journal.removed(page.path);
|
|
36669
|
+
else await rm(page.path, {
|
|
36670
|
+
recursive: true,
|
|
36671
|
+
force: true
|
|
36672
|
+
});
|
|
36673
|
+
return order.filter((name) => name !== page.name);
|
|
36674
|
+
}, journal);
|
|
36675
|
+
return { deleted: `${page.project}/${page.name}` };
|
|
36676
|
+
}
|
|
36677
|
+
/**
|
|
36678
|
+
* Runs one page change under the project file's lock, returning the page's
|
|
36679
|
+
* name after it and the order written. The file is read and
|
|
36680
|
+
* validated before `change` touches a folder, and written back holding exactly
|
|
36681
|
+
* the page folders on disk, in the order `change` returns, which the journal
|
|
36682
|
+
* is told of when it differs from the order the file held.
|
|
36683
|
+
*/
|
|
36684
|
+
async function reorder(root, page, change, journal) {
|
|
36685
|
+
const projectDir = join(root, page.project);
|
|
36686
|
+
const path = join(projectDir, PROJECT_FILE);
|
|
36687
|
+
return withLocks([path], async () => {
|
|
36688
|
+
const file = await readRecord(path, {
|
|
36689
|
+
...projectSpec,
|
|
36690
|
+
empty: emptyProject
|
|
36691
|
+
});
|
|
36692
|
+
const changed = await change(orderPages(file.pages, await listPageFolders(projectDir)));
|
|
36693
|
+
const { name, order } = Array.isArray(changed) ? {
|
|
36694
|
+
name: page.name,
|
|
36695
|
+
order: changed
|
|
36696
|
+
} : changed;
|
|
36697
|
+
const pages = orderPages(order, await listPageFolders(projectDir));
|
|
36698
|
+
await writeRecord(path, {
|
|
36699
|
+
...file,
|
|
36700
|
+
pages
|
|
36701
|
+
});
|
|
36702
|
+
if (journal && !isDeepStrictEqual(file.pages, pages)) journal.pages(projectDir, file.pages, pages);
|
|
36703
|
+
return {
|
|
36704
|
+
name,
|
|
36705
|
+
pages
|
|
36706
|
+
};
|
|
36707
|
+
});
|
|
36708
|
+
}
|
|
36709
|
+
async function recordOf(root, page, { name, pages }) {
|
|
36710
|
+
return scanPage(root, page.project, name, pages.indexOf(name));
|
|
36711
|
+
}
|
|
36712
|
+
/**
|
|
36713
|
+
* The explicit name when free and valid, else the next free copy of the
|
|
36714
|
+
* source's. A rename frees the source's own name, so a case-only rename runs.
|
|
36715
|
+
*/
|
|
36716
|
+
async function freeName(source, projectDir, name, freesSource) {
|
|
36717
|
+
const others = (await listPageFolders(projectDir)).filter((page) => !freesSource || page !== source.name);
|
|
36718
|
+
if (name === void 0) return nextFreeName(source.name, others);
|
|
36719
|
+
assertValidName("page", name);
|
|
36720
|
+
const holder = matchName(others, name);
|
|
36721
|
+
if (holder) throw taken(source, holder);
|
|
36722
|
+
return name;
|
|
36723
|
+
}
|
|
36724
|
+
function insert(order, name, index) {
|
|
36725
|
+
const at = Math.max(0, Math.min(index, order.length));
|
|
36726
|
+
return [
|
|
36727
|
+
...order.slice(0, at),
|
|
36728
|
+
name,
|
|
36729
|
+
...order.slice(at)
|
|
36730
|
+
];
|
|
36731
|
+
}
|
|
36732
|
+
/** Whether a copy of a page or project folder takes the file or folder `name`. */
|
|
36733
|
+
function isCopied(name) {
|
|
36734
|
+
return !NOT_COPIED.has(name) && !name.endsWith(".lock") && !name.endsWith(".tmp");
|
|
36735
|
+
}
|
|
36736
|
+
function taken(page, holder) {
|
|
36737
|
+
return new FrameboardError("name-taken", `Project ${page.project} already has a page ${holder}.`, {
|
|
36738
|
+
project: page.project,
|
|
36739
|
+
name: holder
|
|
36740
|
+
});
|
|
36741
|
+
}
|
|
36742
|
+
// src/server/board/projects.ts
|
|
36743
|
+
/** A new project holding one empty page. */
|
|
36744
|
+
async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journal } = {}) {
|
|
36745
|
+
assertValidName("project", name);
|
|
36746
|
+
await assertFree$1(root, name);
|
|
36747
|
+
await mkdir(join(root, name, START_PAGE), { recursive: true });
|
|
36748
|
+
await writeRecord(join(root, name, PROJECT_FILE), {
|
|
36749
|
+
version: 1,
|
|
36750
|
+
pages: [START_PAGE],
|
|
36751
|
+
createdAt: now.toISOString()
|
|
36752
|
+
});
|
|
36753
|
+
await journal?.created(join(root, name));
|
|
36754
|
+
return scanProject(root, name);
|
|
36755
|
+
}
|
|
36756
|
+
async function renameProject(root, name, newName, { journal } = {}) {
|
|
36757
|
+
const project = await resolveProject(root, name);
|
|
36758
|
+
assertValidName("project", newName);
|
|
36759
|
+
await assertFree$1(root, newName, project.name);
|
|
36760
|
+
const renamed = join(root, newName);
|
|
36761
|
+
if (journal) await journal.moved(project.path, renamed);
|
|
36762
|
+
else await rename(project.path, renamed);
|
|
36763
|
+
return scanProject(root, newName);
|
|
36764
|
+
}
|
|
36765
|
+
/**
|
|
36766
|
+
* A copy of the project under the next free name, without its notes, and
|
|
36767
|
+
* stamped as made `now`.
|
|
36768
|
+
*/
|
|
36769
|
+
async function duplicateProject(root, name, now = /* @__PURE__ */ new Date(), { journal } = {}) {
|
|
36770
|
+
const source = await resolveProject(root, name);
|
|
36771
|
+
const file = await readRecord(join(source.path, PROJECT_FILE), {
|
|
36772
|
+
...projectSpec,
|
|
36773
|
+
empty: emptyProject
|
|
36774
|
+
});
|
|
36775
|
+
const copy = nextFreeName(source.name, await listProjects(root));
|
|
36776
|
+
const copyPath = join(root, copy);
|
|
36777
|
+
await cp(source.path, copyPath, {
|
|
36778
|
+
recursive: true,
|
|
36779
|
+
errorOnExist: true,
|
|
36780
|
+
force: false,
|
|
36781
|
+
filter: (path) => isCopied(basename(path))
|
|
36782
|
+
});
|
|
36783
|
+
const { archived: _archived, ...kept } = file;
|
|
36784
|
+
await writeRecord(join(copyPath, PROJECT_FILE), {
|
|
36785
|
+
...kept,
|
|
36786
|
+
createdAt: now.toISOString()
|
|
36787
|
+
});
|
|
36788
|
+
await journal?.created(copyPath);
|
|
36789
|
+
return scanProject(root, copy);
|
|
36790
|
+
}
|
|
36791
|
+
async function deleteProject(root, name, { journal } = {}) {
|
|
36792
|
+
const project = await resolveProject(root, name);
|
|
36793
|
+
if (journal) await journal.removed(project.path);
|
|
36794
|
+
else await rm(project.path, {
|
|
36795
|
+
recursive: true,
|
|
36796
|
+
force: true
|
|
36797
|
+
});
|
|
36798
|
+
return { deleted: project.name };
|
|
36799
|
+
}
|
|
36800
|
+
/**
|
|
36801
|
+
* Files every named project at once, each `project.json` read and merged
|
|
36802
|
+
* under its lock so pages, checks, and unknown keys stay as written. A file
|
|
36803
|
+
* that does not parse refuses the whole filing before any is written. The
|
|
36804
|
+
* file's and folder's times are put back, since a filing is not an edit to
|
|
36805
|
+
* the project and must not move it in home's Edited sort.
|
|
36806
|
+
*/
|
|
36807
|
+
async function fileProjects(root, names, filing, { journal } = {}) {
|
|
36808
|
+
const projects = await Promise.all(names.map((name) => resolveProject(root, name)));
|
|
36809
|
+
const paths = [...new Set(projects.map((project) => join(project.path, PROJECT_FILE)))];
|
|
36810
|
+
await keepingTimes(paths, (keep) => withLocks(paths, async () => {
|
|
36811
|
+
const files = await Promise.all(paths.map((path) => readRecord(path, {
|
|
36812
|
+
...projectSpec,
|
|
36813
|
+
empty: emptyProject
|
|
36814
|
+
})));
|
|
36815
|
+
for (const [index, path] of paths.entries()) {
|
|
36816
|
+
const file = files[index];
|
|
36817
|
+
if (!file) continue;
|
|
36818
|
+
const next = filed(file, filing);
|
|
36819
|
+
const before = filingOf(file);
|
|
36820
|
+
const after = filingOf(next);
|
|
36821
|
+
if (isSameFiling(before, after)) continue;
|
|
36822
|
+
await keep(path);
|
|
36823
|
+
await writeRecord(path, next);
|
|
36824
|
+
journal?.project(path, before, after);
|
|
36825
|
+
}
|
|
36826
|
+
}));
|
|
36827
|
+
return Promise.all(projects.map((project) => scanProject(root, project.name)));
|
|
36828
|
+
}
|
|
36829
|
+
function filed(file, filing) {
|
|
36830
|
+
const { group, archived, ...rest } = file;
|
|
36831
|
+
if ("group" in filing) {
|
|
36832
|
+
const name = filing.group?.trim();
|
|
36833
|
+
return {
|
|
36834
|
+
...rest,
|
|
36835
|
+
...name ? { group: name } : {},
|
|
36836
|
+
...archived === void 0 ? {} : { archived }
|
|
36837
|
+
};
|
|
36838
|
+
}
|
|
36839
|
+
return {
|
|
36840
|
+
...rest,
|
|
36841
|
+
...group === void 0 ? {} : { group },
|
|
36842
|
+
...filing.archived ? { archived: true } : {}
|
|
36843
|
+
};
|
|
36844
|
+
}
|
|
36845
|
+
/** The filing keys a project file holds, leaving out the ones it lacks. */
|
|
36846
|
+
function filingOf(file) {
|
|
36847
|
+
return {
|
|
36848
|
+
...file.group === void 0 ? {} : { group: file.group },
|
|
36849
|
+
...file.archived === void 0 ? {} : { archived: file.archived }
|
|
36850
|
+
};
|
|
36851
|
+
}
|
|
36852
|
+
function isSameFiling(a, b) {
|
|
36853
|
+
return a.group === b.group && a.archived === b.archived;
|
|
36854
|
+
}
|
|
36855
|
+
/**
|
|
36856
|
+
* Runs `run`, a section holding the lock of each project file it writes, and
|
|
36857
|
+
* puts back the times that file and its folder held, which the scanner reads
|
|
36858
|
+
* as the project's last edit. `run` calls `keep` under the lock before each
|
|
36859
|
+
* write, so the file's time is read after any writer that held the lock first.
|
|
36860
|
+
* The folder's time is read before the lock, since taking and dropping the
|
|
36861
|
+
* lock moves it, and goes back only where the file kept its time until `keep`,
|
|
36862
|
+
* so a writer that ran in between keeps the Edited time it earned.
|
|
36863
|
+
*/
|
|
36864
|
+
async function keepingTimes(files, run) {
|
|
36865
|
+
const before = new Map(await Promise.all(files.map(async (file) => [file, {
|
|
36866
|
+
file: await stat(file).catch(() => void 0),
|
|
36867
|
+
folder: await stat(dirname(file)).catch(() => void 0)
|
|
36868
|
+
}])));
|
|
36869
|
+
const kept = /* @__PURE__ */ new Map();
|
|
36870
|
+
const keep = async (file) => {
|
|
36871
|
+
const time = await stat(file).catch(() => void 0);
|
|
36872
|
+
if (time && !kept.has(file)) kept.set(file, time);
|
|
36873
|
+
};
|
|
36874
|
+
const put = (path, time) => utimes(path, time.atimeMs / 1e3, time.mtimeMs / 1e3).catch(() => {});
|
|
36875
|
+
try {
|
|
36876
|
+
return await run(keep);
|
|
36877
|
+
} finally {
|
|
36878
|
+
await Promise.all([...kept].map(async ([file, time]) => {
|
|
36879
|
+
await put(file, time);
|
|
36880
|
+
const { file: was, folder } = before.get(file) ?? {};
|
|
36881
|
+
if (folder && was?.mtimeMs === time.mtimeMs) await put(dirname(file), folder);
|
|
36882
|
+
}));
|
|
36883
|
+
}
|
|
36884
|
+
}
|
|
36885
|
+
/** Throws `name-taken` when another project holds `name` in any case. */
|
|
36886
|
+
async function assertFree$1(root, name, self) {
|
|
36887
|
+
const taken = matchName((await listProjects(root)).filter((project) => project !== self), name);
|
|
36888
|
+
if (taken) throw new FrameboardError("name-taken", `The board already has a project ${taken}.`, {
|
|
36889
|
+
name,
|
|
36890
|
+
taken
|
|
36891
|
+
});
|
|
36892
|
+
}
|
|
36592
36893
|
// src/server/look/token-edit.ts
|
|
36593
36894
|
const NAME = /^--[\w-]+$/;
|
|
36594
36895
|
const UNSAFE_VALUE = /[;{}\n\r]|\/\*/;
|
|
@@ -36832,7 +37133,7 @@ async function emptyTrash(root) {
|
|
|
36832
37133
|
/** The records a change writes, whose locks are held while it is checked and written. */
|
|
36833
37134
|
function lockPaths(change) {
|
|
36834
37135
|
if (change.kind === "entry" || change.kind === "section") return [change.layout];
|
|
36835
|
-
if (change.kind === "pages") return [change.file];
|
|
37136
|
+
if (change.kind === "pages" || change.kind === "project") return [change.file];
|
|
36836
37137
|
return [];
|
|
36837
37138
|
}
|
|
36838
37139
|
/**
|
|
@@ -36867,6 +37168,10 @@ async function reads(change, side) {
|
|
|
36867
37168
|
});
|
|
36868
37169
|
return isDeepStrictEqual(file.pages, change[side]);
|
|
36869
37170
|
}
|
|
37171
|
+
case "project": {
|
|
37172
|
+
const file = await readRecord(change.file, projectSpec);
|
|
37173
|
+
return isDeepStrictEqual(filingOf(file), change[side]);
|
|
37174
|
+
}
|
|
36870
37175
|
case "moved": {
|
|
36871
37176
|
const [present, absent] = side === "after" ? [change.to, change.from] : [change.from, change.to];
|
|
36872
37177
|
return await exists(present) && !await exists(absent);
|
|
@@ -36938,6 +37243,14 @@ async function restore(change, side) {
|
|
|
36938
37243
|
});
|
|
36939
37244
|
return;
|
|
36940
37245
|
}
|
|
37246
|
+
case "project": {
|
|
37247
|
+
const { group: _group, archived: _archived, ...rest } = await readRecord(change.file, projectSpec);
|
|
37248
|
+
await writeRecord(change.file, {
|
|
37249
|
+
...rest,
|
|
37250
|
+
...change[side]
|
|
37251
|
+
});
|
|
37252
|
+
return;
|
|
37253
|
+
}
|
|
36941
37254
|
case "moved":
|
|
36942
37255
|
if (side === "before") await rename(change.to, change.from);
|
|
36943
37256
|
else await rename(change.from, change.to);
|
|
@@ -37066,6 +37379,14 @@ var StepJournal = class {
|
|
|
37066
37379
|
after
|
|
37067
37380
|
});
|
|
37068
37381
|
}
|
|
37382
|
+
project(file, before, after) {
|
|
37383
|
+
this.changes.push({
|
|
37384
|
+
kind: "project",
|
|
37385
|
+
file,
|
|
37386
|
+
before,
|
|
37387
|
+
after
|
|
37388
|
+
});
|
|
37389
|
+
}
|
|
37069
37390
|
async moved(from, to) {
|
|
37070
37391
|
await rename(from, to);
|
|
37071
37392
|
this.changes.push({
|
|
@@ -37267,15 +37588,17 @@ var History = class {
|
|
|
37267
37588
|
const was = to === "before" ? "after" : "before";
|
|
37268
37589
|
const hashes = {};
|
|
37269
37590
|
const locks = step.changes.flatMap(lockPaths).filter((path) => existsSync(dirname(path)));
|
|
37591
|
+
const timed = step.changes.flatMap((change) => change.kind === "project" ? [change.file] : []);
|
|
37270
37592
|
try {
|
|
37271
|
-
await withLocks(locks, async () => {
|
|
37593
|
+
await keepingTimes(timed, (keep) => withLocks(locks, async () => {
|
|
37272
37594
|
for (const change of step.changes) if (!await holds(change, was)) throw new FrameboardError("undo-overtaken", `An agent changed ${nameOf(change)} after your edit, so that step was dropped.`, { change: change.kind });
|
|
37595
|
+
for (const file of timed) await keep(file);
|
|
37273
37596
|
const ordered = to === "before" ? [...step.changes].reverse() : step.changes;
|
|
37274
37597
|
for (const change of ordered) {
|
|
37275
37598
|
const hash = await restore(change, to);
|
|
37276
37599
|
if (hash !== void 0 && "ref" in change) hashes[change.ref] = hash;
|
|
37277
37600
|
}
|
|
37278
|
-
});
|
|
37601
|
+
}));
|
|
37279
37602
|
} catch (error) {
|
|
37280
37603
|
if (!(error instanceof FrameboardError && error.code === "undo-overtaken")) from.push(step);
|
|
37281
37604
|
this.onChange(this.counts());
|
|
@@ -37299,11 +37622,12 @@ var History = class {
|
|
|
37299
37622
|
return run;
|
|
37300
37623
|
}
|
|
37301
37624
|
};
|
|
37302
|
-
/** What a refusal names as overtaken, being a frame, a section, a page,
|
|
37625
|
+
/** What a refusal names as overtaken, being a frame, a section, a page, the page order, or a filed project. */
|
|
37303
37626
|
function nameOf(change) {
|
|
37304
37627
|
if (change.kind === "entry") return change.frame;
|
|
37305
37628
|
if (change.kind === "section") return `section ${change.section}`;
|
|
37306
37629
|
if (change.kind === "pages") return "the page order";
|
|
37630
|
+
if (change.kind === "project") return basename(dirname(change.file));
|
|
37307
37631
|
if (change.kind === "token") return change.name;
|
|
37308
37632
|
const path = change.kind === "moved" ? change.to : change.path;
|
|
37309
37633
|
return basename(path, FRAME_EXTENSION);
|
|
@@ -39272,135 +39596,6 @@ function parseScale$1(value) {
|
|
|
39272
39596
|
if (value === "1" || value === "2" || value === "3") return Number(value);
|
|
39273
39597
|
return null;
|
|
39274
39598
|
}
|
|
39275
|
-
// src/server/board/pages.ts
|
|
39276
|
-
/** Notes and their images belong to the page they were pinned on, so a copy starts without them. */
|
|
39277
|
-
const NOT_COPIED = /* @__PURE__ */ new Set(["notes.json", ".notes"]);
|
|
39278
|
-
async function addPage(root, ref, { index, ...options }) {
|
|
39279
|
-
const page = await resolvePageRef(root, ref, {
|
|
39280
|
-
...options,
|
|
39281
|
-
allowMissing: true
|
|
39282
|
-
});
|
|
39283
|
-
if (existsSync(page.path)) throw taken(page, page.name);
|
|
39284
|
-
return recordOf(root, page, await reorder(root, page, async (order) => {
|
|
39285
|
-
await mkdir(page.path);
|
|
39286
|
-
await options.journal?.created(page.path);
|
|
39287
|
-
return insert(order, page.name, index ?? order.length);
|
|
39288
|
-
}, options.journal));
|
|
39289
|
-
}
|
|
39290
|
-
async function duplicatePage(root, ref, { name, ...options }) {
|
|
39291
|
-
const source = await resolvePageRef(root, ref, options);
|
|
39292
|
-
const projectDir = join(root, source.project);
|
|
39293
|
-
return recordOf(root, source, await reorder(root, source, async (order) => {
|
|
39294
|
-
const copy = await freeName(source, projectDir, name, false);
|
|
39295
|
-
const copyPath = join(projectDir, copy);
|
|
39296
|
-
await cp(source.path, copyPath, {
|
|
39297
|
-
recursive: true,
|
|
39298
|
-
errorOnExist: true,
|
|
39299
|
-
force: false,
|
|
39300
|
-
filter: (path) => isCopied(basename(path))
|
|
39301
|
-
});
|
|
39302
|
-
await options.journal?.created(copyPath);
|
|
39303
|
-
return {
|
|
39304
|
-
name: copy,
|
|
39305
|
-
order: insert(order, copy, order.indexOf(source.name) + 1)
|
|
39306
|
-
};
|
|
39307
|
-
}, options.journal));
|
|
39308
|
-
}
|
|
39309
|
-
async function renamePage(root, ref, newName, { journal, ...options }) {
|
|
39310
|
-
const page = await resolvePageRef(root, ref, options);
|
|
39311
|
-
const projectDir = join(root, page.project);
|
|
39312
|
-
return recordOf(root, page, await reorder(root, page, async (order) => {
|
|
39313
|
-
const renamed = await freeName(page, projectDir, newName, true);
|
|
39314
|
-
const renamedPath = join(projectDir, renamed);
|
|
39315
|
-
if (journal) await journal.moved(page.path, renamedPath);
|
|
39316
|
-
else await rename(page.path, renamedPath);
|
|
39317
|
-
return {
|
|
39318
|
-
name: renamed,
|
|
39319
|
-
order: order.map((name) => name === page.name ? renamed : name)
|
|
39320
|
-
};
|
|
39321
|
-
}, journal));
|
|
39322
|
-
}
|
|
39323
|
-
async function movePage(root, ref, { index, ...options }) {
|
|
39324
|
-
const page = await resolvePageRef(root, ref, options);
|
|
39325
|
-
return recordOf(root, page, await reorder(root, page, async (order) => insert(order.filter((name) => name !== page.name), page.name, index), options.journal));
|
|
39326
|
-
}
|
|
39327
|
-
async function deletePage(root, ref, { journal, ...options }) {
|
|
39328
|
-
const page = await resolvePageRef(root, ref, options);
|
|
39329
|
-
await reorder(root, page, async (order) => {
|
|
39330
|
-
if (journal) await journal.removed(page.path);
|
|
39331
|
-
else await rm(page.path, {
|
|
39332
|
-
recursive: true,
|
|
39333
|
-
force: true
|
|
39334
|
-
});
|
|
39335
|
-
return order.filter((name) => name !== page.name);
|
|
39336
|
-
}, journal);
|
|
39337
|
-
return { deleted: `${page.project}/${page.name}` };
|
|
39338
|
-
}
|
|
39339
|
-
/**
|
|
39340
|
-
* Runs one page change under the project file's lock, returning the page's
|
|
39341
|
-
* name after it and the order written. The file is read and
|
|
39342
|
-
* validated before `change` touches a folder, and written back holding exactly
|
|
39343
|
-
* the page folders on disk, in the order `change` returns, which the journal
|
|
39344
|
-
* is told of when it differs from the order the file held.
|
|
39345
|
-
*/
|
|
39346
|
-
async function reorder(root, page, change, journal) {
|
|
39347
|
-
const projectDir = join(root, page.project);
|
|
39348
|
-
const path = join(projectDir, PROJECT_FILE);
|
|
39349
|
-
return withLocks([path], async () => {
|
|
39350
|
-
const file = await readRecord(path, {
|
|
39351
|
-
...projectSpec,
|
|
39352
|
-
empty: emptyProject
|
|
39353
|
-
});
|
|
39354
|
-
const changed = await change(orderPages(file.pages, await listPageFolders(projectDir)));
|
|
39355
|
-
const { name, order } = Array.isArray(changed) ? {
|
|
39356
|
-
name: page.name,
|
|
39357
|
-
order: changed
|
|
39358
|
-
} : changed;
|
|
39359
|
-
const pages = orderPages(order, await listPageFolders(projectDir));
|
|
39360
|
-
await writeRecord(path, {
|
|
39361
|
-
...file,
|
|
39362
|
-
pages
|
|
39363
|
-
});
|
|
39364
|
-
if (journal && !isDeepStrictEqual(file.pages, pages)) journal.pages(projectDir, file.pages, pages);
|
|
39365
|
-
return {
|
|
39366
|
-
name,
|
|
39367
|
-
pages
|
|
39368
|
-
};
|
|
39369
|
-
});
|
|
39370
|
-
}
|
|
39371
|
-
async function recordOf(root, page, { name, pages }) {
|
|
39372
|
-
return scanPage(root, page.project, name, pages.indexOf(name));
|
|
39373
|
-
}
|
|
39374
|
-
/**
|
|
39375
|
-
* The explicit name when free and valid, else the next free copy of the
|
|
39376
|
-
* source's. A rename frees the source's own name, so a case-only rename runs.
|
|
39377
|
-
*/
|
|
39378
|
-
async function freeName(source, projectDir, name, freesSource) {
|
|
39379
|
-
const others = (await listPageFolders(projectDir)).filter((page) => !freesSource || page !== source.name);
|
|
39380
|
-
if (name === void 0) return nextFreeName(source.name, others);
|
|
39381
|
-
assertValidName("page", name);
|
|
39382
|
-
const holder = matchName(others, name);
|
|
39383
|
-
if (holder) throw taken(source, holder);
|
|
39384
|
-
return name;
|
|
39385
|
-
}
|
|
39386
|
-
function insert(order, name, index) {
|
|
39387
|
-
const at = Math.max(0, Math.min(index, order.length));
|
|
39388
|
-
return [
|
|
39389
|
-
...order.slice(0, at),
|
|
39390
|
-
name,
|
|
39391
|
-
...order.slice(at)
|
|
39392
|
-
];
|
|
39393
|
-
}
|
|
39394
|
-
/** Whether a copy of a page or project folder takes the file or folder `name`. */
|
|
39395
|
-
function isCopied(name) {
|
|
39396
|
-
return !NOT_COPIED.has(name) && !name.endsWith(".lock") && !name.endsWith(".tmp");
|
|
39397
|
-
}
|
|
39398
|
-
function taken(page, holder) {
|
|
39399
|
-
return new FrameboardError("name-taken", `Project ${page.project} already has a page ${holder}.`, {
|
|
39400
|
-
project: page.project,
|
|
39401
|
-
name: holder
|
|
39402
|
-
});
|
|
39403
|
-
}
|
|
39404
39599
|
// src/server/board/paste.ts
|
|
39405
39600
|
/** Reads each frame's file and placement under its page's lock, in the order given. */
|
|
39406
39601
|
async function holdFrames(root, refs, options) {
|
|
@@ -39465,71 +39660,6 @@ async function pasteFrames(root, pageRef, held, options) {
|
|
|
39465
39660
|
}, journal);
|
|
39466
39661
|
return Promise.all(names.map((name) => readFrame$1(root, `${target.project}/${target.name}/${name}`, options)));
|
|
39467
39662
|
}
|
|
39468
|
-
// src/server/board/projects.ts
|
|
39469
|
-
/** A new project holding one empty page. */
|
|
39470
|
-
async function addProject(root, name, now = /* @__PURE__ */ new Date(), { journal } = {}) {
|
|
39471
|
-
assertValidName("project", name);
|
|
39472
|
-
await assertFree$1(root, name);
|
|
39473
|
-
await mkdir(join(root, name, START_PAGE), { recursive: true });
|
|
39474
|
-
await writeRecord(join(root, name, PROJECT_FILE), {
|
|
39475
|
-
version: 1,
|
|
39476
|
-
pages: [START_PAGE],
|
|
39477
|
-
createdAt: now.toISOString()
|
|
39478
|
-
});
|
|
39479
|
-
await journal?.created(join(root, name));
|
|
39480
|
-
return scanProject(root, name);
|
|
39481
|
-
}
|
|
39482
|
-
async function renameProject(root, name, newName, { journal } = {}) {
|
|
39483
|
-
const project = await resolveProject(root, name);
|
|
39484
|
-
assertValidName("project", newName);
|
|
39485
|
-
await assertFree$1(root, newName, project.name);
|
|
39486
|
-
const renamed = join(root, newName);
|
|
39487
|
-
if (journal) await journal.moved(project.path, renamed);
|
|
39488
|
-
else await rename(project.path, renamed);
|
|
39489
|
-
return scanProject(root, newName);
|
|
39490
|
-
}
|
|
39491
|
-
/**
|
|
39492
|
-
* A copy of the project under the next free name, without its notes, and
|
|
39493
|
-
* stamped as made `now`.
|
|
39494
|
-
*/
|
|
39495
|
-
async function duplicateProject(root, name, now = /* @__PURE__ */ new Date(), { journal } = {}) {
|
|
39496
|
-
const source = await resolveProject(root, name);
|
|
39497
|
-
const file = await readRecord(join(source.path, PROJECT_FILE), {
|
|
39498
|
-
...projectSpec,
|
|
39499
|
-
empty: emptyProject
|
|
39500
|
-
});
|
|
39501
|
-
const copy = nextFreeName(source.name, await listProjects(root));
|
|
39502
|
-
const copyPath = join(root, copy);
|
|
39503
|
-
await cp(source.path, copyPath, {
|
|
39504
|
-
recursive: true,
|
|
39505
|
-
errorOnExist: true,
|
|
39506
|
-
force: false,
|
|
39507
|
-
filter: (path) => isCopied(basename(path))
|
|
39508
|
-
});
|
|
39509
|
-
await writeRecord(join(copyPath, PROJECT_FILE), {
|
|
39510
|
-
...file,
|
|
39511
|
-
createdAt: now.toISOString()
|
|
39512
|
-
});
|
|
39513
|
-
await journal?.created(copyPath);
|
|
39514
|
-
return scanProject(root, copy);
|
|
39515
|
-
}
|
|
39516
|
-
async function deleteProject(root, name, { journal } = {}) {
|
|
39517
|
-
const project = await resolveProject(root, name);
|
|
39518
|
-
if (journal) await journal.removed(project.path);
|
|
39519
|
-
else await rm(project.path, {
|
|
39520
|
-
recursive: true,
|
|
39521
|
-
force: true
|
|
39522
|
-
});
|
|
39523
|
-
return { deleted: project.name };
|
|
39524
|
-
}
|
|
39525
|
-
/** Throws `name-taken` when another project holds `name` in any case. */
|
|
39526
|
-
async function assertFree$1(root, name, self) {
|
|
39527
|
-
const taken = matchName((await listProjects(root)).filter((project) => project !== self), name);
|
|
39528
|
-
if (taken) throw new FrameboardError("name-taken", `The board already has a project ${taken}.`, {
|
|
39529
|
-
name,
|
|
39530
|
-
taken
|
|
39531
|
-
});
|
|
39532
|
-
}
|
|
39533
39663
|
// src/server/board/sections.ts
|
|
39534
39664
|
/** The name a section takes when the developer gives none, `-2` and on once taken. */
|
|
39535
39665
|
const DEFAULT_NAME = "section";
|
|
@@ -39706,6 +39836,16 @@ const sectionSchema = object$1({
|
|
|
39706
39836
|
});
|
|
39707
39837
|
const projectAddSchema = object$1({ name: name.optional() });
|
|
39708
39838
|
const projectSchema = object$1({ ref });
|
|
39839
|
+
/** More projects than any board holds, so a body cannot grow without bound. */
|
|
39840
|
+
const projectRefs$1 = array$1(ref).min(1).max(1e3);
|
|
39841
|
+
const projectGroupSchema = object$1({
|
|
39842
|
+
refs: projectRefs$1,
|
|
39843
|
+
group: name.nullable()
|
|
39844
|
+
});
|
|
39845
|
+
const projectArchiveSchema = object$1({
|
|
39846
|
+
refs: projectRefs$1,
|
|
39847
|
+
archived: boolean$1()
|
|
39848
|
+
});
|
|
39709
39849
|
const projectTokensSchema = object$1({
|
|
39710
39850
|
ref,
|
|
39711
39851
|
accent: _enum$1(Object.keys(STARTER_ACCENTS)).default(DEFAULT_LOOK.accent),
|
|
@@ -40091,6 +40231,31 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
40091
40231
|
data: project
|
|
40092
40232
|
});
|
|
40093
40233
|
});
|
|
40234
|
+
/** Refuses a filing of any project another session holds, as rename does, before anything is written. */
|
|
40235
|
+
const refuseHeldProjects = async (refs) => {
|
|
40236
|
+
const projects = await Promise.all(refs.map((project) => resolveProject(root, project)));
|
|
40237
|
+
await refuseHeld(projects.map((project) => project.name));
|
|
40238
|
+
};
|
|
40239
|
+
/** Files the named projects in one folder, a null group taking them out of theirs. */
|
|
40240
|
+
app.post("/api/project/group", async (c) => {
|
|
40241
|
+
const body = await parseBody$1(c.req.raw, projectGroupSchema);
|
|
40242
|
+
await refuseHeldProjects(body.refs);
|
|
40243
|
+
const projects = await recorded((journal) => fileProjects(root, body.refs, { group: body.group }, { journal }), onHome);
|
|
40244
|
+
return c.json({
|
|
40245
|
+
ok: true,
|
|
40246
|
+
data: projects
|
|
40247
|
+
});
|
|
40248
|
+
});
|
|
40249
|
+
/** Moves the named projects into home's Archived section, or back out of it. */
|
|
40250
|
+
app.post("/api/project/archive", async (c) => {
|
|
40251
|
+
const body = await parseBody$1(c.req.raw, projectArchiveSchema);
|
|
40252
|
+
await refuseHeldProjects(body.refs);
|
|
40253
|
+
const projects = await recorded((journal) => fileProjects(root, body.refs, { archived: body.archived }, { journal }), onHome);
|
|
40254
|
+
return c.json({
|
|
40255
|
+
ok: true,
|
|
40256
|
+
data: projects
|
|
40257
|
+
});
|
|
40258
|
+
});
|
|
40094
40259
|
/** Creates the project's `tokens.css` from a preset, refusing where any sheet already reaches it. */
|
|
40095
40260
|
app.post("/api/project/tokens", async (c) => {
|
|
40096
40261
|
const body = await parseBody$1(c.req.raw, projectTokensSchema);
|
|
@@ -42624,6 +42789,10 @@ const projectRecordSchema = object$1({
|
|
|
42624
42789
|
modifiedAt: string$1(),
|
|
42625
42790
|
/** When the project was made, null for one made before the time was recorded. */
|
|
42626
42791
|
createdAt: string$1().nullable(),
|
|
42792
|
+
/** The folder home files the project under, null for one in no folder. */
|
|
42793
|
+
group: string$1().nullable(),
|
|
42794
|
+
/** Whether home holds the project out of the main list, in its Archived section. */
|
|
42795
|
+
archived: boolean$1(),
|
|
42627
42796
|
projectFileError: recordErrorSchema,
|
|
42628
42797
|
pages: array$1(pageRecordSchema)
|
|
42629
42798
|
});
|
|
@@ -42973,6 +43142,25 @@ const inspectResultSchema = object$1({
|
|
|
42973
43142
|
editable: boolean$1(),
|
|
42974
43143
|
elements: array$1(inspectedElementSchema)
|
|
42975
43144
|
});
|
|
43145
|
+
// src/shared/records/references.ts
|
|
43146
|
+
/** What `references sync` returns, each path relative to the folder and sorted. */
|
|
43147
|
+
const referencesSyncSchema = object$1({
|
|
43148
|
+
folder: string$1(),
|
|
43149
|
+
written: array$1(string$1()),
|
|
43150
|
+
removed: array$1(string$1())
|
|
43151
|
+
});
|
|
43152
|
+
/**
|
|
43153
|
+
* What `references sync --check` returns, and the details of its
|
|
43154
|
+
* `references-stale`, each path relative to the folder and sorted. `pngDiffers`
|
|
43155
|
+
* warns and never fails, since a PNG varies with the browser build.
|
|
43156
|
+
*/
|
|
43157
|
+
const referencesCheckSchema = object$1({
|
|
43158
|
+
folder: string$1(),
|
|
43159
|
+
changed: array$1(string$1()),
|
|
43160
|
+
missing: array$1(string$1()),
|
|
43161
|
+
stray: array$1(string$1()),
|
|
43162
|
+
pngDiffers: array$1(string$1())
|
|
43163
|
+
});
|
|
42976
43164
|
const tokenRowSchema = object$1({
|
|
42977
43165
|
/** The custom property, with its leading `--`. */
|
|
42978
43166
|
name: string$1(),
|
|
@@ -43026,7 +43214,9 @@ const RECORDS = {
|
|
|
43026
43214
|
assetAdd: assetAddResultSchema,
|
|
43027
43215
|
elements: elementTreeSchema,
|
|
43028
43216
|
selection: selectionResultSchema,
|
|
43029
|
-
find: findResultSchema
|
|
43217
|
+
find: findResultSchema,
|
|
43218
|
+
referencesSync: referencesSyncSchema,
|
|
43219
|
+
referencesCheck: referencesCheckSchema
|
|
43030
43220
|
};
|
|
43031
43221
|
// src/cli/docs/content-format.ts
|
|
43032
43222
|
/** The content format `docs` prints, built from the constants the verbs run on. */
|
|
@@ -47414,6 +47604,275 @@ function registerProject(program, context) {
|
|
|
47414
47604
|
};
|
|
47415
47605
|
});
|
|
47416
47606
|
}
|
|
47607
|
+
// src/server/references/assets.ts
|
|
47608
|
+
/**
|
|
47609
|
+
* The files a frame loads inside its project's `assets/`, by their path there,
|
|
47610
|
+
* sorted and each once. A load naming no file is left to the link check's
|
|
47611
|
+
* `missing-file`, so it copies nothing here. A file in the frame's page folder
|
|
47612
|
+
* refuses `page-file-load`, since the link check allows it and a reference
|
|
47613
|
+
* folder holds nothing it could resolve to, so it would land broken.
|
|
47614
|
+
*/
|
|
47615
|
+
function frameAssets(source) {
|
|
47616
|
+
const assets = assetsDirOf(source);
|
|
47617
|
+
const found = /* @__PURE__ */ new Set();
|
|
47618
|
+
for (const load of frameLoads(source)) {
|
|
47619
|
+
const target = localTarget(load.url, load.base);
|
|
47620
|
+
if (target === null) continue;
|
|
47621
|
+
if (!statSync(target, { throwIfNoEntry: false })?.isFile()) continue;
|
|
47622
|
+
if (isInside(assets, target)) found.add(relative(assets, target).split(sep).join("/"));
|
|
47623
|
+
else if (isInside(source.pageDir, target)) throw new FrameboardError("page-file-load", `${source.ref} loads ${load.url} from its page folder, which a reference folder cannot hold. Move the file into the project's assets/ and link it there. Nothing written.`, {
|
|
47624
|
+
frame: source.ref,
|
|
47625
|
+
load: load.url
|
|
47626
|
+
});
|
|
47627
|
+
}
|
|
47628
|
+
return [...found].sort();
|
|
47629
|
+
}
|
|
47630
|
+
// src/server/references/drift.ts
|
|
47631
|
+
/** Compares what a sync would write against the files the folder holds, the HTML as the source and a PNG as derived. */
|
|
47632
|
+
function classifyDrift(expected, tracked) {
|
|
47633
|
+
const changed = [];
|
|
47634
|
+
const pngDiffers = [];
|
|
47635
|
+
const missing = [];
|
|
47636
|
+
for (const [path, data] of expected) {
|
|
47637
|
+
const copy = tracked.get(path);
|
|
47638
|
+
if (copy === void 0) missing.push(path);
|
|
47639
|
+
else if (!Buffer.from(copy).equals(Buffer.from(data))) (path.endsWith(".png") ? pngDiffers : changed).push(path);
|
|
47640
|
+
}
|
|
47641
|
+
return {
|
|
47642
|
+
changed,
|
|
47643
|
+
pngDiffers,
|
|
47644
|
+
missing,
|
|
47645
|
+
stray: [...tracked.keys()].filter((path) => !expected.has(path))
|
|
47646
|
+
};
|
|
47647
|
+
}
|
|
47648
|
+
// src/server/references/format.ts
|
|
47649
|
+
/** A frame's asset link, never the tail of a longer path such as `../../assets/`. */
|
|
47650
|
+
const BOARD_ASSETS = /(?<![\w./-])\.\.\/assets\//g;
|
|
47651
|
+
const OPTIONS = {
|
|
47652
|
+
semi: false,
|
|
47653
|
+
singleQuote: true,
|
|
47654
|
+
printWidth: 80,
|
|
47655
|
+
sortPackageJson: false
|
|
47656
|
+
};
|
|
47657
|
+
/**
|
|
47658
|
+
* What the folder holds of a board frame: its asset links moved to its
|
|
47659
|
+
* project's subtree, so two projects never collide, formatted so a reference
|
|
47660
|
+
* diffs line by line while the board file stays as the agent wrote it. The
|
|
47661
|
+
* write and `--check` both build through it, so they compare the same bytes.
|
|
47662
|
+
*/
|
|
47663
|
+
async function toReference(source, reference, folder) {
|
|
47664
|
+
const result = await (await importFormat(folder))(`${reference}.html`, withProjectAssets(source), OPTIONS);
|
|
47665
|
+
const [error] = result.errors;
|
|
47666
|
+
if (error) {
|
|
47667
|
+
const [reason] = error.message.split("\n");
|
|
47668
|
+
throw new FrameboardError("format-refused", `${reference} does not parse as HTML: ${reason}. Fix its board frame and sync again. Nothing written.`, { reference });
|
|
47669
|
+
}
|
|
47670
|
+
return result.code;
|
|
47671
|
+
}
|
|
47672
|
+
/**
|
|
47673
|
+
* Rewrites the frame's text only at the spans its loads occupy, so text naming
|
|
47674
|
+
* `../assets/` that loads nothing, such as a `<code>` sample, keeps its bytes.
|
|
47675
|
+
*/
|
|
47676
|
+
function withProjectAssets(source) {
|
|
47677
|
+
const framePath = boardPath(source.root, source.path);
|
|
47678
|
+
const spans = /* @__PURE__ */ new Map();
|
|
47679
|
+
for (const { path, location } of frameLoads(source)) if (path === framePath && location) spans.set(location.startOffset, location.endOffset);
|
|
47680
|
+
let html = source.html;
|
|
47681
|
+
for (const [start, end] of [...spans].sort(([a], [b]) => b - a)) {
|
|
47682
|
+
const span = html.slice(start, end).replace(BOARD_ASSETS, `../assets/${source.project}/`);
|
|
47683
|
+
html = `${html.slice(0, start)}${span}${html.slice(end)}`;
|
|
47684
|
+
}
|
|
47685
|
+
return html;
|
|
47686
|
+
}
|
|
47687
|
+
async function importFormat(folder) {
|
|
47688
|
+
try {
|
|
47689
|
+
const { format } = await import("oxfmt");
|
|
47690
|
+
return format;
|
|
47691
|
+
} catch {
|
|
47692
|
+
try {
|
|
47693
|
+
const path = createRequire(join(folder, "frames.json")).resolve("oxfmt");
|
|
47694
|
+
const { format } = await import(
|
|
47695
|
+
/* @vite-ignore */
|
|
47696
|
+
pathToFileURL(path).href
|
|
47697
|
+
);
|
|
47698
|
+
return format;
|
|
47699
|
+
} catch (error) {
|
|
47700
|
+
const version = peerDependencies.oxfmt;
|
|
47701
|
+
const install = {
|
|
47702
|
+
npm: `npm install --save-dev oxfmt@${version}`,
|
|
47703
|
+
bun: `bun add --dev oxfmt@${version}`
|
|
47704
|
+
};
|
|
47705
|
+
throw new FrameboardError("formatter-not-found", `references sync needs oxfmt to format each reference, and it found none. Install it in the project holding ${folder} with ${install.npm}, or ${install.bun}.`, { install }, { cause: error });
|
|
47706
|
+
}
|
|
47707
|
+
}
|
|
47708
|
+
}
|
|
47709
|
+
// src/server/references/frame-map.ts
|
|
47710
|
+
const REFERENCE = /^[a-z0-9]+(-[a-z0-9]+)*\/[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
47711
|
+
const BOARD_REF = /^[^/\s]+\/[^/\s]+\/[^/\s]+$/;
|
|
47712
|
+
/**
|
|
47713
|
+
* Reads `frames.json`, mapping each reference, `<group>/<name>`, to the
|
|
47714
|
+
* board frame `<project>/<page>/<frame>` it is captured from. An entry in
|
|
47715
|
+
* any other shape refuses rather than filing into the wrong folder.
|
|
47716
|
+
*/
|
|
47717
|
+
function parseFrameMap(json) {
|
|
47718
|
+
const parsed = parseJson(json);
|
|
47719
|
+
const frames = typeof parsed === "object" && parsed !== null && "frames" in parsed ? parsed.frames : void 0;
|
|
47720
|
+
if (typeof frames !== "object" || frames === null || Array.isArray(frames)) throw new FrameboardError("frame-map-invalid", "frames.json needs a frames object.");
|
|
47721
|
+
if (Object.keys(frames).length === 0) throw new FrameboardError("frame-map-invalid", "frames.json maps no frames, so a sync would remove every reference.");
|
|
47722
|
+
const map = /* @__PURE__ */ new Map();
|
|
47723
|
+
for (const [reference, ref] of Object.entries(frames)) {
|
|
47724
|
+
if (!REFERENCE.test(reference)) throw new FrameboardError("frame-map-invalid", `frames.json entry "${reference}" needs a kebab-case <group>/<name>.`, { reference });
|
|
47725
|
+
if (typeof ref !== "string" || !BOARD_REF.test(ref)) throw new FrameboardError("frame-map-invalid", `frames.json entry "${reference}" needs a board frame as <project>/<page>/<frame>.`, { reference });
|
|
47726
|
+
map.set(reference, ref);
|
|
47727
|
+
}
|
|
47728
|
+
return map;
|
|
47729
|
+
}
|
|
47730
|
+
function parseJson(json) {
|
|
47731
|
+
try {
|
|
47732
|
+
return JSON.parse(json);
|
|
47733
|
+
} catch (error) {
|
|
47734
|
+
throw new FrameboardError("frame-map-invalid", "frames.json does not parse as JSON.", {}, { cause: error });
|
|
47735
|
+
}
|
|
47736
|
+
}
|
|
47737
|
+
/** The mapped board frames the board does not hold. */
|
|
47738
|
+
function missingFrames(map, board) {
|
|
47739
|
+
return [...map.values()].filter((ref) => !board.has(ref));
|
|
47740
|
+
}
|
|
47741
|
+
// src/server/references/sync.ts
|
|
47742
|
+
/**
|
|
47743
|
+
* Writes what the board holds into the folder and removes every other file
|
|
47744
|
+
* below its first level. It builds the whole output first, so a refusal leaves
|
|
47745
|
+
* the folder as it was.
|
|
47746
|
+
*/
|
|
47747
|
+
async function syncReferences(options) {
|
|
47748
|
+
const { folder } = options;
|
|
47749
|
+
const output = await buildOutput(options);
|
|
47750
|
+
const removed = (await heldFiles(folder)).filter((path) => !output.has(path));
|
|
47751
|
+
await Promise.all([...output].map(async ([path, data]) => {
|
|
47752
|
+
await mkdir(dirname(join(folder, path)), { recursive: true });
|
|
47753
|
+
await writeFile(join(folder, path), data);
|
|
47754
|
+
}));
|
|
47755
|
+
await Promise.all(removed.map((path) => rm(join(folder, path))));
|
|
47756
|
+
await removeEmptyFolders(folder, folder);
|
|
47757
|
+
return {
|
|
47758
|
+
folder,
|
|
47759
|
+
written: [...output.keys()].sort(),
|
|
47760
|
+
removed: removed.sort()
|
|
47761
|
+
};
|
|
47762
|
+
}
|
|
47763
|
+
/** Compares the folder against what a sync would write, writing nothing. */
|
|
47764
|
+
async function checkReferences(options) {
|
|
47765
|
+
const { folder } = options;
|
|
47766
|
+
const output = await buildOutput(options);
|
|
47767
|
+
const held = /* @__PURE__ */ new Map();
|
|
47768
|
+
await Promise.all((await heldFiles(folder)).map(async (path) => {
|
|
47769
|
+
held.set(path, await readFile(join(folder, path)));
|
|
47770
|
+
}));
|
|
47771
|
+
const drift = classifyDrift(output, held);
|
|
47772
|
+
return {
|
|
47773
|
+
folder,
|
|
47774
|
+
changed: [...drift.changed].sort(),
|
|
47775
|
+
missing: [...drift.missing].sort(),
|
|
47776
|
+
stray: [...drift.stray].sort(),
|
|
47777
|
+
pngDiffers: [...drift.pngDiffers].sort()
|
|
47778
|
+
};
|
|
47779
|
+
}
|
|
47780
|
+
async function buildOutput({ root, folder, facesDir }) {
|
|
47781
|
+
const map = parseFrameMap(await readFile(join(folder, "frames.json"), "utf8"));
|
|
47782
|
+
const frames = await mappedFrames(root, map);
|
|
47783
|
+
const output = /* @__PURE__ */ new Map();
|
|
47784
|
+
await Promise.all([...map].map(async ([reference, ref]) => {
|
|
47785
|
+
const { project, page, name } = frameOf(frames, ref);
|
|
47786
|
+
const source = readFrame({
|
|
47787
|
+
root,
|
|
47788
|
+
project,
|
|
47789
|
+
page,
|
|
47790
|
+
name
|
|
47791
|
+
});
|
|
47792
|
+
output.set(`${reference}.html`, await toReference(source, reference, folder));
|
|
47793
|
+
for (const asset of frameAssets(source)) output.set(join("assets", project, asset), await readFile(join(assetsDirOf(source), asset)));
|
|
47794
|
+
}));
|
|
47795
|
+
const captures = await mkdtemp(join(tmpdir(), "frameboard-references-"));
|
|
47796
|
+
try {
|
|
47797
|
+
const images = await withFrameHost({
|
|
47798
|
+
root,
|
|
47799
|
+
facesDir
|
|
47800
|
+
}, "references sync", (browser, baseUrl) => captureFrameImages(browser, {
|
|
47801
|
+
baseUrl,
|
|
47802
|
+
frames: [...frames.values()],
|
|
47803
|
+
themes: THEMES,
|
|
47804
|
+
out: captures
|
|
47805
|
+
}));
|
|
47806
|
+
for (const [reference, ref] of map) for (const image of images.filter((image) => image.ref === ref)) output.set(`${reference}-${image.theme}.png`, await readFile(image.path));
|
|
47807
|
+
} finally {
|
|
47808
|
+
await rm(captures, {
|
|
47809
|
+
recursive: true,
|
|
47810
|
+
force: true
|
|
47811
|
+
});
|
|
47812
|
+
}
|
|
47813
|
+
return output;
|
|
47814
|
+
}
|
|
47815
|
+
/** The board frame each mapped ref names, each once, or a refusal listing every one it lacks. */
|
|
47816
|
+
async function mappedFrames(root, map) {
|
|
47817
|
+
const { projects } = await scanBoard(root);
|
|
47818
|
+
const board = new Map(projects.flatMap((project) => project.pages).flatMap((page) => page.frames).map((frame) => [frame.ref, frame]));
|
|
47819
|
+
const missing = missingFrames(map, new Set(board.keys()));
|
|
47820
|
+
if (missing.length > 0) throw new FrameboardError("frame-not-found", `No board frame for: ${missing.join(", ")}. Nothing written.`, { missing });
|
|
47821
|
+
return new Map([...map.values()].map((ref) => [ref, frameOf(board, ref)]));
|
|
47822
|
+
}
|
|
47823
|
+
function frameOf(frames, ref) {
|
|
47824
|
+
const frame = frames.get(ref);
|
|
47825
|
+
if (!frame) throw new Error(`${ref} was not resolved.`);
|
|
47826
|
+
return frame;
|
|
47827
|
+
}
|
|
47828
|
+
/** Every file below the folder's first level, which the sync owns. A top-level file is the consumer's own. */
|
|
47829
|
+
async function heldFiles(folder) {
|
|
47830
|
+
return (await readdir(folder, {
|
|
47831
|
+
recursive: true,
|
|
47832
|
+
withFileTypes: true
|
|
47833
|
+
})).filter((entry) => entry.isFile()).map((entry) => relative(folder, join(entry.parentPath, entry.name))).filter((path) => path.includes(sep));
|
|
47834
|
+
}
|
|
47835
|
+
async function removeEmptyFolders(dir, folder) {
|
|
47836
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
47837
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory()).map((entry) => removeEmptyFolders(join(dir, entry.name), folder)));
|
|
47838
|
+
if (dir !== folder && (await readdir(dir)).length === 0) await rmdir(dir);
|
|
47839
|
+
}
|
|
47840
|
+
// src/cli/commands/references.ts
|
|
47841
|
+
function registerReferences(program, context) {
|
|
47842
|
+
const { io } = context;
|
|
47843
|
+
act(addVerb(program.command("references").description("Fill a folder of design references from the board's frames"), "sync", "Write each frame <folder>/frames.json maps as its HTML, a PNG per theme, and the project assets it loads, removing every other file below the folder's first level").argument("<folder>", "the folder holding frames.json").option("--check", "write nothing, and exit 14 when the folder differs from what a sync would write"), context, async ([given = ""], options) => {
|
|
47844
|
+
const folder = resolve(io.cwd, given);
|
|
47845
|
+
if (!existsSync(join(folder, "frames.json"))) throw new FrameboardError("usage", `${folder} holds no frames.json, mapping each reference to a board frame.`);
|
|
47846
|
+
const target = {
|
|
47847
|
+
root: await boardOf(options, io),
|
|
47848
|
+
folder,
|
|
47849
|
+
facesDir: context.facesDir
|
|
47850
|
+
};
|
|
47851
|
+
if (options.check) {
|
|
47852
|
+
const result = await checkReferences(target);
|
|
47853
|
+
const lines = driftLines(result);
|
|
47854
|
+
if (result.changed.length + result.missing.length + result.stray.length > 0) throw new FrameboardError("references-stale", [`${folder} differs from what a sync would write.`, ...lines].join("\n"), { ...result });
|
|
47855
|
+
return {
|
|
47856
|
+
data: result,
|
|
47857
|
+
human: [`${folder} matches the board.`, ...lines].join("\n")
|
|
47858
|
+
};
|
|
47859
|
+
}
|
|
47860
|
+
const result = await syncReferences(target);
|
|
47861
|
+
const removed = result.removed.length > 0 ? `, removed ${result.removed.length}` : "";
|
|
47862
|
+
return {
|
|
47863
|
+
data: result,
|
|
47864
|
+
human: `Wrote ${result.written.length} files to ${folder}${removed}.`
|
|
47865
|
+
};
|
|
47866
|
+
});
|
|
47867
|
+
}
|
|
47868
|
+
function driftLines({ changed, missing, stray, pngDiffers }) {
|
|
47869
|
+
return [
|
|
47870
|
+
...changed.map((path) => `Changed: ${path}`),
|
|
47871
|
+
...missing.map((path) => `Missing: ${path}`),
|
|
47872
|
+
...stray.map((path) => `Stray: ${path}`),
|
|
47873
|
+
...pngDiffers.map((path) => `Warning: PNG bytes differ: ${path}`)
|
|
47874
|
+
];
|
|
47875
|
+
}
|
|
47417
47876
|
// src/cli/commands/selection.ts
|
|
47418
47877
|
function registerSelection(program, context) {
|
|
47419
47878
|
const { io } = context;
|
|
@@ -52444,6 +52903,7 @@ function createProgram(context) {
|
|
|
52444
52903
|
registerEditing(program, context);
|
|
52445
52904
|
registerCapture(program, faced);
|
|
52446
52905
|
registerInspect(program, faced);
|
|
52906
|
+
registerReferences(program, faced);
|
|
52447
52907
|
registerDocs(program, context);
|
|
52448
52908
|
return program;
|
|
52449
52909
|
}
|