@tomsher/cms-theme-kit 0.1.7 → 0.1.10

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.
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ buildPreviewRequest,
4
+ createFixturesDataSource,
5
+ createLiveDataSource,
6
+ normalizePreviewData,
7
+ withFixtureRecording
8
+ } from "./chunk-VA6IQPFX.js";
9
+ import "./chunk-Z7WA4YHH.js";
10
+ import "./chunk-NLFY255A.js";
11
+ export {
12
+ buildPreviewRequest,
13
+ createFixturesDataSource,
14
+ createLiveDataSource,
15
+ normalizePreviewData,
16
+ withFixtureRecording
17
+ };
18
+ //# sourceMappingURL=data-source-IVR7NX5Z.js.map
@@ -1,37 +1,37 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  closeServer,
4
- createLiquidFilters,
5
4
  createReloadHub,
6
5
  createRouteServer,
7
6
  linkListHtml,
8
7
  listenOnLocalhost,
9
8
  notFoundHtml,
10
9
  renderErrorPage,
11
- renderLiquidThemeBundle,
12
10
  safeDecode,
13
11
  sendHtml,
14
12
  sendResponse,
15
13
  serveFile
16
- } from "./chunk-VDICVCKJ.js";
14
+ } from "./chunk-RR53HSKJ.js";
17
15
  import {
18
16
  isTextPath,
19
17
  readLocalTheme
20
- } from "./chunk-PEG6K5NX.js";
18
+ } from "./chunk-MHTCCMQU.js";
21
19
  import {
22
20
  buildPreviewRequest
23
- } from "./chunk-OATE235V.js";
21
+ } from "./chunk-VA6IQPFX.js";
24
22
  import {
25
23
  applyThemeCustomizerLocaleOverrides,
24
+ createLiquidFilters,
25
+ createThemeMediaUrlResolver,
26
26
  ensureThemeStylesheetsBeforeContent,
27
27
  getThemeAssetUrls,
28
- resolveThemeMediaUrl,
28
+ renderLiquidThemeBundle,
29
29
  rewriteLiquidThemeAssetBuffers
30
- } from "./chunk-UMGL5N53.js";
30
+ } from "./chunk-Z7WA4YHH.js";
31
31
  import {
32
32
  defaultLanguageCode,
33
33
  liquidThemeFolderNames
34
- } from "./chunk-VY553LTO.js";
34
+ } from "./chunk-NLFY255A.js";
35
35
 
36
36
  // src/lib/dev/server.ts
37
37
  import { join, resolve } from "path";
@@ -56,17 +56,19 @@ var buildPageContext = (data) => {
56
56
  };
57
57
  };
58
58
  var renderThemePage = async (options) => {
59
- const { buffers, assetPaths, templatePath, data, languageCode, countryCode, assetOrigin } = options;
59
+ const { buffers, assetPaths, templatePath, data, languageCode, countryCode, assetOrigin, mediaBaseUrl } = options;
60
+ const resolveMediaUrl = createThemeMediaUrlResolver(mediaBaseUrl);
60
61
  const localizedBuffers = applyThemeCustomizerLocaleOverrides(buffers, languageCode, defaultLanguageCode);
61
62
  const assetFiles = assetPaths.map((path) => ({ path, fileUrl: `${assetOrigin}/${path}` }));
62
- const themeAssetUrls = getThemeAssetUrls(assetFiles, liquidThemeFolderNames.assets, resolveThemeMediaUrl);
63
+ const themeAssetUrls = getThemeAssetUrls(assetFiles, liquidThemeFolderNames.assets, resolveMediaUrl);
63
64
  const previewBuffers = rewriteLiquidThemeAssetBuffers(localizedBuffers, themeAssetUrls);
64
65
  const localization = buildLocalization(languageCode, countryCode);
65
- const customFilters = createLiquidFilters({ fileBuffers: localizedBuffers, activeLocale: languageCode, localization });
66
+ const customFilters = createLiquidFilters({ fileBuffers: localizedBuffers, activeLocale: languageCode, localization, resolveMediaUrl });
66
67
  const { entities: entityQueries } = buildPreviewRequest(buffers, templatePath);
67
68
  const renderedHtml = await renderLiquidThemeBundle(previewBuffers, {
68
69
  customFilters,
69
70
  themeAssetUrls,
71
+ resolveMediaUrl,
70
72
  templatePath,
71
73
  context: {
72
74
  entities: data.entities,
@@ -118,7 +120,8 @@ var startDevServer = async (options) => {
118
120
  data,
119
121
  languageCode: options.languageCode,
120
122
  countryCode: options.countryCode,
121
- assetOrigin
123
+ assetOrigin,
124
+ mediaBaseUrl: options.mediaBaseUrl ?? ""
122
125
  });
123
126
  sendHtml(response, 200, html);
124
127
  } catch (error) {
@@ -169,6 +172,11 @@ var startDevServer = async (options) => {
169
172
  await renderTemplate(response, templatePath, assetOrigin);
170
173
  return;
171
174
  }
175
+ if (options.storefrontUrl && pathname.startsWith("/apps/")) {
176
+ const search = new URL(request.url ?? "/", "http://localhost").search;
177
+ sendResponse(response, 302, { Location: `${options.storefrontUrl.replace(/\/$/, "")}${pathname}${search}` }, "");
178
+ return;
179
+ }
172
180
  if (!options.dataSource.resolveRoute) {
173
181
  sendHtml(response, 404, notFoundHtml(`No route for ${pathname}.`));
174
182
  return;
@@ -181,7 +189,8 @@ var startDevServer = async (options) => {
181
189
  return;
182
190
  }
183
191
  if (routedTemplatePath === null) {
184
- sendHtml(response, 404, notFoundHtml(`No route for ${pathname}. See /__routes.`));
192
+ const hint = pathname.startsWith("/apps/") ? " This is a built-in storefront page: start dev with --storefront-url to open it on the storefront." : " See /__routes.";
193
+ sendHtml(response, 404, notFoundHtml(`No route for ${pathname}.${hint}`));
185
194
  return;
186
195
  }
187
196
  await renderTemplate(response, routedTemplatePath, assetOrigin, pathname);
@@ -201,4 +210,4 @@ var startDevServer = async (options) => {
201
210
  export {
202
211
  startDevServer
203
212
  };
204
- //# sourceMappingURL=server-PV5PFQ7A.js.map
213
+ //# sourceMappingURL=server-OIS3KTQY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/dev/server.ts","../src/lib/dev/render-page.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport { join, resolve } from 'node:path';\nimport { isTextPath, readLocalTheme } from '../theme-files';\nimport type { DataSource } from './data-source';\nimport { renderThemePage } from './render-page';\nimport { closeServer, createReloadHub, createRouteServer, linkListHtml, listenOnLocalhost, notFoundHtml, renderErrorPage, safeDecode, sendHtml, sendResponse, serveFile } from './server-shared';\n\nexport interface DevServerOptions {\n themeDir: string;\n port: number;\n templatePath: string;\n languageCode: string;\n countryCode?: string;\n dataSource: DataSource;\n mediaBaseUrl?: string;\n storefrontUrl?: string;\n}\n\nexport interface DevServer {\n url: string;\n notifyChanged: () => Promise<void>;\n close: () => Promise<void>;\n}\n\ninterface ThemeSnapshot {\n buffers: Record<string, string>;\n assetPaths: string[];\n}\n\nconst readThemeSnapshot = async (themeDir: string): Promise<ThemeSnapshot> => {\n const files = await readLocalTheme(themeDir);\n const buffers: Record<string, string> = {};\n const assetPaths: string[] = [];\n\n for (const file of files) {\n if (file.path.startsWith('assets/')) {\n assetPaths.push(file.path);\n }\n\n if (isTextPath(file.path)) {\n buffers[file.path] = new TextDecoder().decode(file.bytes);\n }\n }\n\n return { buffers, assetPaths };\n};\n\n// Dev server for one theme folder. The theme is read at start and again on each notifyChanged call.\nexport const startDevServer = async (options: DevServerOptions): Promise<DevServer> => {\n const themeDir = resolve(options.themeDir);\n const assetsDir = join(themeDir, 'assets');\n const reload = createReloadHub();\n let snapshot = await readThemeSnapshot(themeDir);\n\n const templatePathsOf = (): string[] => {\n return Object.keys(snapshot.buffers)\n .filter((path) => /^templates\\/[^/]+\\.json$/.test(path))\n .sort();\n };\n\n const renderTemplate = async (response: ServerResponse, templatePath: string, assetOrigin: string, path?: string): Promise<void> => {\n if (snapshot.buffers[templatePath] === undefined) {\n sendHtml(response, 404, notFoundHtml(`${templatePath} does not exist. See /__templates.`));\n return;\n }\n\n try {\n const data = await options.dataSource.load({ templatePath, buffers: snapshot.buffers, path });\n const html = await renderThemePage({\n buffers: snapshot.buffers,\n assetPaths: snapshot.assetPaths,\n templatePath,\n data,\n languageCode: options.languageCode,\n countryCode: options.countryCode,\n assetOrigin,\n mediaBaseUrl: options.mediaBaseUrl ?? '',\n });\n sendHtml(response, 200, html);\n } catch (error) {\n sendHtml(response, 500, renderErrorPage(error));\n }\n };\n\n const route = async (request: IncomingMessage, response: ServerResponse): Promise<void> => {\n if (request.method !== 'GET') {\n sendResponse(response, 405, { 'Content-Type': 'text/plain; charset=utf-8', Allow: 'GET' }, 'Method not allowed');\n return;\n }\n\n const pathname = new URL(request.url ?? '/', 'http://localhost').pathname;\n const address = server.address() as AddressInfo;\n const assetOrigin = `http://localhost:${address.port}`;\n\n if (pathname === '/__events') {\n reload.open(request, response);\n return;\n }\n\n if (pathname === '/__templates') {\n const links = templatePathsOf().map((path) => ({ href: `/t/${encodeURI(path)}`, label: path }));\n sendHtml(response, 200, linkListHtml('Templates', links));\n return;\n }\n\n if (pathname === '/__routes' && options.dataSource.listRoutes) {\n try {\n const routes = await options.dataSource.listRoutes();\n const links = routes.map((route) => ({ href: encodeURI(route.path), label: `${route.path} (${route.kind})` }));\n sendHtml(response, 200, linkListHtml('Routes', links));\n } catch (error) {\n sendHtml(response, 500, renderErrorPage(error));\n }\n\n return;\n }\n\n if (pathname.startsWith('/assets/')) {\n await serveFile(response, assetsDir, pathname.slice('/assets/'.length));\n return;\n }\n\n if (pathname === '/') {\n await renderTemplate(response, options.templatePath, assetOrigin);\n return;\n }\n\n if (pathname.startsWith('/t/')) {\n const templatePath = safeDecode(pathname.slice('/t/'.length));\n\n if (templatePath === null) {\n sendHtml(response, 400, notFoundHtml('Malformed template path.'));\n return;\n }\n\n await renderTemplate(response, templatePath, assetOrigin);\n return;\n }\n\n if (options.storefrontUrl && pathname.startsWith('/apps/')) {\n const search = new URL(request.url ?? '/', 'http://localhost').search;\n sendResponse(response, 302, { Location: `${options.storefrontUrl.replace(/\\/$/, '')}${pathname}${search}` }, '');\n return;\n }\n\n if (!options.dataSource.resolveRoute) {\n sendHtml(response, 404, notFoundHtml(`No route for ${pathname}.`));\n return;\n }\n\n let routedTemplatePath: string | null;\n\n try {\n routedTemplatePath = await options.dataSource.resolveRoute(pathname, templatePathsOf());\n } catch (error) {\n sendHtml(response, 500, renderErrorPage(error));\n return;\n }\n\n if (routedTemplatePath === null) {\n const hint = pathname.startsWith('/apps/') ? ' This is a built-in storefront page: start dev with --storefront-url to open it on the storefront.' : ' See /__routes.';\n sendHtml(response, 404, notFoundHtml(`No route for ${pathname}.${hint}`));\n return;\n }\n\n await renderTemplate(response, routedTemplatePath, assetOrigin, pathname);\n };\n\n const server = createRouteServer(route);\n\n await listenOnLocalhost(server, options.port);\n\n const address = server.address() as AddressInfo;\n\n return {\n url: `http://localhost:${address.port}`,\n notifyChanged: async () => {\n snapshot = await readThemeSnapshot(themeDir);\n reload.broadcast();\n },\n close: () => closeServer(server, reload),\n };\n};\n","import { getThemeAssetUrls } from '@tomsher/cms-core/utils';\nimport { createThemeMediaUrlResolver } from '@tomsher/cms-core/utils';\nimport { applyThemeCustomizerLocaleOverrides, createLiquidFilters, renderLiquidThemeBundle } from '@tomsher/cms-core/renderer';\nimport { defaultLanguageCode } from '@tomsher/cms-core/constants';\nimport { ensureThemeStylesheetsBeforeContent, rewriteLiquidThemeAssetBuffers } from '@tomsher/cms-core/utils';\nimport { liquidThemeFolderNames } from '@tomsher/cms-core/constants';\nimport type { StorefrontLocalization } from '@tomsher/cms-core/types';\nimport { buildPreviewRequest, type PreviewData } from './data-source';\n\nexport interface RenderPageOptions {\n buffers: Record<string, string>;\n assetPaths: string[];\n templatePath: string;\n data: PreviewData;\n languageCode: string;\n countryCode?: string;\n assetOrigin: string;\n mediaBaseUrl: string;\n}\n\nconst buildLocalization = (languageCode: string, countryCode?: string): StorefrontLocalization => {\n return {\n country: countryCode ? { name: countryCode, countryCode } : undefined,\n language: { languageCode, languageName: languageCode },\n availableCountries: [],\n availableLanguages: [],\n };\n};\n\n// Same page context shape as useThemeVisualBuilderPreview.\nconst buildPageContext = (data: PreviewData): Record<string, unknown> => {\n if (!data.page) {\n return {};\n }\n\n const entry = (data.page.entry as Record<string, unknown> | undefined) ?? {};\n\n return {\n page: { ...entry, entity: data.page.entity, type: data.page.type },\n collection: data.collection,\n };\n};\n\n// Renders one template the way the admin editor preview does. Throws on render failure.\nexport const renderThemePage = async (options: RenderPageOptions): Promise<string> => {\n const { buffers, assetPaths, templatePath, data, languageCode, countryCode, assetOrigin, mediaBaseUrl } = options;\n const resolveMediaUrl = createThemeMediaUrlResolver(mediaBaseUrl);\n const localizedBuffers = applyThemeCustomizerLocaleOverrides(buffers, languageCode, defaultLanguageCode);\n const assetFiles = assetPaths.map((path) => ({ path, fileUrl: `${assetOrigin}/${path}` }));\n const themeAssetUrls = getThemeAssetUrls(assetFiles, liquidThemeFolderNames.assets, resolveMediaUrl);\n const previewBuffers = rewriteLiquidThemeAssetBuffers(localizedBuffers, themeAssetUrls);\n const localization = buildLocalization(languageCode, countryCode);\n const customFilters = createLiquidFilters({ fileBuffers: localizedBuffers, activeLocale: languageCode, localization, resolveMediaUrl });\n const { entities: entityQueries } = buildPreviewRequest(buffers, templatePath);\n const renderedHtml = await renderLiquidThemeBundle(previewBuffers, {\n customFilters,\n themeAssetUrls,\n resolveMediaUrl,\n templatePath,\n context: {\n entities: data.entities,\n contentCollections: data.contentCollections,\n entityQueries,\n linkTargets: data.linkTargets ?? {},\n contentLoading: false,\n localization,\n ...buildPageContext(data),\n },\n });\n\n return ensureThemeStylesheetsBeforeContent(renderedHtml);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,MAAM,eAAe;;;ACkB9B,IAAM,oBAAoB,CAAC,cAAsB,gBAAiD;AAC9F,SAAO;AAAA,IACH,SAAS,cAAc,EAAE,MAAM,aAAa,YAAY,IAAI;AAAA,IAC5D,UAAU,EAAE,cAAc,cAAc,aAAa;AAAA,IACrD,oBAAoB,CAAC;AAAA,IACrB,oBAAoB,CAAC;AAAA,EACzB;AACJ;AAGA,IAAM,mBAAmB,CAAC,SAA+C;AACrE,MAAI,CAAC,KAAK,MAAM;AACZ,WAAO,CAAC;AAAA,EACZ;AAEA,QAAM,QAAS,KAAK,KAAK,SAAiD,CAAC;AAE3E,SAAO;AAAA,IACH,MAAM,EAAE,GAAG,OAAO,QAAQ,KAAK,KAAK,QAAQ,MAAM,KAAK,KAAK,KAAK;AAAA,IACjE,YAAY,KAAK;AAAA,EACrB;AACJ;AAGO,IAAM,kBAAkB,OA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I,QAAQ,OAAO,KAAK,kBAAkB,EAAE;AAC/D,mBAAa,UAAU,KAAK,EAAE,UAAU,GAAG,QAAQ,cAAc,QAAQ,OAAO,EAAE,CAAC,GAAG,QAAQ,GAAG,MAAM,GAAG,GAAG,EAAE;AAC/G;AAAA,IACJ;AAEA,QAAI,CAAC,QAAQ,WAAW,cAAc;AAClC,eAAS,UAAU,KAAK,aAAa,gBAAgB,QAAQ,GAAG,CAAC;AACjE;AAAA,IACJ;AAEA,QAAI;AAEJ,QAAI;AACA,2BAAqB,MAAM,QAAQ,WAAW,aAAa,UAAU,gBAAgB,CAAC;AAAA,IAC1F,SAAS,OAAO;AACZ,eAAS,UAAU,KAAK,gBAAgB,KAAK,CAAC;AAC9C;AAAA,IACJ;AAEA,QAAI,uBAAuB,MAAM;AAC7B,YAAM,OAAO,SAAS,WAAW,QAAQ,IAAI,uGAAuG;AACpJ,eAAS,UAAU,KAAK,aAAa,gBAAgB,QAAQ,IAAI,IAAI,EAAE,CAAC;AACxE;AAAA,IACJ;AAEA,UAAM,eAAe,UAAU,oBAAoB,aAAa,QAAQ;AAAA,EAC5E;AAEA,QAAM,SAAS,kBAAkB,KAAK;AAEtC,QAAM,kBAAkB,QAAQ,QAAQ,IAAI;AAE5C,QAAM,UAAU,OAAO,QAAQ;AAE/B,SAAO;AAAA,IACH,KAAK,oBAAoB,QAAQ,IAAI;AAAA,IACrC,eAAe,YAAY;AACvB,iBAAW,MAAM,kBAAkB,QAAQ;AAC3C,aAAO,UAAU;AAAA,IACrB;AAAA,IACA,OAAO,MAAM,YAAY,QAAQ,MAAM;AAAA,EAC3C;AACJ;","names":["address","route"]}
@@ -7,22 +7,23 @@ import {
7
7
  listenOnLocalhost,
8
8
  notFoundHtml,
9
9
  renderErrorPage,
10
- renderStaticHtmlTheme,
11
10
  safeDecode,
12
11
  sendHtml,
13
12
  sendResponse,
14
13
  serveFile
15
- } from "./chunk-VDICVCKJ.js";
14
+ } from "./chunk-RR53HSKJ.js";
16
15
  import {
17
16
  isTextPath
18
- } from "./chunk-PEG6K5NX.js";
19
- import "./chunk-UMGL5N53.js";
17
+ } from "./chunk-MHTCCMQU.js";
18
+ import {
19
+ renderStaticHtmlTheme
20
+ } from "./chunk-Z7WA4YHH.js";
20
21
  import {
21
22
  CliError,
22
23
  staticThemeFolderNames,
23
24
  staticThemeHomePath,
24
25
  themeFileExtensions
25
- } from "./chunk-VY553LTO.js";
26
+ } from "./chunk-NLFY255A.js";
26
27
 
27
28
  // src/lib/dev/static-server.ts
28
29
  import { readdir, readFile } from "fs/promises";
@@ -129,4 +130,4 @@ var startStaticDevServer = async (options) => {
129
130
  export {
130
131
  startStaticDevServer
131
132
  };
132
- //# sourceMappingURL=static-server-7NG4AY2E.js.map
133
+ //# sourceMappingURL=static-server-LFDHJZB6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/dev/static-server.ts"],"sourcesContent":["import { readdir, readFile } from 'node:fs/promises';\nimport type { IncomingMessage, ServerResponse } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport { join, relative, resolve, sep } from 'node:path';\nimport { staticThemeFolderNames, staticThemeHomePath, themeFileExtensions } from '@tomsher/cms-core/constants';\nimport { renderStaticHtmlTheme } from '@tomsher/cms-core/renderer';\nimport { CliError } from '../errors';\nimport { isTextPath } from '../theme-files';\nimport type { DevServer } from './server';\nimport { closeServer, createReloadHub, createRouteServer, linkListHtml, listenOnLocalhost, notFoundHtml, renderErrorPage, safeDecode, sendHtml, sendResponse, serveFile } from './server-shared';\n\nexport interface StaticDevServerOptions {\n themeDir: string;\n port: number;\n}\n\ninterface StaticSnapshot {\n files: Record<string, string>;\n assetUrls: Record<string, string>;\n}\n\nconst staticRootPrefix = `${staticThemeFolderNames.root}/`;\nconst staticFilesPrefix = '/static-files/';\nconst htmlExtension = themeFileExtensions.html;\n\n// Text files are renderer sources. Every non-HTML file gets a local URL that the dev server serves from disk.\nconst readStaticSnapshot = async (themeDir: string): Promise<StaticSnapshot> => {\n const staticDir = join(themeDir, staticThemeFolderNames.root);\n const entries = await readdir(staticDir, { recursive: true, withFileTypes: true }).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') {\n throw new CliError(`No ${staticThemeFolderNames.root}/ folder in ${themeDir}. Pass --mode liquid for a liquid theme.`);\n }\n\n throw error;\n });\n const files: Record<string, string> = {};\n const assetUrls: Record<string, string> = {};\n\n for (const entry of entries) {\n if (!entry.isFile()) {\n continue;\n }\n\n const absolutePath = join(entry.parentPath, entry.name);\n const path = relative(themeDir, absolutePath).split(sep).join('/');\n const relativePath = path.slice(staticRootPrefix.length);\n\n if (!path.toLowerCase().endsWith(htmlExtension)) {\n assetUrls[path] = `${staticFilesPrefix}${relativePath.split('/').map(encodeURIComponent).join('/')}`;\n }\n\n if (isTextPath(path)) {\n files[path] = new TextDecoder().decode(await readFile(absolutePath));\n }\n }\n\n return { files, assetUrls };\n};\n\n// Lookup order for a route: static/<route>.html, then static/<route>/index.html. The route \"\" is the home page.\nconst pageCandidates = (route: string): string[] => {\n const name = route.replace(/\\/+$/, '');\n\n if (name === '') {\n return [staticThemeHomePath];\n }\n\n if (name.endsWith(htmlExtension)) {\n return [`${staticRootPrefix}${name}`];\n }\n\n return [`${staticRootPrefix}${name}${htmlExtension}`, `${staticRootPrefix}${name}/index${htmlExtension}`];\n};\n\n// static/docs/index.html is served at /docs and static/index.html at /.\nconst routeOfPage = (path: string): string => {\n const name = path.slice(staticRootPrefix.length, -htmlExtension.length);\n\n return name === 'index' ? '/' : `/${name.replace(/\\/index$/, '')}`;\n};\n\n// Dev server for a static theme folder (static/ holds the pages and their assets). Files are re-read on each notifyChanged call.\nexport const startStaticDevServer = async (options: StaticDevServerOptions): Promise<DevServer> => {\n const themeDir = resolve(options.themeDir);\n const staticDir = join(themeDir, staticThemeFolderNames.root);\n const reload = createReloadHub();\n let snapshot = await readStaticSnapshot(themeDir);\n\n const renderPage = (response: ServerResponse, pathname: string, route: string): void => {\n const templatePath = pageCandidates(route).find((candidate) => snapshot.files[candidate] !== undefined);\n\n if (templatePath === undefined) {\n sendHtml(response, 404, notFoundHtml(`No page for ${pathname}. See /__templates.`));\n return;\n }\n\n try {\n const { documentHtml } = renderStaticHtmlTheme({ templatePath, files: snapshot.files, assetUrls: snapshot.assetUrls });\n sendHtml(response, 200, documentHtml ?? '');\n } catch (error) {\n sendHtml(response, 500, renderErrorPage(error));\n }\n };\n\n const handleRequest = async (request: IncomingMessage, response: ServerResponse): Promise<void> => {\n if (request.method !== 'GET') {\n sendResponse(response, 405, { 'Content-Type': 'text/plain; charset=utf-8', Allow: 'GET' }, 'Method not allowed');\n return;\n }\n\n const pathname = new URL(request.url ?? '/', 'http://localhost').pathname;\n\n if (pathname === '/__events') {\n reload.open(request, response);\n return;\n }\n\n if (pathname === '/__templates') {\n const links = Object.keys(snapshot.files)\n .filter((path) => path.toLowerCase().endsWith(htmlExtension))\n .sort()\n .map((path) => ({ href: encodeURI(routeOfPage(path)), label: path }));\n sendHtml(response, 200, linkListHtml('Pages', links));\n return;\n }\n\n if (pathname.startsWith(staticFilesPrefix)) {\n await serveFile(response, staticDir, pathname.slice(staticFilesPrefix.length));\n return;\n }\n\n const routePath = safeDecode(pathname.slice(1));\n\n if (routePath === null) {\n sendHtml(response, 400, notFoundHtml('Malformed page path.'));\n return;\n }\n\n renderPage(response, pathname, routePath);\n };\n\n const server = createRouteServer(handleRequest);\n\n await listenOnLocalhost(server, options.port);\n\n const address = server.address() as AddressInfo;\n\n return {\n url: `http://localhost:${address.port}`,\n notifyChanged: async () => {\n snapshot = await readStaticSnapshot(themeDir);\n reload.broadcast();\n },\n close: () => closeServer(server, reload),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS,gBAAgB;AAGlC,SAAS,MAAM,UAAU,SAAS,WAAW;AAkB7C,IAAM,mBAAmB,GAAG,uBAAuB,IAAI;AACvD,IAAM,oBAAoB;AAC1B,IAAM,gBAAgB,oBAAoB;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gBAAgB;AAC7B,YAAM,QAAQ,OAAO,KAAK,SAAS,KAAK,EACnC,OAAO,CAAC,SAAS,KAAK,YAAY,EAAE,SAAS,aAAa,CAAC,EAC3D,KAAK,EACL,IAAI,CAAC,UAAU,EAAE,MAAM,UAAU,YAAY,IAAI,CAAC,GAAG,OAAO,KAAK,EAAE;AACxE,eAAS,UAAU,KAAK,aAAa,SAAS,KAAK,CAAC;AACpD;AAAA,IACJ;AAEA,QAAI,SAAS,WAAW,iBAAiB,GAAG;AACxC,YAAM,UAAU,UAAU,WAAW,SAAS,MAAM,kBAAkB,MAAM,CAAC;AAC7E;AAAA,IACJ;AAEA,UAAM,YAAY,WAAW,SAAS,MAAM,CAAC,CAAC;AAE9C,QAAI,cAAc,MAAM;AACpB,eAAS,UAAU,KAAK,aAAa,sBAAsB,CAAC;AAC5D;AAAA,IACJ;AAEA,eAAW,UAAU,UAAU,SAAS;AAAA,EAC5C;AAEA,QAAM,SAAS,kBAAkB,aAAa;AAE9C,QAAM,kBAAkB,QAAQ,QAAQ,IAAI;AAE5C,QAAM,UAAU,OAAO,QAAQ;AAE/B,SAAO;AAAA,IACH,KAAK,oBAAoB,QAAQ,IAAI;AAAA,IACrC,eAAe,YAAY;AACvB,iBAAW,MAAM,mBAAmB,QAAQ;AAC5C,aAAO,UAAU;AAAA,IACrB;AAAA,IACA,OAAO,MAAM,YAAY,QAAQ,MAAM;AAAA,EAC3C;AACJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsher/cms-theme-kit",
3
- "version": "0.1.7",
3
+ "version": "0.1.10",
4
4
  "description": "Pull a theme from a Tomsher CMS, edit it locally and push it back as a draft.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  "sanitize-html": "^2.18.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@tomsher/cms-core": "0.1.7",
25
+ "@tomsher/cms-core": "0.1.10",
26
26
  "@types/node": "^22.10.0",
27
27
  "tsup": "^8.5.0",
28
28
  "typescript": "^5.9.3",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/dev/data-source.ts","../../cms-core/src/utils/liquid/analysis/template.utils.ts","../../cms-core/src/utils/static/editor/html-editor.utils.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { getLiquidThemeCollectionHandles, getLiquidThemeEntityQueries, getLiquidThemeEntitySources, getLiquidThemeReachableBuffers, getLiquidThemeTemplateCategory, requiresCurrentEntry } from '@tomsher/cms-core/utils';\nimport { themeTemplateCategoryKeys } from '@tomsher/cms-core/constants';\nimport { collectThemeLinkTargetReferences } from '@tomsher/cms-core/utils';\nimport type { CmsClient, RemoteRoute, ThemePreviewRequest } from '../cms-client';\nimport { CliError } from '../errors';\nimport { sha256Hex } from '../hash';\n\nexport interface PreviewData {\n entities: Record<string, Record<string, unknown>>;\n contentCollections: Record<string, unknown>;\n linkTargets?: Record<string, unknown>;\n page?: Record<string, unknown>;\n collection?: Record<string, unknown>;\n}\n\nexport interface DataSourceInput {\n templatePath: string;\n buffers: Record<string, string>;\n path?: string;\n}\n\nexport interface DataSource {\n load: (input: DataSourceInput) => Promise<PreviewData>;\n resolveRoute?: (path: string, templatePaths: string[]) => Promise<string | null>;\n listRoutes?: () => Promise<RemoteRoute[]>;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n};\n\nconst emptyPreviewData = (): PreviewData => {\n return { entities: {}, contentCollections: {} };\n};\n\nconst hasLinkTargetReferences = (content: string): boolean => {\n try {\n return collectThemeLinkTargetReferences(JSON.parse(content)).length > 0;\n } catch {\n return false;\n }\n};\n\n// Mirrors useThemeVisualBuilderEntities in the admin editor.\nexport const buildPreviewRequest = (buffers: Record<string, string>, templatePath: string, path?: string): ThemePreviewRequest => {\n const reachable = getLiquidThemeReachableBuffers(buffers, templatePath);\n const category = getLiquidThemeTemplateCategory(templatePath);\n const page = category === themeTemplateCategoryKeys.collections || category === themeTemplateCategoryKeys.details ? { templatePath, category, ...(path ? { path } : {}) } : undefined;\n const entities = getLiquidThemeEntityQueries(reachable, templatePath).filter((query) => page || !requiresCurrentEntry(query));\n const contentCollections = getLiquidThemeCollectionHandles(buffers, templatePath);\n const sources = getLiquidThemeEntitySources(reachable, templatePath);\n\n const templatePaths = Object.keys(buffers).filter((path) => /^templates\\/[^/]+\\.json$/.test(path));\n const linkSources = Object.entries(buffers)\n .filter(([path, content]) => path.endsWith('.json') && hasLinkTargetReferences(content))\n .map(([, content]) => content);\n\n return { entities, contentCollections, sources, linkSources, templatePaths, page };\n};\n\n// The response is either the envelope { requestedData } or a bare payload; the editor reads requestedData.\nexport const normalizePreviewData = (raw: unknown): PreviewData => {\n const body = isRecord(raw) ? raw : {};\n let payload: Record<string, unknown> = body;\n\n if (isRecord(body.requestedData)) {\n payload = body.requestedData;\n } else if (isRecord(body.data)) {\n payload = body.data;\n }\n\n return {\n entities: isRecord(payload.entities) ? (payload.entities as PreviewData['entities']) : {},\n contentCollections: isRecord(payload.contentCollections) ? payload.contentCollections : {},\n linkTargets: isRecord(payload.linkTargets) ? payload.linkTargets : undefined,\n page: isRecord(payload.page) ? payload.page : undefined,\n collection: isRecord(payload.collection) ? payload.collection : undefined,\n };\n};\n\nexport const createFixturesDataSource = (themeDir: string): DataSource => {\n return {\n load: async ({ templatePath }) => {\n const fixturePath = join(themeDir, 'fixtures', templatePath.replace(/\\//g, '-'));\n let raw: string;\n\n try {\n raw = await readFile(fixturePath, 'utf8');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n return emptyPreviewData();\n }\n\n throw error;\n }\n\n try {\n return normalizePreviewData(JSON.parse(raw));\n } catch {\n throw new CliError(`${fixturePath} is not valid JSON.`);\n }\n },\n };\n};\n\nexport interface LiveDataSourceOptions {\n client: CmsClient;\n themeId: string;\n countryCode?: string;\n}\n\nconst hasPreviewWork = (request: ThemePreviewRequest): boolean => {\n return request.entities.length > 0 || request.contentCollections.length > 0 || request.linkSources.length > 0 || Boolean(request.page);\n};\n\n// The key covers the query inputs only, so markup and CSS edits that keep the same queries reuse the cached data.\nconst cacheKeyOf = (request: ThemePreviewRequest): string => {\n const keyInput = { entities: request.entities, contentCollections: request.contentCollections, linkSources: request.linkSources, templatePaths: request.templatePaths, page: request.page };\n return sha256Hex(new TextEncoder().encode(JSON.stringify(keyInput)));\n};\n\n// Cached until the process restarts; a restart is also the only time theme metadata is read again.\nexport const createLiveDataSource = (options: LiveDataSourceOptions): DataSource => {\n const cache = new Map<string, Promise<PreviewData>>();\n\n return {\n resolveRoute: (path, templatePaths) => options.client.resolveRoute(options.themeId, path, templatePaths, options.countryCode),\n listRoutes: () => options.client.listRoutes(options.themeId, options.countryCode),\n load: async ({ buffers, templatePath, path }) => {\n const request = buildPreviewRequest(buffers, templatePath, path);\n\n if (!hasPreviewWork(request)) {\n return emptyPreviewData();\n }\n\n const key = cacheKeyOf(request);\n const cached = cache.get(key);\n\n if (cached) {\n return cached;\n }\n\n const pending = options.client\n .previewData(options.themeId, request, options.countryCode)\n .then(normalizePreviewData);\n\n cache.set(key, pending);\n pending.catch(() => {\n if (cache.get(key) === pending) {\n cache.delete(key);\n }\n });\n\n return pending;\n },\n };\n};\n","import { themeTemplateCategories, themeTemplateCategoryKeys, type ThemeTemplateCategory } from '../../../constants/theme';\nimport { liquidThemeFolderNames, liquidThemeTemplatePaths } from '../../../constants/theme';\n\nexport const getLiquidThemeTemplateCategory = (path: string): ThemeTemplateCategory | 'system' | null => {\n if (path === liquidThemeTemplatePaths.index) return themeTemplateCategoryKeys.pages;\n if (path === liquidThemeTemplatePaths.collection) return themeTemplateCategoryKeys.collections;\n if (path === liquidThemeTemplatePaths.entityDetails) return themeTemplateCategoryKeys.details;\n if (path === liquidThemeTemplatePaths.notFound) return themeTemplateCategoryKeys.system;\n\n for (const category of Object.keys(themeTemplateCategories) as (keyof typeof themeTemplateCategories)[]) {\n const prefix = themeTemplateCategories[category].prefix;\n if (!prefix) continue;\n const categoryPrefix = `${liquidThemeFolderNames.templates}/${prefix}`;\n const name = path.startsWith(categoryPrefix) ? path.slice(categoryPrefix.length) : '';\n if (/^[a-z0-9][a-z0-9_-]*\\.json$/.test(name)) return category;\n }\n return null;\n};\n\nexport const getLiquidThemeTemplateTitle = (path: string, category?: ThemeTemplateCategory): string => {\n if (path === liquidThemeTemplatePaths.index) return 'Home page';\n if (path === liquidThemeTemplatePaths.collection) return 'Collection';\n if (path === liquidThemeTemplatePaths.entityDetails) return 'Entity details';\n\n const templateCategory = category || getLiquidThemeTemplateCategory(path);\n const prefix = templateCategory && templateCategory !== themeTemplateCategoryKeys.system ? themeTemplateCategories[templateCategory].prefix : null;\n const templateName = path.replace(`${liquidThemeFolderNames.templates}/`, '').replace(/\\.json$/, '').replace(prefix || '', '');\n return templateName.replace(/[-_]/g, ' ').replace(/\\b\\w/g, (letter) => letter.toUpperCase());\n};\n\nexport const createLiquidThemeTemplatePath = (category: ThemeTemplateCategory, name: string): string =>\n `${liquidThemeFolderNames.templates}/${themeTemplateCategories[category].prefix}${name}.json`;\n","import { staticThemeFolderNames, staticThemeHtmlExtensionPattern } from '../../../constants/theme';\n\nexport const getStaticHtmlPaths = (files: Array<{ path: string }>): string[] =>\n files\n .map((file) => file.path)\n .filter((path) => path.startsWith(`${staticThemeFolderNames.root}/`) && staticThemeHtmlExtensionPattern.test(path))\n .sort();\n\nexport const getStaticHtmlPageOptions = (paths: string[]) => paths.map((path) => ({ value: path, label: path }));\n\nexport const getStaticHtmlPageContent = (\n selectedPath: string,\n fileBuffers: Record<string, string | undefined>,\n files: Array<{ path: string; content?: string | null }>,\n): string => selectedPath ? fileBuffers[selectedPath] ?? files.find((file) => file.path === selectedPath)?.content ?? '' : '';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY;;;ACEd,IAAM,iCAAiC,CAAC,SAA0D;AACrG,MAAI,SA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