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,657 @@
|
|
|
1
|
+
// skills/editlet/scripts/style.ts
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
// core/issues.ts
|
|
6
|
+
var EditletError = class extends Error {
|
|
7
|
+
issues;
|
|
8
|
+
constructor(issues, message) {
|
|
9
|
+
super(message ?? issues.map((i) => i.path ? `${i.path}: ${i.message}` : i.message).join("; "));
|
|
10
|
+
this.name = "EditletError";
|
|
11
|
+
this.issues = issues;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// core/paths.ts
|
|
16
|
+
var SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
17
|
+
function slugify(text) {
|
|
18
|
+
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
19
|
+
}
|
|
20
|
+
function hasCollection(schema2, collection) {
|
|
21
|
+
return Object.hasOwn(schema2.collections, collection);
|
|
22
|
+
}
|
|
23
|
+
function isCanonicalPath(path) {
|
|
24
|
+
if (path === "" || /[\\\0:]/.test(path)) return false;
|
|
25
|
+
return path.split("/").every((seg) => seg !== "" && seg !== "." && seg !== "..");
|
|
26
|
+
}
|
|
27
|
+
function parseEntryPath(schema2, path) {
|
|
28
|
+
const prefix = `${schema2.contentDir}/`;
|
|
29
|
+
if (!path.startsWith(prefix) || !isCanonicalPath(path)) return null;
|
|
30
|
+
const parts = path.slice(prefix.length).split("/");
|
|
31
|
+
if (parts.length !== 2) return null;
|
|
32
|
+
const [collection, file] = parts;
|
|
33
|
+
if (!hasCollection(schema2, collection) || !file.endsWith(".md")) return null;
|
|
34
|
+
const name = file.slice(0, -3);
|
|
35
|
+
if (name === "") return null;
|
|
36
|
+
if (schema2.collections[collection].singleton) return file === "index.md" ? { collection, slug: "index" } : null;
|
|
37
|
+
return { collection, slug: name };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// core/schema.ts
|
|
41
|
+
import { z as z2 } from "zod";
|
|
42
|
+
|
|
43
|
+
// core/fields.ts
|
|
44
|
+
import { z } from "zod";
|
|
45
|
+
function isStringValued(field) {
|
|
46
|
+
switch (field.type) {
|
|
47
|
+
case "string":
|
|
48
|
+
return !field.list;
|
|
49
|
+
case "select":
|
|
50
|
+
case "reference":
|
|
51
|
+
return !field.multiple;
|
|
52
|
+
case "text":
|
|
53
|
+
case "datetime":
|
|
54
|
+
case "url":
|
|
55
|
+
case "color":
|
|
56
|
+
return true;
|
|
57
|
+
default:
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function isAbsentValue(field, value) {
|
|
62
|
+
return value === void 0 || value === null || value === "" && isStringValued(field);
|
|
63
|
+
}
|
|
64
|
+
function err(field, message) {
|
|
65
|
+
return (iss) => field.required && isAbsentValue(field, iss.input) ? "Required" : message;
|
|
66
|
+
}
|
|
67
|
+
function optional(field, schema2, message) {
|
|
68
|
+
if (field.required) return schema2;
|
|
69
|
+
return isStringValued(field) ? z.union([schema2, z.literal("")], { error: message }).nullish() : schema2.nullish();
|
|
70
|
+
}
|
|
71
|
+
function isUrl(v) {
|
|
72
|
+
return v.startsWith("/") || URL.canParse(v);
|
|
73
|
+
}
|
|
74
|
+
function noRepeats(message) {
|
|
75
|
+
return (items, ctx) => {
|
|
76
|
+
const seen = /* @__PURE__ */ new Set();
|
|
77
|
+
items.forEach((item, i) => {
|
|
78
|
+
if (seen.has(item)) ctx.addIssue({ code: "custom", path: [i], message: message(item) });
|
|
79
|
+
seen.add(item);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function listField(field, item, min, max, unique) {
|
|
84
|
+
const effective = Math.max(field.required ? 1 : 0, min);
|
|
85
|
+
let arr = z.array(item, { error: err(field, "Expected a list") });
|
|
86
|
+
if (effective > 0) {
|
|
87
|
+
arr = arr.min(effective, {
|
|
88
|
+
error: (iss) => Array.isArray(iss.input) && iss.input.length === 0 && field.required ? "Required" : `Must have at least ${effective}`
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (max !== void 0) arr = arr.max(max, { error: `Must have at most ${max}` });
|
|
92
|
+
return optional(field, unique ? arr.superRefine(noRepeats(unique)) : arr, "Expected a list");
|
|
93
|
+
}
|
|
94
|
+
var escapeRegex = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
95
|
+
function fieldsShape(fields) {
|
|
96
|
+
const shape = {};
|
|
97
|
+
for (const [key, field] of Object.entries(fields)) shape[key] = nestedValueSchema(field);
|
|
98
|
+
return shape;
|
|
99
|
+
}
|
|
100
|
+
function nestedValueSchema(field) {
|
|
101
|
+
if (field.type !== "markdown") return fieldValueSchema(field);
|
|
102
|
+
const base2 = z.string({ error: err(field, "Expected text") });
|
|
103
|
+
return field.required ? base2.regex(/\S/, "Required") : base2.nullish();
|
|
104
|
+
}
|
|
105
|
+
function fieldValueSchema(field) {
|
|
106
|
+
switch (field.type) {
|
|
107
|
+
case "markdown":
|
|
108
|
+
return null;
|
|
109
|
+
case "object": {
|
|
110
|
+
const obj = z.strictObject(fieldsShape(field.fields), { error: err(field, "Expected an object") });
|
|
111
|
+
if (field.list) return listField(field, obj, field.min ?? 0, field.max);
|
|
112
|
+
return optional(field, obj, "");
|
|
113
|
+
}
|
|
114
|
+
case "blocks": {
|
|
115
|
+
const kinds = Object.keys(field.blocks);
|
|
116
|
+
const message = `Expected ${BLOCK_KEY}: ${kinds.join(", ")}`;
|
|
117
|
+
const options = Object.entries(field.blocks).map(
|
|
118
|
+
([kind, block]) => z.strictObject({ [BLOCK_KEY]: z.literal(kind), ...fieldsShape(block.fields) })
|
|
119
|
+
);
|
|
120
|
+
const item = z.discriminatedUnion(BLOCK_KEY, options, {
|
|
121
|
+
error: message
|
|
122
|
+
});
|
|
123
|
+
return listField(field, item, field.min ?? 0, field.max);
|
|
124
|
+
}
|
|
125
|
+
case "string":
|
|
126
|
+
case "text": {
|
|
127
|
+
if (field.type === "string" && field.list) return listField(field, z.string({ error: "Expected text" }), 0);
|
|
128
|
+
const base2 = z.string({ error: err(field, "Expected text") });
|
|
129
|
+
return field.required ? base2.regex(/\S/, "Required") : base2.nullish();
|
|
130
|
+
}
|
|
131
|
+
case "boolean":
|
|
132
|
+
return optional(field, z.boolean({ error: err(field, "Expected true or false") }), "");
|
|
133
|
+
case "select": {
|
|
134
|
+
const values = field.options.map((o) => o.value);
|
|
135
|
+
const message = `Expected one of: ${values.join(", ")}`;
|
|
136
|
+
if (field.multiple) return listField(field, z.enum(values, { error: message }), 0);
|
|
137
|
+
return optional(field, z.enum(values, { error: err(field, message) }), message);
|
|
138
|
+
}
|
|
139
|
+
case "number": {
|
|
140
|
+
let n = z.number({ error: err(field, "Expected a number") });
|
|
141
|
+
if (field.integer) n = n.int("Must be a whole number");
|
|
142
|
+
if (field.min !== void 0) n = n.min(field.min, `Must be at least ${field.min}`);
|
|
143
|
+
if (field.max !== void 0) n = n.max(field.max, `Must be at most ${field.max}`);
|
|
144
|
+
return optional(field, n, "");
|
|
145
|
+
}
|
|
146
|
+
case "datetime": {
|
|
147
|
+
const base2 = field.dateOnly ? z.iso.date({ error: err(field, "Invalid date") }) : z.iso.datetime({ offset: true, local: true, error: err(field, "Invalid date") });
|
|
148
|
+
return optional(field, base2, "Invalid date");
|
|
149
|
+
}
|
|
150
|
+
case "json": {
|
|
151
|
+
if (!field.required) return z.unknown().optional();
|
|
152
|
+
return z.union([z.string(), z.number(), z.boolean(), z.array(z.unknown()), z.record(z.string(), z.unknown())], {
|
|
153
|
+
error: "Required"
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
case "url": {
|
|
157
|
+
const message = "Must be an http(s) URL or start with /";
|
|
158
|
+
const base2 = z.string({ error: err(field, "Expected text") }).regex(/^(?:https?:\/\/|\/(?!\/))/i, { error: err(field, message) }).refine(isUrl, { error: message });
|
|
159
|
+
return optional(field, base2, message);
|
|
160
|
+
}
|
|
161
|
+
case "color": {
|
|
162
|
+
const message = "Must be a hex color like #a1b2c3";
|
|
163
|
+
const base2 = z.string({ error: err(field, "Expected text") }).regex(/^#[0-9a-fA-F]{6}$/, { error: err(field, message) });
|
|
164
|
+
return optional(field, base2, message);
|
|
165
|
+
}
|
|
166
|
+
case "image": {
|
|
167
|
+
const nonEmpty = z.string({ error: (iss) => iss.input === void 0 || iss.input === null ? "Required" : "Expected text" }).regex(/\S/, "Required");
|
|
168
|
+
const obj = z.strictObject({ src: nonEmpty, alt: nonEmpty }, { error: err(field, "Expected { src, alt }") });
|
|
169
|
+
return optional(field, obj, "");
|
|
170
|
+
}
|
|
171
|
+
case "reference": {
|
|
172
|
+
const message = `Must reference an entry in: ${field.collections.join(", ")}`;
|
|
173
|
+
const slug = SLUG_RE.source.slice(1, -1);
|
|
174
|
+
const ref = z.string({ error: err(field, 'Expected a reference like "collection/slug"') }).regex(new RegExp(`^(?:${field.collections.map(escapeRegex).join("|")})/${slug}$`), {
|
|
175
|
+
error: err(field, message)
|
|
176
|
+
});
|
|
177
|
+
if (field.multiple) return listField(field, ref, field.min ?? 0, field.max, (r) => `Duplicate reference: ${r}`);
|
|
178
|
+
return optional(field, ref, message);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// core/schema.ts
|
|
184
|
+
var BLOCK_KEY = "block";
|
|
185
|
+
var COMMIT_PLACEHOLDERS = ["action", "Action", "collection", "slug", "target"];
|
|
186
|
+
var TITLE_PLACEHOLDERS = ["branch", "name", "login"];
|
|
187
|
+
var REF_SEGMENTS = /^[A-Za-z0-9][A-Za-z0-9._-]*(\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
|
|
188
|
+
function isRefPath(value) {
|
|
189
|
+
return REF_SEGMENTS.test(value) && !value.includes("..") && !value.split("/").some((s) => s.endsWith(".lock"));
|
|
190
|
+
}
|
|
191
|
+
function template(placeholders, max) {
|
|
192
|
+
return z2.string().trim().min(1).max(max).refine((t) => !/[\r\n]/.test(t), "must be one line").superRefine((t, ctx) => {
|
|
193
|
+
for (const [, name] of t.matchAll(/\{([^{}]*)\}/g)) {
|
|
194
|
+
if (!placeholders.includes(name)) {
|
|
195
|
+
ctx.addIssue({
|
|
196
|
+
code: "custom",
|
|
197
|
+
message: `unknown placeholder "{${name}}" (use ${placeholders.map((p) => `{${p}}`).join(", ")})`
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
var gitSchema = z2.strictObject({
|
|
204
|
+
baseBranch: z2.string().min(1),
|
|
205
|
+
branchPrefix: z2.string().refine(
|
|
206
|
+
(p) => p.endsWith("/") && isRefPath(p.slice(0, -1)),
|
|
207
|
+
'must be branch name segments ending in "/", for example "editlet/"'
|
|
208
|
+
).optional(),
|
|
209
|
+
commitMessage: template(COMMIT_PLACEHOLDERS, 200).optional(),
|
|
210
|
+
pullRequest: z2.strictObject({
|
|
211
|
+
title: template(TITLE_PLACEHOLDERS, 256).optional(),
|
|
212
|
+
labels: z2.array(
|
|
213
|
+
z2.string().trim().min(1).max(50).refine((l) => !l.includes(","), 'must not contain ","')
|
|
214
|
+
).max(10).optional(),
|
|
215
|
+
draft: z2.boolean().optional()
|
|
216
|
+
}).optional()
|
|
217
|
+
});
|
|
218
|
+
var IDENT = /^[a-zA-Z][a-zA-Z0-9]*$/;
|
|
219
|
+
var identMsg = "must start with a letter and contain only letters and digits";
|
|
220
|
+
var base = {
|
|
221
|
+
label: z2.string(),
|
|
222
|
+
hint: z2.string().optional(),
|
|
223
|
+
required: z2.boolean().optional()
|
|
224
|
+
};
|
|
225
|
+
var strOrList = z2.union([z2.string(), z2.array(z2.string())]);
|
|
226
|
+
var nestedFields = z2.lazy(
|
|
227
|
+
() => z2.record(z2.string().regex(IDENT, `field key ${identMsg}`), fieldSchema).refine((o) => Object.keys(o).length > 0, "fields must not be empty")
|
|
228
|
+
);
|
|
229
|
+
var fieldSchema = z2.discriminatedUnion("type", [
|
|
230
|
+
z2.strictObject({ ...base, type: z2.literal("string"), list: z2.boolean().optional(), default: strOrList.optional() }),
|
|
231
|
+
z2.strictObject({
|
|
232
|
+
...base,
|
|
233
|
+
type: z2.literal("text"),
|
|
234
|
+
rows: z2.number().int().positive().optional(),
|
|
235
|
+
default: z2.string().optional()
|
|
236
|
+
}),
|
|
237
|
+
z2.strictObject({ ...base, type: z2.literal("markdown") }),
|
|
238
|
+
z2.strictObject({
|
|
239
|
+
...base,
|
|
240
|
+
type: z2.literal("boolean"),
|
|
241
|
+
default: z2.boolean().optional(),
|
|
242
|
+
labels: z2.strictObject({ true: z2.string(), false: z2.string() }).optional()
|
|
243
|
+
}),
|
|
244
|
+
z2.strictObject({
|
|
245
|
+
...base,
|
|
246
|
+
type: z2.literal("select"),
|
|
247
|
+
options: z2.array(z2.strictObject({ label: z2.string(), value: z2.string() })).min(1, "options must not be empty"),
|
|
248
|
+
multiple: z2.boolean().optional(),
|
|
249
|
+
default: strOrList.optional()
|
|
250
|
+
}),
|
|
251
|
+
z2.strictObject({
|
|
252
|
+
...base,
|
|
253
|
+
type: z2.literal("number"),
|
|
254
|
+
min: z2.number().optional(),
|
|
255
|
+
max: z2.number().optional(),
|
|
256
|
+
step: z2.number().optional(),
|
|
257
|
+
integer: z2.boolean().optional(),
|
|
258
|
+
default: z2.number().optional()
|
|
259
|
+
}),
|
|
260
|
+
z2.strictObject({
|
|
261
|
+
...base,
|
|
262
|
+
type: z2.literal("datetime"),
|
|
263
|
+
dateOnly: z2.boolean().optional(),
|
|
264
|
+
defaultNow: z2.boolean().optional()
|
|
265
|
+
}),
|
|
266
|
+
z2.strictObject({ ...base, type: z2.literal("json") }),
|
|
267
|
+
z2.strictObject({ ...base, type: z2.literal("url") }),
|
|
268
|
+
z2.strictObject({ ...base, type: z2.literal("color"), default: z2.string().optional() }),
|
|
269
|
+
z2.strictObject({ ...base, type: z2.literal("image") }),
|
|
270
|
+
z2.strictObject({
|
|
271
|
+
...base,
|
|
272
|
+
type: z2.literal("reference"),
|
|
273
|
+
collections: z2.array(z2.string()).min(1, "collections must not be empty"),
|
|
274
|
+
multiple: z2.boolean().optional(),
|
|
275
|
+
min: z2.number().int().nonnegative().optional(),
|
|
276
|
+
max: z2.number().int().nonnegative().optional()
|
|
277
|
+
}),
|
|
278
|
+
z2.strictObject({
|
|
279
|
+
...base,
|
|
280
|
+
type: z2.literal("object"),
|
|
281
|
+
fields: nestedFields,
|
|
282
|
+
list: z2.boolean().optional(),
|
|
283
|
+
min: z2.number().int().nonnegative().optional(),
|
|
284
|
+
max: z2.number().int().nonnegative().optional()
|
|
285
|
+
}),
|
|
286
|
+
z2.strictObject({
|
|
287
|
+
...base,
|
|
288
|
+
type: z2.literal("blocks"),
|
|
289
|
+
blocks: z2.record(
|
|
290
|
+
z2.string().regex(IDENT, `block key ${identMsg}`),
|
|
291
|
+
z2.strictObject({ label: z2.string(), fields: nestedFields })
|
|
292
|
+
).refine((o) => Object.keys(o).length > 0, "blocks must not be empty"),
|
|
293
|
+
min: z2.number().int().nonnegative().optional(),
|
|
294
|
+
max: z2.number().int().nonnegative().optional()
|
|
295
|
+
})
|
|
296
|
+
]);
|
|
297
|
+
var collectionSchema = z2.strictObject({
|
|
298
|
+
label: z2.string(),
|
|
299
|
+
singleton: z2.boolean().optional(),
|
|
300
|
+
titleField: z2.string().optional(),
|
|
301
|
+
slugFrom: z2.string().optional(),
|
|
302
|
+
fields: z2.record(z2.string().regex(IDENT, `field key ${identMsg}`), fieldSchema)
|
|
303
|
+
});
|
|
304
|
+
function checkFields(schema2, fields, at, nested, add) {
|
|
305
|
+
for (const [fk, f] of Object.entries(fields)) {
|
|
306
|
+
const path = [...at, fk];
|
|
307
|
+
if (fk === "draft" && !nested) add(path, 'field key "draft" is reserved for the draft flag');
|
|
308
|
+
if ("default" in f && f.default !== void 0) {
|
|
309
|
+
const checked = fieldValueSchema(f)?.safeParse(f.default);
|
|
310
|
+
for (const issue of checked?.success === false ? checked.error.issues : []) {
|
|
311
|
+
add([...path, "default", ...issue.path.map(String)], `default: ${issue.message}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (f.type === "reference") {
|
|
315
|
+
f.collections.forEach((target, i) => {
|
|
316
|
+
if (!Object.hasOwn(schema2.collections, target))
|
|
317
|
+
add([...path, "collections", i], `unknown collection "${target}"`);
|
|
318
|
+
});
|
|
319
|
+
if (!f.multiple && (f.min !== void 0 || f.max !== void 0)) add(path, "min/max require multiple: true");
|
|
320
|
+
}
|
|
321
|
+
if (f.type === "object") {
|
|
322
|
+
if (!f.list && (f.min !== void 0 || f.max !== void 0)) add(path, "min/max require list: true");
|
|
323
|
+
checkFields(schema2, f.fields, [...path, "fields"], true, add);
|
|
324
|
+
}
|
|
325
|
+
if (f.type === "blocks") {
|
|
326
|
+
for (const [bk, block] of Object.entries(f.blocks)) {
|
|
327
|
+
if (Object.hasOwn(block.fields, BLOCK_KEY)) {
|
|
328
|
+
add([...path, "blocks", bk, "fields", BLOCK_KEY], `field key "${BLOCK_KEY}" is reserved for the block type`);
|
|
329
|
+
}
|
|
330
|
+
checkFields(schema2, block.fields, [...path, "blocks", bk, "fields"], true, add);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if ((f.type === "reference" || f.type === "object" || f.type === "blocks") && f.min !== void 0 && f.max !== void 0 && f.min > f.max) {
|
|
334
|
+
add([...path, "min"], "min must not exceed max");
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
var schemaSchema = z2.strictObject({
|
|
339
|
+
$schema: z2.string().optional(),
|
|
340
|
+
contentDir: z2.string().min(1).refine(
|
|
341
|
+
isCanonicalPath,
|
|
342
|
+
'must be a relative posix path without empty, "." or ".." segments, backslashes, NUL or ":"'
|
|
343
|
+
),
|
|
344
|
+
git: gitSchema,
|
|
345
|
+
collections: z2.record(z2.string().regex(IDENT, `collection key ${identMsg}`), collectionSchema)
|
|
346
|
+
}).superRefine((schema2, ctx) => {
|
|
347
|
+
const add = (path, message) => ctx.addIssue({ code: "custom", path, message });
|
|
348
|
+
const { baseBranch, branchPrefix } = schema2.git;
|
|
349
|
+
if (branchPrefix !== void 0 && (baseBranch.startsWith(branchPrefix) || branchPrefix.startsWith(`${baseBranch}/`))) {
|
|
350
|
+
add(["git", "branchPrefix"], `branchPrefix "${branchPrefix}" clashes with the base branch "${baseBranch}"`);
|
|
351
|
+
}
|
|
352
|
+
const lowerKeys = /* @__PURE__ */ new Map();
|
|
353
|
+
for (const [ck, col] of Object.entries(schema2.collections)) {
|
|
354
|
+
const other = lowerKeys.get(ck.toLowerCase());
|
|
355
|
+
if (other !== void 0) add(["collections", ck], `collection key "${ck}" differs from "${other}" only in case`);
|
|
356
|
+
else lowerKeys.set(ck.toLowerCase(), ck);
|
|
357
|
+
const fields = Object.entries(col.fields);
|
|
358
|
+
if (fields.filter(([, f]) => f.type === "markdown").length > 1) {
|
|
359
|
+
add(["collections", ck, "fields"], "a collection can have at most one markdown field");
|
|
360
|
+
}
|
|
361
|
+
if (col.titleField !== void 0 && !Object.hasOwn(col.fields, col.titleField)) {
|
|
362
|
+
add(["collections", ck, "titleField"], `titleField "${col.titleField}" is not a field of ${ck}`);
|
|
363
|
+
}
|
|
364
|
+
if (col.slugFrom !== void 0 && !Object.hasOwn(col.fields, col.slugFrom)) {
|
|
365
|
+
add(["collections", ck, "slugFrom"], `slugFrom "${col.slugFrom}" is not a field of ${ck}`);
|
|
366
|
+
}
|
|
367
|
+
checkFields(schema2, col.fields, ["collections", ck, "fields"], false, add);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
function toIssues(error) {
|
|
371
|
+
const out = [];
|
|
372
|
+
for (const issue of error.issues) {
|
|
373
|
+
let path = issue.path.map(String);
|
|
374
|
+
let message = issue.message;
|
|
375
|
+
if (issue.code === "invalid_union" && ("discriminator" in issue || path.at(-1) !== "type")) {
|
|
376
|
+
if (path.at(-1) !== "type") path = [...path, "type"];
|
|
377
|
+
message = "unknown field type";
|
|
378
|
+
}
|
|
379
|
+
if (issue.code === "unrecognized_keys") {
|
|
380
|
+
for (const key of issue.keys) out.push({ path: [...path, key].join("."), message: `unknown key "${key}"` });
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
out.push({ path: path.join("."), message });
|
|
384
|
+
}
|
|
385
|
+
return out;
|
|
386
|
+
}
|
|
387
|
+
function loadSchema(input) {
|
|
388
|
+
const parsed = schemaSchema.safeParse(input);
|
|
389
|
+
if (!parsed.success) throw new EditletError(toIssues(parsed.error));
|
|
390
|
+
return parsed.data;
|
|
391
|
+
}
|
|
392
|
+
function parseSchemaText(text, file) {
|
|
393
|
+
let json;
|
|
394
|
+
try {
|
|
395
|
+
json = JSON.parse(text);
|
|
396
|
+
} catch (error) {
|
|
397
|
+
throw new EditletError([
|
|
398
|
+
{ file, path: "", message: `Invalid JSON: ${error instanceof Error ? error.message : error}` }
|
|
399
|
+
]);
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
return loadSchema(json);
|
|
403
|
+
} catch (error) {
|
|
404
|
+
if (error instanceof EditletError) throw new EditletError(error.issues.map((issue) => ({ ...issue, file })));
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// core/gitStyle.ts
|
|
410
|
+
var DEFAULT_BRANCH_PREFIX = "editlet/";
|
|
411
|
+
var DEFAULT_COMMIT_MESSAGE = "{Action} {target}";
|
|
412
|
+
var DEFAULT_PULL_REQUEST_TITLE = "Update {branch}";
|
|
413
|
+
var DEFAULT_LABELS = ["editlet"];
|
|
414
|
+
var SOURCE_TRAILER = "Editlet-Source";
|
|
415
|
+
var PULL_REQUEST_BODY_START = "<!-- editlet:start -->";
|
|
416
|
+
var PULL_REQUEST_BODY_END = "<!-- editlet:end -->";
|
|
417
|
+
function resolveGitStyle(git) {
|
|
418
|
+
return {
|
|
419
|
+
branchPrefix: git?.branchPrefix ?? DEFAULT_BRANCH_PREFIX,
|
|
420
|
+
commitMessage: git?.commitMessage ?? DEFAULT_COMMIT_MESSAGE,
|
|
421
|
+
pullRequest: {
|
|
422
|
+
title: git?.pullRequest?.title ?? DEFAULT_PULL_REQUEST_TITLE,
|
|
423
|
+
labels: [...git?.pullRequest?.labels ?? DEFAULT_LABELS],
|
|
424
|
+
draft: git?.pullRequest?.draft ?? false
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function entrySubject(action, collection, slug) {
|
|
429
|
+
return { action, collection, slug, target: `${collection}/${slug}` };
|
|
430
|
+
}
|
|
431
|
+
function renameSubject(collection, from, to) {
|
|
432
|
+
return { action: "rename", collection, slug: to, target: `${collection}/${from} \u2192 ${collection}/${to}` };
|
|
433
|
+
}
|
|
434
|
+
function entriesSubject(action, entries) {
|
|
435
|
+
const [first, ...rest2] = entries;
|
|
436
|
+
if (!first) return { action, collection: "content", slug: "", target: "content" };
|
|
437
|
+
if (rest2.length === 0) return entrySubject(action, first.collection, first.slug);
|
|
438
|
+
const collection = rest2.every((e) => e.collection === first.collection) ? first.collection : "content";
|
|
439
|
+
const more = ` +${rest2.length}`;
|
|
440
|
+
return { action, collection, slug: `${first.slug}${more}`, target: `${first.collection}/${first.slug}${more}` };
|
|
441
|
+
}
|
|
442
|
+
function filesSubject(schema2, action, paths) {
|
|
443
|
+
const collectionOf = (path) => {
|
|
444
|
+
const rel = path.startsWith(`${schema2.contentDir}/`) ? path.slice(schema2.contentDir.length + 1) : "";
|
|
445
|
+
const top = rel.split("/")[0] ?? "";
|
|
446
|
+
return rel.includes("/") && Object.hasOwn(schema2.collections, top) ? top : "media";
|
|
447
|
+
};
|
|
448
|
+
const collections = new Set(paths.map(collectionOf));
|
|
449
|
+
const collection = collections.size === 1 ? [...collections][0] : "media";
|
|
450
|
+
if (paths.length === 1) {
|
|
451
|
+
const name = paths[0].split("/").pop();
|
|
452
|
+
return { action, collection, slug: name, target: `${collection}/${name}` };
|
|
453
|
+
}
|
|
454
|
+
const count = `${paths.length} images`;
|
|
455
|
+
return { action, collection, slug: count, target: count };
|
|
456
|
+
}
|
|
457
|
+
function schemaSubject(entries = 0) {
|
|
458
|
+
const more = entries > 0 ? ` +${entries}` : "";
|
|
459
|
+
return {
|
|
460
|
+
action: "update",
|
|
461
|
+
collection: "schema",
|
|
462
|
+
slug: `schema.json${more}`,
|
|
463
|
+
target: entries > 0 ? `schema +${entries} entries` : "schema"
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
var ACTION_OF = { added: "create", modified: "update", removed: "delete" };
|
|
467
|
+
function changesSubject(schema2, schemaPath, files) {
|
|
468
|
+
const entries = files.flatMap((f) => {
|
|
469
|
+
const ref = parseEntryPath(schema2, f.path);
|
|
470
|
+
return ref ? [{ ...ref, status: f.status }] : [];
|
|
471
|
+
});
|
|
472
|
+
if (files.some((f) => f.path === schemaPath)) return schemaSubject(entries.length);
|
|
473
|
+
const one = (statuses) => statuses.every((s) => s === statuses[0]) ? statuses[0] ?? null : null;
|
|
474
|
+
if (entries.length > 0) {
|
|
475
|
+
const status2 = one(entries.map((e) => e.status));
|
|
476
|
+
return entriesSubject(status2 ? ACTION_OF[status2] : "update", entries);
|
|
477
|
+
}
|
|
478
|
+
const status = one(files.map((f) => f.status));
|
|
479
|
+
const action = status === "added" ? "upload" : status ? ACTION_OF[status] : "update";
|
|
480
|
+
return filesSubject(
|
|
481
|
+
schema2,
|
|
482
|
+
action,
|
|
483
|
+
files.map((f) => f.path)
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
function fill(template2, values) {
|
|
487
|
+
return template2.replace(/\{([A-Za-z]+)\}/g, (whole, key) => Object.hasOwn(values, key) ? values[key] : whole).replace(/\s+/g, " ").trim();
|
|
488
|
+
}
|
|
489
|
+
function formatCommitMessage(style2, subject) {
|
|
490
|
+
const Action = subject.action.charAt(0).toUpperCase() + subject.action.slice(1);
|
|
491
|
+
return fill(style2.commitMessage, { ...subject, Action });
|
|
492
|
+
}
|
|
493
|
+
function withTrailer(message, source) {
|
|
494
|
+
return `${message}
|
|
495
|
+
|
|
496
|
+
${SOURCE_TRAILER}: ${source}`;
|
|
497
|
+
}
|
|
498
|
+
function branchShortName(style2, branch) {
|
|
499
|
+
return branch.startsWith(style2.branchPrefix) ? branch.slice(style2.branchPrefix.length) : branch;
|
|
500
|
+
}
|
|
501
|
+
function formatPullRequestTitle(style2, values) {
|
|
502
|
+
return fill(style2.pullRequest.title, { ...values, name: branchShortName(style2, values.branch) });
|
|
503
|
+
}
|
|
504
|
+
var CHANGE_STATUS = { added: "created", modified: "updated", removed: "deleted" };
|
|
505
|
+
function describeChanges(schema2, files) {
|
|
506
|
+
const entries = [];
|
|
507
|
+
const others = [];
|
|
508
|
+
for (const file of files) {
|
|
509
|
+
const status = CHANGE_STATUS[file.status];
|
|
510
|
+
const ref = schema2 ? parseEntryPath(schema2, file.path) : null;
|
|
511
|
+
if (ref) entries.push({ label: schema2.collections[ref.collection].label, name: ref.slug, status });
|
|
512
|
+
else others.push({ label: null, name: file.path, status });
|
|
513
|
+
}
|
|
514
|
+
return [...entries, ...others];
|
|
515
|
+
}
|
|
516
|
+
var MAX_BODY_LINES = 30;
|
|
517
|
+
function pullRequestBlock(input) {
|
|
518
|
+
const lines = input.changes.slice(0, MAX_BODY_LINES).map((c) => `- ${c.label === null ? `\`${c.name}\`` : `${c.label} \xB7 ${c.name}`} \u2014 ${c.status}`);
|
|
519
|
+
if (input.changes.length > MAX_BODY_LINES) lines.push(`- \u2026and ${input.changes.length - MAX_BODY_LINES} more`);
|
|
520
|
+
return [
|
|
521
|
+
PULL_REQUEST_BODY_START,
|
|
522
|
+
`Opened in Editlet by @${input.login}.`,
|
|
523
|
+
"",
|
|
524
|
+
"**Changes**",
|
|
525
|
+
...lines.length > 0 ? lines : ["- none yet"],
|
|
526
|
+
...input.reviewUrl ? ["", `Review on the site: ${input.reviewUrl}`] : [],
|
|
527
|
+
PULL_REQUEST_BODY_END
|
|
528
|
+
].join("\n");
|
|
529
|
+
}
|
|
530
|
+
function mergePullRequestBody(current, block) {
|
|
531
|
+
if (current === null || current.trim() === "") return block;
|
|
532
|
+
const start = current.indexOf(PULL_REQUEST_BODY_START);
|
|
533
|
+
const end = current.indexOf(PULL_REQUEST_BODY_END, start);
|
|
534
|
+
if (start < 0 || end < 0) return null;
|
|
535
|
+
return current.slice(0, start) + block + current.slice(end + PULL_REQUEST_BODY_END.length);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// loader/protocol.ts
|
|
539
|
+
var EDITLET_PARAM = "editlet";
|
|
540
|
+
|
|
541
|
+
// node/fs.ts
|
|
542
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
543
|
+
import { join, resolve } from "node:path";
|
|
544
|
+
var DEFAULT_SCHEMA_PATH = "cms/schema.json";
|
|
545
|
+
async function loadProjectSchema(root2, schemaPath) {
|
|
546
|
+
let raw;
|
|
547
|
+
try {
|
|
548
|
+
raw = await readFile(join(root2, schemaPath), "utf8");
|
|
549
|
+
} catch (error) {
|
|
550
|
+
throw new EditletError([
|
|
551
|
+
{ file: schemaPath, path: "", message: `Cannot read schema: ${error instanceof Error ? error.message : error}` }
|
|
552
|
+
]);
|
|
553
|
+
}
|
|
554
|
+
return parseSchemaText(raw, schemaPath);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// skills/editlet/scripts/style.ts
|
|
558
|
+
var USAGE = `Usage: node style.mjs <command> [--root <dir>]
|
|
559
|
+
branch <name> the branch for a change set: <prefix><name>
|
|
560
|
+
commit <action> <collection>/<slug> a commit message (action: create, update, delete, upload)
|
|
561
|
+
commit rename <collection>/<old> <new> the message of a slug rename (refs.mjs rename)
|
|
562
|
+
commit --staged a commit message for the staged files
|
|
563
|
+
pr <branch> --login <login> [--site <url>] [--param <name>] JSON { title, body, labels, draft } from <base>...HEAD
|
|
564
|
+
pr-body <branch> --login <login> [--site <url>] [--param <name>] the current body on stdin \u2192 the body with the Editlet part replaced
|
|
565
|
+
`;
|
|
566
|
+
function fail(message) {
|
|
567
|
+
process.stderr.write(`${message}
|
|
568
|
+
${USAGE}`);
|
|
569
|
+
process.exit(2);
|
|
570
|
+
}
|
|
571
|
+
function option(args2, name) {
|
|
572
|
+
const i = args2.indexOf(name);
|
|
573
|
+
if (i < 0) return void 0;
|
|
574
|
+
const value = args2[i + 1];
|
|
575
|
+
if (value === void 0 || value.startsWith("--")) fail(`${name} needs a value`);
|
|
576
|
+
args2.splice(i, 2);
|
|
577
|
+
return value;
|
|
578
|
+
}
|
|
579
|
+
function nameStatus(root2, diffArgs) {
|
|
580
|
+
const out = execFileSync("git", ["diff", "--name-status", "--no-renames", ...diffArgs], {
|
|
581
|
+
cwd: root2,
|
|
582
|
+
encoding: "utf8"
|
|
583
|
+
});
|
|
584
|
+
return out.split("\n").filter(Boolean).map((line) => {
|
|
585
|
+
const [code = "", path = ""] = line.split(" ");
|
|
586
|
+
const status = code.startsWith("A") ? "added" : code.startsWith("D") ? "removed" : "modified";
|
|
587
|
+
return { path, status };
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
var args = process.argv.slice(2);
|
|
591
|
+
var root = option(args, "--root") ?? process.cwd();
|
|
592
|
+
var [command, ...rest] = args;
|
|
593
|
+
var schema;
|
|
594
|
+
try {
|
|
595
|
+
schema = await loadProjectSchema(root, DEFAULT_SCHEMA_PATH);
|
|
596
|
+
} catch (error) {
|
|
597
|
+
if (!(error instanceof EditletError)) throw error;
|
|
598
|
+
process.stderr.write(`${DEFAULT_SCHEMA_PATH} is invalid; run validate.mjs
|
|
599
|
+
`);
|
|
600
|
+
process.exit(1);
|
|
601
|
+
}
|
|
602
|
+
var style = resolveGitStyle(schema.git);
|
|
603
|
+
switch (command) {
|
|
604
|
+
case "branch": {
|
|
605
|
+
const name = slugify(rest.join(" "));
|
|
606
|
+
if (!name) fail("branch needs a name");
|
|
607
|
+
process.stdout.write(`${style.branchPrefix}${name}
|
|
608
|
+
`);
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
case "commit": {
|
|
612
|
+
let subject;
|
|
613
|
+
if (rest[0] === "--staged") {
|
|
614
|
+
const files = nameStatus(root, ["--cached", "--", "."]);
|
|
615
|
+
if (files.length === 0) fail("nothing is staged");
|
|
616
|
+
subject = changesSubject(schema, DEFAULT_SCHEMA_PATH, files);
|
|
617
|
+
} else {
|
|
618
|
+
const [action, ref = "", to] = rest;
|
|
619
|
+
const [collection, slug] = ref.split("/");
|
|
620
|
+
if (!["create", "update", "delete", "upload", "rename"].includes(action ?? "") || !collection || !slug) {
|
|
621
|
+
fail("commit needs an action and <collection>/<slug>");
|
|
622
|
+
}
|
|
623
|
+
if (action === "rename" && !to) fail("commit rename needs <collection>/<old> <new>");
|
|
624
|
+
subject = action === "rename" ? renameSubject(collection, slug, to) : entrySubject(action, collection, slug);
|
|
625
|
+
}
|
|
626
|
+
process.stdout.write(`${withTrailer(formatCommitMessage(style, subject), "agent")}
|
|
627
|
+
`);
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
case "pr":
|
|
631
|
+
case "pr-body": {
|
|
632
|
+
const login = option(rest, "--login");
|
|
633
|
+
const site = option(rest, "--site");
|
|
634
|
+
const param = option(rest, "--param") ?? process.env.EDITLET_PARAM?.trim() ?? EDITLET_PARAM;
|
|
635
|
+
const [branch] = rest;
|
|
636
|
+
if (!branch || !login) fail(`${command} needs a branch and --login`);
|
|
637
|
+
const changes = describeChanges(
|
|
638
|
+
schema,
|
|
639
|
+
nameStatus(root, [`${schema.git.baseBranch}...HEAD`, "--", DEFAULT_SCHEMA_PATH, schema.contentDir])
|
|
640
|
+
);
|
|
641
|
+
const name = branch.startsWith(style.branchPrefix) ? branch.slice(style.branchPrefix.length) : branch;
|
|
642
|
+
const reviewUrl = site ? `${site.replace(/\/+$/, "")}/?${param || EDITLET_PARAM}=branch:${name}` : null;
|
|
643
|
+
const block = pullRequestBlock({ login, changes, reviewUrl });
|
|
644
|
+
if (command === "pr") {
|
|
645
|
+
const title = formatPullRequestTitle(style, { branch, login });
|
|
646
|
+
const { labels, draft } = style.pullRequest;
|
|
647
|
+
process.stdout.write(`${JSON.stringify({ title, body: block, labels, draft }, null, 2)}
|
|
648
|
+
`);
|
|
649
|
+
} else {
|
|
650
|
+
const current = readFileSync(0, "utf8");
|
|
651
|
+
process.stdout.write(mergePullRequestBody(current, block) ?? current);
|
|
652
|
+
}
|
|
653
|
+
break;
|
|
654
|
+
}
|
|
655
|
+
default:
|
|
656
|
+
fail(command ? `unknown command "${command}"` : "no command");
|
|
657
|
+
}
|