@korajs/cli 1.0.0-beta.5 → 1.0.0-beta.7

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 (36) hide show
  1. package/dist/bin.cjs +49 -10
  2. package/dist/bin.cjs.map +1 -1
  3. package/dist/bin.js +41 -2
  4. package/dist/bin.js.map +1 -1
  5. package/package.json +8 -8
  6. package/templates/react-basic/README.md.hbs +1 -1
  7. package/templates/react-basic/vite.config.ts +7 -4
  8. package/templates/react-sync/README.md.hbs +6 -5
  9. package/templates/react-sync/server.ts +42 -2
  10. package/templates/react-sync/vite.config.ts +14 -4
  11. package/templates/react-tailwind/README.md.hbs +1 -1
  12. package/templates/react-tailwind/vite.config.ts +7 -4
  13. package/templates/react-tailwind-sync/README.md.hbs +6 -5
  14. package/templates/react-tailwind-sync/server.ts +42 -2
  15. package/templates/react-tailwind-sync/vite.config.ts +14 -4
  16. package/templates/svelte-basic/README.md.hbs +1 -1
  17. package/templates/svelte-basic/vite.config.ts +4 -2
  18. package/templates/svelte-sync/README.md.hbs +6 -5
  19. package/templates/svelte-sync/server.ts +42 -2
  20. package/templates/svelte-sync/vite.config.ts +11 -2
  21. package/templates/svelte-tailwind/README.md.hbs +1 -1
  22. package/templates/svelte-tailwind/vite.config.ts +4 -2
  23. package/templates/svelte-tailwind-sync/README.md.hbs +6 -5
  24. package/templates/svelte-tailwind-sync/server.ts +42 -2
  25. package/templates/svelte-tailwind-sync/vite.config.ts +11 -2
  26. package/templates/tauri-react/server.ts +40 -0
  27. package/templates/vue-basic/README.md.hbs +1 -1
  28. package/templates/vue-basic/vite.config.ts +4 -2
  29. package/templates/vue-sync/README.md.hbs +6 -5
  30. package/templates/vue-sync/server.ts +42 -2
  31. package/templates/vue-sync/vite.config.ts +11 -2
  32. package/templates/vue-tailwind/README.md.hbs +1 -1
  33. package/templates/vue-tailwind/vite.config.ts +4 -2
  34. package/templates/vue-tailwind-sync/README.md.hbs +6 -5
  35. package/templates/vue-tailwind-sync/server.ts +42 -2
  36. package/templates/vue-tailwind-sync/vite.config.ts +11 -2
package/dist/bin.js CHANGED
@@ -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";
@@ -582,6 +583,7 @@ var devCommand = defineCommand3({
582
583
  if (!projectRoot) {
583
584
  throw new InvalidProjectError(process.cwd());
584
585
  }
586
+ loadProjectEnv(projectRoot);
585
587
  const config = await loadKoraConfig(projectRoot);
586
588
  const vitePort = typeof args.port === "string" ? args.port : String(config?.dev?.port ?? 5173);
587
589
  const syncPortFromConfig = typeof config?.dev?.sync === "object" && typeof config.dev.sync.port === "number" ? config.dev.sync.port : 3001;
@@ -760,6 +762,43 @@ async function fileExists(path) {
760
762
  return false;
761
763
  }
762
764
  }
765
+ function loadProjectEnv(projectRoot, mode = "development") {
766
+ const files = [".env", ".env.local", `.env.${mode}`, `.env.${mode}.local`];
767
+ const existingKeys = new Set(Object.keys(process.env));
768
+ for (const file of files) {
769
+ const path = join4(projectRoot, file);
770
+ if (!existsSync(path)) continue;
771
+ const parsed = parseEnvFile(readFileSync(path, "utf8"));
772
+ for (const [key, value] of Object.entries(parsed)) {
773
+ if (!existingKeys.has(key)) {
774
+ process.env[key] = value;
775
+ }
776
+ }
777
+ }
778
+ }
779
+ function parseEnvFile(contents) {
780
+ const env = {};
781
+ for (const rawLine of contents.split(/\r?\n/)) {
782
+ const line = rawLine.trim();
783
+ if (!line || line.startsWith("#")) continue;
784
+ const normalized = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
785
+ const equalsIndex = normalized.indexOf("=");
786
+ if (equalsIndex <= 0) continue;
787
+ const key = normalized.slice(0, equalsIndex).trim();
788
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
789
+ env[key] = parseEnvValue(normalized.slice(equalsIndex + 1).trim());
790
+ }
791
+ return env;
792
+ }
793
+ function parseEnvValue(value) {
794
+ const quote = value[0];
795
+ if ((quote === '"' || quote === "'") && value[value.length - 1] === quote) {
796
+ const inner = value.slice(1, -1);
797
+ return quote === '"' ? inner.replace(/\\n/g, "\n").replace(/\\r/g, "\r") : inner;
798
+ }
799
+ const commentIndex = value.search(/\s#/);
800
+ return (commentIndex >= 0 ? value.slice(0, commentIndex) : value).trim();
801
+ }
763
802
  function normalizeManagedSyncStore(config, projectRoot) {
764
803
  const sync = config?.dev?.sync;
765
804
  if (typeof sync !== "object" || sync === null) return null;
@@ -2512,7 +2551,7 @@ function printStatus(status, url, logger) {
2512
2551
  }
2513
2552
 
2514
2553
  // src/commands/studio/studio-command.ts
2515
- import { existsSync } from "fs";
2554
+ import { existsSync as existsSync2 } from "fs";
2516
2555
  import { resolve as resolve6 } from "path";
2517
2556
  import { defineCommand as defineCommand9 } from "citty";
2518
2557
  var studioCommand = defineCommand9({
@@ -2617,7 +2656,7 @@ var studioCommand = defineCommand9({
2617
2656
  );
2618
2657
  }
2619
2658
  const dbPath = resolve6(process.cwd(), args.db);
2620
- if (!existsSync(dbPath)) {
2659
+ if (!existsSync2(dbPath)) {
2621
2660
  throw new Error(`Database file not found: ${dbPath}`);
2622
2661
  }
2623
2662
  const server = await startStudioServer({ port, dbPath });