@dogsbay/ssg-cli 0.2.0-beta.186 → 0.2.0-beta.188
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/AGENTS.md +168 -0
- package/README.md +3 -1
- package/THIRD-PARTY-NOTICES.txt +23 -17
- package/chunks/{build-command-X76EICE4.mjs → build-command-NJATVOUY.mjs} +34 -25
- package/chunks/check-command-FL5O3AXB.mjs +577 -0
- package/chunks/chunk-2EM7IEQT.mjs +95 -0
- package/chunks/{chunk-JABACD5T.mjs → chunk-5A2QPRCV.mjs} +1 -30
- package/chunks/chunk-5NQOUB5I.mjs +4534 -0
- package/chunks/{chunk-YQ2K646L.mjs → chunk-CYJ6GFVM.mjs} +32 -3
- package/chunks/{chunk-XQORVEL6.mjs → chunk-FFIXBXHD.mjs} +60 -233
- package/chunks/chunk-GFG5I7WI.mjs +807 -0
- package/chunks/{chunk-AOHGXC4D.mjs → chunk-GZ3E45TE.mjs} +518 -240
- package/chunks/chunk-IAAKV7V2.mjs +37 -0
- package/chunks/{chunk-YA6TJOAM.mjs → chunk-VJ6AESSJ.mjs} +216 -24
- package/chunks/chunk-X3UPCLX5.mjs +503 -0
- package/chunks/{chunk-TRECVC6H.mjs → chunk-ZDH4JRVX.mjs} +1041 -4051
- package/chunks/{chunk-FNP5PNJW.mjs → chunk-ZRGJHNES.mjs} +6 -0
- package/chunks/compare-W4DJYVHT.mjs +239 -0
- package/chunks/compare-command-U36H55IE.mjs +144 -0
- package/chunks/{css-build-VKKTSP6P.mjs → css-build-MKIHYHCX.mjs} +2 -1
- package/chunks/{dev-DXMZPST7.mjs → dev-X3PKN4G3.mjs} +77 -26
- package/chunks/{menu-W7ZXME4A.mjs → menu-J3CLVADF.mjs} +5 -3
- package/chunks/{publish-command-AVMRM4UZ.mjs → publish-command-SAPICGGM.mjs} +15 -8
- package/chunks/{release-diff-3OZOYBXR.mjs → release-diff-Y7X63MT3.mjs} +13 -7
- package/chunks/{serve-U2YV7AQH.mjs → serve-7DR4WSYA.mjs} +2 -2
- package/cli.mjs +17 -10
- package/package.json +4 -3
- package/chunks/check-command-SXDUKSAZ.mjs +0 -256
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
projectRoots,
|
|
5
|
+
sourceRoot,
|
|
6
|
+
unitKeyString,
|
|
7
|
+
unitManifest
|
|
8
|
+
} from "./chunk-5NQOUB5I.mjs";
|
|
9
|
+
import {
|
|
10
|
+
dirname,
|
|
11
|
+
normalize
|
|
12
|
+
} from "./chunk-GZ3E45TE.mjs";
|
|
13
|
+
import {
|
|
14
|
+
RenderLimitError,
|
|
15
|
+
composeTextMaps,
|
|
16
|
+
diffTextMap,
|
|
17
|
+
maskMinjaInCode,
|
|
18
|
+
offsetIncludeMaps,
|
|
19
|
+
render,
|
|
20
|
+
renderWithSourceMap,
|
|
21
|
+
stripFenceMinjaMarkers,
|
|
22
|
+
stripInlineMinjaMarkers,
|
|
23
|
+
textMapOfLines,
|
|
24
|
+
unmaskMinjaInCode
|
|
25
|
+
} from "./chunk-VJ6AESSJ.mjs";
|
|
26
|
+
import {
|
|
27
|
+
TEXT_FILE,
|
|
28
|
+
isLazyText,
|
|
29
|
+
isRef,
|
|
30
|
+
isStream
|
|
31
|
+
} from "./chunk-5A2QPRCV.mjs";
|
|
32
|
+
|
|
33
|
+
// src/core/unit-manifest.ts
|
|
34
|
+
function unitKey(u) {
|
|
35
|
+
return unitKeyString({ product: u.product, locale: u.locale, version: u.version });
|
|
36
|
+
}
|
|
37
|
+
function manifestPath(u, folder = "_dogsbay") {
|
|
38
|
+
return `${manifestDir(folder)}${unitKey(u)}.json`;
|
|
39
|
+
}
|
|
40
|
+
function manifestDir(folder = "_dogsbay") {
|
|
41
|
+
return `${folder}/units/`;
|
|
42
|
+
}
|
|
43
|
+
var MANIFEST_DIR = manifestDir();
|
|
44
|
+
function makeManifest(u, ssg, redirects) {
|
|
45
|
+
const inside = (p) => !u.prefix ? p : p === u.prefix ? "" : p.startsWith(`${u.prefix}/`) ? p.slice(u.prefix.length + 1) : p;
|
|
46
|
+
return { ...unitManifest({ product: u.product, locale: u.locale, version: u.version }, { pages: ssg.pageOut.map(([p]) => inside(p)), sitemap: [], redirects }), ssg };
|
|
47
|
+
}
|
|
48
|
+
function parseManifest(raw) {
|
|
49
|
+
let v = raw;
|
|
50
|
+
if (typeof raw === "string") {
|
|
51
|
+
try {
|
|
52
|
+
v = JSON.parse(raw);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return { problem: `not JSON (${e.message})` };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const m = v;
|
|
58
|
+
if (!m || typeof m !== "object" || m.schemaVersion !== 1) return { problem: "not a unit manifest (schemaVersion 1)" };
|
|
59
|
+
const s = m.ssg;
|
|
60
|
+
const strings = (x) => Array.isArray(x) && x.every((y) => typeof y === "string");
|
|
61
|
+
const pairs = (x) => Array.isArray(x) && x.every((y) => Array.isArray(y) && y.length === 2 && typeof y[0] === "string" && typeof y[1] === "string");
|
|
62
|
+
if (!s || typeof s !== "object" || typeof s.prefix !== "string" || !Array.isArray(s.redirectInputs) || !pairs(s.pageOut) || !strings(s.sitemaps) || !strings(s.files) || typeof s.client !== "string" || typeof s.builder !== "string") {
|
|
63
|
+
return { problem: "has no dogsbay-ssg section (written by another tool, or an older dogsbay-ssg)" };
|
|
64
|
+
}
|
|
65
|
+
if (s.searchPage !== void 0 && typeof s.searchPage !== "string") return { problem: "has a malformed search page" };
|
|
66
|
+
if (s.math !== void 0 && typeof s.math !== "boolean" || s.iconSets !== void 0 && !strings(s.iconSets)) return { problem: "has a malformed notices record" };
|
|
67
|
+
const triples = (x) => Array.isArray(x) && x.every((y) => Array.isArray(y) && y.length === 3 && typeof y[0] === "string" && typeof y[1] === "string" && typeof y[2] === "number");
|
|
68
|
+
if (!triples(m.redirects)) return { problem: "has malformed redirects" };
|
|
69
|
+
const inputs = s.redirectInputs;
|
|
70
|
+
if (!inputs.every((r) => !!r && typeof r === "object" && typeof r.from === "string" && typeof r.to === "string" && typeof r.status === "number")) {
|
|
71
|
+
return { problem: "has a malformed redirect" };
|
|
72
|
+
}
|
|
73
|
+
return { manifest: m };
|
|
74
|
+
}
|
|
75
|
+
var CLIENT_PATTERN = /^dogsbay-[0-9a-f]{10}\.js$/;
|
|
76
|
+
function unitFilesOf(text) {
|
|
77
|
+
const m = parseManifest(text).manifest;
|
|
78
|
+
return m ? { prefix: m.ssg.prefix, files: m.ssg.files, client: m.ssg.client } : null;
|
|
79
|
+
}
|
|
80
|
+
function staleUnitFiles(previous, now, written, assets, folder = "_dogsbay") {
|
|
81
|
+
const prefixes = [...new Set([...previous.values(), ...now.values()].flatMap((m) => m ? [m.prefix] : []))];
|
|
82
|
+
const ownerOf = (p) => {
|
|
83
|
+
let best;
|
|
84
|
+
for (const x of prefixes) if ((x === "" || p.startsWith(`${x}/`)) && (best === void 0 || x.length > best.length)) best = x;
|
|
85
|
+
return best;
|
|
86
|
+
};
|
|
87
|
+
const plain = (p) => !p.startsWith("/") && !p.split("/").some((x) => x === ".." || x === "." || x === "");
|
|
88
|
+
const out = /* @__PURE__ */ new Set();
|
|
89
|
+
for (const [path, before] of previous) {
|
|
90
|
+
const next = now.get(path);
|
|
91
|
+
if (!before || !next || !written.has(path) || before.prefix !== next.prefix) continue;
|
|
92
|
+
const kept = new Set(next.files);
|
|
93
|
+
for (const f of before.files) if (plain(f) && !kept.has(f) && !written.has(f) && ownerOf(f) === before.prefix && !f.startsWith(manifestDir(folder))) out.add(f);
|
|
94
|
+
}
|
|
95
|
+
const all = [...now.values()];
|
|
96
|
+
if (all.every((m) => m !== null)) {
|
|
97
|
+
const clients = new Set(all.map((m) => m.client));
|
|
98
|
+
for (const f of assets) if (CLIENT_PATTERN.test(f) && !clients.has(f) && !written.has(`${folder}/assets/${f}`)) out.add(`${folder}/assets/${f}`);
|
|
99
|
+
}
|
|
100
|
+
return [...out];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/node/fs.ts
|
|
104
|
+
import { readdirSync, readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, statSync, lstatSync, realpathSync, copyFileSync, openSync, writeSync, closeSync } from "node:fs";
|
|
105
|
+
import { join, dirname as dirname2, relative, resolve, sep, posix } from "node:path";
|
|
106
|
+
|
|
107
|
+
// src/core/variable-places.ts
|
|
108
|
+
function lineStarts(text) {
|
|
109
|
+
const starts = [0];
|
|
110
|
+
for (let i = text.indexOf("\n"); i >= 0; i = text.indexOf("\n", i + 1)) starts.push(i + 1);
|
|
111
|
+
starts.push(text.length + 1);
|
|
112
|
+
return starts;
|
|
113
|
+
}
|
|
114
|
+
function lineOf(starts, at) {
|
|
115
|
+
let lo = 0;
|
|
116
|
+
let hi = starts.length - 2;
|
|
117
|
+
while (lo < hi) {
|
|
118
|
+
const mid = lo + hi + 1 >> 1;
|
|
119
|
+
if (starts[mid] <= at) lo = mid;
|
|
120
|
+
else hi = mid - 1;
|
|
121
|
+
}
|
|
122
|
+
return lo;
|
|
123
|
+
}
|
|
124
|
+
var lineText = (text, starts, i) => text.slice(starts[i], starts[i + 1] - 1);
|
|
125
|
+
function carryVariables(variables, before, after, map) {
|
|
126
|
+
if (before === after) return [...variables];
|
|
127
|
+
const bs = lineStarts(before);
|
|
128
|
+
const as = lineStarts(after);
|
|
129
|
+
const to = /* @__PURE__ */ new Map();
|
|
130
|
+
let out = 0;
|
|
131
|
+
for (const s of map.segments) {
|
|
132
|
+
if (s.kind === "copy") {
|
|
133
|
+
for (let k = 0; k < s.lines; k++) if (!to.has(s.from - 1 + k)) to.set(s.from - 1 + k, { line: out + k, same: true });
|
|
134
|
+
} else if (s.kind === "expr" && s.to - s.from + 1 === s.lines) {
|
|
135
|
+
for (let k = 0; k < s.lines; k++) if (!to.has(s.from - 1 + k)) to.set(s.from - 1 + k, { line: out + k, same: false });
|
|
136
|
+
}
|
|
137
|
+
out += s.lines;
|
|
138
|
+
}
|
|
139
|
+
return variables.map((v) => {
|
|
140
|
+
if (v.from === void 0 || v.to === void 0) return v;
|
|
141
|
+
const { from: _f, to: _t, ...unplaced } = v;
|
|
142
|
+
const line = lineOf(bs, v.from);
|
|
143
|
+
const target = to.get(line);
|
|
144
|
+
if (!target || target.line >= as.length - 1 || v.to > bs[line + 1] - 1) return unplaced;
|
|
145
|
+
const col = v.from - bs[line];
|
|
146
|
+
const len = v.to - v.from;
|
|
147
|
+
const was = lineText(before, bs, line);
|
|
148
|
+
const now = lineText(after, as, target.line);
|
|
149
|
+
let at;
|
|
150
|
+
if (target.same || was === now) at = col;
|
|
151
|
+
else {
|
|
152
|
+
let p = 0;
|
|
153
|
+
while (p < was.length && p < now.length && was[p] === now[p]) p++;
|
|
154
|
+
let q = 0;
|
|
155
|
+
while (q < was.length - p && q < now.length - p && was[was.length - 1 - q] === now[now.length - 1 - q]) q++;
|
|
156
|
+
if (col + len <= p) at = col;
|
|
157
|
+
else if (col >= was.length - q) at = col + now.length - was.length;
|
|
158
|
+
}
|
|
159
|
+
if (at === void 0) return unplaced;
|
|
160
|
+
const from = as[target.line] + at;
|
|
161
|
+
if (after.slice(from, from + len) !== v.value) return unplaced;
|
|
162
|
+
return { ...v, from, to: from + len };
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/core/preprocess.ts
|
|
167
|
+
var HASH_SENTINEL = " DBMINJA_HASH_OPEN ";
|
|
168
|
+
var mask = (s) => maskMinjaInCode(s).replace(/\{#/g, `{${HASH_SENTINEL}`);
|
|
169
|
+
var unmask = (s) => unmaskMinjaInCode(s).split(HASH_SENTINEL).join("#");
|
|
170
|
+
function stripFrontmatter(s) {
|
|
171
|
+
if (!s.startsWith("---")) return s;
|
|
172
|
+
const end = s.indexOf("\n---", 3);
|
|
173
|
+
if (end < 0) return s;
|
|
174
|
+
const after = s.indexOf("\n", end + 4);
|
|
175
|
+
return after < 0 ? "" : s.slice(after + 1);
|
|
176
|
+
}
|
|
177
|
+
function minjaName(path, basePath) {
|
|
178
|
+
if (path.startsWith("/") || !basePath) return path;
|
|
179
|
+
const combined = `${basePath.endsWith("/") ? basePath : basePath + "/"}${path}`;
|
|
180
|
+
const out = [];
|
|
181
|
+
for (const part of combined.split("/")) {
|
|
182
|
+
if (part === "." || part === "") continue;
|
|
183
|
+
if (part === "..") out.pop();
|
|
184
|
+
else out.push(part);
|
|
185
|
+
}
|
|
186
|
+
return (combined.startsWith("/") ? "/" : "") + out.join("/");
|
|
187
|
+
}
|
|
188
|
+
var MapLoader = class {
|
|
189
|
+
constructor(files, loaded) {
|
|
190
|
+
this.files = files;
|
|
191
|
+
this.loaded = loaded;
|
|
192
|
+
}
|
|
193
|
+
async load(path, basePath) {
|
|
194
|
+
const candidates = path.startsWith("/") ? [normalize(path).slice(1)] : [normalize(basePath ? `${basePath}/${path}` : path), normalize(path)];
|
|
195
|
+
for (const c of candidates) {
|
|
196
|
+
const file = c.replace(/^\/+/, "");
|
|
197
|
+
const hit = await this.files(file);
|
|
198
|
+
if (hit != null) {
|
|
199
|
+
const body = stripFrontmatter(hit);
|
|
200
|
+
this.loaded?.set(minjaName(path, basePath), { file, frontMatter: hit.length === body.length ? 0 : hit.slice(0, hit.length - body.length).split("\n").length - 1 });
|
|
201
|
+
return mask(body);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
throw new Error(`include not found: ${path}${basePath ? ` (from ${basePath})` : ""}`);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var TemplateBudget = class {
|
|
208
|
+
constructor(renderMs, buildMs, now = () => Date.now()) {
|
|
209
|
+
this.renderMs = renderMs;
|
|
210
|
+
this.buildMs = buildMs;
|
|
211
|
+
this.now = now;
|
|
212
|
+
}
|
|
213
|
+
spentMs = 0;
|
|
214
|
+
active = 0;
|
|
215
|
+
since = 0;
|
|
216
|
+
/** Renders not run because the budget was spent, by what they were for. */
|
|
217
|
+
skipped = { pages: 0, titles: 0 };
|
|
218
|
+
get spent() {
|
|
219
|
+
return this.spentMs + (this.active ? this.now() - this.since : 0);
|
|
220
|
+
}
|
|
221
|
+
/** The time the next render may take; 0 when the budget is spent. */
|
|
222
|
+
next() {
|
|
223
|
+
return Math.max(0, Math.min(this.renderMs, this.buildMs - this.spent));
|
|
224
|
+
}
|
|
225
|
+
start() {
|
|
226
|
+
if (this.active++ === 0) this.since = this.now();
|
|
227
|
+
}
|
|
228
|
+
end() {
|
|
229
|
+
if (--this.active === 0) this.spentMs += this.now() - this.since;
|
|
230
|
+
}
|
|
231
|
+
reset() {
|
|
232
|
+
this.spentMs = 0;
|
|
233
|
+
this.since = this.now();
|
|
234
|
+
this.skipped = { pages: 0, titles: 0 };
|
|
235
|
+
}
|
|
236
|
+
/** The problem to report when renders were skipped since the last reset, else undefined. */
|
|
237
|
+
problem() {
|
|
238
|
+
const { pages, titles } = this.skipped;
|
|
239
|
+
if (!pages && !titles) return void 0;
|
|
240
|
+
const what = [pages && `${pages} page(s)`, titles && `${titles} title(s)`].filter(Boolean).join(" and ");
|
|
241
|
+
return `[template] the template time budget (${this.buildMs / 1e3} s) ran out: ${what} shown without their templates rendered`;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
function templateBudget(untrusted, given) {
|
|
245
|
+
return new TemplateBudget(given?.renderMs ?? (untrusted ? 2e3 : 1e4), given?.buildMs ?? (untrusted ? 3e4 : 6e5));
|
|
246
|
+
}
|
|
247
|
+
function needsTemplating(text) {
|
|
248
|
+
return text.includes("{{") || text.includes("{%");
|
|
249
|
+
}
|
|
250
|
+
async function preprocess(text, path, attributes, files, undefinedRefs = "preserve", run = {}) {
|
|
251
|
+
if (!needsTemplating(text)) return { text };
|
|
252
|
+
const budget = run.budget;
|
|
253
|
+
const timeout = budget ? budget.next() : 1e4;
|
|
254
|
+
const skip = () => {
|
|
255
|
+
if (run.kind !== "copy") budget.skipped[run.kind === "title" ? "titles" : "pages"]++;
|
|
256
|
+
return { text, skipped: true };
|
|
257
|
+
};
|
|
258
|
+
if (budget && timeout <= 0) return skip();
|
|
259
|
+
budget?.start();
|
|
260
|
+
const warnings = [];
|
|
261
|
+
const loaded = run.sourceMap ? /* @__PURE__ */ new Map() : void 0;
|
|
262
|
+
try {
|
|
263
|
+
const options = {
|
|
264
|
+
context: withUnderscoreAliases(attributes),
|
|
265
|
+
undefinedBehavior: undefinedRefs,
|
|
266
|
+
undefinedConditions: "falsy",
|
|
267
|
+
hyphenToUnderscore: true,
|
|
268
|
+
basePath: dirname(path),
|
|
269
|
+
loader: new MapLoader(files, loaded),
|
|
270
|
+
timeout,
|
|
271
|
+
// A mapped render parses with positions, bypassing it, but expands variables through it
|
|
272
|
+
...run.parseCache !== void 0 ? { parseCache: run.parseCache } : {},
|
|
273
|
+
// Once per tag and place: a page that includes a file twice is told once.
|
|
274
|
+
onWarning: (w) => {
|
|
275
|
+
if (!warnings.some((x) => x.tag === w.tag && x.line === w.line && x.include === w.include && x.variable === w.variable))
|
|
276
|
+
warnings.push({ tag: w.tag, line: w.line, ...w.include ? { include: w.include } : {}, ...w.variable ? { variable: w.variable } : {} });
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const traced = loaded ? await renderWithSourceMap(mask(text), { ...options, markVariables: true }) : { output: await render(mask(text), options), map: void 0, variables: void 0 };
|
|
280
|
+
const unmasked = unmask(traced.output);
|
|
281
|
+
const out = stripFenceMinjaMarkers(stripInlineMinjaMarkers(unmasked));
|
|
282
|
+
let map;
|
|
283
|
+
if (traced.map && loaded) {
|
|
284
|
+
const inFile = offsetIncludeMaps(traced.map, (f) => loaded.get(f)?.frontMatter ?? 0);
|
|
285
|
+
map = renameIncludes(inFile, (f) => loaded.get(f)?.file ?? f);
|
|
286
|
+
if (out !== unmasked) map = composeTextMaps(map, diffTextMap(unmasked, out));
|
|
287
|
+
}
|
|
288
|
+
const printed = traced.variables?.length ? traced.variables : void 0;
|
|
289
|
+
const carried = printed && (traced.output === out ? printed : carryVariables(printed, traced.output, out, lineForLine(traced.output, out)));
|
|
290
|
+
const variables = carried?.map((v) => {
|
|
291
|
+
const d = v.definition;
|
|
292
|
+
if (d.via !== "set" || d.file === void 0 || !loaded) return v;
|
|
293
|
+
const got = loaded.get(d.file);
|
|
294
|
+
return { ...v, definition: { ...d, file: got?.file ?? d.file, line: d.line + (got?.frontMatter ?? 0) } };
|
|
295
|
+
});
|
|
296
|
+
return { text: out, ...warnings.length ? { warnings } : {}, ...map ? { map } : {}, ...variables?.length ? { variables } : {} };
|
|
297
|
+
} catch (err) {
|
|
298
|
+
if (budget && timeout < budget.renderMs && err instanceof RenderLimitError && budget.next() <= 0) return skip();
|
|
299
|
+
return { text, error: err instanceof Error ? err.message : String(err) };
|
|
300
|
+
} finally {
|
|
301
|
+
budget?.end();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function lineForLine(before, after) {
|
|
305
|
+
const a = before.split("\n");
|
|
306
|
+
const b = after.split("\n");
|
|
307
|
+
if (a.length !== b.length) return diffTextMap(before, after);
|
|
308
|
+
return textMapOfLines(b.map((l, i) => l === a[i] ? i + 1 : { kind: "expr", from: i + 1, to: i + 1 }));
|
|
309
|
+
}
|
|
310
|
+
function renameIncludes(map, name) {
|
|
311
|
+
const seg = (s) => s.kind === "include" ? { ...s, file: name(s.file), ...s.map ? { map: renameIncludes(s.map, name) } : {} } : s;
|
|
312
|
+
return { segments: map.segments.map(seg) };
|
|
313
|
+
}
|
|
314
|
+
function withUnderscoreAliases(attrs) {
|
|
315
|
+
const out = { ...attrs };
|
|
316
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
317
|
+
const u = k.replace(/-/g, "_");
|
|
318
|
+
if (!(u in out)) out[u] = v;
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// src/node/fs.ts
|
|
324
|
+
function diskRef(path) {
|
|
325
|
+
return { ref: true, path, read: () => new Uint8Array(readFileSync(path)) };
|
|
326
|
+
}
|
|
327
|
+
function insideProject(root, full, bases = []) {
|
|
328
|
+
try {
|
|
329
|
+
const f = realpathSync(full);
|
|
330
|
+
return [root, ...bases].some((b) => {
|
|
331
|
+
let r;
|
|
332
|
+
try {
|
|
333
|
+
r = realpathSync(b);
|
|
334
|
+
} catch {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
return f === r || f.startsWith(r + sep);
|
|
338
|
+
});
|
|
339
|
+
} catch {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".dogsbay", ".wrangler", "dist", "out", "site", ".astro", "astro"]);
|
|
344
|
+
function fileEntry(full, name) {
|
|
345
|
+
return TEXT_FILE.test(name) ? { lazyText: true, path: full, read: () => readFileSync(full, "utf8") } : diskRef(full);
|
|
346
|
+
}
|
|
347
|
+
function readProject(root, only, exclude = [], confine = false) {
|
|
348
|
+
const files = /* @__PURE__ */ new Map();
|
|
349
|
+
const skip = new Set(exclude.map((p) => resolve(p)));
|
|
350
|
+
const walk = (dir) => {
|
|
351
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
352
|
+
const full = join(dir, e.name);
|
|
353
|
+
if (skip.has(resolve(full))) continue;
|
|
354
|
+
if (e.isDirectory()) {
|
|
355
|
+
if (SKIP_DIRS.has(e.name) && dir === root) continue;
|
|
356
|
+
if (e.name === "node_modules" || e.name === ".git") continue;
|
|
357
|
+
walk(full);
|
|
358
|
+
} else if (e.isFile()) {
|
|
359
|
+
const rel = relative(root, full).split(sep).join("/");
|
|
360
|
+
files.set(rel, fileEntry(full, e.name));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
for (const o of only ?? [""]) {
|
|
365
|
+
const d = posix.normalize(o.replace(/\\/g, "/")).replace(/^(\.\/)+|\/+$/g, "").replace(/^\.$/, "");
|
|
366
|
+
if (d === ".." || d.startsWith("../") || posix.isAbsolute(d)) throw new Error(`${o} is outside the project ${root}; the build reads only the project's files`);
|
|
367
|
+
const start = join(root, d);
|
|
368
|
+
if (!existsSync(start) || skip.has(resolve(start))) continue;
|
|
369
|
+
if (confine && !insideProject(root, start)) throw new Error(`${o} resolves outside the project ${root} (a symbolic link); an untrusted build reads only the project's files`);
|
|
370
|
+
const st = statSync(start);
|
|
371
|
+
if (st.isDirectory()) walk(start);
|
|
372
|
+
else if (st.isFile() && !files.has(d)) files.set(d, fileEntry(start, d));
|
|
373
|
+
}
|
|
374
|
+
return files;
|
|
375
|
+
}
|
|
376
|
+
async function readBuildFiles(root, cfg, exclude = [], confine = false) {
|
|
377
|
+
const files = readProject(root, projectRoots(cfg), exclude, confine);
|
|
378
|
+
return { files, maps: await readMenus(root, cfg, files, exclude) };
|
|
379
|
+
}
|
|
380
|
+
async function readMenus(root, cfg, files, exclude = []) {
|
|
381
|
+
const maps = /* @__PURE__ */ new Set();
|
|
382
|
+
const skip = exclude.map((p) => resolve(p));
|
|
383
|
+
for (const s of cfg.sources) {
|
|
384
|
+
if (s.from === "openapi") continue;
|
|
385
|
+
const path = s.nav ?? ["nav.yml", "nav.yaml", "nav.json"].map((f) => sourceRoot(s) + f).find((f) => files.has(f));
|
|
386
|
+
if (!path) continue;
|
|
387
|
+
const { sourceMenu } = await import("./menu-J3CLVADF.mjs");
|
|
388
|
+
const read = async (p) => {
|
|
389
|
+
let c = files.get(p);
|
|
390
|
+
if (c === void 0) {
|
|
391
|
+
const full = resolve(root, p);
|
|
392
|
+
if (skip.some((x) => full === x || full.startsWith(x + sep))) return void 0;
|
|
393
|
+
c = projectFile(root, p);
|
|
394
|
+
if (c === void 0) return void 0;
|
|
395
|
+
files.set(p, c);
|
|
396
|
+
}
|
|
397
|
+
return typeof c === "string" ? c : isLazyText(c) ? c.read() : new TextDecoder().decode(isRef(c) ? await c.read() : c);
|
|
398
|
+
};
|
|
399
|
+
const got = await sourceMenu(path, sourceRoot(s), read, withUnderscoreAliases({ ...cfg.attributes, ...s.attributes ?? {} }), !s.nav && s.from !== "dogsbay-md", (p) => files.has(p));
|
|
400
|
+
for (const m of got.files) maps.add(m);
|
|
401
|
+
}
|
|
402
|
+
return [...maps];
|
|
403
|
+
}
|
|
404
|
+
function projectFile(root, rel, bases = []) {
|
|
405
|
+
const full = join(root, rel);
|
|
406
|
+
try {
|
|
407
|
+
if (!lstatSync(full).isFile() || !insideProject(root, full, bases)) return void 0;
|
|
408
|
+
} catch {
|
|
409
|
+
return void 0;
|
|
410
|
+
}
|
|
411
|
+
return fileEntry(full, rel);
|
|
412
|
+
}
|
|
413
|
+
function isBuild(outDir, folder) {
|
|
414
|
+
if (existsSync(join(outDir, "_dogsbay"))) return true;
|
|
415
|
+
const own = join(outDir, folder);
|
|
416
|
+
if (!existsSync(own)) return false;
|
|
417
|
+
return existsSync(join(own, "site.js")) || existsSync(join(own, "assets", "dogsbay.js")) || lstatSync(own).isDirectory() && readdirSync(own).length === 0;
|
|
418
|
+
}
|
|
419
|
+
function prepareOut(outDir, force = false, folder = "_dogsbay") {
|
|
420
|
+
if (existsSync(outDir)) {
|
|
421
|
+
const entries = readdirSync(outDir);
|
|
422
|
+
const ours = entries.length === 0 || isBuild(outDir, folder);
|
|
423
|
+
if (!ours && !force) throw new Error(`${outDir} exists and is not a dogsbay-ssg build; pass --force to replace it`);
|
|
424
|
+
rmSync(outDir, { recursive: true, force: true });
|
|
425
|
+
}
|
|
426
|
+
mkdirSync(join(outDir, folder), { recursive: true });
|
|
427
|
+
}
|
|
428
|
+
function fileSink(outDir) {
|
|
429
|
+
const made = /* @__PURE__ */ new Set();
|
|
430
|
+
return (p, c) => {
|
|
431
|
+
const full = join(outDir, p);
|
|
432
|
+
const d = dirname2(full);
|
|
433
|
+
if (!made.has(d)) {
|
|
434
|
+
mkdirSync(d, { recursive: true });
|
|
435
|
+
made.add(d);
|
|
436
|
+
}
|
|
437
|
+
if (isRef(c)) {
|
|
438
|
+
if (c.path) return copyFileSync(c.path, full);
|
|
439
|
+
return Promise.resolve(c.read()).then((bytes) => writeFileSync(full, bytes));
|
|
440
|
+
}
|
|
441
|
+
if (isStream(c)) return writeStream(full, c);
|
|
442
|
+
writeFileSync(full, c);
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
async function writeStream(full, s) {
|
|
446
|
+
const fd = openSync(full, "w");
|
|
447
|
+
try {
|
|
448
|
+
for await (const chunk of s.chunks()) writeSync(fd, chunk);
|
|
449
|
+
} finally {
|
|
450
|
+
closeSync(fd);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function readManifests(out, folder = "_dogsbay") {
|
|
454
|
+
const dir = join(out, manifestDir(folder));
|
|
455
|
+
if (!existsSync(dir)) return [];
|
|
456
|
+
const found = [];
|
|
457
|
+
const walk = (d) => {
|
|
458
|
+
for (const e of readdirSync(d, { withFileTypes: true })) {
|
|
459
|
+
const full = join(d, e.name);
|
|
460
|
+
if (e.isDirectory()) walk(full);
|
|
461
|
+
else if (e.isFile() && e.name.endsWith(".json")) found.push({ path: relative(out, full).split(sep).join("/"), text: readFileSync(full, "utf8") });
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
walk(dir);
|
|
465
|
+
return found;
|
|
466
|
+
}
|
|
467
|
+
function removeStaleUnitFiles(out, previous, written, folder = "_dogsbay") {
|
|
468
|
+
const assets = join(out, folder, "assets");
|
|
469
|
+
const now = new Map(readManifests(out, folder).map((m) => [m.path, unitFilesOf(m.text)]));
|
|
470
|
+
const stale = staleUnitFiles(previous, now, written, existsSync(assets) ? readdirSync(assets) : [], folder);
|
|
471
|
+
const root = resolve(out);
|
|
472
|
+
let removed = 0;
|
|
473
|
+
for (const p of stale) {
|
|
474
|
+
const full = join(root, p);
|
|
475
|
+
if (!full.startsWith(root + sep) || !existsSync(full) || !lstatSync(full).isFile()) continue;
|
|
476
|
+
rmSync(full, { force: true });
|
|
477
|
+
removed++;
|
|
478
|
+
for (let d = dirname2(full); d.startsWith(root + sep) && readdirSync(d).length === 0; d = dirname2(d)) rmSync(d, { recursive: true });
|
|
479
|
+
}
|
|
480
|
+
return removed;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
export {
|
|
484
|
+
carryVariables,
|
|
485
|
+
templateBudget,
|
|
486
|
+
preprocess,
|
|
487
|
+
renameIncludes,
|
|
488
|
+
withUnderscoreAliases,
|
|
489
|
+
unitKey,
|
|
490
|
+
manifestPath,
|
|
491
|
+
makeManifest,
|
|
492
|
+
parseManifest,
|
|
493
|
+
unitFilesOf,
|
|
494
|
+
insideProject,
|
|
495
|
+
readProject,
|
|
496
|
+
readBuildFiles,
|
|
497
|
+
readMenus,
|
|
498
|
+
projectFile,
|
|
499
|
+
prepareOut,
|
|
500
|
+
fileSink,
|
|
501
|
+
readManifests,
|
|
502
|
+
removeStaleUnitFiles
|
|
503
|
+
};
|