@tomsher/cms-theme-kit 0.1.0 → 0.1.1
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/bin.js +3 -3
- package/dist/chunk-EUR46QER.js +128 -0
- package/dist/chunk-EUR46QER.js.map +1 -0
- package/dist/{chunk-ND62XRUU.js → chunk-WSX3MAFK.js} +217 -124
- package/dist/chunk-WSX3MAFK.js.map +1 -0
- package/dist/{server-SWGQTMET.js → chunk-WTBGO3HG.js} +222 -171
- package/dist/chunk-WTBGO3HG.js.map +1 -0
- package/dist/{data-source-CKDBOWKF.js → data-source-63RC4O5W.js} +3 -3
- package/dist/server-GITJIQTE.js +177 -0
- package/dist/server-GITJIQTE.js.map +1 -0
- package/dist/{static-server-BTUWXORJ.js → static-server-WWP7CW4C.js} +4 -68
- package/dist/static-server-WWP7CW4C.js.map +1 -0
- package/package.json +2 -3
- package/dist/chunk-6NVYKM2E.js +0 -219
- package/dist/chunk-6NVYKM2E.js.map +0 -1
- package/dist/chunk-ND62XRUU.js.map +0 -1
- package/dist/chunk-UDJL2R66.js +0 -158
- package/dist/chunk-UDJL2R66.js.map +0 -1
- package/dist/server-SWGQTMET.js.map +0 -1
- package/dist/static-server-BTUWXORJ.js.map +0 -1
- /package/dist/{data-source-CKDBOWKF.js.map → data-source-63RC4O5W.js.map} +0 -0
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
closeServer,
|
|
4
|
-
createReloadHub,
|
|
5
|
-
createRouteServer,
|
|
6
|
-
linkListHtml,
|
|
7
|
-
listenOnLocalhost,
|
|
8
|
-
notFoundHtml,
|
|
9
|
-
renderErrorPage,
|
|
10
|
-
safeDecode,
|
|
11
|
-
sendHtml,
|
|
12
|
-
sendResponse,
|
|
13
|
-
serveFile
|
|
14
|
-
} from "./chunk-UDJL2R66.js";
|
|
15
|
-
import {
|
|
16
|
-
isTextPath,
|
|
17
|
-
readLocalTheme
|
|
18
|
-
} from "./chunk-YAYCHT4W.js";
|
|
19
2
|
import {
|
|
20
3
|
allowedFilters,
|
|
21
4
|
allowedTags,
|
|
22
|
-
applyThemeCustomizerLocaleOverrides,
|
|
23
5
|
asTrustedHtml,
|
|
24
6
|
buildBlockList,
|
|
25
7
|
buildCustomCssBlock,
|
|
26
8
|
buildPreviewHeader,
|
|
27
|
-
buildPreviewRequest,
|
|
28
9
|
buildSectionScope,
|
|
29
10
|
buildStorefrontDropsContext,
|
|
30
11
|
containsLiquidExpression,
|
|
@@ -32,12 +13,14 @@ import {
|
|
|
32
13
|
defaultLayout,
|
|
33
14
|
defaultTemplate,
|
|
34
15
|
escapeHtml,
|
|
16
|
+
extractThemeStylesheets,
|
|
35
17
|
inlinePreviewAssets,
|
|
36
18
|
isExternalLiquidAssetUrl,
|
|
37
19
|
isGalleryLiquidAssetUrl,
|
|
38
20
|
isSafePartialName,
|
|
39
21
|
layoutKey,
|
|
40
22
|
loadGlobalSettings,
|
|
23
|
+
localizeStorefrontUrl,
|
|
41
24
|
maxIncludeDepth,
|
|
42
25
|
maxIterations,
|
|
43
26
|
maxOutputBytes,
|
|
@@ -55,38 +38,30 @@ import {
|
|
|
55
38
|
resolveMarkupKey,
|
|
56
39
|
resolveSectionSettings,
|
|
57
40
|
resolveTemplatePath,
|
|
58
|
-
resolveThemeMediaUrl,
|
|
59
41
|
sanitizeRichtext,
|
|
60
42
|
sectionKey,
|
|
61
43
|
stripSectionSchema,
|
|
62
44
|
templateErrorHtml,
|
|
63
45
|
trustedHtml
|
|
64
|
-
} from "./chunk-
|
|
65
|
-
import {
|
|
66
|
-
ensureThemeStylesheetsBeforeContent,
|
|
67
|
-
getThemeAssetUrls,
|
|
68
|
-
localizeStorefrontUrl,
|
|
69
|
-
rewriteLiquidThemeAssetBuffers
|
|
70
|
-
} from "./chunk-6NVYKM2E.js";
|
|
46
|
+
} from "./chunk-WSX3MAFK.js";
|
|
71
47
|
import {
|
|
48
|
+
CliError,
|
|
72
49
|
__toESM,
|
|
73
50
|
defaultLanguageCode,
|
|
74
51
|
liquidThemeConfigFilePaths,
|
|
75
|
-
|
|
76
|
-
|
|
52
|
+
queryKeys,
|
|
53
|
+
staticThemeFolderNames,
|
|
54
|
+
themeFileExtensions
|
|
77
55
|
} from "./chunk-TN3DQWJE.js";
|
|
78
56
|
|
|
79
|
-
//
|
|
80
|
-
import { join as join2, resolve as resolve2 } from "path";
|
|
81
|
-
|
|
82
|
-
// ../liquid-engine/dist/chunk-D73VXFY7.js
|
|
57
|
+
// ../cms-theme-engines/dist/chunk-D73VXFY7.js
|
|
83
58
|
var liquidTemplateLimits = {
|
|
84
59
|
templateMaxBytes: 200 * 1024,
|
|
85
60
|
renderTimeoutMs: 500,
|
|
86
61
|
renderMemoryBytes: 20 * 1024 * 1024
|
|
87
62
|
};
|
|
88
63
|
|
|
89
|
-
// ../
|
|
64
|
+
// ../cms-theme-engines/dist/engine/index.js
|
|
90
65
|
var import_get = __toESM(require_get(), 1);
|
|
91
66
|
|
|
92
67
|
// ../node_modules/liquidjs/dist/liquid.node.mjs
|
|
@@ -2230,8 +2205,8 @@ var Tokenizer = class {
|
|
|
2230
2205
|
return;
|
|
2231
2206
|
let value;
|
|
2232
2207
|
this.skipBlank();
|
|
2233
|
-
const
|
|
2234
|
-
if (this.peek() ===
|
|
2208
|
+
const sep3 = isString(jekyllStyle) ? jekyllStyle : jekyllStyle ? "=" : ":";
|
|
2209
|
+
if (this.peek() === sep3) {
|
|
2235
2210
|
++this.p;
|
|
2236
2211
|
value = this.readValue();
|
|
2237
2212
|
}
|
|
@@ -2868,9 +2843,9 @@ var Loader = class {
|
|
|
2868
2843
|
var _a, _b, _c, _d;
|
|
2869
2844
|
this.options = options;
|
|
2870
2845
|
if (options.relativeReference) {
|
|
2871
|
-
const
|
|
2872
|
-
assert(
|
|
2873
|
-
const prefixes = ["." +
|
|
2846
|
+
const sep3 = options.fs.sep;
|
|
2847
|
+
assert(sep3, "`fs.sep` is required for relative reference");
|
|
2848
|
+
const prefixes = ["." + sep3, ".." + sep3, "./", "../"];
|
|
2874
2849
|
this.shouldLoadRelative = (referencedFile) => prefixes.some((prefix) => referencedFile.startsWith(prefix));
|
|
2875
2850
|
} else {
|
|
2876
2851
|
this.shouldLoadRelative = (_referencedFile) => false;
|
|
@@ -2901,13 +2876,13 @@ var Loader = class {
|
|
|
2901
2876
|
throw this.lookupError(file, dirs);
|
|
2902
2877
|
}
|
|
2903
2878
|
*candidates(file, dirs, currentFile) {
|
|
2904
|
-
const { fs: fs2, extname:
|
|
2879
|
+
const { fs: fs2, extname: extname3 } = this.options;
|
|
2905
2880
|
if (this.shouldLoadRelative(file) && currentFile) {
|
|
2906
|
-
const referenced = fs2.resolve(this.dirname(currentFile), file,
|
|
2881
|
+
const referenced = fs2.resolve(this.dirname(currentFile), file, extname3);
|
|
2907
2882
|
yield referenced;
|
|
2908
2883
|
}
|
|
2909
2884
|
for (const dir of dirs) {
|
|
2910
|
-
const referenced = fs2.resolve(dir, file,
|
|
2885
|
+
const referenced = fs2.resolve(dir, file, extname3);
|
|
2911
2886
|
yield referenced;
|
|
2912
2887
|
}
|
|
2913
2888
|
if (fs2.fallback !== void 0) {
|
|
@@ -3285,12 +3260,12 @@ var urlFilters = /* @__PURE__ */ Object.freeze({
|
|
|
3285
3260
|
});
|
|
3286
3261
|
var join = argumentsToValue(function(v, arg) {
|
|
3287
3262
|
const array = toArray(v);
|
|
3288
|
-
const
|
|
3289
|
-
let outputSize =
|
|
3263
|
+
const sep3 = isNil(arg) ? " " : stringify(arg);
|
|
3264
|
+
let outputSize = sep3.length * Math.max(array.length - 1, 0);
|
|
3290
3265
|
for (let i = 0; i < array.length; i++)
|
|
3291
3266
|
outputSize += String(array[i]).length;
|
|
3292
3267
|
this.context.memoryLimit.use(outputSize);
|
|
3293
|
-
return Array.prototype.join.call(array,
|
|
3268
|
+
return Array.prototype.join.call(array, sep3);
|
|
3294
3269
|
});
|
|
3295
3270
|
var last = argumentsToValue(function(v) {
|
|
3296
3271
|
return isArrayLike(v) ? readArrayElement(v, -1, this.context.ownPropertyOnly) : "";
|
|
@@ -5018,7 +4993,7 @@ var Liquid = class _Liquid {
|
|
|
5018
4993
|
}
|
|
5019
4994
|
};
|
|
5020
4995
|
|
|
5021
|
-
// ../
|
|
4996
|
+
// ../cms-theme-engines/dist/engine/index.js
|
|
5022
4997
|
var import_get2 = __toESM(require_get(), 1);
|
|
5023
4998
|
var LOCALE_FILE_CANDIDATES = (locale) => {
|
|
5024
4999
|
const normalized = locale.trim().replace(/_/g, "-");
|
|
@@ -5458,143 +5433,219 @@ var liquidStorefrontRuntime = `(() => {
|
|
|
5458
5433
|
document.querySelectorAll('[data-load-more]').forEach(restore);
|
|
5459
5434
|
document.addEventListener('click', (event) => { const button = event.target.closest('[data-load-more]'); if (button) load(button); });
|
|
5460
5435
|
})();`;
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5436
|
+
var stripStaticRoot = (path) => path.replace(new RegExp(`^${staticThemeFolderNames.root}/?`), "");
|
|
5437
|
+
var normalizePosixPath = (path) => {
|
|
5438
|
+
const parts = [];
|
|
5439
|
+
for (const part of path.replace(/\\/g, "/").split("/")) {
|
|
5440
|
+
if (!part || part === ".") continue;
|
|
5441
|
+
if (part === "..") parts.pop();
|
|
5442
|
+
else parts.push(part);
|
|
5443
|
+
}
|
|
5444
|
+
return parts.join("/") || ".";
|
|
5470
5445
|
};
|
|
5471
|
-
var
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
return {
|
|
5477
|
-
page: { ...entry, entity: data.page.entity, type: data.page.type },
|
|
5478
|
-
collection: data.collection
|
|
5479
|
-
};
|
|
5446
|
+
var joinPosixPath = (...parts) => normalizePosixPath(parts.filter(Boolean).join("/"));
|
|
5447
|
+
var dirnamePosixPath = (path) => {
|
|
5448
|
+
const normalized = path.replace(/\\/g, "/").replace(/\/$/, "");
|
|
5449
|
+
const separatorIndex = normalized.lastIndexOf("/");
|
|
5450
|
+
return separatorIndex < 0 ? "." : normalized.slice(0, separatorIndex) || "/";
|
|
5480
5451
|
};
|
|
5481
|
-
var
|
|
5482
|
-
|
|
5483
|
-
const
|
|
5484
|
-
|
|
5485
|
-
const
|
|
5486
|
-
const
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5452
|
+
var basenamePosixPath = (path) => path.replace(/\\/g, "/").split("/").filter(Boolean).at(-1) || "";
|
|
5453
|
+
var renderStaticHtmlTheme = (theme) => {
|
|
5454
|
+
const pagePath = theme.templatePath;
|
|
5455
|
+
let documentHtml = theme.files[pagePath] || "";
|
|
5456
|
+
const pageDirectory = dirnamePosixPath(pagePath);
|
|
5457
|
+
const resolveReference = (reference) => {
|
|
5458
|
+
if (!reference || /^(?:[a-z]+:|\/\/|#)/i.test(reference)) return reference;
|
|
5459
|
+
const [pathname, suffix = ""] = reference.split(/(?=[?#])/, 2);
|
|
5460
|
+
const resolved = pathname.startsWith("/") ? pathname.replace(/^\/+/, "") : joinPosixPath(stripStaticRoot(pageDirectory), pathname).replace(/^\.\//, "");
|
|
5461
|
+
const url = theme.assetUrls[`${staticThemeFolderNames.root}/${resolved}`] || theme.assetUrls[resolved] || Object.entries(theme.assetUrls).find(([assetPath]) => assetPath.endsWith(`/${basenamePosixPath(resolved)}`))?.[1];
|
|
5462
|
+
return url ? `${url}${suffix}` : reference;
|
|
5463
|
+
};
|
|
5464
|
+
const rewriteCss = (content, cssDirectory) => content.replace(/url\(\s*(['"]?)(?!data:|https?:|blob:)([^'")]+)\1\s*\)/gi, (match, quote, ref) => {
|
|
5465
|
+
const target = ref.trim().startsWith("/") ? ref.trim().replace(/^\/+/, "") : joinPosixPath(cssDirectory, ref.trim());
|
|
5466
|
+
const url = theme.assetUrls[`${staticThemeFolderNames.root}/${target}`] || theme.assetUrls[target] || Object.entries(theme.assetUrls).find(([assetPath]) => assetPath.endsWith(`/${basenamePosixPath(target)}`))?.[1];
|
|
5467
|
+
return url ? `url(${quote}${url}${quote})` : match;
|
|
5468
|
+
});
|
|
5469
|
+
documentHtml = documentHtml.replace(/<link\b[^>]*\brel=(['"])stylesheet\1[^>]*>/gi, (tag) => {
|
|
5470
|
+
const href = tag.match(/\bhref=(['"])(.*?)\1/i)?.[2];
|
|
5471
|
+
if (!href || /^(?:[a-z]+:|\/\/|data:)/i.test(href)) return tag;
|
|
5472
|
+
const [hrefPath] = href.split(/[?#]/, 1);
|
|
5473
|
+
const cssPath = hrefPath.startsWith("/") ? hrefPath.replace(/^\/+/, "") : joinPosixPath(pageDirectory, hrefPath);
|
|
5474
|
+
const css = theme.files[cssPath] || theme.files[`${staticThemeFolderNames.root}/${cssPath}`];
|
|
5475
|
+
if (!css) return tag;
|
|
5476
|
+
const media = tag.match(/\bmedia=(['"])(.*?)\1/i)?.[2];
|
|
5477
|
+
return `<style${media ? ` media="${media}"` : ""}>${rewriteCss(css, stripStaticRoot(dirnamePosixPath(cssPath)))}</style>`;
|
|
5478
|
+
});
|
|
5479
|
+
documentHtml = documentHtml.replace(/<style\b([^>]*)>([\s\S]*?)<\/style>/gi, (_tag, attributes, css) => `<style${attributes}>${rewriteCss(css, stripStaticRoot(pageDirectory))}</style>`);
|
|
5480
|
+
documentHtml = documentHtml.replace(/\b(src|href|poster)=(['"])(.*?)\2/gi, (match, attr, quote, value) => {
|
|
5481
|
+
if (value.split(/[?#]/, 1)[0].toLowerCase().endsWith(themeFileExtensions.html) || /^(?:mailto:|tel:|javascript:|data:)/i.test(value)) return match;
|
|
5482
|
+
return `${attr}=${quote}${resolveReference(value)}${quote}`;
|
|
5503
5483
|
});
|
|
5504
|
-
|
|
5484
|
+
const head = documentHtml.match(/<head\b[^>]*>([\s\S]*?)<\/head>/i)?.[1] || "";
|
|
5485
|
+
const body = documentHtml.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i)?.[1] || documentHtml.replace(/^[\s\S]*?<body\b[^>]*>/i, "").replace(/<\/body>[\s\S]*$/i, "");
|
|
5486
|
+
const title = head.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i)?.[1]?.trim();
|
|
5487
|
+
const htmlAttributes = documentHtml.match(/<html\b([^>]*)>/i)?.[1] || "";
|
|
5488
|
+
const languageCode = htmlAttributes.match(/\blang\s*=\s*(['"])(.*?)\1/i)?.[2];
|
|
5489
|
+
const direction = htmlAttributes.match(/\bdir\s*=\s*(['"])(.*?)\1/i)?.[2];
|
|
5490
|
+
const headExtras = head.replace(/<title\b[^>]*>[\s\S]*?<\/title>/gi, "");
|
|
5491
|
+
const scripts = head.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi) || [];
|
|
5492
|
+
const extractedHead = extractThemeStylesheets(headExtras);
|
|
5493
|
+
return { html: `${extractedHead.html}${scripts.join("")}${body}`, stylesheets: extractedHead.stylesheets, documentHtml, documentTitle: title, languageCode, direction };
|
|
5505
5494
|
};
|
|
5506
5495
|
|
|
5507
|
-
// src/lib/dev/server.ts
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5496
|
+
// src/lib/dev/server-shared.ts
|
|
5497
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
5498
|
+
import { createServer } from "http";
|
|
5499
|
+
import { extname as extname2, resolve as resolve2, sep as sep2 } from "path";
|
|
5500
|
+
var contentTypes = {
|
|
5501
|
+
".css": "text/css; charset=utf-8",
|
|
5502
|
+
".js": "application/javascript; charset=utf-8",
|
|
5503
|
+
".json": "application/json; charset=utf-8",
|
|
5504
|
+
".svg": "image/svg+xml",
|
|
5505
|
+
".txt": "text/plain; charset=utf-8",
|
|
5506
|
+
".png": "image/png",
|
|
5507
|
+
".jpg": "image/jpeg",
|
|
5508
|
+
".jpeg": "image/jpeg",
|
|
5509
|
+
".webp": "image/webp",
|
|
5510
|
+
".gif": "image/gif",
|
|
5511
|
+
".mp4": "video/mp4",
|
|
5512
|
+
".woff": "font/woff",
|
|
5513
|
+
".woff2": "font/woff2",
|
|
5514
|
+
".ttf": "font/ttf"
|
|
5515
|
+
};
|
|
5516
|
+
var reloadScript = [
|
|
5517
|
+
"<script>",
|
|
5518
|
+
"(function () {",
|
|
5519
|
+
' var source = new EventSource("/__events");',
|
|
5520
|
+
' source.addEventListener("reload", function () { location.reload(); });',
|
|
5521
|
+
"})();",
|
|
5522
|
+
"</script>"
|
|
5523
|
+
].join("\n");
|
|
5524
|
+
var injectReloadScript = (html) => {
|
|
5525
|
+
if (/<\/body>/i.test(html)) {
|
|
5526
|
+
return html.replace(/<\/body>/i, (tag) => `${reloadScript}${tag}`);
|
|
5527
|
+
}
|
|
5528
|
+
return `${html}${reloadScript}`;
|
|
5529
|
+
};
|
|
5530
|
+
var safeDecode = (value) => {
|
|
5531
|
+
try {
|
|
5532
|
+
return decodeURIComponent(value);
|
|
5533
|
+
} catch {
|
|
5534
|
+
return null;
|
|
5519
5535
|
}
|
|
5520
|
-
return { buffers, assetPaths };
|
|
5521
5536
|
};
|
|
5522
|
-
var
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5537
|
+
var escapeHtml2 = (value) => {
|
|
5538
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
5539
|
+
};
|
|
5540
|
+
var sendResponse = (response, status, headers, body) => {
|
|
5541
|
+
response.writeHead(status, { ...headers, "Cache-Control": "no-store" });
|
|
5542
|
+
response.end(body);
|
|
5543
|
+
};
|
|
5544
|
+
var sendHtml = (response, status, html) => {
|
|
5545
|
+
sendResponse(response, status, { "Content-Type": "text/html; charset=utf-8" }, injectReloadScript(html));
|
|
5546
|
+
};
|
|
5547
|
+
var linkListHtml = (title, links) => {
|
|
5548
|
+
const items = links.map((link) => `<li><a href="${escapeHtml2(link.href)}">${escapeHtml2(link.label)}</a></li>`).join("");
|
|
5549
|
+
return `<!DOCTYPE html><html><head><meta charset="utf-8"><title>${escapeHtml2(title)}</title></head><body style="font-family:sans-serif;padding:32px;"><h1>${escapeHtml2(title)}</h1><ul>${items}</ul></body></html>`;
|
|
5550
|
+
};
|
|
5551
|
+
var notFoundHtml = (message) => {
|
|
5552
|
+
return `<!DOCTYPE html><html><body style="font-family:sans-serif;padding:32px;"><h2>Not found</h2><p>${escapeHtml2(message)}</p></body></html>`;
|
|
5553
|
+
};
|
|
5554
|
+
var renderErrorPage = (error) => {
|
|
5555
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5556
|
+
const stack = error instanceof Error ? error.stack ?? "" : "";
|
|
5557
|
+
return `<!DOCTYPE html><html><body style="font-family:sans-serif;padding:32px;color:#dc2626;background:#fff1f2;"><h2 style="margin-top:0;">Theme Preview Rendering Error</h2><p style="color:#991b1b;">${escapeHtml2(message)}</p><pre style="background:#fee2e2;padding:16px;border-radius:8px;overflow:auto;">${escapeHtml2(stack)}</pre></body></html>`;
|
|
5558
|
+
};
|
|
5559
|
+
var serveFile = async (response, rootDir, encodedPath) => {
|
|
5560
|
+
const relativePath = safeDecode(encodedPath);
|
|
5561
|
+
const filePath = relativePath === null ? "" : resolve2(rootDir, relativePath);
|
|
5562
|
+
if (!filePath.startsWith(`${rootDir}${sep2}`)) {
|
|
5563
|
+
sendResponse(response, 404, { "Content-Type": "text/plain; charset=utf-8" }, "Not found");
|
|
5564
|
+
return;
|
|
5565
|
+
}
|
|
5566
|
+
try {
|
|
5567
|
+
const bytes = await readFile2(filePath);
|
|
5568
|
+
const contentType = contentTypes[extname2(filePath).toLowerCase()] ?? "application/octet-stream";
|
|
5569
|
+
sendResponse(response, 200, { "Content-Type": contentType }, bytes);
|
|
5570
|
+
} catch {
|
|
5571
|
+
sendResponse(response, 404, { "Content-Type": "text/plain; charset=utf-8" }, "Not found");
|
|
5572
|
+
}
|
|
5573
|
+
};
|
|
5574
|
+
var createReloadHub = () => {
|
|
5575
|
+
const clients = /* @__PURE__ */ new Set();
|
|
5576
|
+
return {
|
|
5577
|
+
open: (request, response) => {
|
|
5578
|
+
response.writeHead(200, {
|
|
5579
|
+
"Content-Type": "text/event-stream",
|
|
5580
|
+
"Cache-Control": "no-cache",
|
|
5581
|
+
Connection: "keep-alive"
|
|
5582
|
+
});
|
|
5583
|
+
response.write("retry: 1000\n\n");
|
|
5584
|
+
clients.add(response);
|
|
5585
|
+
request.on("close", () => {
|
|
5586
|
+
clients.delete(response);
|
|
5542
5587
|
});
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5588
|
+
},
|
|
5589
|
+
broadcast: () => {
|
|
5590
|
+
for (const client of clients) {
|
|
5591
|
+
client.write("event: reload\ndata: 1\n\n");
|
|
5592
|
+
}
|
|
5593
|
+
},
|
|
5594
|
+
close: () => {
|
|
5595
|
+
for (const client of clients) {
|
|
5596
|
+
client.end();
|
|
5597
|
+
}
|
|
5598
|
+
clients.clear();
|
|
5546
5599
|
}
|
|
5547
5600
|
};
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
sendHtml(response, 200, linkListHtml("Templates", links));
|
|
5564
|
-
return;
|
|
5565
|
-
}
|
|
5566
|
-
if (pathname.startsWith("/assets/")) {
|
|
5567
|
-
await serveFile(response, assetsDir, pathname.slice("/assets/".length));
|
|
5568
|
-
return;
|
|
5569
|
-
}
|
|
5570
|
-
if (pathname === "/") {
|
|
5571
|
-
await renderTemplate(response, options.templatePath, assetOrigin);
|
|
5572
|
-
return;
|
|
5573
|
-
}
|
|
5574
|
-
if (pathname.startsWith("/t/")) {
|
|
5575
|
-
const templatePath = safeDecode(pathname.slice("/t/".length));
|
|
5576
|
-
if (templatePath === null) {
|
|
5577
|
-
sendHtml(response, 400, notFoundHtml("Malformed template path."));
|
|
5601
|
+
};
|
|
5602
|
+
var createRouteServer = (route) => {
|
|
5603
|
+
return createServer((request, response) => {
|
|
5604
|
+
route(request, response).catch((error) => {
|
|
5605
|
+
if (!response.headersSent) {
|
|
5606
|
+
sendHtml(response, 500, renderErrorPage(error));
|
|
5607
|
+
}
|
|
5608
|
+
});
|
|
5609
|
+
});
|
|
5610
|
+
};
|
|
5611
|
+
var listenOnLocalhost = (server, port) => {
|
|
5612
|
+
return new Promise((resolveListen, rejectListen) => {
|
|
5613
|
+
server.once("error", (error) => {
|
|
5614
|
+
if (error.code === "EADDRINUSE") {
|
|
5615
|
+
rejectListen(new CliError(`Port ${port} is already in use. Pass --port <n>.`));
|
|
5578
5616
|
return;
|
|
5579
5617
|
}
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
};
|
|
5618
|
+
rejectListen(error);
|
|
5619
|
+
});
|
|
5620
|
+
server.listen(port, "localhost", () => {
|
|
5621
|
+
resolveListen();
|
|
5622
|
+
});
|
|
5623
|
+
});
|
|
5624
|
+
};
|
|
5625
|
+
var closeServer = (server, reload) => {
|
|
5626
|
+
reload.close();
|
|
5627
|
+
return new Promise((resolveClose) => {
|
|
5628
|
+
server.close(() => {
|
|
5629
|
+
resolveClose();
|
|
5630
|
+
});
|
|
5631
|
+
server.closeAllConnections();
|
|
5632
|
+
});
|
|
5596
5633
|
};
|
|
5634
|
+
|
|
5597
5635
|
export {
|
|
5598
|
-
|
|
5636
|
+
createLiquidFilters,
|
|
5637
|
+
renderLiquidThemeBundle,
|
|
5638
|
+
renderStaticHtmlTheme,
|
|
5639
|
+
safeDecode,
|
|
5640
|
+
sendResponse,
|
|
5641
|
+
sendHtml,
|
|
5642
|
+
linkListHtml,
|
|
5643
|
+
notFoundHtml,
|
|
5644
|
+
renderErrorPage,
|
|
5645
|
+
serveFile,
|
|
5646
|
+
createReloadHub,
|
|
5647
|
+
createRouteServer,
|
|
5648
|
+
listenOnLocalhost,
|
|
5649
|
+
closeServer
|
|
5599
5650
|
};
|
|
5600
|
-
//# sourceMappingURL=
|
|
5651
|
+
//# sourceMappingURL=chunk-WTBGO3HG.js.map
|