@brightsideoy/kama 0.1.0-alpha.113 → 0.1.0-alpha.115

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 (60) hide show
  1. package/bin/cli.js +172 -379
  2. package/content/definitions/blocks/button.yaml +7 -8
  3. package/content/definitions/blocks/header.yaml +7 -9
  4. package/content/definitions/blocks/header_image.yaml +14 -15
  5. package/content/definitions/blocks/hero.yaml +22 -21
  6. package/content/definitions/blocks/image_card.yaml +46 -47
  7. package/content/definitions/blocks/single_image.yaml +19 -20
  8. package/content/definitions/blocks/text.yaml +8 -9
  9. package/content/definitions/channels/ecommerce.yaml +14 -16
  10. package/content/definitions/channels/website.yaml +20 -21
  11. package/content/definitions/field-sets/access.yaml +3 -5
  12. package/content/definitions/field-sets/channel-base.yaml +25 -25
  13. package/content/definitions/field-sets/content-block.yaml +36 -41
  14. package/content/definitions/field-sets/page-base.yaml +40 -45
  15. package/content/definitions/field-sets/page-meta.yaml +1 -4
  16. package/content/definitions/field-sets/page-social.yaml +6 -8
  17. package/content/definitions/field-sets/tree-base.yaml +25 -25
  18. package/content/definitions/nodes/address.yaml +29 -21
  19. package/content/definitions/nodes/article.yaml +24 -19
  20. package/content/definitions/nodes/event.yaml +32 -26
  21. package/content/definitions/nodes/external-link.yaml +20 -17
  22. package/content/definitions/nodes/page.yaml +38 -35
  23. package/content/definitions/nodes/person.yaml +29 -27
  24. package/content/definitions/nodes/product.yaml +52 -49
  25. package/content/definitions/trees/navigation.yaml +26 -21
  26. package/content/definitions/trees/social-links.yaml +5 -2
  27. package/dist/assets/index-8T39DEP3.js +162 -0
  28. package/dist/assets/index-B9oh2_TL.css +1 -0
  29. package/dist/index.html +2 -2
  30. package/dist/index.js +6492 -4249
  31. package/package.json +5 -6
  32. package/schema.sql +5 -13
  33. package/templates/astro-starter/astro.config.mjs +40 -0
  34. package/templates/astro-starter/package.json.template +20 -0
  35. package/templates/astro-starter/src/components/blocks/BlockRenderer.astro +125 -0
  36. package/templates/astro-starter/src/components/blocks/ColumnLayout.astro +66 -0
  37. package/templates/astro-starter/src/components/blocks/HeaderImage.astro +131 -0
  38. package/templates/astro-starter/src/components/blocks/Hero.astro +218 -0
  39. package/templates/astro-starter/src/components/blocks/ImageBlock.astro +160 -0
  40. package/templates/astro-starter/src/components/blocks/TextBlock.astro +13 -0
  41. package/templates/astro-starter/src/components/global/Breadcrumb.astro +62 -0
  42. package/templates/astro-starter/src/components/global/Footer.astro +48 -0
  43. package/templates/astro-starter/src/components/global/Header.astro +92 -0
  44. package/templates/astro-starter/src/components/global/NavigationMenu.astro +450 -0
  45. package/templates/astro-starter/src/components/ui/KamaImage.astro +148 -0
  46. package/templates/astro-starter/src/kama-image-service.ts +41 -0
  47. package/templates/astro-starter/src/layouts/Layout.astro +280 -0
  48. package/templates/astro-starter/src/lib/cms.ts +149 -0
  49. package/templates/astro-starter/src/lib/media-url.ts +34 -0
  50. package/templates/astro-starter/src/middleware.ts +306 -0
  51. package/templates/astro-starter/src/pages/404.astro +46 -0
  52. package/templates/astro-starter/src/pages/[...slug].astro +234 -0
  53. package/templates/astro-starter/src/pages/media/[...path].ts +113 -0
  54. package/templates/astro-starter/tsconfig.json +0 -0
  55. package/test-local.sh +76 -0
  56. package/dist/assets/index-10GEw0KY.css +0 -1
  57. package/dist/assets/index-THJ6BqPP.js +0 -1394
  58. package/kama-worker/bundled-definitions.js +0 -2394
  59. package/kama-worker/bundled-definitions.ts +0 -2395
  60. package/scripts/bundle-definitions.js +0 -224
@@ -1,224 +0,0 @@
1
- // scripts/bundle-definitions.js
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import YAML from 'yaml';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- // 🎯 Package root is one directory up from scripts/
11
- const packageRootDir = path.resolve(__dirname, '..');
12
-
13
- // Look for definitions across package core AND consumer project overrides
14
- function getDefinitionFiles(subDir) {
15
- const fileMap = new Map();
16
-
17
- const possibleDirs = [
18
- // 1. Core package defaults (from inside node_modules or package source)
19
- path.resolve(packageRootDir, "content/definitions", subDir),
20
- path.resolve(packageRootDir, "definitions", subDir),
21
-
22
- // 2. Fallbacks relative to node_modules if running from workspace root
23
- path.resolve(process.cwd(), "node_modules/@brightsideoy/kama/content/definitions", subDir),
24
- path.resolve(process.cwd(), "node_modules/@brightsideoy/kama/definitions", subDir),
25
-
26
- // 3. Consumer project local overrides (highest priority — overwrites defaults)
27
- path.resolve(process.cwd(), "content/definitions", subDir),
28
- path.resolve(process.cwd(), "definitions", subDir),
29
- path.resolve(process.cwd(), "schemas", subDir),
30
- path.resolve(process.cwd(), "server/schemas", subDir),
31
- ];
32
-
33
- for (const dirPath of possibleDirs) {
34
- if (!fs.existsSync(dirPath)) continue;
35
-
36
- const walkDir = (currentDir, relativePath = "") => {
37
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
38
- for (const entry of entries) {
39
- const entryRelPath = path.join(relativePath, entry.name);
40
- const fullPath = path.join(currentDir, entry.name);
41
-
42
- if (entry.isDirectory()) {
43
- walkDir(fullPath, entryRelPath);
44
- } else if (
45
- entry.name.endsWith(".yaml") ||
46
- entry.name.endsWith(".yml") ||
47
- entry.name.endsWith(".json")
48
- ) {
49
- // Overwrite earlier entries so local consumer files override package defaults
50
- fileMap.set(entryRelPath, fullPath);
51
- }
52
- }
53
- };
54
-
55
- walkDir(dirPath);
56
- }
57
-
58
- return Array.from(fileMap.entries()).map(([fileName, filePath]) => ({ fileName, filePath }));
59
- }
60
-
61
- function parseFile(filePath) {
62
- const content = fs.readFileSync(filePath, 'utf-8');
63
- return filePath.endsWith('.json') ? JSON.parse(content) : YAML.parse(content);
64
- }
65
-
66
- function loadDir(...subDirs) {
67
- const res = {};
68
- for (const subDir of subDirs) {
69
- const files = getDefinitionFiles(subDir);
70
- for (const { fileName, filePath } of files) {
71
- const key = path.basename(fileName, path.extname(fileName));
72
- try {
73
- res[key] = parseFile(filePath);
74
- } catch (e) {
75
- console.warn(`Failed to parse ${filePath}:`, e);
76
- }
77
- }
78
- }
79
- return res;
80
- }
81
-
82
- function loadSingle(subDirAndFile) {
83
- const files = getDefinitionFiles(path.dirname(subDirAndFile));
84
- const targetBase = path.basename(subDirAndFile);
85
- const matched = files.find(
86
- f => path.basename(f.fileName) === targetBase ||
87
- path.basename(f.fileName) === targetBase.replace(/\.yaml$/, '.yml') ||
88
- path.basename(f.fileName) === targetBase.replace(/\.yaml$/, '.json')
89
- );
90
- if (!matched) return null;
91
- try {
92
- return parseFile(matched.filePath);
93
- } catch (e) {
94
- return null;
95
- }
96
- }
97
-
98
- // 🎯 MAP DEFINITIONS
99
- const rawBlocks = loadDir("blocks", "elements");
100
- const rawBlockLayouts = loadDir("block-layouts");
101
- const rawNodeLayouts = loadDir("node-layouts", "layouts");
102
- const rawNodes = loadDir("nodes");
103
-
104
- // 🎯 Normalization Helper for Nodes
105
- function normalizeNode(node, idKey) {
106
- if (!node || typeof node !== 'object') return node;
107
-
108
- node.id = node.id || idKey;
109
- node.inTree = node.inTree === true;
110
- node.inVault = node.inVault !== false;
111
- node.hasCanvas = node.hasCanvas === true;
112
-
113
- // Ensure root-level fields object exists
114
- if (!node.fields || typeof node.fields !== 'object') {
115
- node.fields = {};
116
- }
117
-
118
- // Extract tab fields into top-level fields map if missing
119
- if (node.tabs && typeof node.tabs === 'object') {
120
- for (const tab of Object.values(node.tabs)) {
121
- if (tab && tab.fields && typeof tab.fields === 'object') {
122
- if (Array.isArray(tab.fields)) {
123
- for (const fItem of tab.fields) {
124
- if (typeof fItem === 'object' && fItem !== null) {
125
- Object.assign(node.fields, fItem);
126
- }
127
- }
128
- } else {
129
- Object.assign(node.fields, tab.fields);
130
- }
131
- }
132
- }
133
- }
134
-
135
- return node;
136
- }
137
-
138
- // Apply normalization pass across all nodes
139
- for (const [key, node] of Object.entries(rawNodes)) {
140
- rawNodes[key] = normalizeNode(node, key);
141
- }
142
-
143
- const bundled = {
144
- rawNodes,
145
- rawTrees: loadDir("trees"),
146
- rawChannels: loadDir("channels"),
147
- rawBlocks,
148
- rawElements: rawBlocks,
149
- rawBlockLayouts,
150
- rawNodeLayouts,
151
- rawLayouts: { ...rawNodeLayouts, ...rawBlockLayouts },
152
- rawFieldSets: loadDir("field-sets"),
153
- rawTemplates: loadDir("templates"),
154
- nodeTemplate: loadSingle("templates/node.yaml") || { fields: {} },
155
- treeTemplate: loadSingle("templates/tree.yaml") || { fields: {} },
156
- channelTemplate: loadSingle("channels/channel.yaml") || loadSingle("templates/channel.yaml") || { fields: {} },
157
- userTemplate: loadSingle("users/user.yaml") || loadSingle("templates/user.yaml") || { fields: {} },
158
- };
159
-
160
- const outputContent = `// Auto-generated pre-bundled definitions for Kama Core Engine
161
- export const BUNDLED_DEFINITIONS = ${JSON.stringify(bundled, null, 2)};
162
- `;
163
-
164
- // 🎯 Always ensure target worker directory exists before writing
165
- const activeWorkerDir = path.resolve(process.cwd(), 'kama-worker');
166
- if (!fs.existsSync(activeWorkerDir)) {
167
- fs.mkdirSync(activeWorkerDir, { recursive: true });
168
- }
169
-
170
- // 🎯 Write to Kama worker directory as well as package locations
171
- const targetDirs = [
172
- activeWorkerDir,
173
- path.resolve(process.cwd(), 'cms-worker'), // legacy fallback
174
- path.resolve(packageRootDir, 'server/db'),
175
- path.resolve(process.cwd(), 'node_modules/@brightsideoy/kama/server/db'),
176
- path.resolve(process.cwd(), 'node_modules/@brightsideoy/kama/dist'),
177
- path.resolve(process.cwd(), 'server/db'),
178
- ];
179
-
180
- for (const dir of targetDirs) {
181
- if (fs.existsSync(dir)) {
182
- const outputPath = path.resolve(dir, 'bundled-definitions.ts');
183
- fs.writeFileSync(outputPath, outputContent, 'utf-8');
184
- // Also write .js version for built packages / worker runtime imports
185
- const jsOutputPath = path.resolve(dir, 'bundled-definitions.js');
186
- fs.writeFileSync(jsOutputPath, `export const BUNDLED_DEFINITIONS = ${JSON.stringify(bundled, null, 2)};\n`, 'utf-8');
187
- }
188
- }
189
-
190
- console.log(`✅ Definitions bundled successfully:
191
- • Nodes: ${Object.keys(bundled.rawNodes).length} (${Object.keys(bundled.rawNodes).join(', ')})
192
- • Blocks: ${Object.keys(bundled.rawBlocks).length} (${Object.keys(bundled.rawBlocks).join(', ')})
193
- • Channels: ${Object.keys(bundled.rawChannels).length} (${Object.keys(bundled.rawChannels).join(', ')})
194
- • Trees: ${Object.keys(bundled.rawTrees).length} (${Object.keys(bundled.rawTrees).join(', ')})`);
195
-
196
- // Auto-generate SQL Indexes
197
- const indexQueries = new Set([
198
- "-- Native Columns",
199
- "CREATE INDEX IF NOT EXISTS idx_content_nodes_slug ON content_nodes (slug);",
200
- "CREATE INDEX IF NOT EXISTS idx_content_nodes_contentType ON content_nodes (contentType);",
201
- "CREATE INDEX IF NOT EXISTS idx_content_nodes_updatedAt ON content_nodes (updatedAt);\n",
202
- "-- JSON Custom Fields"
203
- ]);
204
-
205
- function extractIndexes(obj) {
206
- if (typeof obj !== 'object' || obj === null) return;
207
- for (const [key, value] of Object.entries(obj)) {
208
- if (typeof value === 'object' && value !== null) {
209
- if (value.index === true && key !== "id" && key !== "slug" && key !== "contentType") {
210
- indexQueries.add(`CREATE INDEX IF NOT EXISTS idx_content_nodes_${key} ON content_nodes (json_extract(dataJson, '$.${key}'));`);
211
- }
212
- extractIndexes(value);
213
- }
214
- }
215
- }
216
-
217
- extractIndexes(bundled.rawNodes);
218
-
219
- const sqlContent = Array.from(indexQueries).join('\n');
220
- const schemaSqlPath = path.resolve(process.cwd(), 'schema.sql');
221
-
222
- if (fs.existsSync(schemaSqlPath)) {
223
- fs.appendFileSync(schemaSqlPath, '\n\n' + sqlContent + '\n', 'utf-8');
224
- }