@uniweb/build 0.1.29 → 0.1.30

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/site/plugin.js +81 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -50,8 +50,8 @@
50
50
  "sharp": "^0.33.2"
51
51
  },
52
52
  "optionalDependencies": {
53
- "@uniweb/runtime": "0.2.16",
54
- "@uniweb/content-reader": "1.0.4"
53
+ "@uniweb/content-reader": "1.0.4",
54
+ "@uniweb/runtime": "0.2.17"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
@@ -37,6 +37,79 @@ import { collectSiteContent } from './content-collector.js'
37
37
  import { processAssets, rewriteSiteContentPaths } from './asset-processor.js'
38
38
  import { processAdvancedAssets } from './advanced-processors.js'
39
39
  import { processCollections, writeCollectionFiles } from './collection-processor.js'
40
+ import { executeFetch, mergeDataIntoContent } from './data-fetcher.js'
41
+
42
+ /**
43
+ * Execute all fetches for site content (used in dev mode)
44
+ * Populates section.cascadedData with fetched data
45
+ *
46
+ * @param {Object} siteContent - The collected site content
47
+ * @param {string} siteDir - Path to site directory
48
+ */
49
+ async function executeDevFetches(siteContent, siteDir) {
50
+ const fetchOptions = { siteRoot: siteDir, publicDir: 'public' }
51
+
52
+ // Site-level fetch
53
+ let siteCascadedData = {}
54
+ const siteFetch = siteContent.config?.fetch
55
+ if (siteFetch) {
56
+ const result = await executeFetch(siteFetch, fetchOptions)
57
+ if (result.data && !result.error) {
58
+ siteCascadedData[siteFetch.schema] = result.data
59
+ }
60
+ }
61
+
62
+ // Process each page
63
+ for (const page of siteContent.pages || []) {
64
+ let pageCascadedData = { ...siteCascadedData }
65
+
66
+ // Page-level fetch
67
+ const pageFetch = page.fetch
68
+ if (pageFetch) {
69
+ const result = await executeFetch(pageFetch, fetchOptions)
70
+ if (result.data && !result.error) {
71
+ pageCascadedData[pageFetch.schema] = result.data
72
+ }
73
+ }
74
+
75
+ // Process sections
76
+ await processDevSectionFetches(page.sections, pageCascadedData, fetchOptions)
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Process fetches for sections recursively
82
+ *
83
+ * @param {Array} sections - Sections to process
84
+ * @param {Object} cascadedData - Data from parent levels
85
+ * @param {Object} fetchOptions - Options for executeFetch
86
+ */
87
+ async function processDevSectionFetches(sections, cascadedData, fetchOptions) {
88
+ if (!sections || !Array.isArray(sections)) return
89
+
90
+ for (const section of sections) {
91
+ // Execute section-level fetch
92
+ const sectionFetch = section.fetch
93
+ if (sectionFetch) {
94
+ const result = await executeFetch(sectionFetch, fetchOptions)
95
+ if (result.data && !result.error) {
96
+ // Merge fetched data into cascadedData for this section
97
+ cascadedData = {
98
+ ...cascadedData,
99
+ [sectionFetch.schema]: result.data
100
+ }
101
+ }
102
+ }
103
+
104
+ // Attach cascaded data to section
105
+ section.cascadedData = { ...cascadedData }
106
+
107
+ // Process subsections recursively
108
+ if (section.subsections && section.subsections.length > 0) {
109
+ await processDevSectionFetches(section.subsections, cascadedData, fetchOptions)
110
+ }
111
+ }
112
+ }
40
113
  import { generateSearchIndex, isSearchEnabled, getSearchIndexFilename } from '../search/index.js'
41
114
  import { mergeTranslations } from '../i18n/merge.js'
42
115
 
@@ -372,6 +445,12 @@ export function siteContentPlugin(options = {}) {
372
445
  await writeCollectionFiles(resolvedSitePath, collections)
373
446
  }
374
447
 
448
+ // Execute data fetches in dev mode
449
+ // In production, prerender handles this
450
+ if (!isProduction) {
451
+ await executeDevFetches(siteContent, resolvedSitePath)
452
+ }
453
+
375
454
  // Update localesDir from site config
376
455
  if (siteContent.config?.i18n?.localesDir) {
377
456
  localesDir = siteContent.config.i18n.localesDir
@@ -402,6 +481,8 @@ export function siteContentPlugin(options = {}) {
402
481
  console.log('[site-content] Content changed, rebuilding...')
403
482
  try {
404
483
  siteContent = await collectSiteContent(resolvedSitePath)
484
+ // Execute fetches for the updated content
485
+ await executeDevFetches(siteContent, resolvedSitePath)
405
486
  console.log(`[site-content] Rebuilt ${siteContent.pages?.length || 0} pages`)
406
487
 
407
488
  // Send full reload to client