@nuasite/cli 0.42.1 → 0.43.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +613 -991
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7599,37 +7599,6 @@ var require_dist = __commonJS((exports) => {
|
|
|
7599
7599
|
exports.visitAsync = visit.visitAsync;
|
|
7600
7600
|
});
|
|
7601
7601
|
|
|
7602
|
-
// ../cms/src/config.ts
|
|
7603
|
-
function getProjectRoot() {
|
|
7604
|
-
return projectRootOverride ?? process.cwd();
|
|
7605
|
-
}
|
|
7606
|
-
var projectRootOverride = null;
|
|
7607
|
-
var init_config = () => {};
|
|
7608
|
-
|
|
7609
|
-
// ../../node_modules/@astrojs/compiler/dist/chunk-W5DTLHV4.js
|
|
7610
|
-
import g from "crypto";
|
|
7611
|
-
import _ from "fs";
|
|
7612
|
-
import { TextDecoder as b, TextEncoder as v } from "util";
|
|
7613
|
-
var y, w;
|
|
7614
|
-
var init_chunk_W5DTLHV4 = __esm(() => {
|
|
7615
|
-
globalThis.fs || Object.defineProperty(globalThis, "fs", { value: _ });
|
|
7616
|
-
globalThis.process || Object.defineProperties(globalThis, "process", { value: process });
|
|
7617
|
-
globalThis.crypto || Object.defineProperty(globalThis, "crypto", { value: g.webcrypto ? g.webcrypto : { getRandomValues(m) {
|
|
7618
|
-
return g.randomFillSync(m);
|
|
7619
|
-
} } });
|
|
7620
|
-
globalThis.performance || Object.defineProperty(globalThis, "performance", { value: { now() {
|
|
7621
|
-
let [m, o] = process.hrtime();
|
|
7622
|
-
return m * 1000 + o / 1e6;
|
|
7623
|
-
} } });
|
|
7624
|
-
y = new v("utf-8");
|
|
7625
|
-
w = new b("utf-8");
|
|
7626
|
-
});
|
|
7627
|
-
|
|
7628
|
-
// ../../node_modules/@astrojs/compiler/dist/node/index.js
|
|
7629
|
-
var init_node = __esm(() => {
|
|
7630
|
-
init_chunk_W5DTLHV4();
|
|
7631
|
-
});
|
|
7632
|
-
|
|
7633
7602
|
// ../../node_modules/@babel/parser/lib/index.js
|
|
7634
7603
|
var require_lib = __commonJS((exports) => {
|
|
7635
7604
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -8155,7 +8124,7 @@ var require_lib = __commonJS((exports) => {
|
|
|
8155
8124
|
let regex = null;
|
|
8156
8125
|
try {
|
|
8157
8126
|
regex = new RegExp(pattern, flags);
|
|
8158
|
-
} catch (
|
|
8127
|
+
} catch (_) {}
|
|
8159
8128
|
const node = this.estreeParseLiteral(regex);
|
|
8160
8129
|
node.regex = {
|
|
8161
8130
|
pattern,
|
|
@@ -8252,7 +8221,7 @@ var require_lib = __commonJS((exports) => {
|
|
|
8252
8221
|
}
|
|
8253
8222
|
parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
|
|
8254
8223
|
super.parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse);
|
|
8255
|
-
const directiveStatements = node.directives.map((
|
|
8224
|
+
const directiveStatements = node.directives.map((d) => this.directiveToStmt(d));
|
|
8256
8225
|
node.body = directiveStatements.concat(node.body);
|
|
8257
8226
|
delete node.directives;
|
|
8258
8227
|
}
|
|
@@ -12909,8 +12878,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12909
12878
|
get strict() {
|
|
12910
12879
|
return (this.flags & 1) > 0;
|
|
12911
12880
|
}
|
|
12912
|
-
set strict(
|
|
12913
|
-
if (
|
|
12881
|
+
set strict(v) {
|
|
12882
|
+
if (v)
|
|
12914
12883
|
this.flags |= 1;
|
|
12915
12884
|
else
|
|
12916
12885
|
this.flags &= -2;
|
|
@@ -12931,8 +12900,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12931
12900
|
get maybeInArrowParameters() {
|
|
12932
12901
|
return (this.flags & 2) > 0;
|
|
12933
12902
|
}
|
|
12934
|
-
set maybeInArrowParameters(
|
|
12935
|
-
if (
|
|
12903
|
+
set maybeInArrowParameters(v) {
|
|
12904
|
+
if (v)
|
|
12936
12905
|
this.flags |= 2;
|
|
12937
12906
|
else
|
|
12938
12907
|
this.flags &= -3;
|
|
@@ -12940,8 +12909,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12940
12909
|
get inType() {
|
|
12941
12910
|
return (this.flags & 4) > 0;
|
|
12942
12911
|
}
|
|
12943
|
-
set inType(
|
|
12944
|
-
if (
|
|
12912
|
+
set inType(v) {
|
|
12913
|
+
if (v)
|
|
12945
12914
|
this.flags |= 4;
|
|
12946
12915
|
else
|
|
12947
12916
|
this.flags &= -5;
|
|
@@ -12949,8 +12918,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12949
12918
|
get noAnonFunctionType() {
|
|
12950
12919
|
return (this.flags & 8) > 0;
|
|
12951
12920
|
}
|
|
12952
|
-
set noAnonFunctionType(
|
|
12953
|
-
if (
|
|
12921
|
+
set noAnonFunctionType(v) {
|
|
12922
|
+
if (v)
|
|
12954
12923
|
this.flags |= 8;
|
|
12955
12924
|
else
|
|
12956
12925
|
this.flags &= -9;
|
|
@@ -12958,8 +12927,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12958
12927
|
get hasFlowComment() {
|
|
12959
12928
|
return (this.flags & 16) > 0;
|
|
12960
12929
|
}
|
|
12961
|
-
set hasFlowComment(
|
|
12962
|
-
if (
|
|
12930
|
+
set hasFlowComment(v) {
|
|
12931
|
+
if (v)
|
|
12963
12932
|
this.flags |= 16;
|
|
12964
12933
|
else
|
|
12965
12934
|
this.flags &= -17;
|
|
@@ -12967,8 +12936,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12967
12936
|
get isAmbientContext() {
|
|
12968
12937
|
return (this.flags & 32) > 0;
|
|
12969
12938
|
}
|
|
12970
|
-
set isAmbientContext(
|
|
12971
|
-
if (
|
|
12939
|
+
set isAmbientContext(v) {
|
|
12940
|
+
if (v)
|
|
12972
12941
|
this.flags |= 32;
|
|
12973
12942
|
else
|
|
12974
12943
|
this.flags &= -33;
|
|
@@ -12976,8 +12945,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12976
12945
|
get inAbstractClass() {
|
|
12977
12946
|
return (this.flags & 64) > 0;
|
|
12978
12947
|
}
|
|
12979
|
-
set inAbstractClass(
|
|
12980
|
-
if (
|
|
12948
|
+
set inAbstractClass(v) {
|
|
12949
|
+
if (v)
|
|
12981
12950
|
this.flags |= 64;
|
|
12982
12951
|
else
|
|
12983
12952
|
this.flags &= -65;
|
|
@@ -12985,8 +12954,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12985
12954
|
get inDisallowConditionalTypesContext() {
|
|
12986
12955
|
return (this.flags & 128) > 0;
|
|
12987
12956
|
}
|
|
12988
|
-
set inDisallowConditionalTypesContext(
|
|
12989
|
-
if (
|
|
12957
|
+
set inDisallowConditionalTypesContext(v) {
|
|
12958
|
+
if (v)
|
|
12990
12959
|
this.flags |= 128;
|
|
12991
12960
|
else
|
|
12992
12961
|
this.flags &= -129;
|
|
@@ -12994,8 +12963,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
12994
12963
|
get soloAwait() {
|
|
12995
12964
|
return (this.flags & 256) > 0;
|
|
12996
12965
|
}
|
|
12997
|
-
set soloAwait(
|
|
12998
|
-
if (
|
|
12966
|
+
set soloAwait(v) {
|
|
12967
|
+
if (v)
|
|
12999
12968
|
this.flags |= 256;
|
|
13000
12969
|
else
|
|
13001
12970
|
this.flags &= -257;
|
|
@@ -13003,8 +12972,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
13003
12972
|
get inFSharpPipelineDirectBody() {
|
|
13004
12973
|
return (this.flags & 512) > 0;
|
|
13005
12974
|
}
|
|
13006
|
-
set inFSharpPipelineDirectBody(
|
|
13007
|
-
if (
|
|
12975
|
+
set inFSharpPipelineDirectBody(v) {
|
|
12976
|
+
if (v)
|
|
13008
12977
|
this.flags |= 512;
|
|
13009
12978
|
else
|
|
13010
12979
|
this.flags &= -513;
|
|
@@ -13012,8 +12981,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
13012
12981
|
get canStartJSXElement() {
|
|
13013
12982
|
return (this.flags & 1024) > 0;
|
|
13014
12983
|
}
|
|
13015
|
-
set canStartJSXElement(
|
|
13016
|
-
if (
|
|
12984
|
+
set canStartJSXElement(v) {
|
|
12985
|
+
if (v)
|
|
13017
12986
|
this.flags |= 1024;
|
|
13018
12987
|
else
|
|
13019
12988
|
this.flags &= -1025;
|
|
@@ -13021,8 +12990,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
13021
12990
|
get containsEsc() {
|
|
13022
12991
|
return (this.flags & 2048) > 0;
|
|
13023
12992
|
}
|
|
13024
|
-
set containsEsc(
|
|
13025
|
-
if (
|
|
12993
|
+
set containsEsc(v) {
|
|
12994
|
+
if (v)
|
|
13026
12995
|
this.flags |= 2048;
|
|
13027
12996
|
else
|
|
13028
12997
|
this.flags &= -2049;
|
|
@@ -13030,8 +12999,8 @@ var require_lib = __commonJS((exports) => {
|
|
|
13030
12999
|
get hasTopLevelAwait() {
|
|
13031
13000
|
return (this.flags & 4096) > 0;
|
|
13032
13001
|
}
|
|
13033
|
-
set hasTopLevelAwait(
|
|
13034
|
-
if (
|
|
13002
|
+
set hasTopLevelAwait(v) {
|
|
13003
|
+
if (v)
|
|
13035
13004
|
this.flags |= 4096;
|
|
13036
13005
|
else
|
|
13037
13006
|
this.flags &= -4097;
|
|
@@ -22413,6 +22382,237 @@ var require_lib = __commonJS((exports) => {
|
|
|
22413
22382
|
exports.tokTypes = tokTypes;
|
|
22414
22383
|
});
|
|
22415
22384
|
|
|
22385
|
+
// ../cms-types/src/index.ts
|
|
22386
|
+
var init_src = () => {};
|
|
22387
|
+
|
|
22388
|
+
// ../cms-core/src/content-config-ast.ts
|
|
22389
|
+
var import_parser, FIELD_HELPER_TYPES, VALID_HINT_KEYS, WRAPPER_METHODS;
|
|
22390
|
+
var init_content_config_ast = __esm(() => {
|
|
22391
|
+
init_src();
|
|
22392
|
+
import_parser = __toESM(require_lib(), 1);
|
|
22393
|
+
FIELD_HELPER_TYPES = new Set([
|
|
22394
|
+
"text",
|
|
22395
|
+
"number",
|
|
22396
|
+
"image",
|
|
22397
|
+
"file",
|
|
22398
|
+
"url",
|
|
22399
|
+
"email",
|
|
22400
|
+
"tel",
|
|
22401
|
+
"color",
|
|
22402
|
+
"date",
|
|
22403
|
+
"datetime",
|
|
22404
|
+
"time",
|
|
22405
|
+
"year",
|
|
22406
|
+
"month",
|
|
22407
|
+
"textarea"
|
|
22408
|
+
]);
|
|
22409
|
+
VALID_HINT_KEYS = new Set([
|
|
22410
|
+
"min",
|
|
22411
|
+
"max",
|
|
22412
|
+
"step",
|
|
22413
|
+
"placeholder",
|
|
22414
|
+
"maxLength",
|
|
22415
|
+
"minLength",
|
|
22416
|
+
"rows",
|
|
22417
|
+
"accept"
|
|
22418
|
+
]);
|
|
22419
|
+
WRAPPER_METHODS = new Set(["optional", "nullable", "nullish", "default"]);
|
|
22420
|
+
});
|
|
22421
|
+
// ../cms-core/src/collection-scanner.ts
|
|
22422
|
+
var import_yaml, SIDEBAR_FIELD_NAMES, FREE_TEXT_FIELD_NAMES, PUBLISH_TOGGLE_NAMES, PUBLISH_DATE_NAMES;
|
|
22423
|
+
var init_collection_scanner = __esm(() => {
|
|
22424
|
+
init_content_config_ast();
|
|
22425
|
+
import_yaml = __toESM(require_dist(), 1);
|
|
22426
|
+
SIDEBAR_FIELD_NAMES = new Set([
|
|
22427
|
+
"title",
|
|
22428
|
+
"date",
|
|
22429
|
+
"pubdate",
|
|
22430
|
+
"publishdate",
|
|
22431
|
+
"draft",
|
|
22432
|
+
"image",
|
|
22433
|
+
"featuredimage",
|
|
22434
|
+
"cover",
|
|
22435
|
+
"coverimage",
|
|
22436
|
+
"thumbnail",
|
|
22437
|
+
"author"
|
|
22438
|
+
]);
|
|
22439
|
+
FREE_TEXT_FIELD_NAMES = new Set([
|
|
22440
|
+
"title",
|
|
22441
|
+
"name",
|
|
22442
|
+
"description",
|
|
22443
|
+
"summary",
|
|
22444
|
+
"excerpt",
|
|
22445
|
+
"subtitle",
|
|
22446
|
+
"heading",
|
|
22447
|
+
"headline",
|
|
22448
|
+
"slug",
|
|
22449
|
+
"alt",
|
|
22450
|
+
"caption"
|
|
22451
|
+
]);
|
|
22452
|
+
PUBLISH_TOGGLE_NAMES = new Set(["draft", "isdraft", "published", "ispublished", "unpublished"]);
|
|
22453
|
+
PUBLISH_DATE_NAMES = new Set([
|
|
22454
|
+
"date",
|
|
22455
|
+
"pubdate",
|
|
22456
|
+
"publishdate",
|
|
22457
|
+
"publisheddate",
|
|
22458
|
+
"publishedate",
|
|
22459
|
+
"publishedat",
|
|
22460
|
+
"datepublished"
|
|
22461
|
+
]);
|
|
22462
|
+
});
|
|
22463
|
+
|
|
22464
|
+
// ../cms-core/src/component-registry.ts
|
|
22465
|
+
var import_parser2;
|
|
22466
|
+
var init_component_registry = __esm(() => {
|
|
22467
|
+
import_parser2 = __toESM(require_lib(), 1);
|
|
22468
|
+
});
|
|
22469
|
+
|
|
22470
|
+
// ../cms-core/src/handlers/entry-ops.ts
|
|
22471
|
+
var import_yaml2;
|
|
22472
|
+
var init_entry_ops = __esm(() => {
|
|
22473
|
+
init_collection_scanner();
|
|
22474
|
+
init_content_config_ast();
|
|
22475
|
+
import_yaml2 = __toESM(require_dist(), 1);
|
|
22476
|
+
});
|
|
22477
|
+
|
|
22478
|
+
// ../cms-core/src/handlers/page-ops.ts
|
|
22479
|
+
var init_page_ops = () => {};
|
|
22480
|
+
// ../cms-core/src/core.ts
|
|
22481
|
+
var init_core = __esm(() => {
|
|
22482
|
+
init_collection_scanner();
|
|
22483
|
+
init_component_registry();
|
|
22484
|
+
init_entry_ops();
|
|
22485
|
+
init_page_ops();
|
|
22486
|
+
});
|
|
22487
|
+
// ../cms-core/src/fs/node-fs.ts
|
|
22488
|
+
var init_node_fs = () => {};
|
|
22489
|
+
// ../cms-core/src/media/local.ts
|
|
22490
|
+
function mimeFromExt(ext) {
|
|
22491
|
+
return MIME_BY_EXT[ext] ?? "application/octet-stream";
|
|
22492
|
+
}
|
|
22493
|
+
var MIME_BY_EXT;
|
|
22494
|
+
var init_local = __esm(() => {
|
|
22495
|
+
MIME_BY_EXT = {
|
|
22496
|
+
".jpg": "image/jpeg",
|
|
22497
|
+
".jpeg": "image/jpeg",
|
|
22498
|
+
".png": "image/png",
|
|
22499
|
+
".gif": "image/gif",
|
|
22500
|
+
".webp": "image/webp",
|
|
22501
|
+
".avif": "image/avif",
|
|
22502
|
+
".svg": "image/svg+xml",
|
|
22503
|
+
".ico": "image/x-icon",
|
|
22504
|
+
".mp4": "video/mp4",
|
|
22505
|
+
".webm": "video/webm",
|
|
22506
|
+
".pdf": "application/pdf"
|
|
22507
|
+
};
|
|
22508
|
+
});
|
|
22509
|
+
|
|
22510
|
+
// ../cms-core/src/media/project-images.ts
|
|
22511
|
+
async function listProjectImages(fs, options) {
|
|
22512
|
+
const excludeDir = options?.excludeDir ? normalizeDir(options.excludeDir) : null;
|
|
22513
|
+
const scanDirs = [
|
|
22514
|
+
{ dir: "public", relativeToRoot: false },
|
|
22515
|
+
{ dir: "src", relativeToRoot: true }
|
|
22516
|
+
];
|
|
22517
|
+
const results = await Promise.all(scanDirs.map(async ({ dir, relativeToRoot }) => {
|
|
22518
|
+
const items2 = [];
|
|
22519
|
+
await scanDirectory(fs, dir, dir, relativeToRoot, excludeDir, items2);
|
|
22520
|
+
return items2;
|
|
22521
|
+
}));
|
|
22522
|
+
const items = results.flat();
|
|
22523
|
+
items.sort((a, b) => a.filename.localeCompare(b.filename));
|
|
22524
|
+
return items;
|
|
22525
|
+
}
|
|
22526
|
+
function normalizeDir(dir) {
|
|
22527
|
+
return dir.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
22528
|
+
}
|
|
22529
|
+
async function scanDirectory(fs, currentDir, baseDir, relativeToRoot, excludeDir, items) {
|
|
22530
|
+
if (excludeDir && normalizeDir(currentDir) === excludeDir)
|
|
22531
|
+
return;
|
|
22532
|
+
const entries = await fs.list(currentDir);
|
|
22533
|
+
const subdirs = [];
|
|
22534
|
+
for (const entry of entries) {
|
|
22535
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
22536
|
+
continue;
|
|
22537
|
+
const fullPath = `${currentDir}/${entry.name}`;
|
|
22538
|
+
if (entry.isDirectory) {
|
|
22539
|
+
subdirs.push(scanDirectory(fs, fullPath, baseDir, relativeToRoot, excludeDir, items));
|
|
22540
|
+
} else {
|
|
22541
|
+
const dotIdx = entry.name.lastIndexOf(".");
|
|
22542
|
+
const ext = dotIdx >= 0 ? entry.name.slice(dotIdx).toLowerCase() : "";
|
|
22543
|
+
if (!IMAGE_EXTENSIONS.has(ext))
|
|
22544
|
+
continue;
|
|
22545
|
+
const url = relativeToRoot ? `/${fullPath}` : `/${fullPath.slice(baseDir.length + 1)}`;
|
|
22546
|
+
items.push({
|
|
22547
|
+
id: `project:${url}`,
|
|
22548
|
+
url,
|
|
22549
|
+
filename: entry.name,
|
|
22550
|
+
contentType: mimeFromExt(ext)
|
|
22551
|
+
});
|
|
22552
|
+
}
|
|
22553
|
+
}
|
|
22554
|
+
await Promise.all(subdirs);
|
|
22555
|
+
}
|
|
22556
|
+
var IMAGE_EXTENSIONS;
|
|
22557
|
+
var init_project_images = __esm(() => {
|
|
22558
|
+
init_local();
|
|
22559
|
+
IMAGE_EXTENSIONS = new Set(Object.entries(MIME_BY_EXT).filter(([, mime]) => mime.startsWith("image/")).map(([ext]) => ext));
|
|
22560
|
+
});
|
|
22561
|
+
|
|
22562
|
+
// ../cms-core/src/media/s3.ts
|
|
22563
|
+
var init_s3 = __esm(() => {
|
|
22564
|
+
init_local();
|
|
22565
|
+
});
|
|
22566
|
+
|
|
22567
|
+
// ../cms-core/src/media/index.ts
|
|
22568
|
+
var init_media = __esm(() => {
|
|
22569
|
+
init_local();
|
|
22570
|
+
init_project_images();
|
|
22571
|
+
init_s3();
|
|
22572
|
+
});
|
|
22573
|
+
|
|
22574
|
+
// ../cms-core/src/index.ts
|
|
22575
|
+
var init_src2 = __esm(() => {
|
|
22576
|
+
init_collection_scanner();
|
|
22577
|
+
init_component_registry();
|
|
22578
|
+
init_content_config_ast();
|
|
22579
|
+
init_core();
|
|
22580
|
+
init_node_fs();
|
|
22581
|
+
init_entry_ops();
|
|
22582
|
+
init_media();
|
|
22583
|
+
});
|
|
22584
|
+
|
|
22585
|
+
// ../cms/src/config.ts
|
|
22586
|
+
function getProjectRoot() {
|
|
22587
|
+
return projectRootOverride ?? process.cwd();
|
|
22588
|
+
}
|
|
22589
|
+
var projectRootOverride = null;
|
|
22590
|
+
var init_config = () => {};
|
|
22591
|
+
|
|
22592
|
+
// ../../node_modules/@astrojs/compiler/dist/chunk-W5DTLHV4.js
|
|
22593
|
+
import g from "crypto";
|
|
22594
|
+
import _ from "fs";
|
|
22595
|
+
import { TextDecoder as b, TextEncoder as v } from "util";
|
|
22596
|
+
var y, w;
|
|
22597
|
+
var init_chunk_W5DTLHV4 = __esm(() => {
|
|
22598
|
+
globalThis.fs || Object.defineProperty(globalThis, "fs", { value: _ });
|
|
22599
|
+
globalThis.process || Object.defineProperties(globalThis, "process", { value: process });
|
|
22600
|
+
globalThis.crypto || Object.defineProperty(globalThis, "crypto", { value: g.webcrypto ? g.webcrypto : { getRandomValues(m) {
|
|
22601
|
+
return g.randomFillSync(m);
|
|
22602
|
+
} } });
|
|
22603
|
+
globalThis.performance || Object.defineProperty(globalThis, "performance", { value: { now() {
|
|
22604
|
+
let [m, o] = process.hrtime();
|
|
22605
|
+
return m * 1000 + o / 1e6;
|
|
22606
|
+
} } });
|
|
22607
|
+
y = new v("utf-8");
|
|
22608
|
+
w = new b("utf-8");
|
|
22609
|
+
});
|
|
22610
|
+
|
|
22611
|
+
// ../../node_modules/@astrojs/compiler/dist/node/index.js
|
|
22612
|
+
var init_node = __esm(() => {
|
|
22613
|
+
init_chunk_W5DTLHV4();
|
|
22614
|
+
});
|
|
22615
|
+
|
|
22416
22616
|
// ../cms/src/error-collector.ts
|
|
22417
22617
|
class ErrorCollector {
|
|
22418
22618
|
errors = [];
|
|
@@ -22474,15 +22674,15 @@ var init_cache = __esm(() => {
|
|
|
22474
22674
|
dirtyFiles = new Set;
|
|
22475
22675
|
});
|
|
22476
22676
|
// ../cms/src/source-finder/variable-extraction.ts
|
|
22477
|
-
var
|
|
22677
|
+
var import_parser3;
|
|
22478
22678
|
var init_variable_extraction = __esm(() => {
|
|
22479
|
-
|
|
22679
|
+
import_parser3 = __toESM(require_lib(), 1);
|
|
22480
22680
|
});
|
|
22481
22681
|
|
|
22482
22682
|
// ../cms/src/source-finder/ast-parser.ts
|
|
22483
|
-
function
|
|
22683
|
+
function parseFrontmatter2(content, filePath) {
|
|
22484
22684
|
try {
|
|
22485
|
-
return
|
|
22685
|
+
return import_parser4.parse(content, {
|
|
22486
22686
|
sourceType: "module",
|
|
22487
22687
|
plugins: ["typescript"],
|
|
22488
22688
|
errorRecovery: true
|
|
@@ -22494,12 +22694,12 @@ function parseFrontmatter(content, filePath) {
|
|
|
22494
22694
|
return null;
|
|
22495
22695
|
}
|
|
22496
22696
|
}
|
|
22497
|
-
var
|
|
22697
|
+
var import_parser4, inFlightParsing;
|
|
22498
22698
|
var init_ast_parser = __esm(() => {
|
|
22499
22699
|
init_node();
|
|
22500
22700
|
init_cache();
|
|
22501
22701
|
init_variable_extraction();
|
|
22502
|
-
|
|
22702
|
+
import_parser4 = __toESM(require_lib(), 1);
|
|
22503
22703
|
inFlightParsing = new Map;
|
|
22504
22704
|
});
|
|
22505
22705
|
|
|
@@ -22519,7 +22719,7 @@ function resolveExpression(node, bindings, visited = new Set) {
|
|
|
22519
22719
|
}
|
|
22520
22720
|
return current;
|
|
22521
22721
|
}
|
|
22522
|
-
async function
|
|
22722
|
+
async function parseContentConfig2() {
|
|
22523
22723
|
const projectRoot = getProjectRoot();
|
|
22524
22724
|
for (const configPath of ["src/content/config.ts", "src/content.config.ts"]) {
|
|
22525
22725
|
const fullPath = path.join(projectRoot, configPath);
|
|
@@ -22536,16 +22736,16 @@ async function parseContentConfig() {
|
|
|
22536
22736
|
continue;
|
|
22537
22737
|
}
|
|
22538
22738
|
const content = await fs.readFile(fullPath, "utf-8");
|
|
22539
|
-
const parsed =
|
|
22739
|
+
const parsed = parseConfigSource2(content, configPath);
|
|
22540
22740
|
parseCache.set(fullPath, { mtimeMs: stat.mtimeMs, parsed });
|
|
22541
22741
|
if (parsed.size > 0)
|
|
22542
22742
|
return parsed;
|
|
22543
22743
|
}
|
|
22544
22744
|
return new Map;
|
|
22545
22745
|
}
|
|
22546
|
-
function
|
|
22746
|
+
function parseConfigSource2(source, sourcePath) {
|
|
22547
22747
|
const result = new Map;
|
|
22548
|
-
const ast =
|
|
22748
|
+
const ast = parseFrontmatter2(source, sourcePath);
|
|
22549
22749
|
if (!ast)
|
|
22550
22750
|
return result;
|
|
22551
22751
|
const bindings = new Map;
|
|
@@ -22733,7 +22933,7 @@ function analyzeFieldExpression(node, field, bindings) {
|
|
|
22733
22933
|
return;
|
|
22734
22934
|
const property = current.callee.property;
|
|
22735
22935
|
const methodName = property.type === "Identifier" ? property.name : "";
|
|
22736
|
-
if (
|
|
22936
|
+
if (WRAPPER_METHODS2.has(methodName)) {
|
|
22737
22937
|
field.required = false;
|
|
22738
22938
|
} else if (methodName === "orderBy") {
|
|
22739
22939
|
const arg = current.arguments[0];
|
|
@@ -22776,7 +22976,7 @@ function analyzeBaseCall(node, field, bindings) {
|
|
|
22776
22976
|
return;
|
|
22777
22977
|
const ns = callee.object.name;
|
|
22778
22978
|
const fn = callee.property.name;
|
|
22779
|
-
if (ns === "n" &&
|
|
22979
|
+
if (ns === "n" && FIELD_HELPER_TYPES2.has(fn)) {
|
|
22780
22980
|
field.type = fn;
|
|
22781
22981
|
const firstArg = node.arguments[0];
|
|
22782
22982
|
if (firstArg?.type === "ObjectExpression") {
|
|
@@ -22840,7 +23040,7 @@ function parseHintsFromObject(obj) {
|
|
|
22840
23040
|
if (prop.type !== "ObjectProperty")
|
|
22841
23041
|
continue;
|
|
22842
23042
|
const key = propertyKeyName(prop.key);
|
|
22843
|
-
if (!key || !
|
|
23043
|
+
if (!key || !VALID_HINT_KEYS2.has(key))
|
|
22844
23044
|
continue;
|
|
22845
23045
|
const value = prop.value;
|
|
22846
23046
|
if (value.type === "NumericLiteral") {
|
|
@@ -22855,11 +23055,11 @@ function parseHintsFromObject(obj) {
|
|
|
22855
23055
|
return;
|
|
22856
23056
|
return raw;
|
|
22857
23057
|
}
|
|
22858
|
-
var
|
|
22859
|
-
var
|
|
23058
|
+
var FIELD_HELPER_TYPES2, VALID_HINT_KEYS2, WRAPPER_METHODS2, parseCache;
|
|
23059
|
+
var init_content_config_ast2 = __esm(() => {
|
|
22860
23060
|
init_config();
|
|
22861
23061
|
init_ast_parser();
|
|
22862
|
-
|
|
23062
|
+
FIELD_HELPER_TYPES2 = new Set([
|
|
22863
23063
|
"text",
|
|
22864
23064
|
"number",
|
|
22865
23065
|
"image",
|
|
@@ -22875,7 +23075,7 @@ var init_content_config_ast = __esm(() => {
|
|
|
22875
23075
|
"month",
|
|
22876
23076
|
"textarea"
|
|
22877
23077
|
]);
|
|
22878
|
-
|
|
23078
|
+
VALID_HINT_KEYS2 = new Set([
|
|
22879
23079
|
"min",
|
|
22880
23080
|
"max",
|
|
22881
23081
|
"step",
|
|
@@ -22885,15 +23085,15 @@ var init_content_config_ast = __esm(() => {
|
|
|
22885
23085
|
"rows",
|
|
22886
23086
|
"accept"
|
|
22887
23087
|
]);
|
|
22888
|
-
|
|
23088
|
+
WRAPPER_METHODS2 = new Set(["optional", "nullable", "nullish", "default"]);
|
|
22889
23089
|
parseCache = new Map;
|
|
22890
23090
|
});
|
|
22891
23091
|
|
|
22892
23092
|
// ../cms/src/shared.ts
|
|
22893
|
-
function
|
|
23093
|
+
function slugify2(text) {
|
|
22894
23094
|
return text.toLowerCase().trim().replace(/[^\w\s\-/]/g, "").replace(/[\s_]+/g, "-").replace(/^[-/]+|[-/]+$/g, "");
|
|
22895
23095
|
}
|
|
22896
|
-
function
|
|
23096
|
+
function slugifyHref2(text) {
|
|
22897
23097
|
return "/" + text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
|
|
22898
23098
|
}
|
|
22899
23099
|
|
|
@@ -22907,22 +23107,22 @@ function extractFrontmatterBlock(content) {
|
|
|
22907
23107
|
const match = content.match(FRONTMATTER_PATTERN);
|
|
22908
23108
|
return match?.[1] ?? null;
|
|
22909
23109
|
}
|
|
22910
|
-
function
|
|
23110
|
+
function parseFrontmatter3(content) {
|
|
22911
23111
|
const block = extractFrontmatterBlock(content);
|
|
22912
23112
|
if (!block)
|
|
22913
23113
|
return null;
|
|
22914
|
-
return
|
|
23114
|
+
return import_yaml3.parse(block);
|
|
22915
23115
|
}
|
|
22916
23116
|
function parseFieldDirectives(content) {
|
|
22917
23117
|
const block = extractFrontmatterBlock(content);
|
|
22918
23118
|
if (!block)
|
|
22919
23119
|
return {};
|
|
22920
|
-
const doc =
|
|
22921
|
-
if (!
|
|
23120
|
+
const doc = import_yaml3.parseDocument(block);
|
|
23121
|
+
if (!import_yaml3.isMap(doc.contents))
|
|
22922
23122
|
return {};
|
|
22923
23123
|
const result = {};
|
|
22924
23124
|
for (const pair of doc.contents.items) {
|
|
22925
|
-
if (!
|
|
23125
|
+
if (!import_yaml3.isPair(pair) || !import_yaml3.isScalar(pair.key))
|
|
22926
23126
|
continue;
|
|
22927
23127
|
const comment = pair.key.commentBefore;
|
|
22928
23128
|
if (!comment)
|
|
@@ -22948,7 +23148,7 @@ function parseFieldDirectives(content) {
|
|
|
22948
23148
|
}
|
|
22949
23149
|
function assignFieldMetadata(fields, directives) {
|
|
22950
23150
|
for (const field of fields) {
|
|
22951
|
-
if (
|
|
23151
|
+
if (SIDEBAR_FIELD_NAMES2.has(normalizeFieldName(field.name)) || field.type === "image" || field.type === "boolean") {
|
|
22952
23152
|
field.position = "sidebar";
|
|
22953
23153
|
} else {
|
|
22954
23154
|
field.position = "header";
|
|
@@ -22982,7 +23182,7 @@ function inferFieldType(value, key) {
|
|
|
22982
23182
|
if (DATE_PATTERN.test(value)) {
|
|
22983
23183
|
return "date";
|
|
22984
23184
|
}
|
|
22985
|
-
if (
|
|
23185
|
+
if (IMAGE_EXTENSIONS2.test(value)) {
|
|
22986
23186
|
return "image";
|
|
22987
23187
|
}
|
|
22988
23188
|
const lowerKey = key.toLowerCase();
|
|
@@ -23027,7 +23227,7 @@ function mergeFieldObservations(observations, depth = 0) {
|
|
|
23027
23227
|
required: obs.presentCount === obs.totalEntries,
|
|
23028
23228
|
examples: nonNullValues.slice(0, 3)
|
|
23029
23229
|
};
|
|
23030
|
-
if (fieldType === "text" && !
|
|
23230
|
+
if (fieldType === "text" && !FREE_TEXT_FIELD_NAMES2.has(normalizeFieldName(obs.name))) {
|
|
23031
23231
|
const uniqueValues = [...new Set(nonNullValues.map((v2) => String(v2)))];
|
|
23032
23232
|
const uniqueRatio = uniqueValues.length / nonNullValues.length;
|
|
23033
23233
|
if (uniqueValues.length > 0 && uniqueValues.length <= MAX_SELECT_OPTIONS && nonNullValues.length >= 2 && uniqueRatio <= 0.8) {
|
|
@@ -23128,7 +23328,7 @@ async function buildCollectionDefinition(basePath, sources, collectionName, cont
|
|
|
23128
23328
|
for (let i = 0;i < sources.length; i++) {
|
|
23129
23329
|
const source = sources[i];
|
|
23130
23330
|
const content = fileContents[i];
|
|
23131
|
-
const frontmatter =
|
|
23331
|
+
const frontmatter = parseFrontmatter3(content);
|
|
23132
23332
|
const directives = parseFieldDirectives(content);
|
|
23133
23333
|
for (const [key, value] of Object.entries(directives)) {
|
|
23134
23334
|
if (!allDirectives[key]) {
|
|
@@ -23201,7 +23401,7 @@ async function scanCollection(collectionPath, collectionName, contentDir) {
|
|
|
23201
23401
|
return null;
|
|
23202
23402
|
}
|
|
23203
23403
|
}
|
|
23204
|
-
function
|
|
23404
|
+
function globToRegExp2(glob) {
|
|
23205
23405
|
let re = "";
|
|
23206
23406
|
for (let i = 0;i < glob.length; i++) {
|
|
23207
23407
|
const c = glob[i];
|
|
@@ -23256,7 +23456,7 @@ async function walkFiles(dir, prefix = "") {
|
|
|
23256
23456
|
async function scanGlobCollection(collectionName, baseRel, pattern, contentDir) {
|
|
23257
23457
|
try {
|
|
23258
23458
|
const absBase = path2.join(getProjectRoot(), baseRel);
|
|
23259
|
-
const matcher =
|
|
23459
|
+
const matcher = globToRegExp2(pattern);
|
|
23260
23460
|
const sources = (await walkFiles(absBase)).filter((rel) => (rel.endsWith(".md") || rel.endsWith(".mdx")) && matcher.test(rel)).map((rel) => ({ slug: rel.replace(/\.(md|mdx)$/, ""), relPath: rel }));
|
|
23261
23461
|
if (sources.length === 0)
|
|
23262
23462
|
return null;
|
|
@@ -23462,9 +23662,9 @@ function assignSemanticRoles(collections) {
|
|
|
23462
23662
|
if (field.hidden || field.role)
|
|
23463
23663
|
continue;
|
|
23464
23664
|
const normalized = normalizeFieldName(field.name);
|
|
23465
|
-
if (!toggle && field.type === "boolean" &&
|
|
23665
|
+
if (!toggle && field.type === "boolean" && PUBLISH_TOGGLE_NAMES2.has(normalized)) {
|
|
23466
23666
|
toggle = field;
|
|
23467
|
-
} else if (!dateByName &&
|
|
23667
|
+
} else if (!dateByName && PUBLISH_DATE_NAMES2.has(normalized)) {
|
|
23468
23668
|
dateByName = field;
|
|
23469
23669
|
} else if (!dateByType && (field.type === "date" || field.type === "datetime")) {
|
|
23470
23670
|
dateByType = field;
|
|
@@ -23506,7 +23706,7 @@ function detectDerivedHrefFields(collections) {
|
|
|
23506
23706
|
const derivedExamples = field.examples.filter((v2) => typeof v2 === "string");
|
|
23507
23707
|
if (sourceExamples.length === 0 || derivedExamples.length === 0)
|
|
23508
23708
|
continue;
|
|
23509
|
-
const expectedHrefs = new Set(sourceExamples.map(
|
|
23709
|
+
const expectedHrefs = new Set(sourceExamples.map(slugifyHref2));
|
|
23510
23710
|
const allMatch = derivedExamples.every((v2) => expectedHrefs.has(v2));
|
|
23511
23711
|
if (allMatch) {
|
|
23512
23712
|
field.hidden = true;
|
|
@@ -23561,7 +23761,7 @@ async function scanDataCollection(collectionPath, collectionName, contentDir) {
|
|
|
23561
23761
|
continue;
|
|
23562
23762
|
let data = null;
|
|
23563
23763
|
try {
|
|
23564
|
-
data = source.relPath.endsWith(".json") ? JSON.parse(raw) :
|
|
23764
|
+
data = source.relPath.endsWith(".json") ? JSON.parse(raw) : import_yaml3.parse(raw);
|
|
23565
23765
|
} catch {
|
|
23566
23766
|
continue;
|
|
23567
23767
|
}
|
|
@@ -23584,7 +23784,7 @@ async function scanDataCollection(collectionPath, collectionName, contentDir) {
|
|
|
23584
23784
|
return null;
|
|
23585
23785
|
}
|
|
23586
23786
|
}
|
|
23587
|
-
async function
|
|
23787
|
+
async function scanCollections2(contentDir = "src/content") {
|
|
23588
23788
|
const projectRoot = getProjectRoot();
|
|
23589
23789
|
const fullContentDir = path2.isAbsolute(contentDir) ? contentDir : path2.join(projectRoot, contentDir);
|
|
23590
23790
|
const collections = {};
|
|
@@ -23599,7 +23799,7 @@ async function scanCollections(contentDir = "src/content") {
|
|
|
23599
23799
|
});
|
|
23600
23800
|
await Promise.all(scanPromises);
|
|
23601
23801
|
} catch {}
|
|
23602
|
-
const parsed = await
|
|
23802
|
+
const parsed = await parseContentConfig2();
|
|
23603
23803
|
for (const [collectionName, parsedCollection] of parsed) {
|
|
23604
23804
|
if (collections[collectionName])
|
|
23605
23805
|
continue;
|
|
@@ -23621,15 +23821,15 @@ async function scanCollections(contentDir = "src/content") {
|
|
|
23621
23821
|
applyCollectionOrderBy(collections, parsed);
|
|
23622
23822
|
return collections;
|
|
23623
23823
|
}
|
|
23624
|
-
var
|
|
23625
|
-
var
|
|
23824
|
+
var import_yaml3, DATE_PATTERN, URL_PATTERN, IMAGE_EXTENSIONS2, MAX_SELECT_OPTIONS = 10, TEXTAREA_MIN_LENGTH = 200, SIDEBAR_FIELD_NAMES2, DIRECTIVE_PATTERN, FREE_TEXT_FIELD_NAMES2, PUBLISH_TOGGLE_NAMES2, PUBLISH_DATE_NAMES2, FRONTMATTER_PATTERN, MAX_NESTED_FIELD_DEPTH = 16, HREF_SUFFIXES;
|
|
23825
|
+
var init_collection_scanner2 = __esm(() => {
|
|
23626
23826
|
init_config();
|
|
23627
|
-
|
|
23628
|
-
|
|
23827
|
+
init_content_config_ast2();
|
|
23828
|
+
import_yaml3 = __toESM(require_dist(), 1);
|
|
23629
23829
|
DATE_PATTERN = /^\d{4}-\d{2}-\d{2}/;
|
|
23630
23830
|
URL_PATTERN = /^(https?:\/\/|\/)/;
|
|
23631
|
-
|
|
23632
|
-
|
|
23831
|
+
IMAGE_EXTENSIONS2 = /\.(jpg|jpeg|png|gif|webp|svg|avif)$/i;
|
|
23832
|
+
SIDEBAR_FIELD_NAMES2 = new Set([
|
|
23633
23833
|
"title",
|
|
23634
23834
|
"date",
|
|
23635
23835
|
"pubdate",
|
|
@@ -23643,7 +23843,7 @@ var init_collection_scanner = __esm(() => {
|
|
|
23643
23843
|
"author"
|
|
23644
23844
|
]);
|
|
23645
23845
|
DIRECTIVE_PATTERN = /^\s*@(position|group)\s+(.+)$/;
|
|
23646
|
-
|
|
23846
|
+
FREE_TEXT_FIELD_NAMES2 = new Set([
|
|
23647
23847
|
"title",
|
|
23648
23848
|
"name",
|
|
23649
23849
|
"description",
|
|
@@ -23656,8 +23856,8 @@ var init_collection_scanner = __esm(() => {
|
|
|
23656
23856
|
"alt",
|
|
23657
23857
|
"caption"
|
|
23658
23858
|
]);
|
|
23659
|
-
|
|
23660
|
-
|
|
23859
|
+
PUBLISH_TOGGLE_NAMES2 = new Set(["draft", "isdraft", "published", "ispublished", "unpublished"]);
|
|
23860
|
+
PUBLISH_DATE_NAMES2 = new Set([
|
|
23661
23861
|
"date",
|
|
23662
23862
|
"pubdate",
|
|
23663
23863
|
"publishdate",
|
|
@@ -23733,7 +23933,7 @@ ${propsContent}
|
|
|
23733
23933
|
}`;
|
|
23734
23934
|
let ast;
|
|
23735
23935
|
try {
|
|
23736
|
-
ast =
|
|
23936
|
+
ast = import_parser5.parse(synthetic, {
|
|
23737
23937
|
sourceType: "module",
|
|
23738
23938
|
plugins: ["typescript"],
|
|
23739
23939
|
errorRecovery: true
|
|
@@ -23940,94 +24140,15 @@ ${propsContent}
|
|
|
23940
24140
|
return;
|
|
23941
24141
|
}
|
|
23942
24142
|
}
|
|
23943
|
-
var
|
|
23944
|
-
var
|
|
24143
|
+
var import_parser5;
|
|
24144
|
+
var init_component_registry2 = __esm(() => {
|
|
23945
24145
|
init_config();
|
|
23946
|
-
|
|
23947
|
-
});
|
|
23948
|
-
|
|
23949
|
-
// ../cms/src/media/local.ts
|
|
23950
|
-
function mimeFromExt(ext) {
|
|
23951
|
-
return MIME_BY_EXT[ext] ?? "application/octet-stream";
|
|
23952
|
-
}
|
|
23953
|
-
var MIME_BY_EXT;
|
|
23954
|
-
var init_local = __esm(() => {
|
|
23955
|
-
MIME_BY_EXT = {
|
|
23956
|
-
".jpg": "image/jpeg",
|
|
23957
|
-
".jpeg": "image/jpeg",
|
|
23958
|
-
".png": "image/png",
|
|
23959
|
-
".gif": "image/gif",
|
|
23960
|
-
".webp": "image/webp",
|
|
23961
|
-
".avif": "image/avif",
|
|
23962
|
-
".svg": "image/svg+xml",
|
|
23963
|
-
".ico": "image/x-icon",
|
|
23964
|
-
".mp4": "video/mp4",
|
|
23965
|
-
".webm": "video/webm",
|
|
23966
|
-
".pdf": "application/pdf"
|
|
23967
|
-
};
|
|
24146
|
+
import_parser5 = __toESM(require_lib(), 1);
|
|
23968
24147
|
});
|
|
23969
24148
|
|
|
23970
|
-
// ../cms/src/
|
|
23971
|
-
import
|
|
24149
|
+
// ../cms/src/utils.ts
|
|
24150
|
+
import { createHash } from "crypto";
|
|
23972
24151
|
import path4 from "path";
|
|
23973
|
-
async function listProjectImages(options) {
|
|
23974
|
-
const root = getProjectRoot();
|
|
23975
|
-
const excludeDir = options?.excludeDir ? path4.resolve(options.excludeDir) : null;
|
|
23976
|
-
const scanDirs = [
|
|
23977
|
-
{ dir: path4.join(root, "public"), urlPrefix: "" },
|
|
23978
|
-
{ dir: path4.join(root, "src"), urlPrefix: null }
|
|
23979
|
-
];
|
|
23980
|
-
const results = await Promise.all(scanDirs.map(({ dir, urlPrefix }) => {
|
|
23981
|
-
const items2 = [];
|
|
23982
|
-
return scanDirectory(dir, dir, urlPrefix, excludeDir, items2).then(() => items2);
|
|
23983
|
-
}));
|
|
23984
|
-
const items = results.flat();
|
|
23985
|
-
items.sort((a, b2) => a.filename.localeCompare(b2.filename));
|
|
23986
|
-
return items;
|
|
23987
|
-
}
|
|
23988
|
-
async function scanDirectory(currentDir, baseDir, urlPrefix, excludeDir, items) {
|
|
23989
|
-
if (excludeDir && path4.resolve(currentDir) === excludeDir)
|
|
23990
|
-
return;
|
|
23991
|
-
let entries;
|
|
23992
|
-
try {
|
|
23993
|
-
entries = await fs4.readdir(currentDir, { withFileTypes: true });
|
|
23994
|
-
} catch {
|
|
23995
|
-
return;
|
|
23996
|
-
}
|
|
23997
|
-
const subdirs = [];
|
|
23998
|
-
for (const entry of entries) {
|
|
23999
|
-
const name = String(entry.name);
|
|
24000
|
-
if (name.startsWith(".") || name === "node_modules")
|
|
24001
|
-
continue;
|
|
24002
|
-
const fullPath = path4.join(currentDir, name);
|
|
24003
|
-
if (entry.isDirectory()) {
|
|
24004
|
-
subdirs.push(scanDirectory(fullPath, baseDir, urlPrefix, excludeDir, items));
|
|
24005
|
-
} else if (entry.isFile()) {
|
|
24006
|
-
const ext = path4.extname(name).toLowerCase();
|
|
24007
|
-
if (!IMAGE_EXTENSIONS2.has(ext))
|
|
24008
|
-
continue;
|
|
24009
|
-
const relativePath = path4.relative(baseDir, fullPath).split(path4.sep).join("/");
|
|
24010
|
-
const url = urlPrefix !== null ? `/${relativePath}` : `/${path4.relative(getProjectRoot(), fullPath).split(path4.sep).join("/")}`;
|
|
24011
|
-
items.push({
|
|
24012
|
-
id: `project:${url}`,
|
|
24013
|
-
url,
|
|
24014
|
-
filename: name,
|
|
24015
|
-
contentType: mimeFromExt(ext)
|
|
24016
|
-
});
|
|
24017
|
-
}
|
|
24018
|
-
}
|
|
24019
|
-
await Promise.all(subdirs);
|
|
24020
|
-
}
|
|
24021
|
-
var IMAGE_EXTENSIONS2;
|
|
24022
|
-
var init_project_images = __esm(() => {
|
|
24023
|
-
init_config();
|
|
24024
|
-
init_local();
|
|
24025
|
-
IMAGE_EXTENSIONS2 = new Set(Object.entries(MIME_BY_EXT).filter(([, mime]) => mime.startsWith("image/")).map(([ext]) => ext));
|
|
24026
|
-
});
|
|
24027
|
-
|
|
24028
|
-
// ../cms/src/utils.ts
|
|
24029
|
-
import { createHash } from "crypto";
|
|
24030
|
-
import path5 from "path";
|
|
24031
24152
|
function normalizePagePath(url) {
|
|
24032
24153
|
let pathname;
|
|
24033
24154
|
try {
|
|
@@ -24080,21 +24201,21 @@ function escapeReplacement(str) {
|
|
|
24080
24201
|
return str.replace(/\$/g, "$$$$");
|
|
24081
24202
|
}
|
|
24082
24203
|
function resolveSourcePath(sourcePath) {
|
|
24083
|
-
return
|
|
24204
|
+
return path4.isAbsolute(sourcePath) ? sourcePath : path4.join(getProjectRoot(), sourcePath);
|
|
24084
24205
|
}
|
|
24085
24206
|
function resolveAndValidatePath(filePath) {
|
|
24086
24207
|
const projectRoot = getProjectRoot();
|
|
24087
|
-
const resolvedRoot =
|
|
24208
|
+
const resolvedRoot = path4.resolve(projectRoot);
|
|
24088
24209
|
const isAbsoluteFs = filePath.startsWith(resolvedRoot);
|
|
24089
24210
|
const normalizedPath = !isAbsoluteFs && filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
|
24090
|
-
const fullPath =
|
|
24091
|
-
if (!fullPath.startsWith(resolvedRoot +
|
|
24211
|
+
const fullPath = path4.isAbsolute(normalizedPath) ? path4.resolve(normalizedPath) : path4.resolve(projectRoot, normalizedPath);
|
|
24212
|
+
if (!fullPath.startsWith(resolvedRoot + path4.sep) && fullPath !== resolvedRoot) {
|
|
24092
24213
|
throw new Error(`Path traversal detected: ${filePath}`);
|
|
24093
24214
|
}
|
|
24094
24215
|
return fullPath;
|
|
24095
24216
|
}
|
|
24096
24217
|
async function acquireFileLock(filePath) {
|
|
24097
|
-
const key =
|
|
24218
|
+
const key = path4.resolve(filePath);
|
|
24098
24219
|
while (fileLocks.has(key)) {
|
|
24099
24220
|
await fileLocks.get(key);
|
|
24100
24221
|
}
|
|
@@ -24108,15 +24229,12 @@ async function acquireFileLock(filePath) {
|
|
|
24108
24229
|
release();
|
|
24109
24230
|
};
|
|
24110
24231
|
}
|
|
24111
|
-
function
|
|
24112
|
-
return error instanceof Error && "code" in error && error.code === code;
|
|
24113
|
-
}
|
|
24114
|
-
function escapeHtml(text) {
|
|
24232
|
+
function escapeHtml2(text) {
|
|
24115
24233
|
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
24116
24234
|
}
|
|
24117
|
-
function
|
|
24118
|
-
const fromDir =
|
|
24119
|
-
let rel =
|
|
24235
|
+
function relativeImportPath2(fromFile, toFile) {
|
|
24236
|
+
const fromDir = path4.dirname(fromFile);
|
|
24237
|
+
let rel = path4.relative(fromDir, toFile).split(path4.sep).join("/");
|
|
24120
24238
|
if (!rel.startsWith("."))
|
|
24121
24239
|
rel = `./${rel}`;
|
|
24122
24240
|
return rel;
|
|
@@ -24128,8 +24246,8 @@ var init_utils2 = __esm(() => {
|
|
|
24128
24246
|
});
|
|
24129
24247
|
|
|
24130
24248
|
// ../cms/src/handlers/component-ops.ts
|
|
24131
|
-
import
|
|
24132
|
-
import
|
|
24249
|
+
import fs4 from "fs/promises";
|
|
24250
|
+
import path5 from "path";
|
|
24133
24251
|
async function handleInsertComponent(request, manifestWriter) {
|
|
24134
24252
|
const { position, referenceComponentId, componentName, props, meta } = request;
|
|
24135
24253
|
if (!meta?.url) {
|
|
@@ -24162,7 +24280,7 @@ async function handleInsertComponent(request, manifestWriter) {
|
|
|
24162
24280
|
try {
|
|
24163
24281
|
let currentContent;
|
|
24164
24282
|
try {
|
|
24165
|
-
currentContent = await
|
|
24283
|
+
currentContent = await fs4.readFile(fullPath, "utf-8");
|
|
24166
24284
|
} catch {
|
|
24167
24285
|
return { success: false, error: `Source file not found: ${filePath}` };
|
|
24168
24286
|
}
|
|
@@ -24187,7 +24305,7 @@ async function handleInsertComponent(request, manifestWriter) {
|
|
|
24187
24305
|
`);
|
|
24188
24306
|
lines.splice(insertIndex, 0, indentedJsx);
|
|
24189
24307
|
ensureComponentImport(lines, componentName, componentDef.file, filePath);
|
|
24190
|
-
await
|
|
24308
|
+
await fs4.writeFile(fullPath, lines.join(`
|
|
24191
24309
|
`), "utf-8");
|
|
24192
24310
|
return {
|
|
24193
24311
|
success: true,
|
|
@@ -24230,7 +24348,7 @@ async function handleRemoveComponent(request, manifestWriter) {
|
|
|
24230
24348
|
try {
|
|
24231
24349
|
let currentContent;
|
|
24232
24350
|
try {
|
|
24233
|
-
currentContent = await
|
|
24351
|
+
currentContent = await fs4.readFile(fullPath, "utf-8");
|
|
24234
24352
|
} catch {
|
|
24235
24353
|
return { success: false, error: `Source file not found: ${filePath}` };
|
|
24236
24354
|
}
|
|
@@ -24252,7 +24370,7 @@ async function handleRemoveComponent(request, manifestWriter) {
|
|
|
24252
24370
|
removeCount++;
|
|
24253
24371
|
}
|
|
24254
24372
|
lines.splice(startLine, removeCount);
|
|
24255
|
-
await
|
|
24373
|
+
await fs4.writeFile(fullPath, lines.join(`
|
|
24256
24374
|
`), "utf-8");
|
|
24257
24375
|
return {
|
|
24258
24376
|
success: true,
|
|
@@ -24347,9 +24465,9 @@ function getComponentOccurrenceIndex(manifest, referenceComponent) {
|
|
|
24347
24465
|
async function findComponentInvocationFile(projectRoot, pageUrl, manifest, referenceComponent) {
|
|
24348
24466
|
if (referenceComponent.invocationSourcePath) {
|
|
24349
24467
|
const filePath = normalizeFilePath(referenceComponent.invocationSourcePath);
|
|
24350
|
-
const fullPath =
|
|
24468
|
+
const fullPath = path5.resolve(projectRoot, filePath);
|
|
24351
24469
|
try {
|
|
24352
|
-
const content = await
|
|
24470
|
+
const content = await fs4.readFile(fullPath, "utf-8");
|
|
24353
24471
|
const lines = content.split(`
|
|
24354
24472
|
`);
|
|
24355
24473
|
const lineIndex = findComponentInvocationLine(lines, referenceComponent.componentName, referenceComponent.invocationIndex ?? 0);
|
|
@@ -24361,9 +24479,9 @@ async function findComponentInvocationFile(projectRoot, pageUrl, manifest, refer
|
|
|
24361
24479
|
const candidates = getPageFileCandidates(pageUrl);
|
|
24362
24480
|
const occurrenceIndex = getComponentOccurrenceIndex(manifest, referenceComponent);
|
|
24363
24481
|
for (const candidate of candidates) {
|
|
24364
|
-
const fullPath =
|
|
24482
|
+
const fullPath = path5.resolve(projectRoot, candidate);
|
|
24365
24483
|
try {
|
|
24366
|
-
const content = await
|
|
24484
|
+
const content = await fs4.readFile(fullPath, "utf-8");
|
|
24367
24485
|
const lines = content.split(`
|
|
24368
24486
|
`);
|
|
24369
24487
|
const lineIndex = findComponentInvocationLine(lines, referenceComponent.componentName, occurrenceIndex);
|
|
@@ -24399,7 +24517,7 @@ function findFrontmatterEnd(lines) {
|
|
|
24399
24517
|
function generateComponentJsx(componentName, props, _definition) {
|
|
24400
24518
|
const propsString = Object.entries(props).map(([key, value]) => {
|
|
24401
24519
|
if (typeof value === "string") {
|
|
24402
|
-
return `${key}="${
|
|
24520
|
+
return `${key}="${escapeHtml2(value)}"`;
|
|
24403
24521
|
}
|
|
24404
24522
|
if (typeof value === "boolean") {
|
|
24405
24523
|
return value ? key : `${key}={false}`;
|
|
@@ -24421,7 +24539,7 @@ function getIndentation(line) {
|
|
|
24421
24539
|
function normalizeFilePath(p) {
|
|
24422
24540
|
if (!p.startsWith("/"))
|
|
24423
24541
|
return p;
|
|
24424
|
-
const projectRoot =
|
|
24542
|
+
const projectRoot = path5.resolve(getProjectRoot());
|
|
24425
24543
|
if (p.startsWith(projectRoot))
|
|
24426
24544
|
return p;
|
|
24427
24545
|
return p.slice(1);
|
|
@@ -24434,7 +24552,7 @@ function ensureComponentImport(lines, componentName, componentFile, targetFile)
|
|
|
24434
24552
|
return;
|
|
24435
24553
|
}
|
|
24436
24554
|
}
|
|
24437
|
-
const importStatement = `import ${componentName} from '${
|
|
24555
|
+
const importStatement = `import ${componentName} from '${relativeImportPath2(targetFile, componentFile)}'`;
|
|
24438
24556
|
if (frontmatterEnd > 0) {
|
|
24439
24557
|
let insertAt = 1;
|
|
24440
24558
|
for (let i = 1;i < frontmatterEnd - 1; i++) {
|
|
@@ -24453,7 +24571,7 @@ var init_component_ops = __esm(() => {
|
|
|
24453
24571
|
});
|
|
24454
24572
|
|
|
24455
24573
|
// ../cms/src/handlers/array-ops.ts
|
|
24456
|
-
import
|
|
24574
|
+
import fs5 from "fs/promises";
|
|
24457
24575
|
function parseInlineArrayName(componentName) {
|
|
24458
24576
|
if (!componentName.startsWith("__array:"))
|
|
24459
24577
|
return null;
|
|
@@ -24488,7 +24606,7 @@ function detectArrayPattern(lines, invocationLineIndex) {
|
|
|
24488
24606
|
function findArrayDeclaration(frontmatterContent, frontmatterStartLine, arrayVarName) {
|
|
24489
24607
|
let ast;
|
|
24490
24608
|
try {
|
|
24491
|
-
ast =
|
|
24609
|
+
ast = import_parser6.parse(frontmatterContent, {
|
|
24492
24610
|
sourceType: "module",
|
|
24493
24611
|
plugins: ["typescript"],
|
|
24494
24612
|
errorRecovery: true
|
|
@@ -24533,7 +24651,7 @@ async function resolveArrayContext(component, manifest, pageUrl) {
|
|
|
24533
24651
|
const { arrayVarName, mapOccurrence } = parsed;
|
|
24534
24652
|
const filePath2 = normalizeFilePath(component.invocationSourcePath ?? component.sourcePath);
|
|
24535
24653
|
const fullPath2 = resolveAndValidatePath(filePath2);
|
|
24536
|
-
const content2 = await
|
|
24654
|
+
const content2 = await fs5.readFile(fullPath2, "utf-8");
|
|
24537
24655
|
const lines2 = content2.split(`
|
|
24538
24656
|
`);
|
|
24539
24657
|
const fmEnd2 = findFrontmatterEnd(lines2);
|
|
@@ -24578,7 +24696,7 @@ async function resolveArrayContext(component, manifest, pageUrl) {
|
|
|
24578
24696
|
const invocation = await findComponentInvocationFile(projectRoot, pageUrl, manifest, component);
|
|
24579
24697
|
const filePath = invocation?.filePath ?? normalizeFilePath(component.invocationSourcePath ?? component.sourcePath);
|
|
24580
24698
|
const fullPath = resolveAndValidatePath(filePath);
|
|
24581
|
-
const content = await
|
|
24699
|
+
const content = await fs5.readFile(fullPath, "utf-8");
|
|
24582
24700
|
const lines = content.split(`
|
|
24583
24701
|
`);
|
|
24584
24702
|
let refLineIndex;
|
|
@@ -24650,7 +24768,7 @@ async function handleRemoveArrayItem(request, manifestWriter) {
|
|
|
24650
24768
|
const { fullPath, arrayIndex } = ctx;
|
|
24651
24769
|
const release = await acquireFileLock(fullPath);
|
|
24652
24770
|
try {
|
|
24653
|
-
const freshContent = await
|
|
24771
|
+
const freshContent = await fs5.readFile(fullPath, "utf-8");
|
|
24654
24772
|
const freshLines = freshContent.split(`
|
|
24655
24773
|
`);
|
|
24656
24774
|
const freshFmEnd = findFrontmatterEnd(freshLines);
|
|
@@ -24679,7 +24797,7 @@ async function handleRemoveArrayItem(request, manifestWriter) {
|
|
|
24679
24797
|
freshLines[removeStart - 1] = prevLine.replace(/,\s*$/, "");
|
|
24680
24798
|
}
|
|
24681
24799
|
}
|
|
24682
|
-
await
|
|
24800
|
+
await fs5.writeFile(fullPath, freshLines.join(`
|
|
24683
24801
|
`), "utf-8");
|
|
24684
24802
|
return {
|
|
24685
24803
|
success: true,
|
|
@@ -24721,7 +24839,7 @@ async function handleAddArrayItem(request, manifestWriter) {
|
|
|
24721
24839
|
const { fullPath, arrayIndex } = ctx;
|
|
24722
24840
|
const release = await acquireFileLock(fullPath);
|
|
24723
24841
|
try {
|
|
24724
|
-
const freshContent = await
|
|
24842
|
+
const freshContent = await fs5.readFile(fullPath, "utf-8");
|
|
24725
24843
|
const freshLines = freshContent.split(`
|
|
24726
24844
|
`);
|
|
24727
24845
|
const freshFmEnd = findFrontmatterEnd(freshLines);
|
|
@@ -24772,7 +24890,7 @@ async function handleAddArrayItem(request, manifestWriter) {
|
|
|
24772
24890
|
break;
|
|
24773
24891
|
}
|
|
24774
24892
|
}
|
|
24775
|
-
await
|
|
24893
|
+
await fs5.writeFile(fullPath, freshLines.join(`
|
|
24776
24894
|
`), "utf-8");
|
|
24777
24895
|
return {
|
|
24778
24896
|
success: true,
|
|
@@ -24818,56 +24936,56 @@ function formatValue(value) {
|
|
|
24818
24936
|
return generateObjectLiteral(value);
|
|
24819
24937
|
return String(value);
|
|
24820
24938
|
}
|
|
24821
|
-
var
|
|
24939
|
+
var import_parser6;
|
|
24822
24940
|
var init_array_ops = __esm(() => {
|
|
24823
24941
|
init_config();
|
|
24824
24942
|
init_utils2();
|
|
24825
24943
|
init_component_ops();
|
|
24826
|
-
|
|
24944
|
+
import_parser6 = __toESM(require_lib(), 1);
|
|
24827
24945
|
});
|
|
24828
24946
|
|
|
24829
24947
|
// ../cms/src/astro-image-paths.ts
|
|
24830
24948
|
import { createHash as createHash2 } from "crypto";
|
|
24831
|
-
import
|
|
24832
|
-
import
|
|
24949
|
+
import fs6 from "fs/promises";
|
|
24950
|
+
import path6 from "path";
|
|
24833
24951
|
function isHugoStyleEntry(entryAbsPath) {
|
|
24834
|
-
return HUGO_INDEX_RE.test(
|
|
24952
|
+
return HUGO_INDEX_RE.test(path6.basename(entryAbsPath));
|
|
24835
24953
|
}
|
|
24836
24954
|
function shortContentHash(buf) {
|
|
24837
24955
|
return createHash2("sha256").update(buf).digest("hex").slice(0, 8);
|
|
24838
24956
|
}
|
|
24839
24957
|
async function pickAstroImageTarget(args) {
|
|
24840
|
-
const entryDir =
|
|
24958
|
+
const entryDir = path6.dirname(args.entryAbsPath);
|
|
24841
24959
|
const isHugoStyle = isHugoStyleEntry(args.entryAbsPath);
|
|
24842
|
-
const safeFilename =
|
|
24960
|
+
const safeFilename = path6.basename(args.originalFilename);
|
|
24843
24961
|
if (!safeFilename || safeFilename === "." || safeFilename === "..") {
|
|
24844
24962
|
throw new Error(`Invalid filename: ${args.originalFilename}`);
|
|
24845
24963
|
}
|
|
24846
24964
|
const baseName = isHugoStyle ? safeFilename : `${args.slug}-${safeFilename}`;
|
|
24847
|
-
const baseAbs =
|
|
24965
|
+
const baseAbs = path6.join(entryDir, baseName);
|
|
24848
24966
|
if (await isFreeOrMatching(baseAbs, args.compareBuffer)) {
|
|
24849
24967
|
return { absPath: baseAbs, relPath: `./${baseName}` };
|
|
24850
24968
|
}
|
|
24851
24969
|
const candidateAbs = await pickHashedSibling(entryDir, baseName, args.compareBuffer);
|
|
24852
|
-
return { absPath: candidateAbs, relPath: `./${
|
|
24970
|
+
return { absPath: candidateAbs, relPath: `./${path6.basename(candidateAbs)}` };
|
|
24853
24971
|
}
|
|
24854
24972
|
async function pickSiblingTarget(dir, filename, buf) {
|
|
24855
|
-
const safe =
|
|
24973
|
+
const safe = path6.basename(filename);
|
|
24856
24974
|
if (!safe || safe === "." || safe === "..") {
|
|
24857
24975
|
throw new Error(`Invalid filename: ${filename}`);
|
|
24858
24976
|
}
|
|
24859
|
-
const baseAbs =
|
|
24977
|
+
const baseAbs = path6.join(dir, safe);
|
|
24860
24978
|
if (await isFreeOrMatching(baseAbs, buf))
|
|
24861
24979
|
return baseAbs;
|
|
24862
24980
|
return pickHashedSibling(dir, safe, buf);
|
|
24863
24981
|
}
|
|
24864
24982
|
async function pickHashedSibling(dir, baseName, buf) {
|
|
24865
24983
|
const hash = shortContentHash(buf);
|
|
24866
|
-
const ext =
|
|
24867
|
-
const stem =
|
|
24984
|
+
const ext = path6.extname(baseName);
|
|
24985
|
+
const stem = path6.basename(baseName, ext);
|
|
24868
24986
|
for (let attempt = 0;attempt < 5; attempt++) {
|
|
24869
24987
|
const suffix = attempt === 0 ? hash : `${hash}-${attempt}`;
|
|
24870
|
-
const candidateAbs =
|
|
24988
|
+
const candidateAbs = path6.join(dir, `${stem}-${suffix}${ext}`);
|
|
24871
24989
|
if (await isFreeOrMatching(candidateAbs, buf))
|
|
24872
24990
|
return candidateAbs;
|
|
24873
24991
|
}
|
|
@@ -24875,10 +24993,10 @@ async function pickHashedSibling(dir, baseName, buf) {
|
|
|
24875
24993
|
}
|
|
24876
24994
|
async function isFreeOrMatching(absPath, compareBuffer) {
|
|
24877
24995
|
try {
|
|
24878
|
-
const stat = await
|
|
24996
|
+
const stat = await fs6.stat(absPath);
|
|
24879
24997
|
if (stat.size !== compareBuffer.length)
|
|
24880
24998
|
return false;
|
|
24881
|
-
const existing = await
|
|
24999
|
+
const existing = await fs6.readFile(absPath);
|
|
24882
25000
|
return compareBuffer.equals(existing);
|
|
24883
25001
|
} catch {
|
|
24884
25002
|
return true;
|
|
@@ -24890,8 +25008,8 @@ var init_astro_image_paths = __esm(() => {
|
|
|
24890
25008
|
});
|
|
24891
25009
|
|
|
24892
25010
|
// ../cms/src/handlers/astro-image-upload.ts
|
|
24893
|
-
import
|
|
24894
|
-
import
|
|
25011
|
+
import fs7 from "fs/promises";
|
|
25012
|
+
import path7 from "path";
|
|
24895
25013
|
async function tryAstroImageUpload(args) {
|
|
24896
25014
|
const { collection, entry, field } = args.context;
|
|
24897
25015
|
if (!collection || !entry || !field)
|
|
@@ -24913,12 +25031,12 @@ async function tryAstroImageUpload(args) {
|
|
|
24913
25031
|
originalFilename: args.originalFilename,
|
|
24914
25032
|
compareBuffer: args.fileBuffer
|
|
24915
25033
|
});
|
|
24916
|
-
await
|
|
24917
|
-
await
|
|
25034
|
+
await fs7.mkdir(path7.dirname(target.absPath), { recursive: true });
|
|
25035
|
+
await fs7.writeFile(target.absPath, args.fileBuffer);
|
|
24918
25036
|
return {
|
|
24919
25037
|
success: true,
|
|
24920
25038
|
url: target.relPath,
|
|
24921
|
-
filename:
|
|
25039
|
+
filename: path7.basename(target.absPath)
|
|
24922
25040
|
};
|
|
24923
25041
|
}
|
|
24924
25042
|
var init_astro_image_upload = __esm(() => {
|
|
@@ -24926,450 +25044,18 @@ var init_astro_image_upload = __esm(() => {
|
|
|
24926
25044
|
init_utils2();
|
|
24927
25045
|
});
|
|
24928
25046
|
|
|
24929
|
-
// ../cms/src/handlers/markdown-ops.ts
|
|
24930
|
-
import fs9 from "fs/promises";
|
|
24931
|
-
import path9 from "path";
|
|
24932
|
-
async function handleGetMarkdownContent(filePath) {
|
|
24933
|
-
try {
|
|
24934
|
-
const fullPath = resolveAndValidatePath(filePath);
|
|
24935
|
-
const raw = await fs9.readFile(fullPath, "utf-8");
|
|
24936
|
-
if (isDataFile(filePath)) {
|
|
24937
|
-
const data = filePath.endsWith(".json") ? JSON.parse(raw) : import_yaml2.default.parse(raw);
|
|
24938
|
-
return {
|
|
24939
|
-
content: "",
|
|
24940
|
-
frontmatter: data && typeof data === "object" ? data : {},
|
|
24941
|
-
filePath
|
|
24942
|
-
};
|
|
24943
|
-
}
|
|
24944
|
-
const { frontmatter, content } = parseFrontmatter3(raw);
|
|
24945
|
-
return {
|
|
24946
|
-
content,
|
|
24947
|
-
frontmatter,
|
|
24948
|
-
filePath
|
|
24949
|
-
};
|
|
24950
|
-
} catch {
|
|
24951
|
-
return null;
|
|
24952
|
-
}
|
|
24953
|
-
}
|
|
24954
|
-
async function handleUpdateMarkdown(request, componentDefinitions) {
|
|
24955
|
-
try {
|
|
24956
|
-
const fullPath = resolveAndValidatePath(request.filePath);
|
|
24957
|
-
const release = await acquireFileLock(fullPath);
|
|
24958
|
-
try {
|
|
24959
|
-
if (isDataFile(request.filePath)) {
|
|
24960
|
-
const raw = await fs9.readFile(fullPath, "utf-8");
|
|
24961
|
-
const existing = request.filePath.endsWith(".json") ? JSON.parse(raw) : import_yaml2.default.parse(raw);
|
|
24962
|
-
const merged = { ...existing ?? {}, ...request.frontmatter };
|
|
24963
|
-
const output = request.filePath.endsWith(".json") ? JSON.stringify(merged, null, 2) + `
|
|
24964
|
-
` : import_yaml2.default.stringify(merged);
|
|
24965
|
-
await fs9.writeFile(fullPath, output, "utf-8");
|
|
24966
|
-
} else {
|
|
24967
|
-
const raw = await fs9.readFile(fullPath, "utf-8");
|
|
24968
|
-
const existing = parseFrontmatter3(raw);
|
|
24969
|
-
const mergedFrontmatter = {
|
|
24970
|
-
...existing.frontmatter,
|
|
24971
|
-
...request.frontmatter
|
|
24972
|
-
};
|
|
24973
|
-
let finalContent = request.content ?? existing.content;
|
|
24974
|
-
if (request.filePath.endsWith(".mdx") && componentDefinitions) {
|
|
24975
|
-
finalContent = ensureMdxImports(finalContent, request.filePath, componentDefinitions);
|
|
24976
|
-
}
|
|
24977
|
-
const markdownContent = serializeFrontmatter(mergedFrontmatter, finalContent);
|
|
24978
|
-
await fs9.writeFile(fullPath, markdownContent, "utf-8");
|
|
24979
|
-
}
|
|
24980
|
-
return { success: true };
|
|
24981
|
-
} finally {
|
|
24982
|
-
release();
|
|
24983
|
-
}
|
|
24984
|
-
} catch (error) {
|
|
24985
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
24986
|
-
return { success: false, error: message };
|
|
24987
|
-
}
|
|
24988
|
-
}
|
|
24989
|
-
async function handleCreateMarkdown(request) {
|
|
24990
|
-
const { collection, title, slug, frontmatter = {}, content = "" } = request;
|
|
24991
|
-
const normalizedSlug = slugify(slug || title);
|
|
24992
|
-
if (!normalizedSlug) {
|
|
24993
|
-
return { success: false, error: "Could not generate a valid slug from the provided title/slug" };
|
|
24994
|
-
}
|
|
24995
|
-
const allowedExtensions = ["md", "mdx", "json", "yaml", "yml"];
|
|
24996
|
-
const ext = request.fileExtension ?? "md";
|
|
24997
|
-
if (!allowedExtensions.includes(ext)) {
|
|
24998
|
-
return { success: false, error: `Invalid file extension "${ext}". Allowed: ${allowedExtensions.join(", ")}` };
|
|
24999
|
-
}
|
|
25000
|
-
const isData = ext === "json" || ext === "yaml" || ext === "yml";
|
|
25001
|
-
const layout = isData ? "flat" : await detectCollectionMarkdownLayout(collection);
|
|
25002
|
-
const filePath = layout === "index" ? `src/content/${collection}/${normalizedSlug}/index.${ext}` : `src/content/${collection}/${normalizedSlug}.${ext}`;
|
|
25003
|
-
const fullPath = resolveAndValidatePath(filePath);
|
|
25004
|
-
let fileContent;
|
|
25005
|
-
if (isData) {
|
|
25006
|
-
const data = { ...frontmatter };
|
|
25007
|
-
fileContent = ext === "json" ? JSON.stringify(data, null, 2) + `
|
|
25008
|
-
` : import_yaml2.default.stringify(data);
|
|
25009
|
-
} else {
|
|
25010
|
-
const fullFrontmatter = {
|
|
25011
|
-
title,
|
|
25012
|
-
date: new Date().toISOString().split("T")[0],
|
|
25013
|
-
...frontmatter
|
|
25014
|
-
};
|
|
25015
|
-
fileContent = serializeFrontmatter(fullFrontmatter, content);
|
|
25016
|
-
}
|
|
25017
|
-
try {
|
|
25018
|
-
await fs9.mkdir(path9.dirname(fullPath), { recursive: true });
|
|
25019
|
-
await fs9.writeFile(fullPath, fileContent, { encoding: "utf-8", flag: "wx" });
|
|
25020
|
-
return {
|
|
25021
|
-
success: true,
|
|
25022
|
-
filePath,
|
|
25023
|
-
slug: normalizedSlug
|
|
25024
|
-
};
|
|
25025
|
-
} catch (error) {
|
|
25026
|
-
if (error instanceof Error && "code" in error && error.code === "EEXIST") {
|
|
25027
|
-
return { success: false, error: `File already exists: ${filePath}` };
|
|
25028
|
-
}
|
|
25029
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
25030
|
-
return { success: false, error: message };
|
|
25031
|
-
}
|
|
25032
|
-
}
|
|
25033
|
-
async function handleDeleteMarkdown(request) {
|
|
25034
|
-
try {
|
|
25035
|
-
const fullPath = resolveAndValidatePath(request.filePath);
|
|
25036
|
-
await fs9.access(fullPath);
|
|
25037
|
-
await fs9.unlink(fullPath);
|
|
25038
|
-
return { success: true };
|
|
25039
|
-
} catch (error) {
|
|
25040
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
25041
|
-
return { success: false, error: `File not found: ${request.filePath}` };
|
|
25042
|
-
}
|
|
25043
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
25044
|
-
return { success: false, error: message };
|
|
25045
|
-
}
|
|
25046
|
-
}
|
|
25047
|
-
async function handleRenameMarkdown(request) {
|
|
25048
|
-
try {
|
|
25049
|
-
const fullPath = resolveAndValidatePath(request.filePath);
|
|
25050
|
-
const normalizedSlug = slugify(request.newSlug);
|
|
25051
|
-
if (!normalizedSlug) {
|
|
25052
|
-
return { success: false, error: "Invalid slug" };
|
|
25053
|
-
}
|
|
25054
|
-
const dir = path9.dirname(fullPath);
|
|
25055
|
-
const ext = path9.extname(fullPath);
|
|
25056
|
-
const newFullPath = path9.join(dir, `${normalizedSlug}${ext}`);
|
|
25057
|
-
if (fullPath === newFullPath) {
|
|
25058
|
-
return { success: true, newFilePath: request.filePath, newSlug: normalizedSlug };
|
|
25059
|
-
}
|
|
25060
|
-
const release = await acquireFileLock(fullPath);
|
|
25061
|
-
try {
|
|
25062
|
-
try {
|
|
25063
|
-
await fs9.link(fullPath, newFullPath);
|
|
25064
|
-
} catch (err) {
|
|
25065
|
-
if (isNodeError(err, "EEXIST")) {
|
|
25066
|
-
return { success: false, error: `File already exists: ${normalizedSlug}${ext}` };
|
|
25067
|
-
}
|
|
25068
|
-
throw err;
|
|
25069
|
-
}
|
|
25070
|
-
try {
|
|
25071
|
-
await fs9.unlink(fullPath);
|
|
25072
|
-
} catch (err) {
|
|
25073
|
-
await fs9.unlink(newFullPath).catch(() => {});
|
|
25074
|
-
throw err;
|
|
25075
|
-
}
|
|
25076
|
-
} finally {
|
|
25077
|
-
release();
|
|
25078
|
-
}
|
|
25079
|
-
const projectRoot = getProjectRoot();
|
|
25080
|
-
const newFilePath = path9.relative(projectRoot, newFullPath).split(path9.sep).join("/");
|
|
25081
|
-
return { success: true, newFilePath, newSlug: normalizedSlug };
|
|
25082
|
-
} catch (error) {
|
|
25083
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
25084
|
-
return { success: false, error: message };
|
|
25085
|
-
}
|
|
25086
|
-
}
|
|
25087
|
-
function isDataFile(filePath) {
|
|
25088
|
-
return filePath.endsWith(".json") || filePath.endsWith(".yaml") || filePath.endsWith(".yml");
|
|
25089
|
-
}
|
|
25090
|
-
async function detectCollectionMarkdownLayout(collection) {
|
|
25091
|
-
const existingLayout = await inferLayoutFromExistingEntries(collection);
|
|
25092
|
-
if (existingLayout)
|
|
25093
|
-
return existingLayout;
|
|
25094
|
-
const configLayout = await inferLayoutFromContentConfig(collection);
|
|
25095
|
-
if (configLayout)
|
|
25096
|
-
return configLayout;
|
|
25097
|
-
return "flat";
|
|
25098
|
-
}
|
|
25099
|
-
async function inferLayoutFromExistingEntries(collection) {
|
|
25100
|
-
const collectionPath = path9.join(getProjectRoot(), "src", "content", collection);
|
|
25101
|
-
let dirEntries;
|
|
25102
|
-
try {
|
|
25103
|
-
dirEntries = await fs9.readdir(collectionPath, { withFileTypes: true });
|
|
25104
|
-
} catch {
|
|
25105
|
-
return null;
|
|
25106
|
-
}
|
|
25107
|
-
let flatCount = 0;
|
|
25108
|
-
let indexCount = 0;
|
|
25109
|
-
const flatSlugs = new Set;
|
|
25110
|
-
for (const entry of dirEntries) {
|
|
25111
|
-
if (!entry.isFile())
|
|
25112
|
-
continue;
|
|
25113
|
-
const match = entry.name.match(/^(.+)\.(md|mdx)$/);
|
|
25114
|
-
if (!match)
|
|
25115
|
-
continue;
|
|
25116
|
-
flatCount++;
|
|
25117
|
-
flatSlugs.add(match[1]);
|
|
25118
|
-
}
|
|
25119
|
-
const subdirs = dirEntries.filter((entry) => entry.isDirectory() && !entry.name.startsWith("_") && !entry.name.startsWith("."));
|
|
25120
|
-
const indexLookups = await Promise.all(subdirs.map(async (dir) => {
|
|
25121
|
-
if (flatSlugs.has(dir.name))
|
|
25122
|
-
return false;
|
|
25123
|
-
for (const ext of ["md", "mdx"]) {
|
|
25124
|
-
try {
|
|
25125
|
-
await fs9.access(path9.join(collectionPath, dir.name, `index.${ext}`));
|
|
25126
|
-
return true;
|
|
25127
|
-
} catch {}
|
|
25128
|
-
}
|
|
25129
|
-
return false;
|
|
25130
|
-
}));
|
|
25131
|
-
indexCount = indexLookups.filter(Boolean).length;
|
|
25132
|
-
if (indexCount > flatCount)
|
|
25133
|
-
return "index";
|
|
25134
|
-
if (flatCount > 0)
|
|
25135
|
-
return "flat";
|
|
25136
|
-
return null;
|
|
25137
|
-
}
|
|
25138
|
-
async function inferLayoutFromContentConfig(collection) {
|
|
25139
|
-
try {
|
|
25140
|
-
const parsed = await parseContentConfig();
|
|
25141
|
-
const pattern = parsed.get(collection)?.loaderPattern;
|
|
25142
|
-
if (!pattern)
|
|
25143
|
-
return null;
|
|
25144
|
-
return isIndexStyleGlobPattern(pattern) ? "index" : "flat";
|
|
25145
|
-
} catch {
|
|
25146
|
-
return null;
|
|
25147
|
-
}
|
|
25148
|
-
}
|
|
25149
|
-
function isIndexStyleGlobPattern(pattern) {
|
|
25150
|
-
return pattern.includes("index.{") || pattern.includes("*/index") || pattern.includes("**/index");
|
|
25151
|
-
}
|
|
25152
|
-
function parseFrontmatter3(raw) {
|
|
25153
|
-
const trimmed = raw.trimStart();
|
|
25154
|
-
if (!trimmed.startsWith("---")) {
|
|
25155
|
-
return { frontmatter: {}, content: raw };
|
|
25156
|
-
}
|
|
25157
|
-
const lines = trimmed.split(`
|
|
25158
|
-
`);
|
|
25159
|
-
let endLineIndex = -1;
|
|
25160
|
-
for (let i = 1;i < lines.length; i++) {
|
|
25161
|
-
if (lines[i].trimEnd() === "---") {
|
|
25162
|
-
endLineIndex = i;
|
|
25163
|
-
break;
|
|
25164
|
-
}
|
|
25165
|
-
}
|
|
25166
|
-
if (endLineIndex === -1) {
|
|
25167
|
-
return { frontmatter: {}, content: raw };
|
|
25168
|
-
}
|
|
25169
|
-
const yamlStr = lines.slice(1, endLineIndex).join(`
|
|
25170
|
-
`).trim();
|
|
25171
|
-
const content = lines.slice(endLineIndex + 1).join(`
|
|
25172
|
-
`).replace(/^\r?\n/, "");
|
|
25173
|
-
let frontmatter = {};
|
|
25174
|
-
try {
|
|
25175
|
-
frontmatter = import_yaml2.default.parse(yamlStr) ?? {};
|
|
25176
|
-
} catch {}
|
|
25177
|
-
return { frontmatter, content };
|
|
25178
|
-
}
|
|
25179
|
-
function serializeFrontmatter(frontmatter, content) {
|
|
25180
|
-
const doc = new import_yaml2.default.Document(frontmatter);
|
|
25181
|
-
import_yaml2.default.visit(doc, {
|
|
25182
|
-
Scalar(_key, node) {
|
|
25183
|
-
if (typeof node.value === "string" && YAML_DATE_PATTERN.test(node.value)) {
|
|
25184
|
-
node.type = import_yaml2.default.Scalar.QUOTE_SINGLE;
|
|
25185
|
-
}
|
|
25186
|
-
}
|
|
25187
|
-
});
|
|
25188
|
-
const yamlStr = doc.toString().trim();
|
|
25189
|
-
return `---
|
|
25190
|
-
${yamlStr}
|
|
25191
|
-
---
|
|
25192
|
-
${content}`;
|
|
25193
|
-
}
|
|
25194
|
-
function ensureMdxImports(content, filePath, componentDefinitions) {
|
|
25195
|
-
const usedComponents = new Set;
|
|
25196
|
-
const tagRegex = /<([A-Z][A-Za-z0-9]*)\b/g;
|
|
25197
|
-
let match;
|
|
25198
|
-
while ((match = tagRegex.exec(content)) !== null) {
|
|
25199
|
-
if (match[1])
|
|
25200
|
-
usedComponents.add(match[1]);
|
|
25201
|
-
}
|
|
25202
|
-
if (usedComponents.size === 0)
|
|
25203
|
-
return content;
|
|
25204
|
-
const importedNames = new Set;
|
|
25205
|
-
const importLineRegex = /^import\s+(.+)\s+from\s+/gm;
|
|
25206
|
-
let lastImportEnd = -1;
|
|
25207
|
-
while ((match = importLineRegex.exec(content)) !== null) {
|
|
25208
|
-
lastImportEnd = match.index + match[0].length;
|
|
25209
|
-
const fromRest = content.slice(lastImportEnd);
|
|
25210
|
-
const lineEnd = fromRest.indexOf(`
|
|
25211
|
-
`);
|
|
25212
|
-
if (lineEnd >= 0)
|
|
25213
|
-
lastImportEnd += lineEnd;
|
|
25214
|
-
else
|
|
25215
|
-
lastImportEnd = content.length;
|
|
25216
|
-
const clause = match[1];
|
|
25217
|
-
const braceMatch = clause.match(/\{([^}]+)\}/);
|
|
25218
|
-
if (braceMatch?.[1]) {
|
|
25219
|
-
for (const name of braceMatch[1].split(",")) {
|
|
25220
|
-
const parts = name.trim().split(/\s+as\s+/);
|
|
25221
|
-
const imported = (parts[1] ?? parts[0])?.trim();
|
|
25222
|
-
if (imported)
|
|
25223
|
-
importedNames.add(imported);
|
|
25224
|
-
}
|
|
25225
|
-
}
|
|
25226
|
-
const withoutBraces = clause.replace(/\{[^}]*\}/, "").replace(/,/g, " ").trim();
|
|
25227
|
-
for (const token of withoutBraces.split(/\s+/)) {
|
|
25228
|
-
if (token === "*" || token === "as" || token === "")
|
|
25229
|
-
continue;
|
|
25230
|
-
importedNames.add(token);
|
|
25231
|
-
}
|
|
25232
|
-
}
|
|
25233
|
-
const root = getProjectRoot();
|
|
25234
|
-
const mdxFullPath = path9.join(root, filePath);
|
|
25235
|
-
const missingImports = [];
|
|
25236
|
-
for (const name of usedComponents) {
|
|
25237
|
-
if (importedNames.has(name))
|
|
25238
|
-
continue;
|
|
25239
|
-
const def = componentDefinitions[name];
|
|
25240
|
-
if (!def)
|
|
25241
|
-
continue;
|
|
25242
|
-
const componentAbsPath = path9.join(root, def.file);
|
|
25243
|
-
const rel = relativeImportPath(mdxFullPath, componentAbsPath);
|
|
25244
|
-
missingImports.push(`import ${name} from '${rel}'`);
|
|
25245
|
-
}
|
|
25246
|
-
if (missingImports.length === 0)
|
|
25247
|
-
return content;
|
|
25248
|
-
const importBlock = missingImports.join(`
|
|
25249
|
-
`);
|
|
25250
|
-
if (lastImportEnd >= 0) {
|
|
25251
|
-
return content.slice(0, lastImportEnd) + `
|
|
25252
|
-
` + importBlock + content.slice(lastImportEnd);
|
|
25253
|
-
}
|
|
25254
|
-
return importBlock + `
|
|
25255
|
-
|
|
25256
|
-
` + content;
|
|
25257
|
-
}
|
|
25258
|
-
var import_yaml2, YAML_DATE_PATTERN;
|
|
25259
|
-
var init_markdown_ops = __esm(() => {
|
|
25260
|
-
init_config();
|
|
25261
|
-
init_content_config_ast();
|
|
25262
|
-
init_utils2();
|
|
25263
|
-
import_yaml2 = __toESM(require_dist(), 1);
|
|
25264
|
-
YAML_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}/;
|
|
25265
|
-
});
|
|
25266
|
-
|
|
25267
25047
|
// ../cms/src/handlers/page-ops.ts
|
|
25268
|
-
import
|
|
25269
|
-
import path10 from "path";
|
|
25270
|
-
async function handleCreatePage(request) {
|
|
25271
|
-
const { title, slug } = request;
|
|
25272
|
-
const normalizedSlug = slugify(slug || title);
|
|
25273
|
-
if (!normalizedSlug) {
|
|
25274
|
-
return { success: false, error: "Could not generate a valid slug from the provided title/slug" };
|
|
25275
|
-
}
|
|
25276
|
-
const filePath = `src/pages/${normalizedSlug}.astro`;
|
|
25277
|
-
const fullPath = resolveAndValidatePath(filePath);
|
|
25278
|
-
const layoutImport = await resolveLayoutImport(request.layoutPath);
|
|
25279
|
-
const content = generatePageContent(title, layoutImport);
|
|
25280
|
-
try {
|
|
25281
|
-
await fs10.mkdir(path10.dirname(fullPath), { recursive: true });
|
|
25282
|
-
await fs10.writeFile(fullPath, content, { encoding: "utf-8", flag: "wx" });
|
|
25283
|
-
const url = normalizedSlug === "index" ? "/" : `/${normalizedSlug}`;
|
|
25284
|
-
return { success: true, filePath, slug: normalizedSlug, url };
|
|
25285
|
-
} catch (error) {
|
|
25286
|
-
if (isNodeError(error, "EEXIST")) {
|
|
25287
|
-
return { success: false, error: `Page already exists: ${filePath}` };
|
|
25288
|
-
}
|
|
25289
|
-
return { success: false, error: errorMessage(error) };
|
|
25290
|
-
}
|
|
25291
|
-
}
|
|
25292
|
-
async function handleDuplicatePage(request) {
|
|
25293
|
-
const { sourcePagePath, slug, title } = request;
|
|
25294
|
-
const normalizedSlug = slugify(slug);
|
|
25295
|
-
if (!normalizedSlug) {
|
|
25296
|
-
return { success: false, error: "Could not generate a valid slug" };
|
|
25297
|
-
}
|
|
25298
|
-
const sourceFile = await findPageFile(sourcePagePath);
|
|
25299
|
-
if (!sourceFile) {
|
|
25300
|
-
return { success: false, error: `Source page not found: ${sourcePagePath}` };
|
|
25301
|
-
}
|
|
25302
|
-
let content;
|
|
25303
|
-
try {
|
|
25304
|
-
content = await fs10.readFile(resolveAndValidatePath(sourceFile), "utf-8");
|
|
25305
|
-
} catch {
|
|
25306
|
-
return { success: false, error: `Could not read source file: ${sourceFile}` };
|
|
25307
|
-
}
|
|
25308
|
-
if (title) {
|
|
25309
|
-
content = replacePageTitle(content, title);
|
|
25310
|
-
}
|
|
25311
|
-
const newFilePath = `src/pages/${normalizedSlug}.astro`;
|
|
25312
|
-
const newFullPath = resolveAndValidatePath(newFilePath);
|
|
25313
|
-
try {
|
|
25314
|
-
await fs10.mkdir(path10.dirname(newFullPath), { recursive: true });
|
|
25315
|
-
await fs10.writeFile(newFullPath, content, { encoding: "utf-8", flag: "wx" });
|
|
25316
|
-
const url = normalizedSlug === "index" ? "/" : `/${normalizedSlug}`;
|
|
25317
|
-
return { success: true, filePath: newFilePath, slug: normalizedSlug, url };
|
|
25318
|
-
} catch (error) {
|
|
25319
|
-
if (isNodeError(error, "EEXIST")) {
|
|
25320
|
-
return { success: false, error: `Page already exists: ${newFilePath}` };
|
|
25321
|
-
}
|
|
25322
|
-
return { success: false, error: errorMessage(error) };
|
|
25323
|
-
}
|
|
25324
|
-
}
|
|
25325
|
-
async function handleDeletePage(request) {
|
|
25326
|
-
const { pagePath } = request;
|
|
25327
|
-
const pageFile = await findPageFile(pagePath);
|
|
25328
|
-
if (!pageFile) {
|
|
25329
|
-
return { success: false, error: `Page not found: ${pagePath}` };
|
|
25330
|
-
}
|
|
25331
|
-
try {
|
|
25332
|
-
await fs10.unlink(resolveAndValidatePath(pageFile));
|
|
25333
|
-
return { success: true, filePath: pageFile, url: pagePath };
|
|
25334
|
-
} catch (error) {
|
|
25335
|
-
if (isNodeError(error, "ENOENT")) {
|
|
25336
|
-
return { success: false, error: `File not found: ${pageFile}` };
|
|
25337
|
-
}
|
|
25338
|
-
return { success: false, error: errorMessage(error) };
|
|
25339
|
-
}
|
|
25340
|
-
}
|
|
25048
|
+
import fs8 from "fs/promises";
|
|
25341
25049
|
async function handleCheckSlugExists(slug) {
|
|
25342
|
-
const normalizedSlug =
|
|
25050
|
+
const normalizedSlug = slugify2(slug);
|
|
25343
25051
|
if (!normalizedSlug)
|
|
25344
25052
|
return { exists: false };
|
|
25345
25053
|
const found = await findPageFile(`/${normalizedSlug}`);
|
|
25346
25054
|
return found ? { exists: true, filePath: found } : { exists: false };
|
|
25347
25055
|
}
|
|
25348
|
-
async function handleGetLayouts() {
|
|
25349
|
-
const layoutsDir = path10.join(getProjectRoot(), "src", "layouts");
|
|
25350
|
-
let entries;
|
|
25351
|
-
try {
|
|
25352
|
-
entries = await fs10.readdir(layoutsDir, { withFileTypes: true });
|
|
25353
|
-
} catch {
|
|
25354
|
-
return [];
|
|
25355
|
-
}
|
|
25356
|
-
const layouts = [];
|
|
25357
|
-
for (const entry of entries) {
|
|
25358
|
-
if (entry.isFile() && entry.name.endsWith(".astro")) {
|
|
25359
|
-
layouts.push({
|
|
25360
|
-
name: path10.basename(entry.name, ".astro"),
|
|
25361
|
-
path: `src/layouts/${entry.name}`
|
|
25362
|
-
});
|
|
25363
|
-
}
|
|
25364
|
-
}
|
|
25365
|
-
return layouts.sort((a, b2) => a.name.localeCompare(b2.name));
|
|
25366
|
-
}
|
|
25367
|
-
function errorMessage(error) {
|
|
25368
|
-
return error instanceof Error ? error.message : String(error);
|
|
25369
|
-
}
|
|
25370
25056
|
async function fileExists(fullPath) {
|
|
25371
25057
|
try {
|
|
25372
|
-
await
|
|
25058
|
+
await fs8.access(fullPath);
|
|
25373
25059
|
return true;
|
|
25374
25060
|
} catch {
|
|
25375
25061
|
return false;
|
|
@@ -25389,203 +25075,12 @@ async function findPageFile(pagePath) {
|
|
|
25389
25075
|
}
|
|
25390
25076
|
return null;
|
|
25391
25077
|
}
|
|
25392
|
-
async function resolveLayoutImport(layoutPath) {
|
|
25393
|
-
if (layoutPath) {
|
|
25394
|
-
const name = path10.basename(layoutPath, ".astro");
|
|
25395
|
-
const importPath2 = `../${layoutPath.replace(/^src\//, "")}`;
|
|
25396
|
-
return { importPath: importPath2, componentName: pascalCase(name) };
|
|
25397
|
-
}
|
|
25398
|
-
const layouts = await handleGetLayouts();
|
|
25399
|
-
if (layouts.length === 0)
|
|
25400
|
-
return null;
|
|
25401
|
-
const layout = layouts[0];
|
|
25402
|
-
const importPath = `../${layout.path.replace(/^src\//, "")}`;
|
|
25403
|
-
return { importPath, componentName: pascalCase(layout.name) };
|
|
25404
|
-
}
|
|
25405
|
-
function pascalCase(name) {
|
|
25406
|
-
return name.replace(/(^|[-_])(\w)/g, (_2, _sep, char) => char.toUpperCase());
|
|
25407
|
-
}
|
|
25408
|
-
function generatePageContent(title, layoutImport) {
|
|
25409
|
-
const escapedTitle = title.replace(/'/g, "\\'").replace(/`/g, "\\`");
|
|
25410
|
-
const htmlTitle = escapeHtml(title);
|
|
25411
|
-
if (layoutImport) {
|
|
25412
|
-
const { importPath, componentName } = layoutImport;
|
|
25413
|
-
return `---
|
|
25414
|
-
import ${componentName} from '${importPath}'
|
|
25415
|
-
---
|
|
25416
|
-
|
|
25417
|
-
<${componentName} title="${escapedTitle}" description="">
|
|
25418
|
-
<main>
|
|
25419
|
-
<h1>${htmlTitle}</h1>
|
|
25420
|
-
</main>
|
|
25421
|
-
</${componentName}>
|
|
25422
|
-
`;
|
|
25423
|
-
}
|
|
25424
|
-
return `---
|
|
25425
|
-
|
|
25426
|
-
---
|
|
25427
|
-
|
|
25428
|
-
<html lang="en">
|
|
25429
|
-
<head>
|
|
25430
|
-
<meta charset="utf-8" />
|
|
25431
|
-
<meta name="viewport" content="width=device-width" />
|
|
25432
|
-
<title>${escapedTitle}</title>
|
|
25433
|
-
</head>
|
|
25434
|
-
<body>
|
|
25435
|
-
<main>
|
|
25436
|
-
<h1>${htmlTitle}</h1>
|
|
25437
|
-
</main>
|
|
25438
|
-
</body>
|
|
25439
|
-
</html>
|
|
25440
|
-
`;
|
|
25441
|
-
}
|
|
25442
|
-
function replacePageTitle(content, newTitle) {
|
|
25443
|
-
let result = content;
|
|
25444
|
-
result = result.replace(/(title\s*=\s*")([^"]*)(")/, `$1${newTitle}$3`);
|
|
25445
|
-
result = result.replace(/(<title>)([^<]*)(<\/title>)/, `$1${newTitle}$3`);
|
|
25446
|
-
result = result.replace(/(<h1[^>]*>)([^<]*)(<\/h1>)/, `$1${escapeHtml(newTitle)}$3`);
|
|
25447
|
-
return result;
|
|
25448
|
-
}
|
|
25449
25078
|
var PAGE_EXTENSIONS;
|
|
25450
|
-
var
|
|
25451
|
-
init_config();
|
|
25079
|
+
var init_page_ops2 = __esm(() => {
|
|
25452
25080
|
init_utils2();
|
|
25453
25081
|
PAGE_EXTENSIONS = [".astro", ".md", ".mdx"];
|
|
25454
25082
|
});
|
|
25455
25083
|
|
|
25456
|
-
// ../cms/src/handlers/redirect-ops.ts
|
|
25457
|
-
import fs11 from "fs/promises";
|
|
25458
|
-
import path11 from "path";
|
|
25459
|
-
function getRedirectsFilePath() {
|
|
25460
|
-
return path11.join(getProjectRoot(), REDIRECTS_FILE);
|
|
25461
|
-
}
|
|
25462
|
-
async function handleGetRedirects() {
|
|
25463
|
-
const lines = await readRedirectsFile(getRedirectsFilePath());
|
|
25464
|
-
return { rules: parseRedirectLines(lines) };
|
|
25465
|
-
}
|
|
25466
|
-
async function handleAddRedirect(request) {
|
|
25467
|
-
const { source, destination, statusCode = DEFAULT_STATUS_CODE } = request;
|
|
25468
|
-
if (!source || !destination) {
|
|
25469
|
-
return { success: false, error: "Source and destination are required" };
|
|
25470
|
-
}
|
|
25471
|
-
if (!source.startsWith("/")) {
|
|
25472
|
-
return { success: false, error: "Source must start with /" };
|
|
25473
|
-
}
|
|
25474
|
-
if (!destination.startsWith("/") && !destination.startsWith("http")) {
|
|
25475
|
-
return { success: false, error: "Destination must start with / or http" };
|
|
25476
|
-
}
|
|
25477
|
-
const filePath = getRedirectsFilePath();
|
|
25478
|
-
const release = await acquireFileLock(filePath);
|
|
25479
|
-
try {
|
|
25480
|
-
const lines = await readRedirectsFile(filePath);
|
|
25481
|
-
const existing = parseRedirectLines(lines);
|
|
25482
|
-
if (existing.some((r) => r.source === source)) {
|
|
25483
|
-
return { success: false, error: `Redirect already exists for ${source}` };
|
|
25484
|
-
}
|
|
25485
|
-
lines.push(formatRedirectLine(source, destination, statusCode));
|
|
25486
|
-
await writeRedirectsFile(filePath, lines);
|
|
25487
|
-
return { success: true };
|
|
25488
|
-
} finally {
|
|
25489
|
-
release();
|
|
25490
|
-
}
|
|
25491
|
-
}
|
|
25492
|
-
async function handleUpdateRedirect(request) {
|
|
25493
|
-
const { lineIndex, source, destination, statusCode = DEFAULT_STATUS_CODE } = request;
|
|
25494
|
-
if (!source || !destination) {
|
|
25495
|
-
return { success: false, error: "Source and destination are required" };
|
|
25496
|
-
}
|
|
25497
|
-
const filePath = getRedirectsFilePath();
|
|
25498
|
-
const release = await acquireFileLock(filePath);
|
|
25499
|
-
try {
|
|
25500
|
-
const lines = await readRedirectsFile(filePath);
|
|
25501
|
-
const currentLine = lines[lineIndex]?.trim();
|
|
25502
|
-
if (!currentLine || currentLine.startsWith("#")) {
|
|
25503
|
-
return { success: false, error: "Line at index is no longer a redirect rule \u2014 please refresh and try again" };
|
|
25504
|
-
}
|
|
25505
|
-
lines[lineIndex] = formatRedirectLine(source, destination, statusCode);
|
|
25506
|
-
await writeRedirectsFile(filePath, lines);
|
|
25507
|
-
return { success: true };
|
|
25508
|
-
} finally {
|
|
25509
|
-
release();
|
|
25510
|
-
}
|
|
25511
|
-
}
|
|
25512
|
-
async function handleDeleteRedirect(request) {
|
|
25513
|
-
const { lineIndex } = request;
|
|
25514
|
-
const filePath = getRedirectsFilePath();
|
|
25515
|
-
const release = await acquireFileLock(filePath);
|
|
25516
|
-
try {
|
|
25517
|
-
const lines = await readRedirectsFile(filePath);
|
|
25518
|
-
if (lineIndex < 0 || lineIndex >= lines.length) {
|
|
25519
|
-
return { success: false, error: `Invalid line index: ${lineIndex}` };
|
|
25520
|
-
}
|
|
25521
|
-
const line = lines[lineIndex].trim();
|
|
25522
|
-
if (!line || line.startsWith("#")) {
|
|
25523
|
-
return { success: false, error: "Line is not a redirect rule" };
|
|
25524
|
-
}
|
|
25525
|
-
lines.splice(lineIndex, 1);
|
|
25526
|
-
await writeRedirectsFile(filePath, lines);
|
|
25527
|
-
return { success: true };
|
|
25528
|
-
} finally {
|
|
25529
|
-
release();
|
|
25530
|
-
}
|
|
25531
|
-
}
|
|
25532
|
-
function formatRedirectLine(source, destination, statusCode) {
|
|
25533
|
-
return statusCode === DEFAULT_STATUS_CODE ? `${source} ${destination}` : `${source} ${destination} ${statusCode}`;
|
|
25534
|
-
}
|
|
25535
|
-
async function readRedirectsFile(filePath) {
|
|
25536
|
-
try {
|
|
25537
|
-
const content = await fs11.readFile(filePath, "utf-8");
|
|
25538
|
-
return content.split(`
|
|
25539
|
-
`);
|
|
25540
|
-
} catch (error) {
|
|
25541
|
-
if (isNodeError(error, "ENOENT"))
|
|
25542
|
-
return [];
|
|
25543
|
-
throw error;
|
|
25544
|
-
}
|
|
25545
|
-
}
|
|
25546
|
-
async function writeRedirectsFile(filePath, lines) {
|
|
25547
|
-
await fs11.mkdir(path11.dirname(filePath), { recursive: true });
|
|
25548
|
-
const trimmed = lines.slice();
|
|
25549
|
-
while (trimmed.length > 0 && trimmed[trimmed.length - 1].trim() === "") {
|
|
25550
|
-
trimmed.pop();
|
|
25551
|
-
}
|
|
25552
|
-
if (trimmed.length === 0) {
|
|
25553
|
-
await fs11.writeFile(filePath, "", "utf-8");
|
|
25554
|
-
return;
|
|
25555
|
-
}
|
|
25556
|
-
await fs11.writeFile(filePath, trimmed.join(`
|
|
25557
|
-
`) + `
|
|
25558
|
-
`, "utf-8");
|
|
25559
|
-
}
|
|
25560
|
-
function parseRedirectLines(lines) {
|
|
25561
|
-
const rules = [];
|
|
25562
|
-
for (let i = 0;i < lines.length; i++) {
|
|
25563
|
-
const line = lines[i].trim();
|
|
25564
|
-
if (!line || line.startsWith("#"))
|
|
25565
|
-
continue;
|
|
25566
|
-
const parts = line.split(/\s+/);
|
|
25567
|
-
if (parts.length < 2)
|
|
25568
|
-
continue;
|
|
25569
|
-
const source = parts[0];
|
|
25570
|
-
if (!source.startsWith("/"))
|
|
25571
|
-
continue;
|
|
25572
|
-
const destination = parts[1];
|
|
25573
|
-
const statusCode = parts[2] ? parseInt(parts[2], 10) : DEFAULT_STATUS_CODE;
|
|
25574
|
-
rules.push({
|
|
25575
|
-
source,
|
|
25576
|
-
destination,
|
|
25577
|
-
statusCode: Number.isNaN(statusCode) ? DEFAULT_STATUS_CODE : statusCode,
|
|
25578
|
-
lineIndex: i
|
|
25579
|
-
});
|
|
25580
|
-
}
|
|
25581
|
-
return rules;
|
|
25582
|
-
}
|
|
25583
|
-
var DEFAULT_STATUS_CODE = 307, REDIRECTS_FILE = "src/_redirects";
|
|
25584
|
-
var init_redirect_ops = __esm(() => {
|
|
25585
|
-
init_config();
|
|
25586
|
-
init_utils2();
|
|
25587
|
-
});
|
|
25588
|
-
|
|
25589
25084
|
// ../cms/src/handlers/request-utils.ts
|
|
25590
25085
|
function readBody(req, maxSize = MAX_BODY_SIZE) {
|
|
25591
25086
|
return new Promise((resolve, reject) => {
|
|
@@ -31264,23 +30759,23 @@ var require_dist2 = __commonJS((exports) => {
|
|
|
31264
30759
|
});
|
|
31265
30760
|
|
|
31266
30761
|
// ../cms/src/source-finder/collection-finder.ts
|
|
31267
|
-
var
|
|
30762
|
+
var import_yaml4;
|
|
31268
30763
|
var init_collection_finder = __esm(() => {
|
|
31269
30764
|
init_config();
|
|
31270
30765
|
init_cache();
|
|
31271
30766
|
init_snippet_utils();
|
|
31272
|
-
|
|
30767
|
+
import_yaml4 = __toESM(require_dist(), 1);
|
|
31273
30768
|
});
|
|
31274
30769
|
|
|
31275
30770
|
// ../cms/src/source-finder/search-index.ts
|
|
31276
|
-
var
|
|
30771
|
+
var import_parser7, I18N_DIR_NAMES;
|
|
31277
30772
|
var init_search_index = __esm(() => {
|
|
31278
30773
|
init_config();
|
|
31279
30774
|
init_utils2();
|
|
31280
30775
|
init_ast_parser();
|
|
31281
30776
|
init_cache();
|
|
31282
30777
|
init_snippet_utils();
|
|
31283
|
-
|
|
30778
|
+
import_parser7 = __toESM(require_lib(), 1);
|
|
31284
30779
|
I18N_DIR_NAMES = new Set(["i18n", "locales", "locale", "translations", "dictionaries"]);
|
|
31285
30780
|
});
|
|
31286
30781
|
|
|
@@ -31327,7 +30822,7 @@ function extractAstroImageOriginalUrl(src) {
|
|
|
31327
30822
|
} catch {}
|
|
31328
30823
|
return;
|
|
31329
30824
|
}
|
|
31330
|
-
var
|
|
30825
|
+
var import_yaml5;
|
|
31331
30826
|
var init_snippet_utils = __esm(() => {
|
|
31332
30827
|
init_astro_image_paths();
|
|
31333
30828
|
init_config();
|
|
@@ -31337,12 +30832,12 @@ var init_snippet_utils = __esm(() => {
|
|
|
31337
30832
|
init_cross_file_tracker();
|
|
31338
30833
|
init_image_finder();
|
|
31339
30834
|
init_search_index();
|
|
31340
|
-
|
|
30835
|
+
import_yaml5 = __toESM(require_dist(), 1);
|
|
31341
30836
|
});
|
|
31342
30837
|
|
|
31343
30838
|
// ../cms/src/handlers/source-writer.ts
|
|
31344
|
-
import
|
|
31345
|
-
import
|
|
30839
|
+
import fs9 from "fs/promises";
|
|
30840
|
+
import path8 from "path";
|
|
31346
30841
|
async function handleUpdate(request, manifestWriter) {
|
|
31347
30842
|
const { changes, meta } = request;
|
|
31348
30843
|
const errors = [];
|
|
@@ -31372,25 +30867,25 @@ async function handleUpdate(request, manifestWriter) {
|
|
|
31372
30867
|
const fullPath = resolveAndValidatePath(filePath);
|
|
31373
30868
|
const release = await acquireFileLock(fullPath);
|
|
31374
30869
|
try {
|
|
31375
|
-
const currentContent = await
|
|
30870
|
+
const currentContent = await fs9.readFile(fullPath, "utf-8");
|
|
31376
30871
|
const { newContent, appliedCount, failedChanges, fileOps } = await applyChanges(currentContent, fileChanges, manifest, fullPath, meta.url);
|
|
31377
30872
|
if (failedChanges.length > 0) {
|
|
31378
30873
|
errors.push(...failedChanges);
|
|
31379
30874
|
}
|
|
31380
30875
|
if (appliedCount > 0 && newContent !== currentContent) {
|
|
31381
30876
|
for (const op of fileOps) {
|
|
31382
|
-
await
|
|
31383
|
-
await
|
|
30877
|
+
await fs9.mkdir(path8.dirname(op.target), { recursive: true });
|
|
30878
|
+
await fs9.writeFile(op.target, op.bytes);
|
|
31384
30879
|
}
|
|
31385
|
-
await
|
|
30880
|
+
await fs9.writeFile(fullPath, newContent, "utf-8");
|
|
31386
30881
|
updated += appliedCount;
|
|
31387
30882
|
}
|
|
31388
30883
|
} finally {
|
|
31389
30884
|
release();
|
|
31390
30885
|
}
|
|
31391
30886
|
} catch (error) {
|
|
31392
|
-
const
|
|
31393
|
-
errors.push(...fileChanges.map((c) => ({ cmsId: c.cmsId, error:
|
|
30887
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
30888
|
+
errors.push(...fileChanges.map((c) => ({ cmsId: c.cmsId, error: errorMessage })));
|
|
31394
30889
|
}
|
|
31395
30890
|
}
|
|
31396
30891
|
return {
|
|
@@ -31475,7 +30970,7 @@ async function applyImageChange(content, change, absFilePath, originUrl) {
|
|
|
31475
30970
|
const yamlKeyMatch = change.sourceSnippet.match(/^\s*([\w][\w-]*):\s*/);
|
|
31476
30971
|
if (yamlKeyMatch?.[1]) {
|
|
31477
30972
|
try {
|
|
31478
|
-
const parsed =
|
|
30973
|
+
const parsed = import_yaml6.parse(change.sourceSnippet);
|
|
31479
30974
|
if (parsed && typeof parsed === "object") {
|
|
31480
30975
|
const value = parsed[yamlKeyMatch[1]];
|
|
31481
30976
|
if (typeof value === "string" && !srcCandidates.includes(value)) {
|
|
@@ -31645,9 +31140,9 @@ async function tryRewriteAssetImport(content, importInfo, newSrc, absFilePath, o
|
|
|
31645
31140
|
const resolved = await resolveNewSrcBytes(newSrc, originUrl);
|
|
31646
31141
|
if (!resolved)
|
|
31647
31142
|
return null;
|
|
31648
|
-
const originalAssetAbs =
|
|
31649
|
-
const targetAbs = await pickSiblingTarget(
|
|
31650
|
-
const newRelImport =
|
|
31143
|
+
const originalAssetAbs = path8.resolve(path8.dirname(absFilePath), importInfo.source);
|
|
31144
|
+
const targetAbs = await pickSiblingTarget(path8.dirname(originalAssetAbs), resolved.filename, resolved.bytes);
|
|
31145
|
+
const newRelImport = relativeImportPath2(absFilePath, targetAbs);
|
|
31651
31146
|
const newContent = content.slice(0, importInfo.sourceStart) + newRelImport + content.slice(importInfo.sourceEnd);
|
|
31652
31147
|
return {
|
|
31653
31148
|
content: newContent,
|
|
@@ -31656,11 +31151,11 @@ async function tryRewriteAssetImport(content, importInfo, newSrc, absFilePath, o
|
|
|
31656
31151
|
};
|
|
31657
31152
|
}
|
|
31658
31153
|
async function resolveNewSrcBytes(newSrc, originUrl) {
|
|
31659
|
-
const filenameFromPath = (p) =>
|
|
31660
|
-
const diskPath = newSrc.startsWith("/src/") ?
|
|
31154
|
+
const filenameFromPath = (p) => path8.basename(p.split("?")[0] ?? p);
|
|
31155
|
+
const diskPath = newSrc.startsWith("/src/") ? path8.join(getProjectRoot(), newSrc.slice(1)) : newSrc.startsWith("/") && !newSrc.startsWith("//") ? path8.join(getProjectRoot(), "public", newSrc.replace(/^\/+/, "")) : null;
|
|
31661
31156
|
if (diskPath) {
|
|
31662
31157
|
try {
|
|
31663
|
-
return { bytes: await
|
|
31158
|
+
return { bytes: await fs9.readFile(diskPath), filename: filenameFromPath(newSrc) };
|
|
31664
31159
|
} catch {}
|
|
31665
31160
|
}
|
|
31666
31161
|
try {
|
|
@@ -32092,7 +31587,7 @@ function tryYamlValueReplacement(sourceSnippet, resolvedOriginal, resolvedNewTex
|
|
|
32092
31587
|
if (!keyMatch)
|
|
32093
31588
|
return null;
|
|
32094
31589
|
try {
|
|
32095
|
-
const parsed =
|
|
31590
|
+
const parsed = import_yaml6.parse(sourceSnippet);
|
|
32096
31591
|
if (parsed == null || typeof parsed !== "object")
|
|
32097
31592
|
return null;
|
|
32098
31593
|
const value = parsed[keyMatch[2]];
|
|
@@ -32103,7 +31598,7 @@ function tryYamlValueReplacement(sourceSnippet, resolvedOriginal, resolvedNewTex
|
|
|
32103
31598
|
} catch {
|
|
32104
31599
|
return null;
|
|
32105
31600
|
}
|
|
32106
|
-
const serialized =
|
|
31601
|
+
const serialized = import_yaml6.stringify(resolvedNewText, { lineWidth: 0 }).trimEnd();
|
|
32107
31602
|
return `${keyMatch[1]}${serialized}`;
|
|
32108
31603
|
}
|
|
32109
31604
|
function tryDataFileValueReplacement(content, sourceSnippet, originalValue, newValue, sourceLine) {
|
|
@@ -32191,21 +31686,21 @@ function tryBrNormalizedChange(sourceSnippet, resolvedOriginal, resolvedNewText)
|
|
|
32191
31686
|
}
|
|
32192
31687
|
return result !== sourceSnippet ? result : null;
|
|
32193
31688
|
}
|
|
32194
|
-
var import_node_html_parser,
|
|
31689
|
+
var import_node_html_parser, import_yaml6, ASSET_IMPORT_EXT_RE, REMOTE_FETCH_TIMEOUT_MS = 15000, REMOTE_FETCH_MAX_BYTES, QUOTED_LITERAL_DELIMITERS;
|
|
32195
31690
|
var init_source_writer = __esm(() => {
|
|
32196
31691
|
init_astro_image_paths();
|
|
32197
31692
|
init_config();
|
|
32198
31693
|
init_snippet_utils();
|
|
32199
31694
|
init_utils2();
|
|
32200
31695
|
import_node_html_parser = __toESM(require_dist2(), 1);
|
|
32201
|
-
|
|
31696
|
+
import_yaml6 = __toESM(require_dist(), 1);
|
|
32202
31697
|
ASSET_IMPORT_EXT_RE = /\.(jpe?g|png|gif|webp|avif|svg|ico|bmp|tiff?)$/i;
|
|
32203
31698
|
REMOTE_FETCH_MAX_BYTES = 50 * 1024 * 1024;
|
|
32204
31699
|
QUOTED_LITERAL_DELIMITERS = [`'`, `"`, "`"];
|
|
32205
31700
|
});
|
|
32206
31701
|
|
|
32207
31702
|
// ../cms/src/handlers/api-routes.ts
|
|
32208
|
-
import
|
|
31703
|
+
import path9 from "path";
|
|
32209
31704
|
function requireMedia(ctx) {
|
|
32210
31705
|
if (!ctx.mediaAdapter) {
|
|
32211
31706
|
sendError(ctx.res, "Media storage not configured", 501);
|
|
@@ -32216,39 +31711,66 @@ function requireMedia(ctx) {
|
|
|
32216
31711
|
function getQuery(ctx) {
|
|
32217
31712
|
return new URL(ctx.req.url, `http://${ctx.req.headers.host}`).searchParams;
|
|
32218
31713
|
}
|
|
31714
|
+
function filePathToEntry(contentDir, filePath) {
|
|
31715
|
+
const normalized = filePath.replace(/^\/+/, "");
|
|
31716
|
+
const prefix = `${contentDir.replace(/\/+$/, "")}/`;
|
|
31717
|
+
if (!normalized.startsWith(prefix))
|
|
31718
|
+
return null;
|
|
31719
|
+
const rel = normalized.slice(prefix.length);
|
|
31720
|
+
const firstSlash = rel.indexOf("/");
|
|
31721
|
+
if (firstSlash < 0)
|
|
31722
|
+
return null;
|
|
31723
|
+
const collection = rel.slice(0, firstSlash);
|
|
31724
|
+
const entryPath = rel.slice(firstSlash + 1);
|
|
31725
|
+
if (!collection || !entryPath)
|
|
31726
|
+
return null;
|
|
31727
|
+
const withoutExt = entryPath.replace(/\.(md|mdx|json|yaml|yml)$/, "");
|
|
31728
|
+
const slug = withoutExt.replace(/\/index$/, "");
|
|
31729
|
+
if (!slug)
|
|
31730
|
+
return null;
|
|
31731
|
+
return { collection, slug };
|
|
31732
|
+
}
|
|
32219
31733
|
function post(route, handler) {
|
|
32220
31734
|
return [`POST:${route}`, async ({ req, res, manifestWriter }) => {
|
|
32221
31735
|
const body = await parseJsonBody(req);
|
|
32222
31736
|
sendJson(res, await handler(body, manifestWriter));
|
|
32223
31737
|
}];
|
|
32224
31738
|
}
|
|
32225
|
-
function
|
|
32226
|
-
return [`POST:${route}`, async ({ req, res }) => {
|
|
31739
|
+
function postCore(route, handler) {
|
|
31740
|
+
return [`POST:${route}`, async ({ req, res, core }) => {
|
|
32227
31741
|
const body = await parseJsonBody(req);
|
|
32228
|
-
const result = await handler(body);
|
|
31742
|
+
const result = await handler(body, core);
|
|
32229
31743
|
sendJson(res, result, result.success ? 200 : 400);
|
|
32230
31744
|
}];
|
|
32231
31745
|
}
|
|
31746
|
+
function getCore(route, handler) {
|
|
31747
|
+
return [`GET:${route}`, async ({ res, core }) => {
|
|
31748
|
+
sendJson(res, await handler(core));
|
|
31749
|
+
}];
|
|
31750
|
+
}
|
|
31751
|
+
function custom(method, route, handler) {
|
|
31752
|
+
return [`${method}:${route}`, handler];
|
|
31753
|
+
}
|
|
32232
31754
|
function get(route, handler) {
|
|
32233
31755
|
return [`GET:${route}`, async ({ res }) => {
|
|
32234
31756
|
sendJson(res, await handler());
|
|
32235
31757
|
}];
|
|
32236
31758
|
}
|
|
32237
|
-
function
|
|
32238
|
-
|
|
31759
|
+
function lastSlug(sourcePath) {
|
|
31760
|
+
const withoutExt = sourcePath.replace(/\.(md|mdx|json|yaml|yml)$/, "").replace(/\/index$/, "");
|
|
31761
|
+
const slash = withoutExt.lastIndexOf("/");
|
|
31762
|
+
return slash >= 0 ? withoutExt.slice(slash + 1) : withoutExt;
|
|
32239
31763
|
}
|
|
32240
|
-
var ALLOWED_UPLOAD_TYPES, routeMap;
|
|
31764
|
+
var ALLOWED_UPLOAD_TYPES, DATA_EXTENSIONS, routeMap;
|
|
32241
31765
|
var init_api_routes = __esm(() => {
|
|
32242
|
-
|
|
31766
|
+
init_src2();
|
|
31767
|
+
init_collection_scanner2();
|
|
32243
31768
|
init_config();
|
|
32244
31769
|
init_dev_middleware();
|
|
32245
|
-
init_project_images();
|
|
32246
31770
|
init_array_ops();
|
|
32247
31771
|
init_astro_image_upload();
|
|
32248
31772
|
init_component_ops();
|
|
32249
|
-
|
|
32250
|
-
init_page_ops();
|
|
32251
|
-
init_redirect_ops();
|
|
31773
|
+
init_page_ops2();
|
|
32252
31774
|
init_request_utils();
|
|
32253
31775
|
init_source_writer();
|
|
32254
31776
|
ALLOWED_UPLOAD_TYPES = new Set([
|
|
@@ -32260,50 +31782,96 @@ var init_api_routes = __esm(() => {
|
|
|
32260
31782
|
"image/x-icon",
|
|
32261
31783
|
"application/pdf"
|
|
32262
31784
|
]);
|
|
31785
|
+
DATA_EXTENSIONS = new Set(["json", "yaml", "yml"]);
|
|
32263
31786
|
routeMap = new Map([
|
|
32264
31787
|
post("update", (body, mw) => handleUpdate(body, mw)),
|
|
32265
31788
|
post("insert-component", (body, mw) => handleInsertComponent(body, mw)),
|
|
32266
31789
|
post("remove-component", (body, mw) => handleRemoveComponent(body, mw)),
|
|
32267
31790
|
post("add-array-item", (body, mw) => handleAddArrayItem(body, mw)),
|
|
32268
31791
|
post("remove-array-item", (body, mw) => handleRemoveArrayItem(body, mw)),
|
|
32269
|
-
custom("GET", "markdown/content", async ({ req, res }) => {
|
|
31792
|
+
custom("GET", "markdown/content", async ({ req, res, core, contentDir }) => {
|
|
32270
31793
|
const filePath = getQuery({ req }).get("filePath");
|
|
32271
31794
|
if (!filePath) {
|
|
32272
31795
|
sendError(res, "filePath query parameter required");
|
|
32273
31796
|
return;
|
|
32274
31797
|
}
|
|
32275
|
-
const
|
|
31798
|
+
const entry = filePathToEntry(contentDir, filePath);
|
|
31799
|
+
const result = entry ? await core.getEntry(entry.collection, entry.slug) : null;
|
|
32276
31800
|
if (!result) {
|
|
32277
31801
|
sendError(res, "File not found", 404);
|
|
32278
31802
|
return;
|
|
32279
31803
|
}
|
|
32280
|
-
sendJson(res, result);
|
|
31804
|
+
sendJson(res, { content: result.content, frontmatter: result.frontmatter, filePath });
|
|
32281
31805
|
}),
|
|
32282
|
-
custom("POST", "markdown/update", async ({ req, res,
|
|
31806
|
+
custom("POST", "markdown/update", async ({ req, res, core, contentDir }) => {
|
|
32283
31807
|
const body = await parseJsonBody(req);
|
|
32284
|
-
const
|
|
32285
|
-
|
|
31808
|
+
const entry = filePathToEntry(contentDir, body.filePath);
|
|
31809
|
+
if (!entry) {
|
|
31810
|
+
sendJson(res, { success: false, error: `Invalid content path: ${body.filePath}` });
|
|
31811
|
+
return;
|
|
31812
|
+
}
|
|
31813
|
+
const result = await core.updateEntry({
|
|
31814
|
+
collection: entry.collection,
|
|
31815
|
+
slug: entry.slug,
|
|
31816
|
+
frontmatter: body.frontmatter,
|
|
31817
|
+
body: body.content
|
|
31818
|
+
});
|
|
31819
|
+
sendJson(res, { success: result.success, ...result.error ? { error: result.error } : {} });
|
|
32286
31820
|
}),
|
|
32287
|
-
|
|
32288
|
-
custom("POST", "markdown/create", async ({ req, res, manifestWriter, contentDir }) => {
|
|
31821
|
+
custom("POST", "markdown/rename", async ({ req, res, core, contentDir }) => {
|
|
32289
31822
|
const body = await parseJsonBody(req);
|
|
32290
|
-
const
|
|
32291
|
-
if (
|
|
32292
|
-
|
|
31823
|
+
const entry = filePathToEntry(contentDir, body.filePath);
|
|
31824
|
+
if (!entry) {
|
|
31825
|
+
sendJson(res, { success: false, error: `Invalid content path: ${body.filePath}` });
|
|
31826
|
+
return;
|
|
32293
31827
|
}
|
|
32294
|
-
|
|
31828
|
+
const result = await core.renameEntry(entry.collection, entry.slug, body.newSlug);
|
|
31829
|
+
if (!result.success) {
|
|
31830
|
+
sendJson(res, { success: false, error: result.error });
|
|
31831
|
+
return;
|
|
31832
|
+
}
|
|
31833
|
+
const newSlug = result.sourcePath ? lastSlug(result.sourcePath) : undefined;
|
|
31834
|
+
sendJson(res, { success: true, newFilePath: result.sourcePath, newSlug });
|
|
32295
31835
|
}),
|
|
32296
|
-
custom("POST", "markdown/
|
|
31836
|
+
custom("POST", "markdown/create", async ({ req, res, core, manifestWriter, contentDir }) => {
|
|
32297
31837
|
const body = await parseJsonBody(req);
|
|
32298
|
-
const
|
|
31838
|
+
const ext = body.fileExtension ?? "md";
|
|
31839
|
+
const isData = DATA_EXTENSIONS.has(ext);
|
|
31840
|
+
const frontmatter = isData ? { ...body.frontmatter ?? {} } : { title: body.title, date: new Date().toISOString().split("T")[0], ...body.frontmatter ?? {} };
|
|
31841
|
+
const result = await core.createEntry({
|
|
31842
|
+
collection: body.collection,
|
|
31843
|
+
slug: body.slug || body.title,
|
|
31844
|
+
frontmatter,
|
|
31845
|
+
body: body.content,
|
|
31846
|
+
fileExtension: body.fileExtension
|
|
31847
|
+
});
|
|
31848
|
+
if (result.success) {
|
|
31849
|
+
manifestWriter.setCollectionDefinitions(await scanCollections2(contentDir));
|
|
31850
|
+
}
|
|
31851
|
+
const slug = result.sourcePath ? lastSlug(result.sourcePath) : undefined;
|
|
31852
|
+
sendJson(res, {
|
|
31853
|
+
success: result.success,
|
|
31854
|
+
...result.sourcePath ? { filePath: result.sourcePath } : {},
|
|
31855
|
+
...slug ? { slug } : {},
|
|
31856
|
+
...result.error ? { error: result.error } : {}
|
|
31857
|
+
}, result.success ? 200 : 400);
|
|
31858
|
+
}),
|
|
31859
|
+
custom("POST", "markdown/delete", async ({ req, res, core, manifestWriter, contentDir }) => {
|
|
31860
|
+
const body = await parseJsonBody(req);
|
|
31861
|
+
const entry = filePathToEntry(contentDir, body.filePath);
|
|
31862
|
+
if (!entry) {
|
|
31863
|
+
sendJson(res, { success: false, error: `Invalid content path: ${body.filePath}` }, 400);
|
|
31864
|
+
return;
|
|
31865
|
+
}
|
|
31866
|
+
const fullPath = path9.resolve(getProjectRoot(), body.filePath.replace(/^\//, ""));
|
|
32299
31867
|
expectedDeletions.add(fullPath);
|
|
32300
|
-
const result = await
|
|
31868
|
+
const result = await core.deleteEntry(entry.collection, entry.slug);
|
|
32301
31869
|
if (result.success) {
|
|
32302
|
-
manifestWriter.setCollectionDefinitions(await
|
|
31870
|
+
manifestWriter.setCollectionDefinitions(await scanCollections2(contentDir));
|
|
32303
31871
|
} else {
|
|
32304
31872
|
expectedDeletions.delete(fullPath);
|
|
32305
31873
|
}
|
|
32306
|
-
sendJson(res, result, result.success ? 200 : 400);
|
|
31874
|
+
sendJson(res, { success: result.success, ...result.error ? { error: result.error } : {} }, result.success ? 200 : 400);
|
|
32307
31875
|
}),
|
|
32308
31876
|
custom("GET", "media/list", async (ctx) => {
|
|
32309
31877
|
if (!requireMedia(ctx))
|
|
@@ -32316,7 +31884,7 @@ var init_api_routes = __esm(() => {
|
|
|
32316
31884
|
}),
|
|
32317
31885
|
custom("GET", "media/project-images", async (ctx) => {
|
|
32318
31886
|
const excludeDir = ctx.mediaAdapter?.staticFiles?.dir;
|
|
32319
|
-
const items = await listProjectImages({ excludeDir });
|
|
31887
|
+
const items = await listProjectImages(ctx.fs, { excludeDir });
|
|
32320
31888
|
sendJson(ctx.res, { items });
|
|
32321
31889
|
}),
|
|
32322
31890
|
custom("POST", "media/upload", async (ctx) => {
|
|
@@ -32390,23 +31958,23 @@ var init_api_routes = __esm(() => {
|
|
|
32390
31958
|
const result = await ctx.mediaAdapter.createFolder(body.folder);
|
|
32391
31959
|
sendJson(ctx.res, result, result.success ? 200 : 400);
|
|
32392
31960
|
}),
|
|
32393
|
-
|
|
32394
|
-
custom("POST", "page/duplicate", async ({ req, res }) => {
|
|
31961
|
+
postCore("page/create", (body, core) => core.createPage(body)),
|
|
31962
|
+
custom("POST", "page/duplicate", async ({ req, res, core }) => {
|
|
32395
31963
|
const body = await parseJsonBody(req);
|
|
32396
|
-
const result = await
|
|
31964
|
+
const result = await core.duplicatePage(body);
|
|
32397
31965
|
if (result.success && body.createRedirect) {
|
|
32398
|
-
await
|
|
31966
|
+
await core.addRedirect({ source: body.sourcePagePath, destination: result.url, statusCode: 307 });
|
|
32399
31967
|
}
|
|
32400
31968
|
sendJson(res, result, result.success ? 200 : 400);
|
|
32401
31969
|
}),
|
|
32402
|
-
custom("POST", "page/delete", async ({ req, res }) => {
|
|
31970
|
+
custom("POST", "page/delete", async ({ req, res, core }) => {
|
|
32403
31971
|
const body = await parseJsonBody(req);
|
|
32404
|
-
const result = await
|
|
31972
|
+
const result = await core.deletePage(body);
|
|
32405
31973
|
if (result.success && result.filePath) {
|
|
32406
|
-
expectedDeletions.add(
|
|
31974
|
+
expectedDeletions.add(path9.resolve(getProjectRoot(), result.filePath));
|
|
32407
31975
|
}
|
|
32408
31976
|
if (result.success && body.createRedirect && body.redirectTo) {
|
|
32409
|
-
await
|
|
31977
|
+
await core.addRedirect({ source: body.pagePath, destination: body.redirectTo, statusCode: 307 });
|
|
32410
31978
|
}
|
|
32411
31979
|
sendJson(res, result, result.success ? 200 : 400);
|
|
32412
31980
|
}),
|
|
@@ -32418,11 +31986,11 @@ var init_api_routes = __esm(() => {
|
|
|
32418
31986
|
}
|
|
32419
31987
|
sendJson(ctx.res, await handleCheckSlugExists(slug));
|
|
32420
31988
|
}),
|
|
32421
|
-
|
|
32422
|
-
|
|
32423
|
-
|
|
32424
|
-
|
|
32425
|
-
|
|
31989
|
+
getCore("page/layouts", async (core) => ({ layouts: await core.getLayouts() })),
|
|
31990
|
+
getCore("redirects", (core) => core.listRedirects()),
|
|
31991
|
+
postCore("redirects/add", (body, core) => core.addRedirect(body)),
|
|
31992
|
+
postCore("redirects/update", (body, core) => core.updateRedirect(body)),
|
|
31993
|
+
postCore("redirects/delete", (body, core) => core.deleteRedirect(body)),
|
|
32426
31994
|
get("deployment/status", async () => ({ currentDeployment: null, pendingCount: 0, deploymentEnabled: false }))
|
|
32427
31995
|
]);
|
|
32428
31996
|
});
|
|
@@ -32507,8 +32075,8 @@ var init_color_patterns = __esm(() => {
|
|
|
32507
32075
|
});
|
|
32508
32076
|
|
|
32509
32077
|
// ../cms/src/tailwind-colors.ts
|
|
32510
|
-
import
|
|
32511
|
-
import
|
|
32078
|
+
import fs10 from "fs/promises";
|
|
32079
|
+
import path10 from "path";
|
|
32512
32080
|
async function parseTailwindConfig(projectRoot = getProjectRoot()) {
|
|
32513
32081
|
const cssFiles = [
|
|
32514
32082
|
"src/styles/global.css",
|
|
@@ -32522,9 +32090,9 @@ async function parseTailwindConfig(projectRoot = getProjectRoot()) {
|
|
|
32522
32090
|
];
|
|
32523
32091
|
let customColors = [];
|
|
32524
32092
|
for (const cssFile of cssFiles) {
|
|
32525
|
-
const fullPath =
|
|
32093
|
+
const fullPath = path10.join(projectRoot, cssFile);
|
|
32526
32094
|
try {
|
|
32527
|
-
const content = await
|
|
32095
|
+
const content = await fs10.readFile(fullPath, "utf-8");
|
|
32528
32096
|
customColors = extractColorsFromCss(content);
|
|
32529
32097
|
if (customColors.length > 0) {
|
|
32530
32098
|
break;
|
|
@@ -32595,9 +32163,9 @@ async function parseTextStyles(projectRoot = getProjectRoot()) {
|
|
|
32595
32163
|
];
|
|
32596
32164
|
let customTextStyles = {};
|
|
32597
32165
|
for (const cssFile of cssFiles) {
|
|
32598
|
-
const fullPath =
|
|
32166
|
+
const fullPath = path10.join(projectRoot, cssFile);
|
|
32599
32167
|
try {
|
|
32600
|
-
const content = await
|
|
32168
|
+
const content = await fs10.readFile(fullPath, "utf-8");
|
|
32601
32169
|
customTextStyles = extractTextStylesFromCss(content);
|
|
32602
32170
|
if (Object.values(customTextStyles).some((arr) => arr && arr.length > 0)) {
|
|
32603
32171
|
break;
|
|
@@ -33039,6 +32607,7 @@ var init_source_finder = __esm(() => {
|
|
|
33039
32607
|
// ../cms/src/dev-middleware.ts
|
|
33040
32608
|
var expectedDeletions, PAGE_EXTENSIONS2;
|
|
33041
32609
|
var init_dev_middleware = __esm(() => {
|
|
32610
|
+
init_src2();
|
|
33042
32611
|
init_config();
|
|
33043
32612
|
init_api_routes();
|
|
33044
32613
|
init_array_ops();
|
|
@@ -33051,9 +32620,60 @@ var init_dev_middleware = __esm(() => {
|
|
|
33051
32620
|
PAGE_EXTENSIONS2 = new Set([".astro", ".md", ".mdx"]);
|
|
33052
32621
|
});
|
|
33053
32622
|
|
|
32623
|
+
// ../cms-sidecar/src/concurrency.ts
|
|
32624
|
+
class KeyedMutex {
|
|
32625
|
+
tails = new Map;
|
|
32626
|
+
async runExclusive(key, task) {
|
|
32627
|
+
const previous = this.tails.get(key) ?? Promise.resolve();
|
|
32628
|
+
const run = previous.then(() => task(), () => task());
|
|
32629
|
+
this.tails.set(key, run);
|
|
32630
|
+
try {
|
|
32631
|
+
return await run;
|
|
32632
|
+
} finally {
|
|
32633
|
+
if (this.tails.get(key) === run) {
|
|
32634
|
+
this.tails.delete(key);
|
|
32635
|
+
}
|
|
32636
|
+
}
|
|
32637
|
+
}
|
|
32638
|
+
}
|
|
32639
|
+
var init_concurrency = () => {};
|
|
32640
|
+
|
|
32641
|
+
// ../cms-sidecar/src/media-from-env.ts
|
|
32642
|
+
var init_media_from_env = __esm(() => {
|
|
32643
|
+
init_src2();
|
|
32644
|
+
});
|
|
32645
|
+
|
|
32646
|
+
// ../cms-sidecar/src/types.ts
|
|
32647
|
+
var init_types = () => {};
|
|
32648
|
+
|
|
32649
|
+
// ../cms-sidecar/src/server.ts
|
|
32650
|
+
var init_server = __esm(() => {
|
|
32651
|
+
init_concurrency();
|
|
32652
|
+
init_types();
|
|
32653
|
+
});
|
|
32654
|
+
|
|
32655
|
+
// ../cms-sidecar/src/index.ts
|
|
32656
|
+
var init_src3 = __esm(() => {
|
|
32657
|
+
init_src();
|
|
32658
|
+
init_concurrency();
|
|
32659
|
+
init_media_from_env();
|
|
32660
|
+
init_server();
|
|
32661
|
+
init_types();
|
|
32662
|
+
});
|
|
32663
|
+
|
|
32664
|
+
// ../cms/src/local-admin.ts
|
|
32665
|
+
var ADMIN_API_PREFIX = "/_nua/cms-admin-api", ADMIN_API_BASE;
|
|
32666
|
+
var init_local_admin = __esm(() => {
|
|
32667
|
+
init_src2();
|
|
32668
|
+
init_src3();
|
|
32669
|
+
init_config();
|
|
32670
|
+
init_request_utils();
|
|
32671
|
+
ADMIN_API_BASE = `${ADMIN_API_PREFIX}/cms/v1`;
|
|
32672
|
+
});
|
|
32673
|
+
|
|
33054
32674
|
// ../cms/src/manifest-writer.ts
|
|
33055
|
-
import
|
|
33056
|
-
import
|
|
32675
|
+
import fs11 from "fs/promises";
|
|
32676
|
+
import path11 from "path";
|
|
33057
32677
|
|
|
33058
32678
|
class ManifestWriter {
|
|
33059
32679
|
globalManifest;
|
|
@@ -33124,10 +32744,10 @@ class ManifestWriter {
|
|
|
33124
32744
|
}
|
|
33125
32745
|
getPageManifestPath(pagePath) {
|
|
33126
32746
|
if (pagePath === "/" || pagePath === "") {
|
|
33127
|
-
return
|
|
32747
|
+
return path11.join(this.outDir, "index.json");
|
|
33128
32748
|
}
|
|
33129
32749
|
const cleanPath = pagePath.replace(/^\//, "");
|
|
33130
|
-
return
|
|
32750
|
+
return path11.join(this.outDir, `${cleanPath}.json`);
|
|
33131
32751
|
}
|
|
33132
32752
|
addPage(pagePath, entries, components, collection, seo) {
|
|
33133
32753
|
this.pageManifests.set(pagePath, { entries, components, collection, seo });
|
|
@@ -33153,8 +32773,8 @@ class ManifestWriter {
|
|
|
33153
32773
|
}
|
|
33154
32774
|
async writePageManifest(pagePath, entries, components, collection, seo) {
|
|
33155
32775
|
const manifestPath = this.getPageManifestPath(pagePath);
|
|
33156
|
-
const manifestDir =
|
|
33157
|
-
await
|
|
32776
|
+
const manifestDir = path11.dirname(manifestPath);
|
|
32777
|
+
await fs11.mkdir(manifestDir, { recursive: true });
|
|
33158
32778
|
const metadata = {
|
|
33159
32779
|
version: MANIFEST_VERSION,
|
|
33160
32780
|
generatedAt: new Date().toISOString(),
|
|
@@ -33175,7 +32795,7 @@ class ManifestWriter {
|
|
|
33175
32795
|
if (seo) {
|
|
33176
32796
|
pageManifest.seo = seo;
|
|
33177
32797
|
}
|
|
33178
|
-
await
|
|
32798
|
+
await fs11.writeFile(manifestPath, JSON.stringify(pageManifest, null, 2), "utf-8");
|
|
33179
32799
|
}
|
|
33180
32800
|
async finalize() {
|
|
33181
32801
|
await this.writeQueue;
|
|
@@ -33204,7 +32824,7 @@ class ManifestWriter {
|
|
|
33204
32824
|
}
|
|
33205
32825
|
}
|
|
33206
32826
|
if (this.outDir) {
|
|
33207
|
-
const globalManifestPath =
|
|
32827
|
+
const globalManifestPath = path11.join(this.outDir, this.manifestFile);
|
|
33208
32828
|
const globalSettings = {
|
|
33209
32829
|
componentDefinitions: this.componentDefinitions,
|
|
33210
32830
|
pages
|
|
@@ -33218,7 +32838,7 @@ class ManifestWriter {
|
|
|
33218
32838
|
if (this.availableTextStyles) {
|
|
33219
32839
|
globalSettings.availableTextStyles = this.availableTextStyles;
|
|
33220
32840
|
}
|
|
33221
|
-
await
|
|
32841
|
+
await fs11.writeFile(globalManifestPath, JSON.stringify(globalSettings, null, 2), "utf-8");
|
|
33222
32842
|
}
|
|
33223
32843
|
return {
|
|
33224
32844
|
totalEntries: Object.keys(this.globalManifest.entries).length,
|
|
@@ -33271,6 +32891,9 @@ var init_manifest_writer = __esm(() => {
|
|
|
33271
32891
|
init_tailwind_colors();
|
|
33272
32892
|
init_utils2();
|
|
33273
32893
|
});
|
|
32894
|
+
|
|
32895
|
+
// ../cms/src/mode.ts
|
|
32896
|
+
var init_mode = () => {};
|
|
33274
32897
|
// ../cms/src/vite-plugin-array-transform.ts
|
|
33275
32898
|
var init_vite_plugin_array_transform = __esm(() => {
|
|
33276
32899
|
init_array_ops();
|
|
@@ -33343,7 +32966,7 @@ function config(newConfig) {
|
|
|
33343
32966
|
return globalConfig;
|
|
33344
32967
|
}
|
|
33345
32968
|
var NEVER, $brand, globalConfig;
|
|
33346
|
-
var
|
|
32969
|
+
var init_core2 = __esm(() => {
|
|
33347
32970
|
NEVER = Object.freeze({
|
|
33348
32971
|
status: "aborted"
|
|
33349
32972
|
});
|
|
@@ -33492,7 +33115,7 @@ var initializer = (inst, def) => {
|
|
|
33492
33115
|
});
|
|
33493
33116
|
}, $ZodError, $ZodRealError;
|
|
33494
33117
|
var init_errors = __esm(() => {
|
|
33495
|
-
|
|
33118
|
+
init_core2();
|
|
33496
33119
|
init_util();
|
|
33497
33120
|
$ZodError = $constructor("$ZodError", initializer);
|
|
33498
33121
|
$ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
@@ -33691,12 +33314,12 @@ var init_to_json_schema = () => {};
|
|
|
33691
33314
|
var init_json_schema = () => {};
|
|
33692
33315
|
|
|
33693
33316
|
// ../../node_modules/zod/v4/core/index.js
|
|
33694
|
-
var
|
|
33317
|
+
var init_core3 = __esm(() => {
|
|
33695
33318
|
init_util();
|
|
33696
33319
|
init_regexes();
|
|
33697
33320
|
init_locales();
|
|
33698
33321
|
init_json_schema();
|
|
33699
|
-
|
|
33322
|
+
init_core2();
|
|
33700
33323
|
init_parse();
|
|
33701
33324
|
init_errors();
|
|
33702
33325
|
init_schemas();
|
|
@@ -33744,8 +33367,8 @@ var initializer2 = (inst, issues) => {
|
|
|
33744
33367
|
});
|
|
33745
33368
|
}, ZodError, ZodRealError;
|
|
33746
33369
|
var init_errors2 = __esm(() => {
|
|
33747
|
-
|
|
33748
|
-
|
|
33370
|
+
init_core3();
|
|
33371
|
+
init_core3();
|
|
33749
33372
|
init_util();
|
|
33750
33373
|
ZodError = $constructor("ZodError", initializer2);
|
|
33751
33374
|
ZodRealError = $constructor("ZodError", initializer2, {
|
|
@@ -33770,8 +33393,8 @@ var init_coerce = () => {};
|
|
|
33770
33393
|
|
|
33771
33394
|
// ../../node_modules/zod/v4/classic/external.js
|
|
33772
33395
|
var init_external = __esm(() => {
|
|
33773
|
-
|
|
33774
|
-
|
|
33396
|
+
init_core3();
|
|
33397
|
+
init_core3();
|
|
33775
33398
|
init_en();
|
|
33776
33399
|
init_locales();
|
|
33777
33400
|
init_iso();
|
|
@@ -33803,18 +33426,14 @@ var init_zod = __esm(() => {
|
|
|
33803
33426
|
var init_field_types = __esm(() => {
|
|
33804
33427
|
init_zod();
|
|
33805
33428
|
});
|
|
33806
|
-
// ../cms/src/media/s3.ts
|
|
33807
|
-
var init_s3 = __esm(() => {
|
|
33808
|
-
init_local();
|
|
33809
|
-
});
|
|
33810
33429
|
|
|
33811
33430
|
// ../cms/src/migrate-astro-image.ts
|
|
33812
|
-
import
|
|
33813
|
-
import
|
|
33431
|
+
import fs12 from "fs/promises";
|
|
33432
|
+
import path12 from "path";
|
|
33814
33433
|
async function migrateAstroImages(options = {}) {
|
|
33815
33434
|
const projectRoot = options.projectRoot ?? getProjectRoot();
|
|
33816
33435
|
const dryRun = options.dryRun ?? false;
|
|
33817
|
-
const collections = await
|
|
33436
|
+
const collections = await scanCollections2();
|
|
33818
33437
|
const migrations = [];
|
|
33819
33438
|
const skipped = [];
|
|
33820
33439
|
for (const def of Object.values(collections)) {
|
|
@@ -33822,10 +33441,10 @@ async function migrateAstroImages(options = {}) {
|
|
|
33822
33441
|
if (astroFields.length === 0 || !def.entries)
|
|
33823
33442
|
continue;
|
|
33824
33443
|
for (const entry of def.entries) {
|
|
33825
|
-
const entryAbs =
|
|
33444
|
+
const entryAbs = path12.isAbsolute(entry.sourcePath) ? entry.sourcePath : path12.join(projectRoot, entry.sourcePath);
|
|
33826
33445
|
let raw;
|
|
33827
33446
|
try {
|
|
33828
|
-
raw = await
|
|
33447
|
+
raw = await fs12.readFile(entryAbs, "utf-8");
|
|
33829
33448
|
} catch {
|
|
33830
33449
|
skipped.push({ entrySourcePath: entry.sourcePath, fieldName: "*", reason: "read failed" });
|
|
33831
33450
|
continue;
|
|
@@ -33836,7 +33455,7 @@ async function migrateAstroImages(options = {}) {
|
|
|
33836
33455
|
continue;
|
|
33837
33456
|
}
|
|
33838
33457
|
const [fullFm, fmStart, yamlBody, fmEnd] = fmMatch;
|
|
33839
|
-
const doc2 =
|
|
33458
|
+
const doc2 = import_yaml7.parseDocument(yamlBody);
|
|
33840
33459
|
let mutated = false;
|
|
33841
33460
|
for (const field of astroFields) {
|
|
33842
33461
|
const current = doc2.get(field.name);
|
|
@@ -33847,10 +33466,10 @@ async function migrateAstroImages(options = {}) {
|
|
|
33847
33466
|
}
|
|
33848
33467
|
if (!current.startsWith("/") || current.startsWith("//"))
|
|
33849
33468
|
continue;
|
|
33850
|
-
const sourceAbs =
|
|
33469
|
+
const sourceAbs = path12.join(projectRoot, "public", current.replace(/^\/+/, ""));
|
|
33851
33470
|
let sourceBuf;
|
|
33852
33471
|
try {
|
|
33853
|
-
sourceBuf = await
|
|
33472
|
+
sourceBuf = await fs12.readFile(sourceAbs);
|
|
33854
33473
|
} catch {
|
|
33855
33474
|
skipped.push({ entrySourcePath: entry.sourcePath, fieldName: field.name, reason: `source missing: ${sourceAbs}` });
|
|
33856
33475
|
continue;
|
|
@@ -33858,12 +33477,12 @@ async function migrateAstroImages(options = {}) {
|
|
|
33858
33477
|
const target = await pickAstroImageTarget({
|
|
33859
33478
|
entryAbsPath: entryAbs,
|
|
33860
33479
|
slug: entry.slug,
|
|
33861
|
-
originalFilename:
|
|
33480
|
+
originalFilename: path12.basename(current),
|
|
33862
33481
|
compareBuffer: sourceBuf
|
|
33863
33482
|
});
|
|
33864
33483
|
if (!dryRun) {
|
|
33865
|
-
await
|
|
33866
|
-
await
|
|
33484
|
+
await fs12.mkdir(path12.dirname(target.absPath), { recursive: true });
|
|
33485
|
+
await fs12.writeFile(target.absPath, sourceBuf);
|
|
33867
33486
|
}
|
|
33868
33487
|
doc2.set(field.name, target.relPath);
|
|
33869
33488
|
mutated = true;
|
|
@@ -33879,36 +33498,39 @@ async function migrateAstroImages(options = {}) {
|
|
|
33879
33498
|
if (mutated && !dryRun) {
|
|
33880
33499
|
const newYaml = doc2.toString().replace(/\n$/, "");
|
|
33881
33500
|
const newRaw = raw.replace(fullFm, `${fmStart}${newYaml}${fmEnd}`);
|
|
33882
|
-
await
|
|
33501
|
+
await fs12.writeFile(entryAbs, newRaw, "utf-8");
|
|
33883
33502
|
}
|
|
33884
33503
|
}
|
|
33885
33504
|
}
|
|
33886
33505
|
return { migrations, skipped };
|
|
33887
33506
|
}
|
|
33888
|
-
var
|
|
33507
|
+
var import_yaml7, FRONTMATTER_RE;
|
|
33889
33508
|
var init_migrate_astro_image = __esm(() => {
|
|
33890
33509
|
init_astro_image_paths();
|
|
33891
|
-
|
|
33510
|
+
init_collection_scanner2();
|
|
33892
33511
|
init_config();
|
|
33893
|
-
|
|
33512
|
+
import_yaml7 = __toESM(require_dist(), 1);
|
|
33894
33513
|
FRONTMATTER_RE = /^(---\r?\n)([\s\S]*?)(\r?\n---\r?\n?)/;
|
|
33895
33514
|
});
|
|
33896
33515
|
|
|
33897
33516
|
// ../cms/src/index.ts
|
|
33898
33517
|
var DEFAULT_MAX_UPLOAD_SIZE;
|
|
33899
|
-
var
|
|
33900
|
-
|
|
33901
|
-
|
|
33518
|
+
var init_src4 = __esm(() => {
|
|
33519
|
+
init_src2();
|
|
33520
|
+
init_collection_scanner2();
|
|
33521
|
+
init_component_registry2();
|
|
33902
33522
|
init_config();
|
|
33903
33523
|
init_dev_middleware();
|
|
33524
|
+
init_local_admin();
|
|
33904
33525
|
init_manifest_writer();
|
|
33905
|
-
|
|
33526
|
+
init_mode();
|
|
33906
33527
|
init_utils2();
|
|
33907
33528
|
init_vite_plugin();
|
|
33529
|
+
init_src2();
|
|
33530
|
+
init_src();
|
|
33908
33531
|
init_field_types();
|
|
33909
|
-
|
|
33910
|
-
|
|
33911
|
-
init_collection_scanner();
|
|
33532
|
+
init_mode();
|
|
33533
|
+
init_collection_scanner2();
|
|
33912
33534
|
init_config();
|
|
33913
33535
|
init_migrate_astro_image();
|
|
33914
33536
|
init_source_finder();
|
|
@@ -33921,7 +33543,7 @@ var exports_migrate = {};
|
|
|
33921
33543
|
__export(exports_migrate, {
|
|
33922
33544
|
migrate: () => migrate
|
|
33923
33545
|
});
|
|
33924
|
-
import
|
|
33546
|
+
import path13 from "path";
|
|
33925
33547
|
async function migrate(args) {
|
|
33926
33548
|
if (args.target !== "astro-image") {
|
|
33927
33549
|
console.error(`Unknown migrate target: ${args.target}`);
|
|
@@ -33940,7 +33562,7 @@ async function migrate(args) {
|
|
|
33940
33562
|
for (const m of result.migrations) {
|
|
33941
33563
|
console.log(` ${m.entrySourcePath}`);
|
|
33942
33564
|
console.log(` ${m.fieldName}: ${m.originalValue} \u2192 ${m.newValue}`);
|
|
33943
|
-
console.log(` copy: ${
|
|
33565
|
+
console.log(` copy: ${path13.relative(process.cwd(), m.copiedFrom)} \u2192 ${path13.relative(process.cwd(), m.copiedTo)}`);
|
|
33944
33566
|
}
|
|
33945
33567
|
}
|
|
33946
33568
|
if (result.skipped.length > 0) {
|
|
@@ -33956,7 +33578,7 @@ Done. Run your dev server and verify Astro processes the images correctly.`);
|
|
|
33956
33578
|
}
|
|
33957
33579
|
}
|
|
33958
33580
|
var init_migrate = __esm(() => {
|
|
33959
|
-
|
|
33581
|
+
init_src4();
|
|
33960
33582
|
});
|
|
33961
33583
|
|
|
33962
33584
|
// src/index.ts
|