@pradip1995/framework-compiler 0.2.2 → 0.2.4
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/bin/storefront-build.js +14 -83
- package/package.json +1 -1
package/bin/storefront-build.js
CHANGED
|
@@ -39,10 +39,12 @@ function loadClientStorefrontConfig(clientDir) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function generateRootLayout(config) {
|
|
42
|
+
function generateRootLayout(config, clientDir) {
|
|
43
43
|
const loaderJson = JSON.stringify(config.loader)
|
|
44
|
+
const hasThemeOverrides = existsSync(join(clientDir, "theme-overrides.css"))
|
|
45
|
+
const overridesImport = hasThemeOverrides ? `\nimport "./theme-overrides.css"` : ""
|
|
44
46
|
return `import "@pradip1995/segment-tokens/themes/impulse.css"
|
|
45
|
-
import "./globals.css"
|
|
47
|
+
import "./globals.css"${overridesImport}
|
|
46
48
|
import { LoaderProvider, GlobalLoader } from "@pradip1995/segment-loader"
|
|
47
49
|
|
|
48
50
|
const loaderConfig = ${loaderJson} as const
|
|
@@ -103,7 +105,13 @@ function main() {
|
|
|
103
105
|
require("fs").rmSync(legacyCatchAll, { recursive: true, force: true })
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
const themeOverrides = join(clientDir, "theme-overrides.css")
|
|
109
|
+
if (existsSync(themeOverrides)) {
|
|
110
|
+
cpSync(themeOverrides, join(outDir, "app", "theme-overrides.css"))
|
|
111
|
+
console.log(" theme: client theme-overrides.css")
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
writeFileSync(join(outDir, "app", "layout.tsx"), generateRootLayout(loadClientStorefrontConfig(clientDir), clientDir))
|
|
107
115
|
writeFileSync(join(outDir, "app", "globals.css"), GLOBALS_CSS)
|
|
108
116
|
writeFileSync(join(outDir, "app", "page.tsx"), ROOT_PAGE)
|
|
109
117
|
writeFileSync(join(outDir, "app", "error.tsx"), ERROR_PAGE)
|
|
@@ -124,7 +132,9 @@ function main() {
|
|
|
124
132
|
// Copy static assets: plugin public/ dirs, then client overrides
|
|
125
133
|
copyPublicAssets(packages, clientDir, outDir)
|
|
126
134
|
|
|
127
|
-
|
|
135
|
+
console.log(
|
|
136
|
+
" dynamic-config: schema in backend/config/homepage-config.json — storefront fetches GET /store/dynamic-config"
|
|
137
|
+
)
|
|
128
138
|
|
|
129
139
|
console.log(" generated:", packages.segments.length, "segments,", packages.layouts.length, "layouts,", packages.workflows.length, "workflows")
|
|
130
140
|
console.log("Done.")
|
|
@@ -264,85 +274,6 @@ function copyPublicAssets(packages, clientDir, outDir) {
|
|
|
264
274
|
}
|
|
265
275
|
}
|
|
266
276
|
|
|
267
|
-
function resolveDynamicConfigSchemaDir() {
|
|
268
|
-
const bundled = join(__dirname, "..", "dynamic-config-schema")
|
|
269
|
-
if (existsSync(join(bundled, "schemas", "homepage-config.json"))) return bundled
|
|
270
|
-
|
|
271
|
-
const candidates = [
|
|
272
|
-
join(__dirname, "..", "dynamic-config-schema"),
|
|
273
|
-
join(__dirname, "..", "..", "dynamic-config-schema"),
|
|
274
|
-
]
|
|
275
|
-
for (const candidate of candidates) {
|
|
276
|
-
if (existsSync(join(candidate, "schemas", "homepage-config.json"))) return candidate
|
|
277
|
-
}
|
|
278
|
-
let dir = dirname(__dirname)
|
|
279
|
-
for (let depth = 0; depth < 6; depth++) {
|
|
280
|
-
const candidate = join(dir, "packages", "dynamic-config-schema")
|
|
281
|
-
if (existsSync(join(candidate, "schemas", "homepage-config.json"))) return candidate
|
|
282
|
-
const parent = dirname(dir)
|
|
283
|
-
if (parent === dir) break
|
|
284
|
-
dir = parent
|
|
285
|
-
}
|
|
286
|
-
return null
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Emit Medusa dynamic-config schema for backend registration.
|
|
291
|
-
* Output: dynamic-config.generated.json with { configs: { "homepage-config": ... } }
|
|
292
|
-
*
|
|
293
|
-
* Client override: place dynamic-config.schema.json in client root (full { configs } or bare config map).
|
|
294
|
-
*/
|
|
295
|
-
function generateDynamicConfigSchema(clientDir, outDir) {
|
|
296
|
-
const clientOverride = join(clientDir, "dynamic-config.schema.json")
|
|
297
|
-
let payload
|
|
298
|
-
|
|
299
|
-
if (existsSync(clientOverride)) {
|
|
300
|
-
payload = JSON.parse(readFileSync(clientOverride, "utf8"))
|
|
301
|
-
if (!payload.configs) {
|
|
302
|
-
payload = { configs: payload }
|
|
303
|
-
}
|
|
304
|
-
console.log(" dynamic-config: using client dynamic-config.schema.json")
|
|
305
|
-
} else {
|
|
306
|
-
const schemaDir = resolveDynamicConfigSchemaDir()
|
|
307
|
-
if (!schemaDir) {
|
|
308
|
-
console.warn(" dynamic-config: schema package not found — skip generation")
|
|
309
|
-
return
|
|
310
|
-
}
|
|
311
|
-
const homepage = JSON.parse(
|
|
312
|
-
readFileSync(join(schemaDir, "schemas", "homepage-config.json"), "utf8")
|
|
313
|
-
)
|
|
314
|
-
payload = { configs: { "homepage-config": homepage } }
|
|
315
|
-
console.log(" dynamic-config: from packages/dynamic-config-schema")
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
const schemaDir = resolveDynamicConfigSchemaDir()
|
|
319
|
-
const homepageSchema = payload.configs?.["homepage-config"]
|
|
320
|
-
let homepageDefaults = {}
|
|
321
|
-
|
|
322
|
-
if (homepageSchema && schemaDir) {
|
|
323
|
-
const defaultsPath = existsSync(join(schemaDir, "build-defaults.cjs"))
|
|
324
|
-
? join(schemaDir, "build-defaults.cjs")
|
|
325
|
-
: join(schemaDir, "build-defaults.js")
|
|
326
|
-
const { buildHomepageConfigDefaults } = require(defaultsPath)
|
|
327
|
-
homepageDefaults = buildHomepageConfigDefaults(homepageSchema)
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
payload.defaults = {
|
|
331
|
-
...(payload.defaults || {}),
|
|
332
|
-
"homepage-config": homepageDefaults,
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const json = `${JSON.stringify(payload, null, 2)}\n`
|
|
336
|
-
writeFileSync(join(clientDir, "dynamic-config.generated.json"), json)
|
|
337
|
-
writeFileSync(join(outDir, "dynamic-config.generated.json"), json)
|
|
338
|
-
|
|
339
|
-
const defaultsJson = `${JSON.stringify({ "homepage-config": homepageDefaults }, null, 2)}\n`
|
|
340
|
-
writeFileSync(join(clientDir, "dynamic-config.defaults.json"), defaultsJson)
|
|
341
|
-
writeFileSync(join(outDir, "dynamic-config.defaults.json"), defaultsJson)
|
|
342
|
-
console.log(" dynamic-config: wrote dynamic-config.generated.json")
|
|
343
|
-
console.log(" dynamic-config: wrote dynamic-config.defaults.json")
|
|
344
|
-
}
|
|
345
|
-
|
|
346
277
|
function loadPagesConfig(clientDir) {
|
|
347
278
|
const jsonPath = join(clientDir, "pages.config.json")
|
|
348
279
|
if (existsSync(jsonPath)) {
|