@brightsideoy/kama 0.1.0-alpha.148 → 0.1.0-alpha.150

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/cli.js CHANGED
@@ -128,14 +128,14 @@ async function createFullWorkspace() {
128
128
  }
129
129
 
130
130
  if (isCloudflare) {
131
- cmsDomain = (await rl.question('\nCMS Admin Domain (e.g., admin.t3cloud.eu): ')) || 'admin.t3cloud.eu';
131
+ cmsDomain = (await rl.question('\nCMS Admin Domain (e.g., admin.yourdomain.com): ')).trim();
132
132
  if (shouldCreateSite) {
133
- siteDomain = (await rl.question('First Website Domain (e.g., kama.t3cloud.eu): ')) || 'kama.t3cloud.eu';
133
+ siteDomain = (await rl.question('First Website Domain (e.g., yourdomain.com): ')).trim();
134
134
  }
135
135
  }
136
136
 
137
137
  const cmsProtocol = isCloudflare ? 'https://' : 'http://';
138
- const cmsFullUrl = `${cmsProtocol}${cmsDomain.replace(/^https?:\/\//, '')}`;
138
+ const cmsFullUrl = cmsDomain ? `${cmsProtocol}${cmsDomain.replace(/^https?:\/\//, '')}` : 'http://localhost:8787';
139
139
 
140
140
  const workerName = `${projName}-worker`.toLowerCase().replace(/[^a-z0-9_-]/g, '-');
141
141
  let dbName = `${projName}-db`.replace(/[^a-zA-Z0-9_-]/g, '_');
@@ -268,17 +268,15 @@ async function createFullWorkspace() {
268
268
  JSON.stringify(rootPkg, null, 2)
269
269
  );
270
270
 
271
- console.log(`\n☁️ Configuring CMS Worker '${workerName}' (${cmsDomain})...`);
271
+ console.log(`\n☁️ Configuring CMS Worker '${workerName}' (${cmsDomain || 'localhost:8787'})...`);
272
272
  const cmsDir = join(rootDir, 'kama-worker');
273
273
  mkdirSync(cmsDir, { recursive: true });
274
274
 
275
275
  writeFileSync(join(cmsDir, 'seed.sql'), '-- Kama Auto-Generated Seed File\nSELECT 1;\n');
276
276
 
277
- // Initial default bundle with dual exports to satisfy ESM and CJS consumers
278
277
  const emptyDefs = `{ nodes: {}, trees: {}, blocks: {}, nodeLayouts: {}, blockLayouts: {}, channels: {} }`;
279
278
  writeFileSync(join(cmsDir, 'bundled-definitions.js'), `const defs = ${emptyDefs};\nexport const BUNDLED_DEFINITIONS = defs;\nexport default defs;\n`);
280
279
 
281
- // 🎯 ARCHITECTURE SPLIT: Node.js vs Cloudflare
282
280
  if (isCloudflare) {
283
281
  const cmsWorkerIndexContent = `import kamaWorker from '@brightsideoy/kama';
284
282
  import * as localBundle from './bundled-definitions.js';
@@ -286,7 +284,6 @@ import * as localBundle from './bundled-definitions.js';
286
284
  export default {
287
285
  async fetch(request, env, ctx) {
288
286
  const schemas = localBundle.BUNDLED_DEFINITIONS || localBundle.default || localBundle;
289
- // Inject runtime flag natively
290
287
  const customEnv = { ...env, BUNDLED_DEFINITIONS: schemas, KAMA_RUNTIME: 'cloudflare' };
291
288
 
292
289
  if (kamaWorker && typeof kamaWorker.fetch === 'function') {
@@ -333,6 +330,9 @@ export default {
333
330
  main: 'index.js',
334
331
  compatibility_date: '2024-09-23',
335
332
  compatibility_flags: ['nodejs_compat'],
333
+ cache: {
334
+ enabled: true
335
+ },
336
336
  assets: {
337
337
  directory: '../node_modules/@brightsideoy/kama/dist',
338
338
  binding: 'ASSETS'
@@ -361,7 +361,6 @@ export default {
361
361
  writeFileSync(join(cmsDir, 'wrangler.json'), JSON.stringify(cmsWranglerConfig, null, 2));
362
362
  writeFileSync(join(cmsDir, '.dev.vars'), `# Cloudflare Edge Cache Purging Secrets\nCLOUDFLARE_API_TOKEN=cfut_YOUR_CUSTOM_PURGE_TOKEN\n`);
363
363
  } else {
364
- // --- NODE.JS ARCHITECTURE ---
365
364
  const nodeServerContent = `import { serve } from '@hono/node-server';
366
365
  import { serveStatic } from '@hono/node-server/serve-static';
367
366
  import kamaApp from '@brightsideoy/kama';
@@ -372,7 +371,6 @@ import { join } from 'node:path';
372
371
 
373
372
  dotenv.config();
374
373
 
375
- // 🎯 Dynamically find the Kama package dist folder (handles NPM workspace hoisting)
376
374
  const possiblePaths = [
377
375
  './node_modules/@brightsideoy/kama/dist',
378
376
  '../node_modules/@brightsideoy/kama/dist',
@@ -448,6 +446,7 @@ KAMA_RUNTIME=node
448
446
  DB_PATH=./kama.db
449
447
  LOCAL_MEDIA_PATH=./public/media
450
448
  PUBLIC_CMS_URL=${cmsFullUrl}
449
+ PUBLIC_API_URL=${cmsFullUrl}
451
450
  PUBLIC_FRONTEND_URL=${shouldCreateSite ? `http://${siteDomain}` : 'http://localhost:4321'}
452
451
  `);
453
452
  }
@@ -469,7 +468,7 @@ PUBLIC_FRONTEND_URL=${shouldCreateSite ? `http://${siteDomain}` : 'http://localh
469
468
  }
470
469
 
471
470
  if (isCloudflare) {
472
- if (d1DatabaseId === '00000000-0000-0000-0000-000000000000' || d1DatabaseId === 'REPLACE_WITH_YOUR_D1_ID') {
471
+ if (d1DatabaseId === '00000000-0000-0000-0000-000000000000') {
473
472
  console.log(` 3. Run 'npx wrangler login' and create a D1 database manually.`);
474
473
  }
475
474
  console.log(` 4. Update CLOUDFLARE_ZONE_ID in kama-worker/wrangler.json with your actual Zone ID`);
@@ -514,8 +513,8 @@ async function createNewSiteOnly() {
514
513
  let cmsFullUrl = 'http://localhost:8787';
515
514
 
516
515
  if (isCloudflare) {
517
- siteDomain = await rl.question('Website Domain (e.g., brand.com): ');
518
- const cmsDomainInput = (await rl.question('CMS API Domain (e.g., admin.t3cloud.eu): ')) || 'admin.t3cloud.eu';
516
+ siteDomain = (await rl.question('Website Domain (e.g., brand.com): ')).trim();
517
+ const cmsDomainInput = (await rl.question('CMS API Domain (e.g., admin.brand.com): ')).trim();
519
518
  cmsFullUrl = `https://${cmsDomainInput.replace(/^https?:\/\//, '')}`;
520
519
  }
521
520
 
@@ -528,7 +527,6 @@ async function createNewSiteOnly() {
528
527
 
529
528
  /**
530
529
  * COMMAND: npx kama bundle
531
- * Loads the pre-compiled JS compiler natively without runtime tsx/type-stripping issues!
532
530
  */
533
531
  async function bundleWorkspaceSchemas(targetRootDir) {
534
532
  let rootDir = targetRootDir || process.cwd();
@@ -538,15 +536,12 @@ async function bundleWorkspaceSchemas(targetRootDir) {
538
536
  }
539
537
 
540
538
  try {
541
- // 1. First preference: built JavaScript bundle in node_modules/dist
542
539
  let compilerPath = join(__dirname, '../dist/schema-compiler.js');
543
540
 
544
- // 2. Fallback for local monorepo dev where ts source exists
545
541
  if (!existsSync(compilerPath)) {
546
542
  compilerPath = join(__dirname, '../scripts/schema-compiler.ts');
547
543
  }
548
544
 
549
- // 🎯 Native Node ESM Import — Loads pure JS with zero runtime type-stripping errors!
550
545
  const compilerUrl = pathToFileURL(compilerPath).href;
551
546
  await import(compilerUrl);
552
547
  } catch (e) {
@@ -582,12 +577,12 @@ async function promoteLocalToCloudflare() {
582
577
  }
583
578
  }
584
579
 
585
- const cmsDomain = (await rl.question('\nCMS Admin Domain (e.g., admin.t3cloud.eu): ')) || 'admin.t3cloud.eu';
580
+ const cmsDomain = (await rl.question('\nCMS Admin Domain (e.g., admin.yourdomain.com): ')).trim();
586
581
 
587
582
  const sitesFolderDir = join(rootDir, 'sites');
588
583
  let siteDomain = '';
589
584
  if (existsSync(sitesFolderDir)) {
590
- siteDomain = await rl.question('Frontend Website Domain (e.g., kama.t3cloud.eu): ');
585
+ siteDomain = (await rl.question('Frontend Website Domain (e.g., yourdomain.com): ')).trim();
591
586
  }
592
587
 
593
588
  const currentConfig = JSON.parse(readFileSync(workerWranglerPath, 'utf-8'));
@@ -604,6 +599,7 @@ async function promoteLocalToCloudflare() {
604
599
  console.log('⚠️ Could not auto-create D1 (it may already exist). Please verify on your Cloudflare dashboard.');
605
600
  }
606
601
 
602
+ currentConfig.cache = { enabled: true };
607
603
  currentConfig.vars.CDN_DOMAIN = cmsDomain;
608
604
  if (siteDomain) {
609
605
  currentConfig.vars.PUBLIC_FRONTEND_URL = `https://${siteDomain}`;
@@ -621,9 +617,26 @@ async function promoteLocalToCloudflare() {
621
617
  const siteWranglerPath = join(sitesFolderDir, sites[0], 'wrangler.json');
622
618
  if (existsSync(siteWranglerPath)) {
623
619
  const siteConfig = JSON.parse(readFileSync(siteWranglerPath, 'utf-8'));
624
- siteConfig.routes = [{ pattern: siteDomain, custom_domain: true }];
620
+
621
+ siteConfig.cache = { enabled: true };
622
+ siteConfig.routes = [{
623
+ pattern: siteDomain,
624
+ zone_name: siteDomain,
625
+ custom_domain: true,
626
+ enabled: true,
627
+ previews_enabled: false
628
+ }];
629
+
630
+ siteConfig.assets = {
631
+ directory: "./dist/client",
632
+ binding: "ASSETS",
633
+ run_worker_first: true
634
+ };
635
+
636
+ siteConfig.vars = siteConfig.vars || {};
625
637
  siteConfig.vars.PUBLIC_CMS_URL = `https://${cmsDomain}`;
626
638
  siteConfig.vars.PUBLIC_API_URL = `https://${cmsDomain}`;
639
+
627
640
  writeFileSync(siteWranglerPath, JSON.stringify(siteConfig, null, 2));
628
641
  }
629
642
  }
@@ -668,10 +681,34 @@ async function generateAstroSite(rootDir, siteFolder, siteDomain, cmsFullUrl, wo
668
681
  .replace(/\{\{WORKER_NAME\}\}/g, workerName)
669
682
  .replace(/\{\{CMS_URL\}\}/g, cmsFullUrl);
670
683
 
671
- if (isCloudflare) {
684
+ try {
672
685
  const configObj = JSON.parse(wranglerStr);
673
- configObj.routes = [{ pattern: siteDomain, custom_domain: true }];
686
+
687
+ // Enforce worker-level execution & caching controls dynamically
688
+ configObj.cache = { enabled: true };
689
+ configObj.assets = {
690
+ directory: "./dist/client",
691
+ binding: "ASSETS",
692
+ run_worker_first: true
693
+ };
694
+
695
+ configObj.vars = configObj.vars || {};
696
+ configObj.vars.PUBLIC_CMS_URL = cmsFullUrl;
697
+ configObj.vars.PUBLIC_API_URL = cmsFullUrl;
698
+
699
+ if (isCloudflare && siteDomain !== 'localhost:4321') {
700
+ configObj.routes = [{
701
+ pattern: siteDomain,
702
+ zone_name: siteDomain,
703
+ custom_domain: true,
704
+ enabled: true,
705
+ previews_enabled: false
706
+ }];
707
+ }
708
+
674
709
  wranglerStr = JSON.stringify(configObj, null, 2);
710
+ } catch (e) {
711
+ console.warn("⚠️ Could not parse wrangler.json template as JSON, writing raw string.");
675
712
  }
676
713
 
677
714
  writeFileSync(wranglerPath, wranglerStr);