@pradip1995/framework-compiler 0.2.4 → 0.2.6

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.
@@ -132,9 +132,7 @@ function main() {
132
132
  // Copy static assets: plugin public/ dirs, then client overrides
133
133
  copyPublicAssets(packages, clientDir, outDir)
134
134
 
135
- console.log(
136
- " dynamic-config: schema in backend/config/homepage-config.json — storefront fetches GET /store/dynamic-config"
137
- )
135
+ syncBackendDynamicConfigFromBuild(pagesConfig)
138
136
 
139
137
  console.log(" generated:", packages.segments.length, "segments,", packages.layouts.length, "layouts,", packages.workflows.length, "workflows")
140
138
  console.log("Done.")
@@ -274,6 +272,34 @@ function copyPublicAssets(packages, clientDir, outDir) {
274
272
  }
275
273
  }
276
274
 
275
+ function syncBackendDynamicConfigFromBuild(pagesConfig) {
276
+ try {
277
+ const { syncBackendDynamicConfig } = require("../dynamic-config-schema/sync-backend-schema.cjs")
278
+ const result = syncBackendDynamicConfig({
279
+ clientDir,
280
+ pagesConfig,
281
+ compilerDir: join(__dirname, ".."),
282
+ })
283
+
284
+ if (result.synced) {
285
+ console.log(
286
+ ` dynamic-config: synced ${result.fieldCount} field(s) to backend/config/homepage-config.json`
287
+ )
288
+ for (const warning of result.warnings || []) {
289
+ console.warn(` dynamic-config: ${warning}`)
290
+ }
291
+ } else if (result.warnings?.length) {
292
+ console.warn(` dynamic-config: ${result.warnings.join("; ")}`)
293
+ } else {
294
+ console.log(
295
+ " dynamic-config: no ../backend/ — storefront reads GET /store/dynamic-config at runtime"
296
+ )
297
+ }
298
+ } catch (error) {
299
+ console.warn(` dynamic-config: backend sync skipped (${error.message})`)
300
+ }
301
+ }
302
+
277
303
  function loadPagesConfig(clientDir) {
278
304
  const jsonPath = join(clientDir, "pages.config.json")
279
305
  if (existsSync(jsonPath)) {
@@ -0,0 +1,53 @@
1
+ {
2
+ "always": [
3
+ "logo",
4
+ "website-description",
5
+ "promo-bar",
6
+ "social-links",
7
+ "footer-shop-label",
8
+ "footer-company-label",
9
+ "footer-newsletter-label",
10
+ "footer-newsletter-description"
11
+ ],
12
+ "segments": {
13
+ "@pradip1995/segment-hero": ["homepage-banner-array", "app-banner-array"],
14
+ "@pradip1995/segment-promotional-banners": ["promotional-banner-array"],
15
+ "@pradip1995/segment-why-choose-us": ["why-choose-us-title", "why-choose-us-features"],
16
+ "@pradip1995/segment-features": ["trust-strip-features"],
17
+ "@pradip1995/segment-reviews-marquee": [
18
+ "rating-title",
19
+ "rating-eyebrow",
20
+ "rating-description",
21
+ "ratings"
22
+ ],
23
+ "@pradip1995/segment-new-arrivals": [
24
+ "new-arrivals-title",
25
+ "new-arrivals-view-all",
26
+ "new-arrivals-empty-message"
27
+ ],
28
+ "@pradip1995/segment-bestsellers-carousel": ["bestsellers-title", "bestsellers-view-all"],
29
+ "@pradip1995/segment-loved-by-moms": ["loved-by-moms-title", "loved-by-moms-view-all"],
30
+ "@pradip1995/segment-shop-by-category": ["shop-by-category-title", "shop-by-category-cta"],
31
+ "@pradip1995/segment-shop-by-age": ["shop-by-age-title"],
32
+ "@pradip1995/segment-collections-showcase": [
33
+ "collections-showcase-eyebrow",
34
+ "collections-showcase-title"
35
+ ],
36
+ "@pradip1995/segment-related-products": ["related-products-title"],
37
+ "@pradip1995/segment-help": ["faq-array", "contact-us"]
38
+ },
39
+ "workflows": {
40
+ "@pradip1995/workflow-store": ["store-page-title", "store-page-empty-message"],
41
+ "@pradip1995/workflow-cart": ["cart-summary-title", "cart-empty-message", "cart-empty-button"],
42
+ "@pradip1995/workflow-checkout": ["checkout-form-title", "checkout-summary-title"],
43
+ "@pradip1995/workflow-wishlist": [
44
+ "wishlist-sign-in-title",
45
+ "wishlist-sign-in-description",
46
+ "wishlist-sign-in-button",
47
+ "wishlist-empty-title",
48
+ "wishlist-empty-description",
49
+ "wishlist-empty-button"
50
+ ],
51
+ "@pradip1995/workflow-help": ["faq-array", "contact-us"]
52
+ }
53
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Filter homepage-config schema from pages.config segments/workflows
3
+ * and sync to ../backend/config/ (monorepo scaffold layout).
4
+ */
5
+ const { existsSync, readFileSync, writeFileSync, mkdirSync } = require("fs")
6
+ const { join, dirname } = require("path")
7
+
8
+ function resolveSchemaBundleDir(compilerDir) {
9
+ const compilerBundle = join(compilerDir, "dynamic-config-schema")
10
+ if (existsSync(join(compilerBundle, "schemas", "homepage-config.json"))) {
11
+ return compilerBundle
12
+ }
13
+
14
+ const bundled = join(__dirname, "..")
15
+ if (existsSync(join(bundled, "schemas", "homepage-config.json"))) return bundled
16
+
17
+ let dir = compilerDir
18
+ for (let depth = 0; depth < 8; depth++) {
19
+ const candidate = join(dir, "packages", "framework-compiler", "dynamic-config-schema")
20
+ if (existsSync(join(candidate, "schemas", "homepage-config.json"))) return candidate
21
+ const candidate2 = join(dir, "packages", "dynamic-config-schema")
22
+ if (existsSync(join(candidate2, "schemas", "homepage-config.json"))) return candidate2
23
+ const parent = dirname(dir)
24
+ if (parent === dir) break
25
+ dir = parent
26
+ }
27
+ return null
28
+ }
29
+
30
+ function loadJson(path) {
31
+ return JSON.parse(readFileSync(path, "utf8"))
32
+ }
33
+
34
+ function collectRequiredStructureIds(pagesConfig, fieldMap) {
35
+ const required = new Set(fieldMap.always || [])
36
+
37
+ for (const page of pagesConfig) {
38
+ const workflowFields = fieldMap.workflows?.[page.workflow]
39
+ if (workflowFields) workflowFields.forEach((id) => required.add(id))
40
+
41
+ for (const segment of page.segments || []) {
42
+ const segmentFields = fieldMap.segments?.[segment]
43
+ if (segmentFields) {
44
+ segmentFields.forEach((id) => required.add(id))
45
+ }
46
+ }
47
+ }
48
+
49
+ return required
50
+ }
51
+
52
+ function filterHomepageSchema(fullSchema, requiredIds) {
53
+ const structure = (fullSchema.structure || []).filter((field) => requiredIds.has(field.id))
54
+ return { ...fullSchema, structure }
55
+ }
56
+
57
+ function buildHomepageDefaults(schema) {
58
+ const defaultsPath = join(__dirname, "build-defaults.cjs")
59
+ const { buildHomepageConfigDefaults } = require(defaultsPath)
60
+ return buildHomepageConfigDefaults(schema)
61
+ }
62
+
63
+ /**
64
+ * @param {{ clientDir: string, pagesConfig: object[], compilerDir?: string }} options
65
+ * @returns {{ synced: boolean, fieldCount?: number, warnings?: string[] }}
66
+ */
67
+ function syncBackendDynamicConfig({ clientDir, pagesConfig, compilerDir }) {
68
+ const fromDir = compilerDir || join(__dirname, "..")
69
+ const schemaDir = resolveSchemaBundleDir(fromDir)
70
+ if (!schemaDir) {
71
+ return { synced: false, warnings: ["dynamic-config schema bundle not found"] }
72
+ }
73
+
74
+ const backendConfigDir = join(clientDir, "..", "backend", "config")
75
+ const backendConfigPath = join(backendConfigDir, "homepage-config.json")
76
+ if (!existsSync(dirname(backendConfigPath))) {
77
+ return { synced: false }
78
+ }
79
+
80
+ const clientOverride = join(clientDir, "dynamic-config.schema.json")
81
+ let fullSchema
82
+ if (existsSync(clientOverride)) {
83
+ const payload = loadJson(clientOverride)
84
+ fullSchema = payload.configs?.["homepage-config"] || payload["homepage-config"] || payload
85
+ } else {
86
+ fullSchema = loadJson(join(schemaDir, "schemas", "homepage-config.json"))
87
+ }
88
+
89
+ const fieldMap = loadJson(join(schemaDir, "segment-field-map.json"))
90
+ const requiredIds = collectRequiredStructureIds(pagesConfig, fieldMap)
91
+ const filtered = filterHomepageSchema(fullSchema, requiredIds)
92
+
93
+ const warnings = []
94
+ const knownSegments = new Set(Object.keys(fieldMap.segments || {}))
95
+ for (const page of pagesConfig) {
96
+ for (const segment of page.segments || []) {
97
+ if (!knownSegments.has(segment)) {
98
+ warnings.push(`no dynamic-config mapping for segment ${segment}`)
99
+ }
100
+ }
101
+ }
102
+
103
+ mkdirSync(backendConfigDir, { recursive: true })
104
+ writeFileSync(backendConfigPath, `${JSON.stringify(filtered, null, 2)}\n`)
105
+
106
+ const defaults = buildHomepageDefaults(filtered)
107
+ writeFileSync(
108
+ join(backendConfigDir, "homepage-config.defaults.json"),
109
+ `${JSON.stringify(defaults, null, 2)}\n`
110
+ )
111
+
112
+ return {
113
+ synced: true,
114
+ fieldCount: filtered.structure.length,
115
+ warnings,
116
+ backendConfigPath,
117
+ }
118
+ }
119
+
120
+ module.exports = { syncBackendDynamicConfig, collectRequiredStructureIds, filterHomepageSchema }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/framework-compiler",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {