editlet 0.0.0-stage → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +113 -2
- package/dist/admin/config.d.ts +22 -0
- package/dist/admin/config.js +75 -0
- package/dist/admin/dist/assets/RichEditor-BlaCRrEX.css +1 -0
- package/dist/admin/dist/assets/RichEditor-IZKdt6MK.js +42 -0
- package/dist/admin/dist/assets/blank-line-CbGzlqBI.js +1 -0
- package/dist/admin/dist/assets/channel-CljeMIwA.js +1 -0
- package/dist/admin/dist/assets/db-CCMyPgQa.js +1 -0
- package/dist/admin/dist/assets/index-CWoJh4H8.js +257 -0
- package/dist/admin/dist/assets/index-DkRMnD_M.css +1 -0
- package/dist/admin/dist/assets/mdast-util-from-markdown-C79q1_d8.js +3 -0
- package/dist/admin/dist/assets/mdast-util-gfm-cM-_xFJE.js +19 -0
- package/dist/admin/dist/assets/micromark-extension-gfm-Wz6-oszS.js +1 -0
- package/dist/admin/dist/assets/micromark-util-classify-character-BgXaGAja.js +1 -0
- package/dist/admin/dist/assets/micromark-util-html-tag-name-B61T18yC.js +1 -0
- package/dist/admin/dist/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/admin/dist/index.html +16 -0
- package/dist/admin/dist/preview.js +1 -0
- package/dist/admin/dist/window.js +1 -0
- package/dist/astro/content.d.ts +21 -0
- package/dist/astro/content.js +235 -0
- package/dist/astro/devServer.js +89 -0
- package/dist/astro/index.d.ts +15 -0
- package/dist/astro/index.js +98 -0
- package/dist/astro/nodeBridge.js +36 -0
- package/dist/astro/shared.js +10 -0
- package/dist/astro/stub/index.html +71 -0
- package/dist/auth/client.d.ts +24 -0
- package/dist/auth/client.js +120 -0
- package/dist/auth/handler.d.ts +16 -0
- package/dist/auth/handler.js +281 -0
- package/dist/auth/protocol.d.ts +25 -0
- package/dist/auth/protocol.js +3 -0
- package/dist/core/assets.d.ts +73 -0
- package/dist/core/assets.js +405 -0
- package/dist/core/devApi.d.ts +28 -0
- package/dist/core/devApi.js +3 -0
- package/dist/core/entryFile.d.ts +13 -0
- package/dist/core/entryFile.js +81 -0
- package/dist/core/fields.js +147 -0
- package/dist/core/generate.d.ts +3 -0
- package/dist/core/generate.js +70 -0
- package/dist/core/gitStyle.d.ts +92 -0
- package/dist/core/gitStyle.js +206 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +16 -0
- package/dist/core/issues.d.ts +10 -0
- package/dist/core/issues.js +10 -0
- package/dist/core/paths.d.ts +31 -0
- package/dist/core/paths.js +114 -0
- package/dist/core/project.js +56 -0
- package/dist/core/references.d.ts +68 -0
- package/dist/core/references.js +103 -0
- package/dist/core/rename.d.ts +60 -0
- package/dist/core/rename.js +133 -0
- package/dist/core/schema.d.ts +117 -0
- package/dist/core/schema.js +299 -0
- package/dist/core/sha.d.ts +2 -0
- package/dist/core/sha.js +13 -0
- package/dist/core/source.d.ts +48 -0
- package/dist/core/source.js +57 -0
- package/dist/core/validate.d.ts +22 -0
- package/dist/core/validate.js +148 -0
- package/dist/core/walk.d.ts +23 -0
- package/dist/core/walk.js +94 -0
- package/dist/core/writes.d.ts +37 -0
- package/dist/core/writes.js +166 -0
- package/dist/github/base64.js +16 -0
- package/dist/github/cache.d.ts +34 -0
- package/dist/github/cache.js +126 -0
- package/dist/github/client.d.ts +38 -0
- package/dist/github/client.js +228 -0
- package/dist/github/codeowners.d.ts +23 -0
- package/dist/github/codeowners.js +96 -0
- package/dist/github/commitReader.d.ts +25 -0
- package/dist/github/commitReader.js +38 -0
- package/dist/github/deploy.d.ts +15 -0
- package/dist/github/deploy.js +33 -0
- package/dist/github/index.d.ts +9 -0
- package/dist/github/index.js +8 -0
- package/dist/github/repo.d.ts +95 -0
- package/dist/github/repo.js +375 -0
- package/dist/github/source.d.ts +115 -0
- package/dist/github/source.js +558 -0
- package/dist/loader/index.d.ts +27 -0
- package/dist/loader/index.js +151 -0
- package/dist/loader/protocol.d.ts +95 -0
- package/dist/loader/protocol.js +120 -0
- package/dist/loader/window/geometry.js +9 -0
- package/dist/next/EditletLoader.d.ts +5 -0
- package/dist/next/EditletLoader.js +33 -0
- package/dist/next/assetUrl.d.ts +9 -0
- package/dist/next/assetUrl.js +13 -0
- package/dist/next/buildGuard.js +26 -0
- package/dist/next/config.d.ts +18 -0
- package/dist/next/config.js +255 -0
- package/dist/next/devServer.js +70 -0
- package/dist/next/editletField.d.ts +7 -0
- package/dist/next/editletField.js +7 -0
- package/dist/next/index.d.ts +8 -0
- package/dist/next/index.js +6 -0
- package/dist/next/preview.d.ts +18 -0
- package/dist/next/preview.js +100 -0
- package/dist/next/previewCookie.d.ts +5 -0
- package/dist/next/previewCookie.js +72 -0
- package/dist/next/previewEnv.js +25 -0
- package/dist/next/previewRef.d.ts +8 -0
- package/dist/next/previewRef.js +17 -0
- package/dist/next/publicDir.js +65 -0
- package/dist/next/reader.d.ts +49 -0
- package/dist/next/reader.js +161 -0
- package/dist/next/stub/index.html +56 -0
- package/dist/node/devHandler.d.ts +6 -0
- package/dist/node/devHandler.js +430 -0
- package/dist/node/fs.js +37 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.js +3 -0
- package/dist/node/project.d.ts +12 -0
- package/dist/node/project.js +43 -0
- package/package.json +187 -4
- package/skills/README.md +84 -0
- package/skills/editlet/SKILL.md +119 -0
- package/skills/editlet/references/content-format.md +191 -0
- package/skills/editlet/references/preview.md +75 -0
- package/skills/editlet/references/publishing.md +137 -0
- package/skills/editlet/references/schema-changes.md +127 -0
- package/skills/editlet/scripts/guard.mjs +1061 -0
- package/skills/editlet/scripts/link.mjs +193 -0
- package/skills/editlet/scripts/refs.mjs +1480 -0
- package/skills/editlet/scripts/schema.mjs +1340 -0
- package/skills/editlet/scripts/style.mjs +657 -0
- package/skills/editlet/scripts/types.mjs +525 -0
- package/skills/editlet/scripts/validate.mjs +724 -0
- package/skills/editlet-migrate/SKILL.md +92 -0
- package/skills/editlet-migrate/references/mapping.md +73 -0
- package/skills/editlet-migrate/references/sources.md +70 -0
- package/skills/editlet-setup/SKILL.md +108 -0
- package/skills/editlet-setup/references/astro.md +83 -0
- package/skills/editlet-setup/references/doctor.md +89 -0
- package/skills/editlet-setup/references/next.md +140 -0
- package/skills/editlet-setup/references/preview.md +54 -0
- package/skills/editlet-setup/references/production.md +153 -0
- package/skills/editlet-setup/references/roles.md +238 -0
- package/skills/editlet-setup/references/skills.md +99 -0
- package/skills/editlet-setup/scripts/doctor.mjs +1378 -0
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
// skills/editlet/scripts/issues.ts
|
|
2
|
+
function format(issue) {
|
|
3
|
+
if (!issue.file) return `${issue.path || "(schema)"} \u2014 ${issue.message}`;
|
|
4
|
+
return issue.path ? `${issue.file}: ${issue.path} \u2014 ${issue.message}` : `${issue.file} \u2014 ${issue.message}`;
|
|
5
|
+
}
|
|
6
|
+
function reportIssues(issues) {
|
|
7
|
+
for (const issue of issues) process.stderr.write(`${format(issue)}
|
|
8
|
+
`);
|
|
9
|
+
process.exitCode = 1;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// core/issues.ts
|
|
13
|
+
var EditletError = class extends Error {
|
|
14
|
+
issues;
|
|
15
|
+
constructor(issues, message) {
|
|
16
|
+
super(message ?? issues.map((i) => i.path ? `${i.path}: ${i.message}` : i.message).join("; "));
|
|
17
|
+
this.name = "EditletError";
|
|
18
|
+
this.issues = issues;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// node/project.ts
|
|
23
|
+
import { mkdir, readFile as readFile2, writeFile } from "node:fs/promises";
|
|
24
|
+
import { dirname, join as join2, resolve as resolve2 } from "node:path";
|
|
25
|
+
|
|
26
|
+
// node/fs.ts
|
|
27
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
28
|
+
import { join, resolve } from "node:path";
|
|
29
|
+
|
|
30
|
+
// core/schema.ts
|
|
31
|
+
import { z as z2 } from "zod";
|
|
32
|
+
|
|
33
|
+
// core/fields.ts
|
|
34
|
+
import { z } from "zod";
|
|
35
|
+
|
|
36
|
+
// core/paths.ts
|
|
37
|
+
var SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
38
|
+
function isValidSlug(slug) {
|
|
39
|
+
return SLUG_RE.test(slug);
|
|
40
|
+
}
|
|
41
|
+
function hasCollection(schema, collection) {
|
|
42
|
+
return Object.hasOwn(schema.collections, collection);
|
|
43
|
+
}
|
|
44
|
+
function entryFilePath(schema, collection, slug) {
|
|
45
|
+
const singleton = hasCollection(schema, collection) && schema.collections[collection].singleton;
|
|
46
|
+
return `${schema.contentDir}/${collection}/${singleton ? "index" : slug}.md`;
|
|
47
|
+
}
|
|
48
|
+
function isCanonicalPath(path) {
|
|
49
|
+
if (path === "" || /[\\\0:]/.test(path)) return false;
|
|
50
|
+
return path.split("/").every((seg) => seg !== "" && seg !== "." && seg !== "..");
|
|
51
|
+
}
|
|
52
|
+
function isHiddenContentPath(schema, path) {
|
|
53
|
+
const prefix = `${schema.contentDir}/`;
|
|
54
|
+
const rest = path.startsWith(prefix) ? path.slice(prefix.length) : path;
|
|
55
|
+
return rest.split("/").some((seg) => seg.startsWith("."));
|
|
56
|
+
}
|
|
57
|
+
function parseEntryPath(schema, path) {
|
|
58
|
+
const prefix = `${schema.contentDir}/`;
|
|
59
|
+
if (!path.startsWith(prefix) || !isCanonicalPath(path)) return null;
|
|
60
|
+
const parts = path.slice(prefix.length).split("/");
|
|
61
|
+
if (parts.length !== 2) return null;
|
|
62
|
+
const [collection, file] = parts;
|
|
63
|
+
if (!hasCollection(schema, collection) || !file.endsWith(".md")) return null;
|
|
64
|
+
const name = file.slice(0, -3);
|
|
65
|
+
if (name === "") return null;
|
|
66
|
+
if (schema.collections[collection].singleton) return file === "index.md" ? { collection, slug: "index" } : null;
|
|
67
|
+
return { collection, slug: name };
|
|
68
|
+
}
|
|
69
|
+
function resolveAssetPath(schema, entryFile, src) {
|
|
70
|
+
if (src === "" || src.startsWith("/") || src.includes("\\") || /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(src)) return null;
|
|
71
|
+
const srcSegs = src.split("/");
|
|
72
|
+
const last = srcSegs[srcSegs.length - 1];
|
|
73
|
+
if (last === "" || last === "." || last === "..") return null;
|
|
74
|
+
const out = entryFile.split("/").slice(0, -1);
|
|
75
|
+
for (const seg of srcSegs) {
|
|
76
|
+
if (seg === "" || seg === ".") continue;
|
|
77
|
+
if (seg === "..") {
|
|
78
|
+
if (out.length === 0) return null;
|
|
79
|
+
out.pop();
|
|
80
|
+
} else out.push(seg);
|
|
81
|
+
}
|
|
82
|
+
const result = out.join("/");
|
|
83
|
+
return result.startsWith(`${schema.contentDir}/`) ? result : null;
|
|
84
|
+
}
|
|
85
|
+
function refKey(collection, slug) {
|
|
86
|
+
return `${collection}/${slug}`;
|
|
87
|
+
}
|
|
88
|
+
var IMAGE_EXTENSIONS = ["webp", "png", "jpg", "jpeg", "avif", "gif", "svg"];
|
|
89
|
+
function isImagePath(path) {
|
|
90
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
91
|
+
const dot = name.lastIndexOf(".");
|
|
92
|
+
return dot > 0 && IMAGE_EXTENSIONS.includes(name.slice(dot + 1).toLowerCase());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// core/fields.ts
|
|
96
|
+
function isStringValued(field) {
|
|
97
|
+
switch (field.type) {
|
|
98
|
+
case "string":
|
|
99
|
+
return !field.list;
|
|
100
|
+
case "select":
|
|
101
|
+
case "reference":
|
|
102
|
+
return !field.multiple;
|
|
103
|
+
case "text":
|
|
104
|
+
case "datetime":
|
|
105
|
+
case "url":
|
|
106
|
+
case "color":
|
|
107
|
+
return true;
|
|
108
|
+
default:
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function isAbsentValue(field, value) {
|
|
113
|
+
return value === void 0 || value === null || value === "" && isStringValued(field);
|
|
114
|
+
}
|
|
115
|
+
function err(field, message) {
|
|
116
|
+
return (iss) => field.required && isAbsentValue(field, iss.input) ? "Required" : message;
|
|
117
|
+
}
|
|
118
|
+
function optional(field, schema, message) {
|
|
119
|
+
if (field.required) return schema;
|
|
120
|
+
return isStringValued(field) ? z.union([schema, z.literal("")], { error: message }).nullish() : schema.nullish();
|
|
121
|
+
}
|
|
122
|
+
function isUrl(v) {
|
|
123
|
+
return v.startsWith("/") || URL.canParse(v);
|
|
124
|
+
}
|
|
125
|
+
function noRepeats(message) {
|
|
126
|
+
return (items, ctx) => {
|
|
127
|
+
const seen = /* @__PURE__ */ new Set();
|
|
128
|
+
items.forEach((item, i) => {
|
|
129
|
+
if (seen.has(item)) ctx.addIssue({ code: "custom", path: [i], message: message(item) });
|
|
130
|
+
seen.add(item);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function listField(field, item, min, max, unique) {
|
|
135
|
+
const effective = Math.max(field.required ? 1 : 0, min);
|
|
136
|
+
let arr = z.array(item, { error: err(field, "Expected a list") });
|
|
137
|
+
if (effective > 0) {
|
|
138
|
+
arr = arr.min(effective, {
|
|
139
|
+
error: (iss) => Array.isArray(iss.input) && iss.input.length === 0 && field.required ? "Required" : `Must have at least ${effective}`
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (max !== void 0) arr = arr.max(max, { error: `Must have at most ${max}` });
|
|
143
|
+
return optional(field, unique ? arr.superRefine(noRepeats(unique)) : arr, "Expected a list");
|
|
144
|
+
}
|
|
145
|
+
var escapeRegex = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
146
|
+
function fieldsShape(fields) {
|
|
147
|
+
const shape = {};
|
|
148
|
+
for (const [key, field] of Object.entries(fields)) shape[key] = nestedValueSchema(field);
|
|
149
|
+
return shape;
|
|
150
|
+
}
|
|
151
|
+
function nestedValueSchema(field) {
|
|
152
|
+
if (field.type !== "markdown") return fieldValueSchema(field);
|
|
153
|
+
const base2 = z.string({ error: err(field, "Expected text") });
|
|
154
|
+
return field.required ? base2.regex(/\S/, "Required") : base2.nullish();
|
|
155
|
+
}
|
|
156
|
+
function fieldValueSchema(field) {
|
|
157
|
+
switch (field.type) {
|
|
158
|
+
case "markdown":
|
|
159
|
+
return null;
|
|
160
|
+
case "object": {
|
|
161
|
+
const obj = z.strictObject(fieldsShape(field.fields), { error: err(field, "Expected an object") });
|
|
162
|
+
if (field.list) return listField(field, obj, field.min ?? 0, field.max);
|
|
163
|
+
return optional(field, obj, "");
|
|
164
|
+
}
|
|
165
|
+
case "blocks": {
|
|
166
|
+
const kinds = Object.keys(field.blocks);
|
|
167
|
+
const message = `Expected ${BLOCK_KEY}: ${kinds.join(", ")}`;
|
|
168
|
+
const options = Object.entries(field.blocks).map(
|
|
169
|
+
([kind, block]) => z.strictObject({ [BLOCK_KEY]: z.literal(kind), ...fieldsShape(block.fields) })
|
|
170
|
+
);
|
|
171
|
+
const item = z.discriminatedUnion(BLOCK_KEY, options, {
|
|
172
|
+
error: message
|
|
173
|
+
});
|
|
174
|
+
return listField(field, item, field.min ?? 0, field.max);
|
|
175
|
+
}
|
|
176
|
+
case "string":
|
|
177
|
+
case "text": {
|
|
178
|
+
if (field.type === "string" && field.list) return listField(field, z.string({ error: "Expected text" }), 0);
|
|
179
|
+
const base2 = z.string({ error: err(field, "Expected text") });
|
|
180
|
+
return field.required ? base2.regex(/\S/, "Required") : base2.nullish();
|
|
181
|
+
}
|
|
182
|
+
case "boolean":
|
|
183
|
+
return optional(field, z.boolean({ error: err(field, "Expected true or false") }), "");
|
|
184
|
+
case "select": {
|
|
185
|
+
const values = field.options.map((o) => o.value);
|
|
186
|
+
const message = `Expected one of: ${values.join(", ")}`;
|
|
187
|
+
if (field.multiple) return listField(field, z.enum(values, { error: message }), 0);
|
|
188
|
+
return optional(field, z.enum(values, { error: err(field, message) }), message);
|
|
189
|
+
}
|
|
190
|
+
case "number": {
|
|
191
|
+
let n = z.number({ error: err(field, "Expected a number") });
|
|
192
|
+
if (field.integer) n = n.int("Must be a whole number");
|
|
193
|
+
if (field.min !== void 0) n = n.min(field.min, `Must be at least ${field.min}`);
|
|
194
|
+
if (field.max !== void 0) n = n.max(field.max, `Must be at most ${field.max}`);
|
|
195
|
+
return optional(field, n, "");
|
|
196
|
+
}
|
|
197
|
+
case "datetime": {
|
|
198
|
+
const base2 = field.dateOnly ? z.iso.date({ error: err(field, "Invalid date") }) : z.iso.datetime({ offset: true, local: true, error: err(field, "Invalid date") });
|
|
199
|
+
return optional(field, base2, "Invalid date");
|
|
200
|
+
}
|
|
201
|
+
case "json": {
|
|
202
|
+
if (!field.required) return z.unknown().optional();
|
|
203
|
+
return z.union([z.string(), z.number(), z.boolean(), z.array(z.unknown()), z.record(z.string(), z.unknown())], {
|
|
204
|
+
error: "Required"
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
case "url": {
|
|
208
|
+
const message = "Must be an http(s) URL or start with /";
|
|
209
|
+
const base2 = z.string({ error: err(field, "Expected text") }).regex(/^(?:https?:\/\/|\/(?!\/))/i, { error: err(field, message) }).refine(isUrl, { error: message });
|
|
210
|
+
return optional(field, base2, message);
|
|
211
|
+
}
|
|
212
|
+
case "color": {
|
|
213
|
+
const message = "Must be a hex color like #a1b2c3";
|
|
214
|
+
const base2 = z.string({ error: err(field, "Expected text") }).regex(/^#[0-9a-fA-F]{6}$/, { error: err(field, message) });
|
|
215
|
+
return optional(field, base2, message);
|
|
216
|
+
}
|
|
217
|
+
case "image": {
|
|
218
|
+
const nonEmpty = z.string({ error: (iss) => iss.input === void 0 || iss.input === null ? "Required" : "Expected text" }).regex(/\S/, "Required");
|
|
219
|
+
const obj = z.strictObject({ src: nonEmpty, alt: nonEmpty }, { error: err(field, "Expected { src, alt }") });
|
|
220
|
+
return optional(field, obj, "");
|
|
221
|
+
}
|
|
222
|
+
case "reference": {
|
|
223
|
+
const message = `Must reference an entry in: ${field.collections.join(", ")}`;
|
|
224
|
+
const slug = SLUG_RE.source.slice(1, -1);
|
|
225
|
+
const ref = z.string({ error: err(field, 'Expected a reference like "collection/slug"') }).regex(new RegExp(`^(?:${field.collections.map(escapeRegex).join("|")})/${slug}$`), {
|
|
226
|
+
error: err(field, message)
|
|
227
|
+
});
|
|
228
|
+
if (field.multiple) return listField(field, ref, field.min ?? 0, field.max, (r) => `Duplicate reference: ${r}`);
|
|
229
|
+
return optional(field, ref, message);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// core/schema.ts
|
|
235
|
+
var BLOCK_KEY = "block";
|
|
236
|
+
var COMMIT_PLACEHOLDERS = ["action", "Action", "collection", "slug", "target"];
|
|
237
|
+
var TITLE_PLACEHOLDERS = ["branch", "name", "login"];
|
|
238
|
+
var REF_SEGMENTS = /^[A-Za-z0-9][A-Za-z0-9._-]*(\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
|
|
239
|
+
function isRefPath(value) {
|
|
240
|
+
return REF_SEGMENTS.test(value) && !value.includes("..") && !value.split("/").some((s) => s.endsWith(".lock"));
|
|
241
|
+
}
|
|
242
|
+
function template(placeholders, max) {
|
|
243
|
+
return z2.string().trim().min(1).max(max).refine((t) => !/[\r\n]/.test(t), "must be one line").superRefine((t, ctx) => {
|
|
244
|
+
for (const [, name] of t.matchAll(/\{([^{}]*)\}/g)) {
|
|
245
|
+
if (!placeholders.includes(name)) {
|
|
246
|
+
ctx.addIssue({
|
|
247
|
+
code: "custom",
|
|
248
|
+
message: `unknown placeholder "{${name}}" (use ${placeholders.map((p) => `{${p}}`).join(", ")})`
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
var gitSchema = z2.strictObject({
|
|
255
|
+
baseBranch: z2.string().min(1),
|
|
256
|
+
branchPrefix: z2.string().refine(
|
|
257
|
+
(p) => p.endsWith("/") && isRefPath(p.slice(0, -1)),
|
|
258
|
+
'must be branch name segments ending in "/", for example "editlet/"'
|
|
259
|
+
).optional(),
|
|
260
|
+
commitMessage: template(COMMIT_PLACEHOLDERS, 200).optional(),
|
|
261
|
+
pullRequest: z2.strictObject({
|
|
262
|
+
title: template(TITLE_PLACEHOLDERS, 256).optional(),
|
|
263
|
+
labels: z2.array(
|
|
264
|
+
z2.string().trim().min(1).max(50).refine((l) => !l.includes(","), 'must not contain ","')
|
|
265
|
+
).max(10).optional(),
|
|
266
|
+
draft: z2.boolean().optional()
|
|
267
|
+
}).optional()
|
|
268
|
+
});
|
|
269
|
+
var IDENT = /^[a-zA-Z][a-zA-Z0-9]*$/;
|
|
270
|
+
var identMsg = "must start with a letter and contain only letters and digits";
|
|
271
|
+
var base = {
|
|
272
|
+
label: z2.string(),
|
|
273
|
+
hint: z2.string().optional(),
|
|
274
|
+
required: z2.boolean().optional()
|
|
275
|
+
};
|
|
276
|
+
var strOrList = z2.union([z2.string(), z2.array(z2.string())]);
|
|
277
|
+
var nestedFields = z2.lazy(
|
|
278
|
+
() => z2.record(z2.string().regex(IDENT, `field key ${identMsg}`), fieldSchema).refine((o) => Object.keys(o).length > 0, "fields must not be empty")
|
|
279
|
+
);
|
|
280
|
+
var fieldSchema = z2.discriminatedUnion("type", [
|
|
281
|
+
z2.strictObject({ ...base, type: z2.literal("string"), list: z2.boolean().optional(), default: strOrList.optional() }),
|
|
282
|
+
z2.strictObject({
|
|
283
|
+
...base,
|
|
284
|
+
type: z2.literal("text"),
|
|
285
|
+
rows: z2.number().int().positive().optional(),
|
|
286
|
+
default: z2.string().optional()
|
|
287
|
+
}),
|
|
288
|
+
z2.strictObject({ ...base, type: z2.literal("markdown") }),
|
|
289
|
+
z2.strictObject({
|
|
290
|
+
...base,
|
|
291
|
+
type: z2.literal("boolean"),
|
|
292
|
+
default: z2.boolean().optional(),
|
|
293
|
+
labels: z2.strictObject({ true: z2.string(), false: z2.string() }).optional()
|
|
294
|
+
}),
|
|
295
|
+
z2.strictObject({
|
|
296
|
+
...base,
|
|
297
|
+
type: z2.literal("select"),
|
|
298
|
+
options: z2.array(z2.strictObject({ label: z2.string(), value: z2.string() })).min(1, "options must not be empty"),
|
|
299
|
+
multiple: z2.boolean().optional(),
|
|
300
|
+
default: strOrList.optional()
|
|
301
|
+
}),
|
|
302
|
+
z2.strictObject({
|
|
303
|
+
...base,
|
|
304
|
+
type: z2.literal("number"),
|
|
305
|
+
min: z2.number().optional(),
|
|
306
|
+
max: z2.number().optional(),
|
|
307
|
+
step: z2.number().optional(),
|
|
308
|
+
integer: z2.boolean().optional(),
|
|
309
|
+
default: z2.number().optional()
|
|
310
|
+
}),
|
|
311
|
+
z2.strictObject({
|
|
312
|
+
...base,
|
|
313
|
+
type: z2.literal("datetime"),
|
|
314
|
+
dateOnly: z2.boolean().optional(),
|
|
315
|
+
defaultNow: z2.boolean().optional()
|
|
316
|
+
}),
|
|
317
|
+
z2.strictObject({ ...base, type: z2.literal("json") }),
|
|
318
|
+
z2.strictObject({ ...base, type: z2.literal("url") }),
|
|
319
|
+
z2.strictObject({ ...base, type: z2.literal("color"), default: z2.string().optional() }),
|
|
320
|
+
z2.strictObject({ ...base, type: z2.literal("image") }),
|
|
321
|
+
z2.strictObject({
|
|
322
|
+
...base,
|
|
323
|
+
type: z2.literal("reference"),
|
|
324
|
+
collections: z2.array(z2.string()).min(1, "collections must not be empty"),
|
|
325
|
+
multiple: z2.boolean().optional(),
|
|
326
|
+
min: z2.number().int().nonnegative().optional(),
|
|
327
|
+
max: z2.number().int().nonnegative().optional()
|
|
328
|
+
}),
|
|
329
|
+
z2.strictObject({
|
|
330
|
+
...base,
|
|
331
|
+
type: z2.literal("object"),
|
|
332
|
+
fields: nestedFields,
|
|
333
|
+
list: z2.boolean().optional(),
|
|
334
|
+
min: z2.number().int().nonnegative().optional(),
|
|
335
|
+
max: z2.number().int().nonnegative().optional()
|
|
336
|
+
}),
|
|
337
|
+
z2.strictObject({
|
|
338
|
+
...base,
|
|
339
|
+
type: z2.literal("blocks"),
|
|
340
|
+
blocks: z2.record(
|
|
341
|
+
z2.string().regex(IDENT, `block key ${identMsg}`),
|
|
342
|
+
z2.strictObject({ label: z2.string(), fields: nestedFields })
|
|
343
|
+
).refine((o) => Object.keys(o).length > 0, "blocks must not be empty"),
|
|
344
|
+
min: z2.number().int().nonnegative().optional(),
|
|
345
|
+
max: z2.number().int().nonnegative().optional()
|
|
346
|
+
})
|
|
347
|
+
]);
|
|
348
|
+
var collectionSchema = z2.strictObject({
|
|
349
|
+
label: z2.string(),
|
|
350
|
+
singleton: z2.boolean().optional(),
|
|
351
|
+
titleField: z2.string().optional(),
|
|
352
|
+
slugFrom: z2.string().optional(),
|
|
353
|
+
fields: z2.record(z2.string().regex(IDENT, `field key ${identMsg}`), fieldSchema)
|
|
354
|
+
});
|
|
355
|
+
function checkFields(schema, fields, at, nested, add) {
|
|
356
|
+
for (const [fk, f] of Object.entries(fields)) {
|
|
357
|
+
const path = [...at, fk];
|
|
358
|
+
if (fk === "draft" && !nested) add(path, 'field key "draft" is reserved for the draft flag');
|
|
359
|
+
if ("default" in f && f.default !== void 0) {
|
|
360
|
+
const checked = fieldValueSchema(f)?.safeParse(f.default);
|
|
361
|
+
for (const issue of checked?.success === false ? checked.error.issues : []) {
|
|
362
|
+
add([...path, "default", ...issue.path.map(String)], `default: ${issue.message}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (f.type === "reference") {
|
|
366
|
+
f.collections.forEach((target, i) => {
|
|
367
|
+
if (!Object.hasOwn(schema.collections, target))
|
|
368
|
+
add([...path, "collections", i], `unknown collection "${target}"`);
|
|
369
|
+
});
|
|
370
|
+
if (!f.multiple && (f.min !== void 0 || f.max !== void 0)) add(path, "min/max require multiple: true");
|
|
371
|
+
}
|
|
372
|
+
if (f.type === "object") {
|
|
373
|
+
if (!f.list && (f.min !== void 0 || f.max !== void 0)) add(path, "min/max require list: true");
|
|
374
|
+
checkFields(schema, f.fields, [...path, "fields"], true, add);
|
|
375
|
+
}
|
|
376
|
+
if (f.type === "blocks") {
|
|
377
|
+
for (const [bk, block] of Object.entries(f.blocks)) {
|
|
378
|
+
if (Object.hasOwn(block.fields, BLOCK_KEY)) {
|
|
379
|
+
add([...path, "blocks", bk, "fields", BLOCK_KEY], `field key "${BLOCK_KEY}" is reserved for the block type`);
|
|
380
|
+
}
|
|
381
|
+
checkFields(schema, block.fields, [...path, "blocks", bk, "fields"], true, add);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if ((f.type === "reference" || f.type === "object" || f.type === "blocks") && f.min !== void 0 && f.max !== void 0 && f.min > f.max) {
|
|
385
|
+
add([...path, "min"], "min must not exceed max");
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
var schemaSchema = z2.strictObject({
|
|
390
|
+
$schema: z2.string().optional(),
|
|
391
|
+
contentDir: z2.string().min(1).refine(
|
|
392
|
+
isCanonicalPath,
|
|
393
|
+
'must be a relative posix path without empty, "." or ".." segments, backslashes, NUL or ":"'
|
|
394
|
+
),
|
|
395
|
+
git: gitSchema,
|
|
396
|
+
collections: z2.record(z2.string().regex(IDENT, `collection key ${identMsg}`), collectionSchema)
|
|
397
|
+
}).superRefine((schema, ctx) => {
|
|
398
|
+
const add = (path, message) => ctx.addIssue({ code: "custom", path, message });
|
|
399
|
+
const { baseBranch, branchPrefix } = schema.git;
|
|
400
|
+
if (branchPrefix !== void 0 && (baseBranch.startsWith(branchPrefix) || branchPrefix.startsWith(`${baseBranch}/`))) {
|
|
401
|
+
add(["git", "branchPrefix"], `branchPrefix "${branchPrefix}" clashes with the base branch "${baseBranch}"`);
|
|
402
|
+
}
|
|
403
|
+
const lowerKeys = /* @__PURE__ */ new Map();
|
|
404
|
+
for (const [ck, col] of Object.entries(schema.collections)) {
|
|
405
|
+
const other = lowerKeys.get(ck.toLowerCase());
|
|
406
|
+
if (other !== void 0) add(["collections", ck], `collection key "${ck}" differs from "${other}" only in case`);
|
|
407
|
+
else lowerKeys.set(ck.toLowerCase(), ck);
|
|
408
|
+
const fields = Object.entries(col.fields);
|
|
409
|
+
if (fields.filter(([, f]) => f.type === "markdown").length > 1) {
|
|
410
|
+
add(["collections", ck, "fields"], "a collection can have at most one markdown field");
|
|
411
|
+
}
|
|
412
|
+
if (col.titleField !== void 0 && !Object.hasOwn(col.fields, col.titleField)) {
|
|
413
|
+
add(["collections", ck, "titleField"], `titleField "${col.titleField}" is not a field of ${ck}`);
|
|
414
|
+
}
|
|
415
|
+
if (col.slugFrom !== void 0 && !Object.hasOwn(col.fields, col.slugFrom)) {
|
|
416
|
+
add(["collections", ck, "slugFrom"], `slugFrom "${col.slugFrom}" is not a field of ${ck}`);
|
|
417
|
+
}
|
|
418
|
+
checkFields(schema, col.fields, ["collections", ck, "fields"], false, add);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
function toIssues(error) {
|
|
422
|
+
const out = [];
|
|
423
|
+
for (const issue of error.issues) {
|
|
424
|
+
let path = issue.path.map(String);
|
|
425
|
+
let message = issue.message;
|
|
426
|
+
if (issue.code === "invalid_union" && ("discriminator" in issue || path.at(-1) !== "type")) {
|
|
427
|
+
if (path.at(-1) !== "type") path = [...path, "type"];
|
|
428
|
+
message = "unknown field type";
|
|
429
|
+
}
|
|
430
|
+
if (issue.code === "unrecognized_keys") {
|
|
431
|
+
for (const key of issue.keys) out.push({ path: [...path, key].join("."), message: `unknown key "${key}"` });
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
out.push({ path: path.join("."), message });
|
|
435
|
+
}
|
|
436
|
+
return out;
|
|
437
|
+
}
|
|
438
|
+
function loadSchema(input) {
|
|
439
|
+
const parsed = schemaSchema.safeParse(input);
|
|
440
|
+
if (!parsed.success) throw new EditletError(toIssues(parsed.error));
|
|
441
|
+
return parsed.data;
|
|
442
|
+
}
|
|
443
|
+
function parseSchemaText(text, file) {
|
|
444
|
+
let json;
|
|
445
|
+
try {
|
|
446
|
+
json = JSON.parse(text);
|
|
447
|
+
} catch (error) {
|
|
448
|
+
throw new EditletError([
|
|
449
|
+
{ file, path: "", message: `Invalid JSON: ${error instanceof Error ? error.message : error}` }
|
|
450
|
+
]);
|
|
451
|
+
}
|
|
452
|
+
try {
|
|
453
|
+
return loadSchema(json);
|
|
454
|
+
} catch (error) {
|
|
455
|
+
if (error instanceof EditletError) throw new EditletError(error.issues.map((issue) => ({ ...issue, file })));
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function markdownFieldKey(collection) {
|
|
460
|
+
return Object.entries(collection.fields).find(([, f]) => f.type === "markdown")?.[0];
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// node/fs.ts
|
|
464
|
+
var DEFAULT_SCHEMA_PATH = "cms/schema.json";
|
|
465
|
+
async function loadProjectSchema(root2, schemaPath) {
|
|
466
|
+
let raw;
|
|
467
|
+
try {
|
|
468
|
+
raw = await readFile(join(root2, schemaPath), "utf8");
|
|
469
|
+
} catch (error) {
|
|
470
|
+
throw new EditletError([
|
|
471
|
+
{ file: schemaPath, path: "", message: `Cannot read schema: ${error instanceof Error ? error.message : error}` }
|
|
472
|
+
]);
|
|
473
|
+
}
|
|
474
|
+
return parseSchemaText(raw, schemaPath);
|
|
475
|
+
}
|
|
476
|
+
async function listFiles(root2, contentDir) {
|
|
477
|
+
let dirents;
|
|
478
|
+
try {
|
|
479
|
+
dirents = await readdir(join(root2, contentDir), { recursive: true, withFileTypes: true });
|
|
480
|
+
} catch (error) {
|
|
481
|
+
if (error.code === "ENOENT") return [];
|
|
482
|
+
throw error;
|
|
483
|
+
}
|
|
484
|
+
return dirents.filter((d) => d.isFile()).map((d) => `${relativeDir(root2, d.parentPath)}/${d.name}`.split("\\").join("/")).toSorted();
|
|
485
|
+
}
|
|
486
|
+
function relativeDir(root2, dir) {
|
|
487
|
+
return resolve(dir).slice(resolve(root2).length + 1);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// core/generate.ts
|
|
491
|
+
import { z as z4 } from "zod";
|
|
492
|
+
|
|
493
|
+
// core/validate.ts
|
|
494
|
+
import { z as z3 } from "zod";
|
|
495
|
+
|
|
496
|
+
// core/walk.ts
|
|
497
|
+
var isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
498
|
+
function blockFields(field, item) {
|
|
499
|
+
if (!isPlainObject(item)) return void 0;
|
|
500
|
+
const kind = item[BLOCK_KEY];
|
|
501
|
+
return typeof kind === "string" && Object.hasOwn(field.blocks, kind) ? field.blocks[kind].fields : void 0;
|
|
502
|
+
}
|
|
503
|
+
function children(field, value, path) {
|
|
504
|
+
if (field.type === "object") {
|
|
505
|
+
if (!field.list) return isPlainObject(value) ? [[field.fields, value, path]] : [];
|
|
506
|
+
if (!Array.isArray(value)) return [];
|
|
507
|
+
return value.flatMap((item, i) => isPlainObject(item) ? [[field.fields, item, [...path, i]]] : []);
|
|
508
|
+
}
|
|
509
|
+
if (field.type === "blocks") {
|
|
510
|
+
if (!Array.isArray(value)) return [];
|
|
511
|
+
return value.flatMap((item, i) => {
|
|
512
|
+
const fields = blockFields(field, item);
|
|
513
|
+
return fields ? [[fields, item, [...path, i]]] : [];
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return [];
|
|
517
|
+
}
|
|
518
|
+
var isContainer = (field) => field.type === "object" || field.type === "blocks";
|
|
519
|
+
function visitFields(fields, data, visit, at = []) {
|
|
520
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
521
|
+
if (!Object.hasOwn(data, key)) continue;
|
|
522
|
+
const path = [...at, key];
|
|
523
|
+
if (!isContainer(field)) {
|
|
524
|
+
visit(field, data[key], path);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
for (const [childFields, child, childPath] of children(field, data[key], path)) {
|
|
528
|
+
visitFields(childFields, child, visit, childPath);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// core/validate.ts
|
|
534
|
+
function buildDataSchema(collection) {
|
|
535
|
+
const shape = {};
|
|
536
|
+
for (const [key, field] of Object.entries(collection.fields)) {
|
|
537
|
+
const s = fieldValueSchema(field);
|
|
538
|
+
if (s) shape[key] = s;
|
|
539
|
+
}
|
|
540
|
+
shape.draft = z3.boolean({ error: "Expected true or false" }).optional();
|
|
541
|
+
return z3.strictObject(shape);
|
|
542
|
+
}
|
|
543
|
+
function toIssues2(error, file) {
|
|
544
|
+
const out = [];
|
|
545
|
+
for (const issue of error.issues) {
|
|
546
|
+
const path = issue.path.map(String);
|
|
547
|
+
if (issue.code === "unrecognized_keys") {
|
|
548
|
+
for (const key of issue.keys) out.push({ file, path: [...path, key].join("."), message: "Unknown field" });
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
out.push({ file, path: path.join("."), message: issue.message });
|
|
552
|
+
}
|
|
553
|
+
return out;
|
|
554
|
+
}
|
|
555
|
+
function validateEntry(schema, entry, ctx = {}) {
|
|
556
|
+
if (!Object.hasOwn(schema.collections, entry.collection)) {
|
|
557
|
+
return [{ path: "", message: `Unknown collection "${entry.collection}"` }];
|
|
558
|
+
}
|
|
559
|
+
const collection = schema.collections[entry.collection];
|
|
560
|
+
const file = entryFilePath(schema, entry.collection, entry.slug);
|
|
561
|
+
if (collection.singleton ? entry.slug !== "index" : !isValidSlug(entry.slug)) {
|
|
562
|
+
const message = collection.singleton ? 'Slug of a singleton must be "index"' : `Invalid slug "${entry.slug}": use lowercase letters, digits and single hyphens`;
|
|
563
|
+
return [{ file, path: "", message }];
|
|
564
|
+
}
|
|
565
|
+
if (typeof entry.data !== "object" || entry.data === null || Array.isArray(entry.data)) {
|
|
566
|
+
return [{ file, path: "", message: "Entry data must be an object" }];
|
|
567
|
+
}
|
|
568
|
+
const parsed = buildDataSchema(collection).safeParse(entry.data);
|
|
569
|
+
const issues = parsed.success ? [] : toIssues2(parsed.error, file);
|
|
570
|
+
const mdKey = markdownFieldKey(collection);
|
|
571
|
+
if (mdKey === void 0) {
|
|
572
|
+
if (entry.body.trim() !== "") {
|
|
573
|
+
issues.push({ file, path: "", message: "This collection has no markdown field, but the entry has body content" });
|
|
574
|
+
}
|
|
575
|
+
} else if (collection.fields[mdKey].required && entry.body.trim() === "") {
|
|
576
|
+
issues.push({ file, path: mdKey, message: "Required" });
|
|
577
|
+
}
|
|
578
|
+
const shapeIssues = [...issues];
|
|
579
|
+
const bad = (key) => shapeIssues.some((i) => i.path === key || i.path.startsWith(`${key}.`) || key.startsWith(`${i.path}.`));
|
|
580
|
+
visitFields(collection.fields, entry.data, (field, value, at) => {
|
|
581
|
+
const key = at.join(".");
|
|
582
|
+
if (bad(key)) return;
|
|
583
|
+
if (field.type === "image" && value !== null && value !== void 0) {
|
|
584
|
+
const src = value.src;
|
|
585
|
+
const resolved = resolveAssetPath(schema, file, src);
|
|
586
|
+
if (resolved === null) {
|
|
587
|
+
issues.push({ file, path: `${key}.src`, message: "Image path points outside the content directory" });
|
|
588
|
+
} else if (!isImagePath(resolved)) {
|
|
589
|
+
issues.push({ file, path: `${key}.src`, message: "Image path must end in an image extension" });
|
|
590
|
+
} else if (isHiddenContentPath(schema, resolved)) {
|
|
591
|
+
issues.push({ file, path: `${key}.src`, message: 'Image path must not be hidden (a segment starts with ".")' });
|
|
592
|
+
} else if (ctx.fileExists?.(resolved) === false) {
|
|
593
|
+
issues.push({ file, path: `${key}.src`, message: `Image file not found: ${resolved}` });
|
|
594
|
+
}
|
|
595
|
+
} else if (field.type === "reference" && !isAbsentValue(field, value)) {
|
|
596
|
+
const refs = Array.isArray(value) ? value : [value];
|
|
597
|
+
refs.forEach((ref, i) => {
|
|
598
|
+
if (ctx.entryExists?.(ref) === false) {
|
|
599
|
+
issues.push({
|
|
600
|
+
file,
|
|
601
|
+
path: Array.isArray(value) ? `${key}.${i}` : key,
|
|
602
|
+
message: `Referenced entry not found: ${ref}`
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
return issues;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// core/entryFile.ts
|
|
612
|
+
import { parse, Schema as YamlSchema, stringify } from "yaml";
|
|
613
|
+
var YAML_11_SCALARS = new YamlSchema({ schema: "yaml-1.1" }).tags.filter((tag) => !tag.collection);
|
|
614
|
+
function fail(message) {
|
|
615
|
+
throw new EditletError([{ path: "", message }]);
|
|
616
|
+
}
|
|
617
|
+
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
618
|
+
function decodeUtf8(content, file) {
|
|
619
|
+
if (typeof content === "string") return { text: content };
|
|
620
|
+
try {
|
|
621
|
+
return { text: utf8.decode(content) };
|
|
622
|
+
} catch {
|
|
623
|
+
return { issue: { file, path: "", message: "File is not valid UTF-8" } };
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function parseEntryFile(source) {
|
|
627
|
+
let text = source.startsWith("\uFEFF") ? source.slice(1) : source;
|
|
628
|
+
text = text.replace(/\r\n/g, "\n");
|
|
629
|
+
if (!text.startsWith("---\n")) return { data: {}, body: text };
|
|
630
|
+
const rest = text.slice(4);
|
|
631
|
+
const lines = rest.split("\n");
|
|
632
|
+
const close = lines.indexOf("---");
|
|
633
|
+
if (close === -1) fail('Frontmatter is not closed with a "---" line');
|
|
634
|
+
const yamlSrc = lines.slice(0, close).join("\n");
|
|
635
|
+
let body = lines.slice(close + 1).join("\n");
|
|
636
|
+
if (body.startsWith("\n")) body = body.slice(1);
|
|
637
|
+
let data;
|
|
638
|
+
try {
|
|
639
|
+
data = parse(yamlSrc, { schema: "core", logLevel: "error" });
|
|
640
|
+
} catch (error) {
|
|
641
|
+
fail(`Invalid YAML frontmatter: ${error instanceof Error ? error.message : String(error)}`);
|
|
642
|
+
}
|
|
643
|
+
if (data === null || data === void 0) data = {};
|
|
644
|
+
if (typeof data !== "object" || Array.isArray(data)) fail("Frontmatter must be a YAML mapping");
|
|
645
|
+
return { data, body };
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// core/project.ts
|
|
649
|
+
var byFile = (a, b) => (a.file ?? "").localeCompare(b.file ?? "");
|
|
650
|
+
function isSkippedPath(schema, schemaPath, file) {
|
|
651
|
+
return file === schemaPath || isHiddenContentPath(schema, file) || isImagePath(file);
|
|
652
|
+
}
|
|
653
|
+
function entryCandidate(schema, file) {
|
|
654
|
+
return file.endsWith(".md") ? parseEntryPath(schema, file) : null;
|
|
655
|
+
}
|
|
656
|
+
function entriesFromFiles(schema, schemaPath, files) {
|
|
657
|
+
const entries = [];
|
|
658
|
+
const issues = [];
|
|
659
|
+
for (const [file, content] of files) {
|
|
660
|
+
if (isSkippedPath(schema, schemaPath, file)) continue;
|
|
661
|
+
const parsed = entryCandidate(schema, file);
|
|
662
|
+
if (!parsed) {
|
|
663
|
+
issues.push({ file, path: "", message: "Not an entry file" });
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const decoded = decodeUtf8(content, file);
|
|
667
|
+
if ("issue" in decoded) {
|
|
668
|
+
issues.push(decoded.issue);
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
try {
|
|
672
|
+
const { data, body } = parseEntryFile(decoded.text);
|
|
673
|
+
entries.push({ collection: parsed.collection, slug: parsed.slug, data, body });
|
|
674
|
+
} catch (error) {
|
|
675
|
+
if (!(error instanceof EditletError)) throw error;
|
|
676
|
+
issues.push(...error.issues.map((issue) => ({ ...issue, file })));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const fileOf = (e) => entryFilePath(schema, e.collection, e.slug);
|
|
680
|
+
return {
|
|
681
|
+
entries: entries.toSorted((a, b) => fileOf(a).localeCompare(fileOf(b))),
|
|
682
|
+
issues: issues.toSorted(byFile)
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// node/project.ts
|
|
687
|
+
async function readProject(root2, schemaPath = DEFAULT_SCHEMA_PATH) {
|
|
688
|
+
const schema = await loadProjectSchema(root2, schemaPath);
|
|
689
|
+
const files = await listFiles(root2, schema.contentDir);
|
|
690
|
+
const contents = /* @__PURE__ */ new Map();
|
|
691
|
+
for (const file of files) {
|
|
692
|
+
if (isSkippedPath(schema, schemaPath, file)) continue;
|
|
693
|
+
contents.set(
|
|
694
|
+
file,
|
|
695
|
+
entryCandidate(schema, file) ? new Uint8Array(await readFile2(join2(root2, file))) : new Uint8Array()
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
return { root: root2, schema, ...entriesFromFiles(schema, schemaPath, contents) };
|
|
699
|
+
}
|
|
700
|
+
async function validateProject(root2, schemaPath = DEFAULT_SCHEMA_PATH) {
|
|
701
|
+
const project = await readProject(root2, schemaPath);
|
|
702
|
+
const { schema, entries } = project;
|
|
703
|
+
const refs = new Set(entries.map((e) => refKey(e.collection, e.slug)));
|
|
704
|
+
const files = new Set(await listFiles(root2, schema.contentDir));
|
|
705
|
+
const issues = [...project.issues];
|
|
706
|
+
for (const entry of entries) {
|
|
707
|
+
issues.push(
|
|
708
|
+
...validateEntry(schema, entry, { entryExists: (ref) => refs.has(ref), fileExists: (p) => files.has(p) })
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
return issues.toSorted(byFile);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// skills/editlet/scripts/validate.ts
|
|
715
|
+
var root = process.argv[2] ?? process.cwd();
|
|
716
|
+
try {
|
|
717
|
+
const issues = await validateProject(root);
|
|
718
|
+
if (issues.length > 0) reportIssues(issues);
|
|
719
|
+
else process.stdout.write(`\u2713 ${(await readProject(root)).entries.length} entries valid
|
|
720
|
+
`);
|
|
721
|
+
} catch (error) {
|
|
722
|
+
if (error instanceof EditletError) reportIssues(error.issues);
|
|
723
|
+
else throw error;
|
|
724
|
+
}
|