@pradip1995/framework-compiler 0.2.6 → 0.3.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.
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2021",
4
+ "esModuleInterop": true,
5
+ "module": "Node16",
6
+ "moduleResolution": "Node16",
7
+ "emitDecoratorMetadata": true,
8
+ "experimentalDecorators": true,
9
+ "skipLibCheck": true,
10
+ "skipDefaultLibCheck": true,
11
+ "declaration": false,
12
+ "sourceMap": false,
13
+ "inlineSourceMap": true,
14
+ "outDir": "./.medusa/server",
15
+ "rootDir": "./",
16
+ "jsx": "react-jsx",
17
+ "forceConsistentCasingInFileNames": true,
18
+ "resolveJsonModule": true,
19
+ "checkJs": false,
20
+ "strictNullChecks": true
21
+ },
22
+ "ts-node": {
23
+ "swc": false,
24
+ "compiler": "typescript",
25
+ "transpileOnly": true
26
+ },
27
+ "include": ["**/*", ".medusa/types/*"],
28
+ "exclude": ["node_modules", ".medusa/server", ".medusa/admin", ".cache"]
29
+ }
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * backend-build — reads plugins.config.json + backend.config.json,
4
+ * generates Medusa backend into .generated-backend/ (gitignored).
5
+ */
6
+ import {
7
+ cpSync,
8
+ existsSync,
9
+ mkdirSync,
10
+ readFileSync,
11
+ readdirSync,
12
+ rmSync,
13
+ writeFileSync,
14
+ } from "fs"
15
+ import { join, dirname, resolve } from "path"
16
+ import { fileURLToPath } from "url"
17
+ import { createRequire } from "module"
18
+
19
+ const __dirname = dirname(fileURLToPath(import.meta.url))
20
+ const require = createRequire(import.meta.url)
21
+ const COMPILER_ROOT = join(__dirname, "..")
22
+ const TEMPLATE_ROOT = join(COMPILER_ROOT, "backend-templates")
23
+
24
+ const { generateMedusaConfig } = require(join(TEMPLATE_ROOT, "generate-medusa-config.cjs"))
25
+ const {
26
+ buildBackendPackageJson,
27
+ resolveEnabledPlugins,
28
+ resolveDependencies,
29
+ } = require(join(TEMPLATE_ROOT, "generate-backend-package.cjs"))
30
+ const { buildHomepageConfigDefaults } = require(
31
+ join(TEMPLATE_ROOT, "scripts", "build-homepage-defaults.cjs")
32
+ )
33
+
34
+ const clientDir = resolve(process.cwd())
35
+ const outDir = join(clientDir, ".generated-backend")
36
+
37
+ function loadJson(path) {
38
+ return JSON.parse(readFileSync(path, "utf8"))
39
+ }
40
+
41
+ function applyTemplate(content, vars) {
42
+ return content.replace(/\{\{(\w+)\}\}/g, (_, key) => vars[key] ?? "")
43
+ }
44
+
45
+ function copyDir(src, dest, { skip = [] } = {}) {
46
+ if (!existsSync(src)) return
47
+ mkdirSync(dest, { recursive: true })
48
+ for (const entry of readdirSync(src, { withFileTypes: true })) {
49
+ if (skip.includes(entry.name)) continue
50
+ const from = join(src, entry.name)
51
+ const to = join(dest, entry.name)
52
+ if (entry.isDirectory()) {
53
+ copyDir(from, to, { skip })
54
+ } else {
55
+ cpSync(from, to)
56
+ }
57
+ }
58
+ }
59
+
60
+ function resolveTemplateVars(backendConfig) {
61
+ const defaultRegion = backendConfig.defaultRegion || "in"
62
+ const regionCurrency = {
63
+ in: { currency: "inr", name: "India" },
64
+ us: { currency: "usd", name: "United States" },
65
+ gb: { currency: "gbp", name: "United Kingdom" },
66
+ eu: { currency: "eur", name: "Europe" },
67
+ }
68
+ const meta = regionCurrency[defaultRegion] || {
69
+ currency: defaultRegion.length === 2 ? defaultRegion : "usd",
70
+ name: defaultRegion.toUpperCase(),
71
+ }
72
+
73
+ return {
74
+ DEFAULT_REGION: defaultRegion,
75
+ DEFAULT_CURRENCY: meta.currency,
76
+ DEFAULT_REGION_NAME: meta.name,
77
+ }
78
+ }
79
+
80
+ function preserveHomepageConfig() {
81
+ const configDir = join(outDir, "config")
82
+ const homepagePath = join(configDir, "homepage-config.json")
83
+ const defaultsPath = join(configDir, "homepage-config.defaults.json")
84
+ if (!existsSync(homepagePath)) return null
85
+ return {
86
+ homepage: readFileSync(homepagePath, "utf8"),
87
+ defaults: existsSync(defaultsPath) ? readFileSync(defaultsPath, "utf8") : null,
88
+ }
89
+ }
90
+
91
+ function restoreHomepageConfig(configDir, preserved) {
92
+ if (!preserved) return
93
+ writeFileSync(join(configDir, "homepage-config.json"), preserved.homepage)
94
+ if (preserved.defaults) {
95
+ writeFileSync(join(configDir, "homepage-config.defaults.json"), preserved.defaults)
96
+ } else {
97
+ const schema = JSON.parse(preserved.homepage)
98
+ writeFileSync(
99
+ join(configDir, "homepage-config.defaults.json"),
100
+ `${JSON.stringify(buildHomepageConfigDefaults(schema), null, 2)}\n`
101
+ )
102
+ }
103
+ }
104
+
105
+ function main() {
106
+ console.log("backend build")
107
+ console.log(" client:", clientDir)
108
+ console.log(" output:", outDir)
109
+
110
+ const pluginsConfigPath = join(clientDir, "plugins.config.json")
111
+ const backendConfigPath = join(clientDir, "backend.config.json")
112
+
113
+ if (!existsSync(pluginsConfigPath)) {
114
+ console.error("Missing plugins.config.json in", clientDir)
115
+ process.exit(1)
116
+ }
117
+ if (!existsSync(backendConfigPath)) {
118
+ console.error("Missing backend.config.json in", clientDir)
119
+ process.exit(1)
120
+ }
121
+
122
+ const pluginsConfig = loadJson(pluginsConfigPath)
123
+ const backendConfig = loadJson(backendConfigPath)
124
+ const defaults = loadJson(join(TEMPLATE_ROOT, "medusa-plugin-versions.json"))
125
+
126
+ const enabledPlugins = resolveEnabledPlugins(pluginsConfig, backendConfig, defaults)
127
+ const { medusa, plugins } = resolveDependencies(pluginsConfig, enabledPlugins, defaults)
128
+ const preset = backendConfig.preset || "full"
129
+ const templateVars = resolveTemplateVars(backendConfig)
130
+
131
+ const preservedHomepage = preserveHomepageConfig()
132
+
133
+ if (existsSync(outDir)) {
134
+ rmSync(outDir, { recursive: true, force: true })
135
+ }
136
+ mkdirSync(outDir, { recursive: true })
137
+
138
+ copyDir(join(TEMPLATE_ROOT, "src"), join(outDir, "src"))
139
+ copyDir(join(TEMPLATE_ROOT, "scripts"), join(outDir, "scripts"))
140
+ cpSync(join(TEMPLATE_ROOT, "tsconfig.json"), join(outDir, "tsconfig.json"))
141
+
142
+ const seedContent = applyTemplate(
143
+ readFileSync(join(TEMPLATE_ROOT, "src", "scripts", "seed.ts"), "utf8"),
144
+ templateVars
145
+ )
146
+ writeFileSync(join(outDir, "src", "scripts", "seed.ts"), seedContent)
147
+
148
+ const configDir = join(outDir, "config")
149
+ mkdirSync(configDir, { recursive: true })
150
+ if (preservedHomepage) {
151
+ restoreHomepageConfig(configDir, preservedHomepage)
152
+ } else {
153
+ cpSync(join(TEMPLATE_ROOT, "config", "homepage-config.json"), join(configDir, "homepage-config.json"))
154
+ const schema = loadJson(join(configDir, "homepage-config.json"))
155
+ writeFileSync(
156
+ join(configDir, "homepage-config.defaults.json"),
157
+ `${JSON.stringify(buildHomepageConfigDefaults(schema), null, 2)}\n`
158
+ )
159
+ }
160
+
161
+ writeFileSync(
162
+ join(outDir, "medusa-config.ts"),
163
+ generateMedusaConfig({ enabledPlugins, preset })
164
+ )
165
+
166
+ writeFileSync(
167
+ join(outDir, "package.json"),
168
+ `${JSON.stringify(
169
+ buildBackendPackageJson({
170
+ medusa,
171
+ plugins,
172
+ projectName: backendConfig.projectName || "store",
173
+ }),
174
+ null,
175
+ 2
176
+ )}\n`
177
+ )
178
+
179
+ writeFileSync(join(outDir, ".npmrc"), "legacy-peer-deps=true\n")
180
+
181
+ const envSource = join(clientDir, ".env")
182
+ if (existsSync(envSource)) {
183
+ cpSync(envSource, join(outDir, ".env"))
184
+ }
185
+
186
+ console.log(" plugins:", enabledPlugins.length)
187
+ console.log("Done.")
188
+ }
189
+
190
+ main()
@@ -71,9 +71,13 @@ function syncBackendDynamicConfig({ clientDir, pagesConfig, compilerDir }) {
71
71
  return { synced: false, warnings: ["dynamic-config schema bundle not found"] }
72
72
  }
73
73
 
74
- const backendConfigDir = join(clientDir, "..", "backend", "config")
74
+ const backendRoot = join(clientDir, "..", "backend")
75
+ const configOnlyLayout = existsSync(join(backendRoot, "plugins.config.json"))
76
+ const backendConfigDir = configOnlyLayout
77
+ ? join(backendRoot, ".generated-backend", "config")
78
+ : join(backendRoot, "config")
75
79
  const backendConfigPath = join(backendConfigDir, "homepage-config.json")
76
- if (!existsSync(dirname(backendConfigPath))) {
80
+ if (!configOnlyLayout && !existsSync(dirname(backendConfigPath))) {
77
81
  return { synced: false }
78
82
  }
79
83
 
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@pradip1995/framework-compiler",
3
- "version": "0.2.6",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "bin": {
10
- "storefront-build": "./bin/storefront-build.js"
10
+ "storefront-build": "./bin/storefront-build.js",
11
+ "backend-build": "./bin/backend-build.js"
11
12
  },
12
13
  "files": [
13
14
  "bin",
14
15
  "templates",
16
+ "backend-templates",
15
17
  "dynamic-config-schema"
16
18
  ],
17
19
  "dependencies": {