@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.
- package/dist/bin.cjs +123 -41
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +108 -31
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-ZTVVAYHJ.js → chunk-Z7GCXMGW.js} +8 -4
- package/dist/chunk-Z7GCXMGW.js.map +1 -0
- package/dist/create.cjs +7 -3
- package/dist/create.cjs.map +1 -1
- package/dist/create.js +1 -1
- package/package.json +8 -8
- package/templates/react-basic/README.md.hbs +1 -1
- package/templates/react-basic/src/main.tsx +1 -1
- package/templates/react-basic/src/vite-env.d.ts +1 -0
- package/templates/react-sync/README.md.hbs +3 -3
- package/templates/react-sync/server.ts +44 -1
- package/templates/react-sync/src/main.tsx +1 -1
- package/templates/react-sync/src/vite-env.d.ts +1 -0
- package/templates/react-sync/vite.config.ts +1 -1
- package/templates/react-tailwind/README.md.hbs +1 -1
- package/templates/react-tailwind/src/main.tsx +1 -1
- package/templates/react-tailwind/src/vite-env.d.ts +1 -0
- package/templates/react-tailwind-sync/README.md.hbs +3 -3
- package/templates/react-tailwind-sync/server.ts +44 -1
- package/templates/react-tailwind-sync/src/main.tsx +1 -1
- package/templates/react-tailwind-sync/src/vite-env.d.ts +1 -0
- package/templates/react-tailwind-sync/vite.config.ts +1 -1
- package/templates/svelte-basic/README.md.hbs +1 -1
- package/templates/svelte-basic/src/main.ts +1 -1
- package/templates/svelte-sync/README.md.hbs +3 -3
- package/templates/svelte-sync/server.ts +44 -1
- package/templates/svelte-sync/src/main.ts +1 -1
- package/templates/svelte-sync/src/vite-env.d.ts +1 -0
- package/templates/svelte-sync/vite.config.ts +1 -1
- package/templates/svelte-tailwind/README.md.hbs +1 -1
- package/templates/svelte-tailwind/src/main.ts +1 -1
- package/templates/svelte-tailwind-sync/README.md.hbs +3 -3
- package/templates/svelte-tailwind-sync/server.ts +44 -1
- package/templates/svelte-tailwind-sync/src/main.ts +1 -1
- package/templates/svelte-tailwind-sync/src/vite-env.d.ts +1 -0
- package/templates/svelte-tailwind-sync/vite.config.ts +1 -1
- package/templates/tauri-react/server.ts +44 -1
- package/templates/tauri-react/src/AppShell.tsx +1 -1
- package/templates/tauri-react/src/vite-env.d.ts +1 -0
- package/templates/vue-basic/README.md.hbs +1 -1
- package/templates/vue-basic/src/main.ts +1 -1
- package/templates/vue-sync/README.md.hbs +3 -3
- package/templates/vue-sync/server.ts +44 -1
- package/templates/vue-sync/src/main.ts +1 -1
- package/templates/vue-sync/src/vite-env.d.ts +1 -0
- package/templates/vue-sync/vite.config.ts +1 -1
- package/templates/vue-tailwind/README.md.hbs +1 -1
- package/templates/vue-tailwind/src/main.ts +1 -1
- package/templates/vue-tailwind-sync/README.md.hbs +3 -3
- package/templates/vue-tailwind-sync/server.ts +44 -1
- package/templates/vue-tailwind-sync/src/main.ts +1 -1
- package/templates/vue-tailwind-sync/src/vite-env.d.ts +1 -0
- package/templates/vue-tailwind-sync/vite.config.ts +1 -1
- package/dist/chunk-ZTVVAYHJ.js.map +0 -1
package/dist/bin.cjs
CHANGED
|
@@ -1981,11 +1981,11 @@ var spectator_manager_exports = {};
|
|
|
1981
1981
|
__export(spectator_manager_exports, {
|
|
1982
1982
|
SpectatorManager: () => SpectatorManager
|
|
1983
1983
|
});
|
|
1984
|
-
var
|
|
1984
|
+
var import_node_fs7, import_node_os, import_node_path28, FORWARDED_EVENTS, MAX_EVENT_BUFFER, SpectatorManager;
|
|
1985
1985
|
var init_spectator_manager = __esm({
|
|
1986
1986
|
"src/commands/studio/spectator-manager.ts"() {
|
|
1987
1987
|
"use strict";
|
|
1988
|
-
|
|
1988
|
+
import_node_fs7 = require("fs");
|
|
1989
1989
|
import_node_os = require("os");
|
|
1990
1990
|
import_node_path28 = require("path");
|
|
1991
1991
|
FORWARDED_EVENTS = [
|
|
@@ -2001,7 +2001,7 @@ var init_spectator_manager = __esm({
|
|
|
2001
2001
|
SpectatorManager = class {
|
|
2002
2002
|
constructor(options) {
|
|
2003
2003
|
this.options = options;
|
|
2004
|
-
this.tmpDir = (0,
|
|
2004
|
+
this.tmpDir = (0, import_node_fs7.mkdtempSync)((0, import_node_path28.join)((0, import_node_os.tmpdir)(), "kora-studio-spectator-"));
|
|
2005
2005
|
this.dbPath = (0, import_node_path28.join)(this.tmpDir, "spectator-replica.db");
|
|
2006
2006
|
}
|
|
2007
2007
|
options;
|
|
@@ -2099,7 +2099,7 @@ var init_spectator_manager = __esm({
|
|
|
2099
2099
|
this.runtime = null;
|
|
2100
2100
|
}
|
|
2101
2101
|
if (this.tmpDir) {
|
|
2102
|
-
(0,
|
|
2102
|
+
(0, import_node_fs7.rmSync)(this.tmpDir, { recursive: true, force: true });
|
|
2103
2103
|
this.tmpDir = null;
|
|
2104
2104
|
}
|
|
2105
2105
|
}
|
|
@@ -2182,11 +2182,11 @@ function summarizeEvent(type, payload) {
|
|
|
2182
2182
|
return type.replace("lab:", "");
|
|
2183
2183
|
}
|
|
2184
2184
|
}
|
|
2185
|
-
var
|
|
2185
|
+
var import_node_fs8, import_node_os2, import_node_path29, import_core3, DEFAULT_CHAOS, FORWARDED_EVENTS2, MAX_EVENT_BUFFER2, LabManager;
|
|
2186
2186
|
var init_lab_manager = __esm({
|
|
2187
2187
|
"src/commands/studio/lab-manager.ts"() {
|
|
2188
2188
|
"use strict";
|
|
2189
|
-
|
|
2189
|
+
import_node_fs8 = require("fs");
|
|
2190
2190
|
import_node_os2 = require("os");
|
|
2191
2191
|
import_node_path29 = require("path");
|
|
2192
2192
|
import_core3 = require("@korajs/core");
|
|
@@ -2246,7 +2246,7 @@ var init_lab_manager = __esm({
|
|
|
2246
2246
|
}
|
|
2247
2247
|
async start(initialDevices = 2) {
|
|
2248
2248
|
const harness = await this.loadHarness();
|
|
2249
|
-
this.tmpDir = (0,
|
|
2249
|
+
this.tmpDir = (0, import_node_fs8.mkdtempSync)((0, import_node_path29.join)((0, import_node_os2.tmpdir)(), "kora-studio-lab-"));
|
|
2250
2250
|
this.server = new harness.TestServer(this.schema);
|
|
2251
2251
|
for (let i = 0; i < initialDevices; i++) {
|
|
2252
2252
|
await this.addDevice();
|
|
@@ -2377,7 +2377,7 @@ var init_lab_manager = __esm({
|
|
|
2377
2377
|
});
|
|
2378
2378
|
this.server = null;
|
|
2379
2379
|
if (this.tmpDir) {
|
|
2380
|
-
(0,
|
|
2380
|
+
(0, import_node_fs8.rmSync)(this.tmpDir, { recursive: true, force: true });
|
|
2381
2381
|
this.tmpDir = null;
|
|
2382
2382
|
}
|
|
2383
2383
|
}
|
|
@@ -4279,9 +4279,7 @@ function resolveKoraVersion() {
|
|
|
4279
4279
|
if ((0, import_node_fs2.existsSync)(pkgPath)) {
|
|
4280
4280
|
const pkg = JSON.parse((0, import_node_fs2.readFileSync)(pkgPath, "utf-8"));
|
|
4281
4281
|
if (pkg.name === "@korajs/cli") {
|
|
4282
|
-
|
|
4283
|
-
const parts = pkg.version.split(".");
|
|
4284
|
-
return `^${parts[0]}.${parts[1]}.0`;
|
|
4282
|
+
return deriveKoraTemplateVersion(pkg.version);
|
|
4285
4283
|
}
|
|
4286
4284
|
}
|
|
4287
4285
|
dir = (0, import_node_path10.dirname)(dir);
|
|
@@ -4291,6 +4289,12 @@ function resolveKoraVersion() {
|
|
|
4291
4289
|
return "latest";
|
|
4292
4290
|
}
|
|
4293
4291
|
}
|
|
4292
|
+
function deriveKoraTemplateVersion(version) {
|
|
4293
|
+
if (version === "0.0.0") return "latest";
|
|
4294
|
+
if (version.includes("-")) return version;
|
|
4295
|
+
const parts = version.split(".");
|
|
4296
|
+
return `^${parts[0]}.${parts[1]}.0`;
|
|
4297
|
+
}
|
|
4294
4298
|
|
|
4295
4299
|
// src/commands/deploy/deploy-command.ts
|
|
4296
4300
|
var import_node_fs4 = require("fs");
|
|
@@ -6508,6 +6512,7 @@ function hasContextSetter(adapter) {
|
|
|
6508
6512
|
}
|
|
6509
6513
|
|
|
6510
6514
|
// src/commands/dev/dev-command.ts
|
|
6515
|
+
var import_node_fs6 = require("fs");
|
|
6511
6516
|
var import_promises15 = require("fs/promises");
|
|
6512
6517
|
var import_node_path23 = require("path");
|
|
6513
6518
|
var import_node_path24 = require("path");
|
|
@@ -6519,6 +6524,7 @@ var import_node_child_process10 = require("child_process");
|
|
|
6519
6524
|
var ProcessManager = class {
|
|
6520
6525
|
processes = /* @__PURE__ */ new Map();
|
|
6521
6526
|
spawn(config) {
|
|
6527
|
+
this.processes.get(config.label)?.child.kill("SIGTERM");
|
|
6522
6528
|
const options = {
|
|
6523
6529
|
cwd: config.cwd,
|
|
6524
6530
|
env: { ...process.env, ...config.env },
|
|
@@ -6562,6 +6568,20 @@ var ProcessManager = class {
|
|
|
6562
6568
|
hasRunning() {
|
|
6563
6569
|
return this.processes.size > 0;
|
|
6564
6570
|
}
|
|
6571
|
+
async restart(config) {
|
|
6572
|
+
await this.stop(config.label);
|
|
6573
|
+
this.spawn(config);
|
|
6574
|
+
}
|
|
6575
|
+
async stop(label) {
|
|
6576
|
+
const running = this.processes.get(label);
|
|
6577
|
+
if (!running) return;
|
|
6578
|
+
running.child.kill("SIGTERM");
|
|
6579
|
+
await Promise.race([running.exitPromise, delay(5e3)]);
|
|
6580
|
+
const remaining = this.processes.get(label);
|
|
6581
|
+
if (!remaining) return;
|
|
6582
|
+
remaining.child.kill("SIGKILL");
|
|
6583
|
+
await remaining.exitPromise;
|
|
6584
|
+
}
|
|
6565
6585
|
async shutdownAll() {
|
|
6566
6586
|
const running = Array.from(this.processes.values());
|
|
6567
6587
|
if (running.length === 0) return;
|
|
@@ -6606,6 +6626,7 @@ var import_node_child_process11 = require("child_process");
|
|
|
6606
6626
|
var import_node_fs5 = require("fs");
|
|
6607
6627
|
var import_node_path22 = require("path");
|
|
6608
6628
|
init_fs_helpers();
|
|
6629
|
+
init_schema_loader();
|
|
6609
6630
|
var SchemaWatcher = class {
|
|
6610
6631
|
constructor(config) {
|
|
6611
6632
|
this.config = config;
|
|
@@ -6615,6 +6636,7 @@ var SchemaWatcher = class {
|
|
|
6615
6636
|
debounceMs;
|
|
6616
6637
|
watcher = null;
|
|
6617
6638
|
debounceTimer = null;
|
|
6639
|
+
schemaVersion = null;
|
|
6618
6640
|
start() {
|
|
6619
6641
|
if (this.watcher) return;
|
|
6620
6642
|
this.watcher = (0, import_node_fs5.watch)(this.config.schemaPath, () => {
|
|
@@ -6623,6 +6645,9 @@ var SchemaWatcher = class {
|
|
|
6623
6645
|
this.watcher.on("error", (error) => {
|
|
6624
6646
|
this.config.onError?.(toError(error));
|
|
6625
6647
|
});
|
|
6648
|
+
void this.refreshSchemaVersion().catch((error) => {
|
|
6649
|
+
this.config.onError?.(toError(error));
|
|
6650
|
+
});
|
|
6626
6651
|
}
|
|
6627
6652
|
stop() {
|
|
6628
6653
|
if (this.debounceTimer) {
|
|
@@ -6646,6 +6671,15 @@ var SchemaWatcher = class {
|
|
|
6646
6671
|
const args = hasTsx ? ["--import", "tsx", koraBinJs, "generate", "types", "--schema", this.config.schemaPath] : [koraBinJs, "generate", "types", "--schema", this.config.schemaPath];
|
|
6647
6672
|
await spawnCommand(command, args, this.config.projectRoot);
|
|
6648
6673
|
this.config.onRegenerate?.();
|
|
6674
|
+
await this.refreshSchemaVersion();
|
|
6675
|
+
}
|
|
6676
|
+
async refreshSchemaVersion() {
|
|
6677
|
+
const schema = await loadSchemaDefinition(this.config.schemaPath, this.config.projectRoot);
|
|
6678
|
+
const previous = this.schemaVersion;
|
|
6679
|
+
this.schemaVersion = schema.version;
|
|
6680
|
+
if (previous !== null && previous !== schema.version) {
|
|
6681
|
+
this.config.onSchemaVersionChange?.({ previous, next: schema.version });
|
|
6682
|
+
}
|
|
6649
6683
|
}
|
|
6650
6684
|
scheduleRegeneration() {
|
|
6651
6685
|
if (this.debounceTimer) {
|
|
@@ -6730,6 +6764,7 @@ var devCommand = (0, import_citty6.defineCommand)({
|
|
|
6730
6764
|
if (!projectRoot) {
|
|
6731
6765
|
throw new InvalidProjectError(process.cwd());
|
|
6732
6766
|
}
|
|
6767
|
+
loadProjectEnv(projectRoot);
|
|
6733
6768
|
const config = await loadKoraConfig(projectRoot);
|
|
6734
6769
|
const vitePort = typeof args.port === "string" ? args.port : String(config?.dev?.port ?? 5173);
|
|
6735
6770
|
const syncPortFromConfig = typeof config?.dev?.sync === "object" && typeof config.dev.sync.port === "number" ? config.dev.sync.port : 3001;
|
|
@@ -6831,7 +6866,9 @@ var devCommand = (0, import_citty6.defineCommand)({
|
|
|
6831
6866
|
logger.step(" Schema watcher disabled (schema.ts not found)");
|
|
6832
6867
|
}
|
|
6833
6868
|
logger.blank();
|
|
6834
|
-
logger.step(
|
|
6869
|
+
logger.step(
|
|
6870
|
+
" Kora DevTools overlay: Ctrl+Shift+K (Cmd+Shift+K on macOS) when devtools is enabled"
|
|
6871
|
+
);
|
|
6835
6872
|
processManager.spawn({
|
|
6836
6873
|
label: "vite",
|
|
6837
6874
|
command: process.execPath,
|
|
@@ -6842,33 +6879,31 @@ var devCommand = (0, import_citty6.defineCommand)({
|
|
|
6842
6879
|
},
|
|
6843
6880
|
onExit: onManagedProcessExit
|
|
6844
6881
|
});
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
onExit: onManagedProcessExit
|
|
6871
|
-
});
|
|
6882
|
+
const syncProcessConfig = shouldStartSync && hasTsx && syncServerFile ? {
|
|
6883
|
+
label: "sync",
|
|
6884
|
+
command: process.execPath,
|
|
6885
|
+
args: ["--import", "tsx", syncServerFile],
|
|
6886
|
+
cwd: projectRoot,
|
|
6887
|
+
env: {
|
|
6888
|
+
PORT: String(syncPort),
|
|
6889
|
+
KORA_SYNC_PORT: String(syncPort)
|
|
6890
|
+
},
|
|
6891
|
+
onExit: onManagedProcessExit
|
|
6892
|
+
} : shouldStartSync && syncServerFile === null && managedSyncStore !== null ? {
|
|
6893
|
+
label: "sync",
|
|
6894
|
+
command: process.execPath,
|
|
6895
|
+
args: ["--input-type=module", "--eval", MANAGED_SYNC_BOOTSTRAP_SCRIPT],
|
|
6896
|
+
cwd: projectRoot,
|
|
6897
|
+
env: {
|
|
6898
|
+
KORA_DEV_SYNC_CONFIG: JSON.stringify({
|
|
6899
|
+
port: Number(syncPort),
|
|
6900
|
+
store: managedSyncStore
|
|
6901
|
+
})
|
|
6902
|
+
},
|
|
6903
|
+
onExit: onManagedProcessExit
|
|
6904
|
+
} : null;
|
|
6905
|
+
if (syncProcessConfig) {
|
|
6906
|
+
processManager.spawn(syncProcessConfig);
|
|
6872
6907
|
}
|
|
6873
6908
|
if (watchEnabled && schemaPath) {
|
|
6874
6909
|
schemaWatcher = new SchemaWatcher({
|
|
@@ -6878,6 +6913,16 @@ var devCommand = (0, import_citty6.defineCommand)({
|
|
|
6878
6913
|
onRegenerate: () => {
|
|
6879
6914
|
logger.success("Regenerated types from schema changes");
|
|
6880
6915
|
},
|
|
6916
|
+
onSchemaVersionChange: ({ previous, next }) => {
|
|
6917
|
+
if (!syncProcessConfig) {
|
|
6918
|
+
logger.warn(
|
|
6919
|
+
`Schema version changed from ${previous} to ${next}; restart your sync server before clients can sync.`
|
|
6920
|
+
);
|
|
6921
|
+
return;
|
|
6922
|
+
}
|
|
6923
|
+
logger.warn(`Schema version changed from ${previous} to ${next}; restarting sync server.`);
|
|
6924
|
+
void processManager.restart(syncProcessConfig);
|
|
6925
|
+
},
|
|
6881
6926
|
onError: (error) => {
|
|
6882
6927
|
logger.error(`Schema watcher error: ${error.message}`);
|
|
6883
6928
|
}
|
|
@@ -6908,6 +6953,43 @@ async function fileExists3(path) {
|
|
|
6908
6953
|
return false;
|
|
6909
6954
|
}
|
|
6910
6955
|
}
|
|
6956
|
+
function loadProjectEnv(projectRoot, mode = "development") {
|
|
6957
|
+
const files = [".env", ".env.local", `.env.${mode}`, `.env.${mode}.local`];
|
|
6958
|
+
const existingKeys = new Set(Object.keys(process.env));
|
|
6959
|
+
for (const file of files) {
|
|
6960
|
+
const path = (0, import_node_path23.join)(projectRoot, file);
|
|
6961
|
+
if (!(0, import_node_fs6.existsSync)(path)) continue;
|
|
6962
|
+
const parsed = parseEnvFile((0, import_node_fs6.readFileSync)(path, "utf8"));
|
|
6963
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
6964
|
+
if (!existingKeys.has(key)) {
|
|
6965
|
+
process.env[key] = value;
|
|
6966
|
+
}
|
|
6967
|
+
}
|
|
6968
|
+
}
|
|
6969
|
+
}
|
|
6970
|
+
function parseEnvFile(contents) {
|
|
6971
|
+
const env = {};
|
|
6972
|
+
for (const rawLine of contents.split(/\r?\n/)) {
|
|
6973
|
+
const line = rawLine.trim();
|
|
6974
|
+
if (!line || line.startsWith("#")) continue;
|
|
6975
|
+
const normalized = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
|
|
6976
|
+
const equalsIndex = normalized.indexOf("=");
|
|
6977
|
+
if (equalsIndex <= 0) continue;
|
|
6978
|
+
const key = normalized.slice(0, equalsIndex).trim();
|
|
6979
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
|
|
6980
|
+
env[key] = parseEnvValue(normalized.slice(equalsIndex + 1).trim());
|
|
6981
|
+
}
|
|
6982
|
+
return env;
|
|
6983
|
+
}
|
|
6984
|
+
function parseEnvValue(value) {
|
|
6985
|
+
const quote = value[0];
|
|
6986
|
+
if ((quote === '"' || quote === "'") && value[value.length - 1] === quote) {
|
|
6987
|
+
const inner = value.slice(1, -1);
|
|
6988
|
+
return quote === '"' ? inner.replace(/\\n/g, "\n").replace(/\\r/g, "\r") : inner;
|
|
6989
|
+
}
|
|
6990
|
+
const commentIndex = value.search(/\s#/);
|
|
6991
|
+
return (commentIndex >= 0 ? value.slice(0, commentIndex) : value).trim();
|
|
6992
|
+
}
|
|
6911
6993
|
function normalizeManagedSyncStore(config, projectRoot) {
|
|
6912
6994
|
const sync = config?.dev?.sync;
|
|
6913
6995
|
if (typeof sync !== "object" || sync === null) return null;
|
|
@@ -8765,7 +8847,7 @@ function printStatus(status, url, logger) {
|
|
|
8765
8847
|
}
|
|
8766
8848
|
|
|
8767
8849
|
// src/commands/studio/studio-command.ts
|
|
8768
|
-
var
|
|
8850
|
+
var import_node_fs9 = require("fs");
|
|
8769
8851
|
var import_node_path30 = require("path");
|
|
8770
8852
|
var import_citty12 = require("citty");
|
|
8771
8853
|
var studioCommand = (0, import_citty12.defineCommand)({
|
|
@@ -8870,7 +8952,7 @@ var studioCommand = (0, import_citty12.defineCommand)({
|
|
|
8870
8952
|
);
|
|
8871
8953
|
}
|
|
8872
8954
|
const dbPath = (0, import_node_path30.resolve)(process.cwd(), args.db);
|
|
8873
|
-
if (!(0,
|
|
8955
|
+
if (!(0, import_node_fs9.existsSync)(dbPath)) {
|
|
8874
8956
|
throw new Error(`Database file not found: ${dbPath}`);
|
|
8875
8957
|
}
|
|
8876
8958
|
const server = await startStudioServer2({ port, dbPath });
|