@korajs/cli 1.0.0-beta.6 → 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.
- package/dist/bin.cjs +49 -10
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +41 -2
- package/dist/bin.js.map +1 -1
- package/package.json +8 -8
- package/templates/react-basic/README.md.hbs +1 -1
- package/templates/react-sync/README.md.hbs +3 -3
- package/templates/react-sync/server.ts +40 -0
- package/templates/react-tailwind/README.md.hbs +1 -1
- package/templates/react-tailwind-sync/README.md.hbs +3 -3
- package/templates/react-tailwind-sync/server.ts +40 -0
- package/templates/svelte-basic/README.md.hbs +1 -1
- package/templates/svelte-sync/README.md.hbs +3 -3
- package/templates/svelte-sync/server.ts +40 -0
- package/templates/svelte-tailwind/README.md.hbs +1 -1
- package/templates/svelte-tailwind-sync/README.md.hbs +3 -3
- package/templates/svelte-tailwind-sync/server.ts +40 -0
- package/templates/tauri-react/server.ts +40 -0
- package/templates/vue-basic/README.md.hbs +1 -1
- package/templates/vue-sync/README.md.hbs +3 -3
- package/templates/vue-sync/server.ts +40 -0
- package/templates/vue-tailwind/README.md.hbs +1 -1
- package/templates/vue-tailwind-sync/README.md.hbs +3 -3
- package/templates/vue-tailwind-sync/server.ts +40 -0
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 (!
|
|
2659
|
+
if (!existsSync2(dbPath)) {
|
|
2621
2660
|
throw new Error(`Database file not found: ${dbPath}`);
|
|
2622
2661
|
}
|
|
2623
2662
|
const server = await startStudioServer({ port, dbPath });
|