@korajs/cli 1.0.0-beta.6 → 1.0.0-beta.9

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 (58) hide show
  1. package/dist/bin.cjs +123 -41
  2. package/dist/bin.cjs.map +1 -1
  3. package/dist/bin.js +108 -31
  4. package/dist/bin.js.map +1 -1
  5. package/dist/{chunk-ZTVVAYHJ.js → chunk-Z7GCXMGW.js} +8 -4
  6. package/dist/chunk-Z7GCXMGW.js.map +1 -0
  7. package/dist/create.cjs +7 -3
  8. package/dist/create.cjs.map +1 -1
  9. package/dist/create.js +1 -1
  10. package/package.json +8 -8
  11. package/templates/react-basic/README.md.hbs +1 -1
  12. package/templates/react-basic/src/main.tsx +1 -1
  13. package/templates/react-basic/src/vite-env.d.ts +1 -0
  14. package/templates/react-sync/README.md.hbs +3 -3
  15. package/templates/react-sync/server.ts +44 -1
  16. package/templates/react-sync/src/main.tsx +1 -1
  17. package/templates/react-sync/src/vite-env.d.ts +1 -0
  18. package/templates/react-sync/vite.config.ts +1 -1
  19. package/templates/react-tailwind/README.md.hbs +1 -1
  20. package/templates/react-tailwind/src/main.tsx +1 -1
  21. package/templates/react-tailwind/src/vite-env.d.ts +1 -0
  22. package/templates/react-tailwind-sync/README.md.hbs +3 -3
  23. package/templates/react-tailwind-sync/server.ts +44 -1
  24. package/templates/react-tailwind-sync/src/main.tsx +1 -1
  25. package/templates/react-tailwind-sync/src/vite-env.d.ts +1 -0
  26. package/templates/react-tailwind-sync/vite.config.ts +1 -1
  27. package/templates/svelte-basic/README.md.hbs +1 -1
  28. package/templates/svelte-basic/src/main.ts +1 -1
  29. package/templates/svelte-sync/README.md.hbs +3 -3
  30. package/templates/svelte-sync/server.ts +44 -1
  31. package/templates/svelte-sync/src/main.ts +1 -1
  32. package/templates/svelte-sync/src/vite-env.d.ts +1 -0
  33. package/templates/svelte-sync/vite.config.ts +1 -1
  34. package/templates/svelte-tailwind/README.md.hbs +1 -1
  35. package/templates/svelte-tailwind/src/main.ts +1 -1
  36. package/templates/svelte-tailwind-sync/README.md.hbs +3 -3
  37. package/templates/svelte-tailwind-sync/server.ts +44 -1
  38. package/templates/svelte-tailwind-sync/src/main.ts +1 -1
  39. package/templates/svelte-tailwind-sync/src/vite-env.d.ts +1 -0
  40. package/templates/svelte-tailwind-sync/vite.config.ts +1 -1
  41. package/templates/tauri-react/server.ts +44 -1
  42. package/templates/tauri-react/src/AppShell.tsx +1 -1
  43. package/templates/tauri-react/src/vite-env.d.ts +1 -0
  44. package/templates/vue-basic/README.md.hbs +1 -1
  45. package/templates/vue-basic/src/main.ts +1 -1
  46. package/templates/vue-sync/README.md.hbs +3 -3
  47. package/templates/vue-sync/server.ts +44 -1
  48. package/templates/vue-sync/src/main.ts +1 -1
  49. package/templates/vue-sync/src/vite-env.d.ts +1 -0
  50. package/templates/vue-sync/vite.config.ts +1 -1
  51. package/templates/vue-tailwind/README.md.hbs +1 -1
  52. package/templates/vue-tailwind/src/main.ts +1 -1
  53. package/templates/vue-tailwind-sync/README.md.hbs +3 -3
  54. package/templates/vue-tailwind-sync/server.ts +44 -1
  55. package/templates/vue-tailwind-sync/src/main.ts +1 -1
  56. package/templates/vue-tailwind-sync/src/vite-env.d.ts +1 -0
  57. package/templates/vue-tailwind-sync/vite.config.ts +1 -1
  58. package/dist/chunk-ZTVVAYHJ.js.map +0 -1
package/dist/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createCommand
4
- } from "./chunk-ZTVVAYHJ.js";
4
+ } from "./chunk-Z7GCXMGW.js";
5
5
  import {
6
6
  agentsCommand,
7
7
  deployCommand,
@@ -362,6 +362,7 @@ var compactCommand = defineCommand2({
362
362
  });
363
363
 
364
364
  // src/commands/dev/dev-command.ts
365
+ import { existsSync, readFileSync } from "fs";
365
366
  import { access as access2 } from "fs/promises";
366
367
  import { join as join4 } from "path";
367
368
  import { resolve as resolve2 } from "path";
@@ -372,6 +373,7 @@ import { spawn as spawnChild } from "child_process";
372
373
  var ProcessManager = class {
373
374
  processes = /* @__PURE__ */ new Map();
374
375
  spawn(config) {
376
+ this.processes.get(config.label)?.child.kill("SIGTERM");
375
377
  const options = {
376
378
  cwd: config.cwd,
377
379
  env: { ...process.env, ...config.env },
@@ -415,6 +417,20 @@ var ProcessManager = class {
415
417
  hasRunning() {
416
418
  return this.processes.size > 0;
417
419
  }
420
+ async restart(config) {
421
+ await this.stop(config.label);
422
+ this.spawn(config);
423
+ }
424
+ async stop(label) {
425
+ const running = this.processes.get(label);
426
+ if (!running) return;
427
+ running.child.kill("SIGTERM");
428
+ await Promise.race([running.exitPromise, delay(5e3)]);
429
+ const remaining = this.processes.get(label);
430
+ if (!remaining) return;
431
+ remaining.child.kill("SIGKILL");
432
+ await remaining.exitPromise;
433
+ }
418
434
  async shutdownAll() {
419
435
  const running = Array.from(this.processes.values());
420
436
  if (running.length === 0) return;
@@ -467,6 +483,7 @@ var SchemaWatcher = class {
467
483
  debounceMs;
468
484
  watcher = null;
469
485
  debounceTimer = null;
486
+ schemaVersion = null;
470
487
  start() {
471
488
  if (this.watcher) return;
472
489
  this.watcher = watch(this.config.schemaPath, () => {
@@ -475,6 +492,9 @@ var SchemaWatcher = class {
475
492
  this.watcher.on("error", (error) => {
476
493
  this.config.onError?.(toError(error));
477
494
  });
495
+ void this.refreshSchemaVersion().catch((error) => {
496
+ this.config.onError?.(toError(error));
497
+ });
478
498
  }
479
499
  stop() {
480
500
  if (this.debounceTimer) {
@@ -498,6 +518,15 @@ var SchemaWatcher = class {
498
518
  const args = hasTsx ? ["--import", "tsx", koraBinJs, "generate", "types", "--schema", this.config.schemaPath] : [koraBinJs, "generate", "types", "--schema", this.config.schemaPath];
499
519
  await spawnCommand(command, args, this.config.projectRoot);
500
520
  this.config.onRegenerate?.();
521
+ await this.refreshSchemaVersion();
522
+ }
523
+ async refreshSchemaVersion() {
524
+ const schema = await loadSchemaDefinition(this.config.schemaPath, this.config.projectRoot);
525
+ const previous = this.schemaVersion;
526
+ this.schemaVersion = schema.version;
527
+ if (previous !== null && previous !== schema.version) {
528
+ this.config.onSchemaVersionChange?.({ previous, next: schema.version });
529
+ }
501
530
  }
502
531
  scheduleRegeneration() {
503
532
  if (this.debounceTimer) {
@@ -582,6 +611,7 @@ var devCommand = defineCommand3({
582
611
  if (!projectRoot) {
583
612
  throw new InvalidProjectError(process.cwd());
584
613
  }
614
+ loadProjectEnv(projectRoot);
585
615
  const config = await loadKoraConfig(projectRoot);
586
616
  const vitePort = typeof args.port === "string" ? args.port : String(config?.dev?.port ?? 5173);
587
617
  const syncPortFromConfig = typeof config?.dev?.sync === "object" && typeof config.dev.sync.port === "number" ? config.dev.sync.port : 3001;
@@ -683,7 +713,9 @@ var devCommand = defineCommand3({
683
713
  logger.step(" Schema watcher disabled (schema.ts not found)");
684
714
  }
685
715
  logger.blank();
686
- logger.step(" Kora DevTools overlay: Ctrl+Shift+K (Cmd+Shift+K on macOS) when devtools: true");
716
+ logger.step(
717
+ " Kora DevTools overlay: Ctrl+Shift+K (Cmd+Shift+K on macOS) when devtools is enabled"
718
+ );
687
719
  processManager.spawn({
688
720
  label: "vite",
689
721
  command: process.execPath,
@@ -694,33 +726,31 @@ var devCommand = defineCommand3({
694
726
  },
695
727
  onExit: onManagedProcessExit
696
728
  });
697
- if (shouldStartSync && hasTsx && syncServerFile) {
698
- processManager.spawn({
699
- label: "sync",
700
- command: process.execPath,
701
- args: ["--import", "tsx", syncServerFile],
702
- cwd: projectRoot,
703
- env: {
704
- PORT: String(syncPort),
705
- KORA_SYNC_PORT: String(syncPort)
706
- },
707
- onExit: onManagedProcessExit
708
- });
709
- }
710
- if (shouldStartSync && syncServerFile === null && managedSyncStore !== null) {
711
- processManager.spawn({
712
- label: "sync",
713
- command: process.execPath,
714
- args: ["--input-type=module", "--eval", MANAGED_SYNC_BOOTSTRAP_SCRIPT],
715
- cwd: projectRoot,
716
- env: {
717
- KORA_DEV_SYNC_CONFIG: JSON.stringify({
718
- port: Number(syncPort),
719
- store: managedSyncStore
720
- })
721
- },
722
- onExit: onManagedProcessExit
723
- });
729
+ const syncProcessConfig = shouldStartSync && hasTsx && syncServerFile ? {
730
+ label: "sync",
731
+ command: process.execPath,
732
+ args: ["--import", "tsx", syncServerFile],
733
+ cwd: projectRoot,
734
+ env: {
735
+ PORT: String(syncPort),
736
+ KORA_SYNC_PORT: String(syncPort)
737
+ },
738
+ onExit: onManagedProcessExit
739
+ } : shouldStartSync && syncServerFile === null && managedSyncStore !== null ? {
740
+ label: "sync",
741
+ command: process.execPath,
742
+ args: ["--input-type=module", "--eval", MANAGED_SYNC_BOOTSTRAP_SCRIPT],
743
+ cwd: projectRoot,
744
+ env: {
745
+ KORA_DEV_SYNC_CONFIG: JSON.stringify({
746
+ port: Number(syncPort),
747
+ store: managedSyncStore
748
+ })
749
+ },
750
+ onExit: onManagedProcessExit
751
+ } : null;
752
+ if (syncProcessConfig) {
753
+ processManager.spawn(syncProcessConfig);
724
754
  }
725
755
  if (watchEnabled && schemaPath) {
726
756
  schemaWatcher = new SchemaWatcher({
@@ -730,6 +760,16 @@ var devCommand = defineCommand3({
730
760
  onRegenerate: () => {
731
761
  logger.success("Regenerated types from schema changes");
732
762
  },
763
+ onSchemaVersionChange: ({ previous, next }) => {
764
+ if (!syncProcessConfig) {
765
+ logger.warn(
766
+ `Schema version changed from ${previous} to ${next}; restart your sync server before clients can sync.`
767
+ );
768
+ return;
769
+ }
770
+ logger.warn(`Schema version changed from ${previous} to ${next}; restarting sync server.`);
771
+ void processManager.restart(syncProcessConfig);
772
+ },
733
773
  onError: (error) => {
734
774
  logger.error(`Schema watcher error: ${error.message}`);
735
775
  }
@@ -760,6 +800,43 @@ async function fileExists(path) {
760
800
  return false;
761
801
  }
762
802
  }
803
+ function loadProjectEnv(projectRoot, mode = "development") {
804
+ const files = [".env", ".env.local", `.env.${mode}`, `.env.${mode}.local`];
805
+ const existingKeys = new Set(Object.keys(process.env));
806
+ for (const file of files) {
807
+ const path = join4(projectRoot, file);
808
+ if (!existsSync(path)) continue;
809
+ const parsed = parseEnvFile(readFileSync(path, "utf8"));
810
+ for (const [key, value] of Object.entries(parsed)) {
811
+ if (!existingKeys.has(key)) {
812
+ process.env[key] = value;
813
+ }
814
+ }
815
+ }
816
+ }
817
+ function parseEnvFile(contents) {
818
+ const env = {};
819
+ for (const rawLine of contents.split(/\r?\n/)) {
820
+ const line = rawLine.trim();
821
+ if (!line || line.startsWith("#")) continue;
822
+ const normalized = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
823
+ const equalsIndex = normalized.indexOf("=");
824
+ if (equalsIndex <= 0) continue;
825
+ const key = normalized.slice(0, equalsIndex).trim();
826
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
827
+ env[key] = parseEnvValue(normalized.slice(equalsIndex + 1).trim());
828
+ }
829
+ return env;
830
+ }
831
+ function parseEnvValue(value) {
832
+ const quote = value[0];
833
+ if ((quote === '"' || quote === "'") && value[value.length - 1] === quote) {
834
+ const inner = value.slice(1, -1);
835
+ return quote === '"' ? inner.replace(/\\n/g, "\n").replace(/\\r/g, "\r") : inner;
836
+ }
837
+ const commentIndex = value.search(/\s#/);
838
+ return (commentIndex >= 0 ? value.slice(0, commentIndex) : value).trim();
839
+ }
763
840
  function normalizeManagedSyncStore(config, projectRoot) {
764
841
  const sync = config?.dev?.sync;
765
842
  if (typeof sync !== "object" || sync === null) return null;
@@ -2512,7 +2589,7 @@ function printStatus(status, url, logger) {
2512
2589
  }
2513
2590
 
2514
2591
  // src/commands/studio/studio-command.ts
2515
- import { existsSync } from "fs";
2592
+ import { existsSync as existsSync2 } from "fs";
2516
2593
  import { resolve as resolve6 } from "path";
2517
2594
  import { defineCommand as defineCommand9 } from "citty";
2518
2595
  var studioCommand = defineCommand9({
@@ -2617,7 +2694,7 @@ var studioCommand = defineCommand9({
2617
2694
  );
2618
2695
  }
2619
2696
  const dbPath = resolve6(process.cwd(), args.db);
2620
- if (!existsSync(dbPath)) {
2697
+ if (!existsSync2(dbPath)) {
2621
2698
  throw new Error(`Database file not found: ${dbPath}`);
2622
2699
  }
2623
2700
  const server = await startStudioServer({ port, dbPath });