@korajs/cli 0.1.6 → 0.1.8
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 +84 -73
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +50 -53
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-TZPACPP6.js → chunk-AUDUNRYA.js} +27 -11
- package/dist/chunk-AUDUNRYA.js.map +1 -0
- package/dist/create.cjs.map +1 -1
- package/dist/create.js +1 -1
- package/package.json +1 -1
- package/templates/react-basic/package.json.hbs +2 -0
- package/templates/react-basic/src/kora-worker.ts +3 -0
- package/templates/react-basic/src/main.tsx +7 -2
- package/templates/react-basic/vite.config.ts +3 -0
- package/templates/react-sync/package.json.hbs +2 -0
- package/templates/react-sync/src/kora-worker.ts +3 -0
- package/templates/react-sync/src/main.tsx +4 -1
- package/templates/react-sync/vite.config.ts +3 -0
- package/dist/chunk-TZPACPP6.js.map +0 -1
package/dist/bin.cjs
CHANGED
|
@@ -146,17 +146,32 @@ async function findSchemaFile(projectRoot) {
|
|
|
146
146
|
}
|
|
147
147
|
return null;
|
|
148
148
|
}
|
|
149
|
-
async function
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
async function hasTsxInstalled(projectRoot) {
|
|
150
|
+
try {
|
|
151
|
+
await (0, import_promises.access)((0, import_node_path.join)(projectRoot, "node_modules", "tsx", "package.json"));
|
|
152
|
+
return true;
|
|
153
|
+
} catch {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function resolveProjectBinaryEntryPoint(projectRoot, packageName, binaryName) {
|
|
158
|
+
const pkgJsonPath = (0, import_node_path.join)(projectRoot, "node_modules", packageName, "package.json");
|
|
159
|
+
try {
|
|
160
|
+
const content = await (0, import_promises.readFile)(pkgJsonPath, "utf-8");
|
|
161
|
+
const pkg = JSON.parse(content);
|
|
162
|
+
let binPath;
|
|
163
|
+
if (typeof pkg.bin === "string") {
|
|
164
|
+
binPath = pkg.bin;
|
|
165
|
+
} else if (typeof pkg.bin === "object" && pkg.bin !== null) {
|
|
166
|
+
binPath = pkg.bin[binaryName];
|
|
167
|
+
}
|
|
168
|
+
if (!binPath) return null;
|
|
169
|
+
const fullPath = (0, import_node_path.join)(projectRoot, "node_modules", packageName, binPath);
|
|
170
|
+
await (0, import_promises.access)(fullPath);
|
|
171
|
+
return fullPath;
|
|
172
|
+
} catch {
|
|
173
|
+
return null;
|
|
158
174
|
}
|
|
159
|
-
return null;
|
|
160
175
|
}
|
|
161
176
|
function isKoraProject(pkg) {
|
|
162
177
|
if (typeof pkg !== "object" || pkg === null) return false;
|
|
@@ -473,8 +488,8 @@ function resolveKoraVersion() {
|
|
|
473
488
|
|
|
474
489
|
// src/commands/dev/dev-command.ts
|
|
475
490
|
var import_promises4 = require("fs/promises");
|
|
476
|
-
var import_node_path5 = require("path");
|
|
477
491
|
var import_node_path6 = require("path");
|
|
492
|
+
var import_node_path7 = require("path");
|
|
478
493
|
var import_citty2 = require("citty");
|
|
479
494
|
|
|
480
495
|
// src/commands/dev/kora-config.ts
|
|
@@ -513,14 +528,17 @@ async function findKoraConfigFile(projectRoot) {
|
|
|
513
528
|
return null;
|
|
514
529
|
}
|
|
515
530
|
async function loadTypeScriptConfig(configPath, projectRoot) {
|
|
516
|
-
|
|
517
|
-
if (!tsxBinary) {
|
|
531
|
+
if (!await hasTsxInstalled(projectRoot)) {
|
|
518
532
|
throw new Error(
|
|
519
533
|
`Found TypeScript config at ${configPath}, but "tsx" is not installed in this project. Install tsx or use kora.config.js.`
|
|
520
534
|
);
|
|
521
535
|
}
|
|
522
536
|
const script = "const configPath = process.argv[process.argv.length - 1];import('node:url').then(u => import(u.pathToFileURL(configPath).href)).then(mod => { const v = mod.default ?? mod; process.stdout.write(JSON.stringify(v)) }).catch(e => { process.stderr.write(String(e)); process.exit(1) })";
|
|
523
|
-
const output = await runCommand(
|
|
537
|
+
const output = await runCommand(
|
|
538
|
+
process.execPath,
|
|
539
|
+
["--import", "tsx", "--eval", script, configPath],
|
|
540
|
+
projectRoot
|
|
541
|
+
);
|
|
524
542
|
try {
|
|
525
543
|
return JSON.parse(output);
|
|
526
544
|
} catch {
|
|
@@ -532,8 +550,7 @@ async function runCommand(command, args, cwd) {
|
|
|
532
550
|
const child = (0, import_node_child_process3.spawn)(command, args, {
|
|
533
551
|
cwd,
|
|
534
552
|
stdio: ["ignore", "pipe", "pipe"],
|
|
535
|
-
env: process.env
|
|
536
|
-
shell: process.platform === "win32"
|
|
553
|
+
env: process.env
|
|
537
554
|
});
|
|
538
555
|
let stdout = "";
|
|
539
556
|
let stderr = "";
|
|
@@ -574,9 +591,7 @@ var ProcessManager = class {
|
|
|
574
591
|
const options = {
|
|
575
592
|
cwd: config.cwd,
|
|
576
593
|
env: { ...process.env, ...config.env },
|
|
577
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
578
|
-
// On Windows, .cmd shims require shell to execute
|
|
579
|
-
shell: process.platform === "win32"
|
|
594
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
580
595
|
};
|
|
581
596
|
const child = (0, import_node_child_process4.spawn)(config.command, config.args, options);
|
|
582
597
|
let resolveExit;
|
|
@@ -658,6 +673,7 @@ function delay(ms) {
|
|
|
658
673
|
// src/commands/dev/schema-watcher.ts
|
|
659
674
|
var import_node_child_process5 = require("child_process");
|
|
660
675
|
var import_node_fs3 = require("fs");
|
|
676
|
+
var import_node_path5 = require("path");
|
|
661
677
|
var SchemaWatcher = class {
|
|
662
678
|
constructor(config) {
|
|
663
679
|
this.config = config;
|
|
@@ -685,16 +701,10 @@ var SchemaWatcher = class {
|
|
|
685
701
|
this.watcher = null;
|
|
686
702
|
}
|
|
687
703
|
async regenerate() {
|
|
688
|
-
const
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const tsxBinary = await resolveProjectBinary(this.config.projectRoot, "tsx");
|
|
693
|
-
if (!tsxBinary) {
|
|
694
|
-
process.stderr.write('[kora] Could not find "tsx" binary. Falling back to node.\n');
|
|
695
|
-
}
|
|
696
|
-
const command = tsxBinary ?? process.execPath;
|
|
697
|
-
const args = [koraBinary, "generate", "types", "--schema", this.config.schemaPath];
|
|
704
|
+
const koraBinJs = (0, import_node_path5.join)(this.config.projectRoot, "node_modules", "@korajs", "cli", "dist", "bin.js");
|
|
705
|
+
const hasTsx = await hasTsxInstalled(this.config.projectRoot);
|
|
706
|
+
const command = process.execPath;
|
|
707
|
+
const args = hasTsx ? ["--import", "tsx", koraBinJs, "generate", "types", "--schema", this.config.schemaPath] : [koraBinJs, "generate", "types", "--schema", this.config.schemaPath];
|
|
698
708
|
await spawnCommand(command, args, this.config.projectRoot);
|
|
699
709
|
this.config.onRegenerate?.();
|
|
700
710
|
}
|
|
@@ -715,8 +725,7 @@ async function spawnCommand(command, args, cwd) {
|
|
|
715
725
|
const child = (0, import_node_child_process5.spawn)(command, args, {
|
|
716
726
|
cwd,
|
|
717
727
|
stdio: ["ignore", "pipe", "pipe"],
|
|
718
|
-
env: process.env
|
|
719
|
-
shell: process.platform === "win32"
|
|
728
|
+
env: process.env
|
|
720
729
|
});
|
|
721
730
|
child.stdout?.on("data", (chunk) => {
|
|
722
731
|
writePrefixedLines(chunk, false);
|
|
@@ -789,25 +798,25 @@ var devCommand = (0, import_citty2.defineCommand)({
|
|
|
789
798
|
const configSyncEnabled = config?.dev?.sync === void 0 || config.dev.sync === true || typeof config.dev.sync === "object" && config.dev.sync.enabled !== false;
|
|
790
799
|
const configWatchEnabled = config?.dev?.watch === void 0 || config.dev.watch === true || typeof config.dev.watch === "object" && config.dev.watch.enabled !== false;
|
|
791
800
|
const watchDebounceMs = typeof config?.dev?.watch === "object" && typeof config.dev.watch.debounceMs === "number" ? config.dev.watch.debounceMs : 300;
|
|
792
|
-
const
|
|
793
|
-
if (!
|
|
794
|
-
throw new DevServerError("vite", (0,
|
|
801
|
+
const viteEntryPoint = await resolveProjectBinaryEntryPoint(projectRoot, "vite", "vite");
|
|
802
|
+
if (!viteEntryPoint) {
|
|
803
|
+
throw new DevServerError("vite", (0, import_node_path6.join)(projectRoot, "node_modules", ".bin", "vite"));
|
|
795
804
|
}
|
|
796
805
|
const syncServerFile = await findSyncServerFile(projectRoot);
|
|
797
806
|
let managedSyncStore = normalizeManagedSyncStore(config, projectRoot);
|
|
798
807
|
const postgresEnvRequested = isPostgresEnvRequested(config);
|
|
799
808
|
const syncAllowed = args["no-sync"] !== true && configSyncEnabled;
|
|
800
809
|
let shouldStartSync = syncAllowed && (syncServerFile !== null || managedSyncStore !== null);
|
|
801
|
-
let
|
|
810
|
+
let hasTsx = false;
|
|
802
811
|
if (shouldStartSync && syncServerFile !== null) {
|
|
803
|
-
|
|
804
|
-
if (!
|
|
805
|
-
logger.warn('Sync server detected, but
|
|
812
|
+
hasTsx = await hasTsxInstalled(projectRoot);
|
|
813
|
+
if (!hasTsx) {
|
|
814
|
+
logger.warn('Sync server detected, but "tsx" is not installed. Skipping sync.');
|
|
806
815
|
}
|
|
807
816
|
}
|
|
808
817
|
if (shouldStartSync && syncServerFile === null && managedSyncStore) {
|
|
809
818
|
const hasServerPackage = await fileExists(
|
|
810
|
-
(0,
|
|
819
|
+
(0, import_node_path6.join)(projectRoot, "node_modules", "@korajs", "server", "package.json")
|
|
811
820
|
);
|
|
812
821
|
if (!hasServerPackage) {
|
|
813
822
|
logger.warn(
|
|
@@ -824,7 +833,7 @@ var devCommand = (0, import_citty2.defineCommand)({
|
|
|
824
833
|
}
|
|
825
834
|
let configuredSchemaPath = null;
|
|
826
835
|
if (typeof config?.schema === "string") {
|
|
827
|
-
const candidate = (0,
|
|
836
|
+
const candidate = (0, import_node_path7.resolve)(projectRoot, config.schema);
|
|
828
837
|
if (await fileExists(candidate)) {
|
|
829
838
|
configuredSchemaPath = candidate;
|
|
830
839
|
} else {
|
|
@@ -864,7 +873,7 @@ var devCommand = (0, import_citty2.defineCommand)({
|
|
|
864
873
|
logger.info("Starting development environment:");
|
|
865
874
|
logger.blank();
|
|
866
875
|
logger.step(` Vite dev server on port ${vitePort}`);
|
|
867
|
-
if (shouldStartSync &&
|
|
876
|
+
if (shouldStartSync && hasTsx && syncServerFile) {
|
|
868
877
|
logger.step(` Sync server on port ${syncPort}`);
|
|
869
878
|
} else if (shouldStartSync && syncServerFile === null && managedSyncStore !== null) {
|
|
870
879
|
logger.step(` Managed sync server on port ${syncPort} (${managedSyncStore.type})`);
|
|
@@ -883,16 +892,16 @@ var devCommand = (0, import_citty2.defineCommand)({
|
|
|
883
892
|
logger.blank();
|
|
884
893
|
processManager.spawn({
|
|
885
894
|
label: "vite",
|
|
886
|
-
command:
|
|
887
|
-
args: ["--port", String(vitePort)],
|
|
895
|
+
command: process.execPath,
|
|
896
|
+
args: [viteEntryPoint, "--port", String(vitePort)],
|
|
888
897
|
cwd: projectRoot,
|
|
889
898
|
onExit: onManagedProcessExit
|
|
890
899
|
});
|
|
891
|
-
if (shouldStartSync &&
|
|
900
|
+
if (shouldStartSync && hasTsx && syncServerFile) {
|
|
892
901
|
processManager.spawn({
|
|
893
902
|
label: "sync",
|
|
894
|
-
command:
|
|
895
|
-
args: [syncServerFile],
|
|
903
|
+
command: process.execPath,
|
|
904
|
+
args: ["--import", "tsx", syncServerFile],
|
|
896
905
|
cwd: projectRoot,
|
|
897
906
|
env: {
|
|
898
907
|
PORT: String(syncPort),
|
|
@@ -936,7 +945,7 @@ var devCommand = (0, import_citty2.defineCommand)({
|
|
|
936
945
|
}
|
|
937
946
|
});
|
|
938
947
|
async function findSyncServerFile(projectRoot) {
|
|
939
|
-
const candidates = [(0,
|
|
948
|
+
const candidates = [(0, import_node_path6.join)(projectRoot, "server.ts"), (0, import_node_path6.join)(projectRoot, "server.js")];
|
|
940
949
|
for (const candidate of candidates) {
|
|
941
950
|
try {
|
|
942
951
|
await (0, import_promises4.access)(candidate);
|
|
@@ -960,7 +969,7 @@ function normalizeManagedSyncStore(config, projectRoot) {
|
|
|
960
969
|
const store = sync.store;
|
|
961
970
|
if (store === void 0) return { type: "memory" };
|
|
962
971
|
if (store === "memory") return { type: "memory" };
|
|
963
|
-
if (store === "sqlite") return { type: "sqlite", filename: (0,
|
|
972
|
+
if (store === "sqlite") return { type: "sqlite", filename: (0, import_node_path6.join)(projectRoot, "kora-sync.db") };
|
|
964
973
|
if (store === "postgres") {
|
|
965
974
|
const connectionString = process.env.DATABASE_URL;
|
|
966
975
|
if (!connectionString) return null;
|
|
@@ -969,7 +978,7 @@ function normalizeManagedSyncStore(config, projectRoot) {
|
|
|
969
978
|
if (typeof store === "object" && store !== null) {
|
|
970
979
|
if (store.type === "memory") return { type: "memory" };
|
|
971
980
|
if (store.type === "sqlite") {
|
|
972
|
-
const filename = typeof store.filename === "string" && store.filename.length > 0 ? (0,
|
|
981
|
+
const filename = typeof store.filename === "string" && store.filename.length > 0 ? (0, import_node_path7.resolve)(projectRoot, store.filename) : (0, import_node_path6.join)(projectRoot, "kora-sync.db");
|
|
973
982
|
return { type: "sqlite", filename };
|
|
974
983
|
}
|
|
975
984
|
if (store.type === "postgres" && typeof store.connectionString === "string") {
|
|
@@ -1033,7 +1042,7 @@ await new Promise(() => {});
|
|
|
1033
1042
|
|
|
1034
1043
|
// src/commands/generate/generate-command.ts
|
|
1035
1044
|
var import_promises5 = require("fs/promises");
|
|
1036
|
-
var
|
|
1045
|
+
var import_node_path8 = require("path");
|
|
1037
1046
|
var import_citty3 = require("citty");
|
|
1038
1047
|
|
|
1039
1048
|
// src/commands/generate/type-generator.ts
|
|
@@ -1164,7 +1173,7 @@ var generateCommand = (0, import_citty3.defineCommand)({
|
|
|
1164
1173
|
}
|
|
1165
1174
|
let schemaPath;
|
|
1166
1175
|
if (args.schema && typeof args.schema === "string") {
|
|
1167
|
-
schemaPath = (0,
|
|
1176
|
+
schemaPath = (0, import_node_path8.resolve)(args.schema);
|
|
1168
1177
|
} else {
|
|
1169
1178
|
const found = await findSchemaFile(projectRoot);
|
|
1170
1179
|
if (!found) {
|
|
@@ -1187,8 +1196,8 @@ var generateCommand = (0, import_citty3.defineCommand)({
|
|
|
1187
1196
|
}
|
|
1188
1197
|
const output = generateTypes(schema);
|
|
1189
1198
|
const outputFile = typeof args.output === "string" ? args.output : "kora/generated/types.ts";
|
|
1190
|
-
const outputPath = (0,
|
|
1191
|
-
await (0, import_promises5.mkdir)((0,
|
|
1199
|
+
const outputPath = (0, import_node_path8.resolve)(projectRoot, outputFile);
|
|
1200
|
+
await (0, import_promises5.mkdir)((0, import_node_path8.dirname)(outputPath), { recursive: true });
|
|
1192
1201
|
await (0, import_promises5.writeFile)(outputPath, output, "utf-8");
|
|
1193
1202
|
logger.success(`Generated types at ${outputPath}`);
|
|
1194
1203
|
}
|
|
@@ -1210,7 +1219,7 @@ function isSchemaDefinition(value) {
|
|
|
1210
1219
|
|
|
1211
1220
|
// src/commands/migrate/migrate-command.ts
|
|
1212
1221
|
var import_promises6 = require("fs/promises");
|
|
1213
|
-
var
|
|
1222
|
+
var import_node_path10 = require("path");
|
|
1214
1223
|
var import_citty4 = require("citty");
|
|
1215
1224
|
|
|
1216
1225
|
// src/commands/migrate/migration-generator.ts
|
|
@@ -1780,10 +1789,10 @@ async function loadPostgresModule() {
|
|
|
1780
1789
|
|
|
1781
1790
|
// src/commands/migrate/schema-loader.ts
|
|
1782
1791
|
var import_node_child_process6 = require("child_process");
|
|
1783
|
-
var
|
|
1792
|
+
var import_node_path9 = require("path");
|
|
1784
1793
|
var import_node_url4 = require("url");
|
|
1785
1794
|
async function loadSchemaDefinition(schemaPath, projectRoot) {
|
|
1786
|
-
const ext = (0,
|
|
1795
|
+
const ext = (0, import_node_path9.extname)(schemaPath);
|
|
1787
1796
|
const moduleValue = ext === ".ts" || ext === ".mts" || ext === ".cts" ? await loadTypeScriptModule(schemaPath, projectRoot) : await import(`${(0, import_node_url4.pathToFileURL)(schemaPath).href}?t=${Date.now()}-${Math.random()}`);
|
|
1788
1797
|
return extractSchema2(moduleValue);
|
|
1789
1798
|
}
|
|
@@ -1804,14 +1813,17 @@ function isSchemaDefinition2(value) {
|
|
|
1804
1813
|
return typeof object.version === "number" && typeof object.collections === "object" && object.collections !== null && typeof object.relations === "object" && object.relations !== null;
|
|
1805
1814
|
}
|
|
1806
1815
|
async function loadTypeScriptModule(schemaPath, projectRoot) {
|
|
1807
|
-
|
|
1808
|
-
if (!tsxBinary) {
|
|
1816
|
+
if (!await hasTsxInstalled(projectRoot)) {
|
|
1809
1817
|
throw new Error(
|
|
1810
1818
|
`Schema file is TypeScript (${schemaPath}) but local "tsx" was not found. Install tsx in the project.`
|
|
1811
1819
|
);
|
|
1812
1820
|
}
|
|
1813
1821
|
const script = "const modulePath = process.argv[process.argv.length - 1];import('node:url').then(u => import(u.pathToFileURL(modulePath).href)).then(mod => { const v = mod.default ?? mod; process.stdout.write(JSON.stringify(v)) }).catch(e => { process.stderr.write(String(e)); process.exit(1) })";
|
|
1814
|
-
const output = await runCommand2(
|
|
1822
|
+
const output = await runCommand2(
|
|
1823
|
+
process.execPath,
|
|
1824
|
+
["--import", "tsx", "--eval", script, schemaPath],
|
|
1825
|
+
projectRoot
|
|
1826
|
+
);
|
|
1815
1827
|
try {
|
|
1816
1828
|
return JSON.parse(output);
|
|
1817
1829
|
} catch {
|
|
@@ -1823,8 +1835,7 @@ async function runCommand2(command, args, cwd) {
|
|
|
1823
1835
|
const child = (0, import_node_child_process6.spawn)(command, args, {
|
|
1824
1836
|
cwd,
|
|
1825
1837
|
stdio: ["ignore", "pipe", "pipe"],
|
|
1826
|
-
env: process.env
|
|
1827
|
-
shell: process.platform === "win32"
|
|
1838
|
+
env: process.env
|
|
1828
1839
|
});
|
|
1829
1840
|
let stdout = "";
|
|
1830
1841
|
let stderr = "";
|
|
@@ -1894,12 +1905,12 @@ var migrateCommand = (0, import_citty4.defineCommand)({
|
|
|
1894
1905
|
throw new InvalidProjectError(process.cwd());
|
|
1895
1906
|
}
|
|
1896
1907
|
const config = await loadKoraConfig(projectRoot);
|
|
1897
|
-
const resolvedSchemaPath = typeof args.schema === "string" ? (0,
|
|
1908
|
+
const resolvedSchemaPath = typeof args.schema === "string" ? (0, import_node_path10.resolve)(projectRoot, args.schema) : typeof config?.schema === "string" ? (0, import_node_path10.resolve)(projectRoot, config.schema) : await findSchemaFile(projectRoot);
|
|
1898
1909
|
if (!resolvedSchemaPath) {
|
|
1899
1910
|
throw new SchemaNotFoundError(["src/schema.ts", "schema.ts", "src/schema.js", "schema.js"]);
|
|
1900
1911
|
}
|
|
1901
1912
|
const currentSchema = await loadSchemaDefinition(resolvedSchemaPath, projectRoot);
|
|
1902
|
-
const snapshotFile = (0,
|
|
1913
|
+
const snapshotFile = (0, import_node_path10.join)(projectRoot, SNAPSHOT_PATH);
|
|
1903
1914
|
const previousSchema = await readSchemaSnapshot(snapshotFile);
|
|
1904
1915
|
if (!previousSchema) {
|
|
1905
1916
|
if (args["dry-run"] === true) {
|
|
@@ -1912,7 +1923,7 @@ var migrateCommand = (0, import_citty4.defineCommand)({
|
|
|
1912
1923
|
return;
|
|
1913
1924
|
}
|
|
1914
1925
|
const diff = diffSchemas(previousSchema, currentSchema);
|
|
1915
|
-
const outputDir = typeof args["output-dir"] === "string" ? (0,
|
|
1926
|
+
const outputDir = typeof args["output-dir"] === "string" ? (0, import_node_path10.resolve)(projectRoot, args["output-dir"]) : (0, import_node_path10.resolve)(projectRoot, MIGRATIONS_DIR);
|
|
1916
1927
|
if (!diff.hasChanges) {
|
|
1917
1928
|
logger.success("No schema changes detected.");
|
|
1918
1929
|
if (args.apply === true) {
|
|
@@ -2016,7 +2027,7 @@ function isInteractiveTerminal() {
|
|
|
2016
2027
|
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
2017
2028
|
}
|
|
2018
2029
|
async function writeSchemaSnapshot(path, schema) {
|
|
2019
|
-
await (0, import_promises6.mkdir)((0,
|
|
2030
|
+
await (0, import_promises6.mkdir)((0, import_node_path10.dirname)(path), { recursive: true });
|
|
2020
2031
|
await (0, import_promises6.writeFile)(path, `${JSON.stringify(schema, null, 2)}
|
|
2021
2032
|
`, "utf-8");
|
|
2022
2033
|
}
|
|
@@ -2024,7 +2035,7 @@ async function writeMigrationFile(outputDir, fromVersion, toVersion, generated)
|
|
|
2024
2035
|
const existing = await (0, import_promises6.readdir)(outputDir).catch(() => []);
|
|
2025
2036
|
const sequence = existing.filter((file) => /^\d{3}-/.test(file)).length + 1;
|
|
2026
2037
|
const filename = `${String(sequence).padStart(3, "0")}-v${fromVersion}-to-v${toVersion}.ts`;
|
|
2027
|
-
const path = (0,
|
|
2038
|
+
const path = (0, import_node_path10.join)(outputDir, filename);
|
|
2028
2039
|
const migrationId = filename.replace(/\.ts$/, "");
|
|
2029
2040
|
const fileContent = [
|
|
2030
2041
|
`export const up = ${JSON.stringify(generated.up, null, 2)} as const`,
|
|
@@ -2037,7 +2048,7 @@ async function writeMigrationFile(outputDir, fromVersion, toVersion, generated)
|
|
|
2037
2048
|
""
|
|
2038
2049
|
].join("\n");
|
|
2039
2050
|
await (0, import_promises6.writeFile)(path, fileContent, "utf-8");
|
|
2040
|
-
await writeMigrationManifest((0,
|
|
2051
|
+
await writeMigrationManifest((0, import_node_path10.join)(outputDir, `${migrationId}.json`), {
|
|
2041
2052
|
id: migrationId,
|
|
2042
2053
|
fromVersion,
|
|
2043
2054
|
toVersion,
|
|
@@ -2058,13 +2069,13 @@ async function listMigrationManifests(outputDir) {
|
|
|
2058
2069
|
const manifests = [];
|
|
2059
2070
|
for (const file of migrationFiles) {
|
|
2060
2071
|
const id = file.replace(/\.ts$/, "");
|
|
2061
|
-
const manifestPath = (0,
|
|
2072
|
+
const manifestPath = (0, import_node_path10.join)(outputDir, `${id}.json`);
|
|
2062
2073
|
const jsonManifest = await readMigrationManifest(manifestPath);
|
|
2063
2074
|
if (jsonManifest) {
|
|
2064
2075
|
manifests.push({ ...jsonManifest, id });
|
|
2065
2076
|
continue;
|
|
2066
2077
|
}
|
|
2067
|
-
const migrationPath = (0,
|
|
2078
|
+
const migrationPath = (0, import_node_path10.join)(outputDir, file);
|
|
2068
2079
|
const sourceManifest = await readMigrationManifestFromSource(migrationPath, id);
|
|
2069
2080
|
manifests.push(sourceManifest);
|
|
2070
2081
|
}
|
|
@@ -2140,18 +2151,18 @@ function parseLiteralExport(source, exportName) {
|
|
|
2140
2151
|
}
|
|
2141
2152
|
function resolveSqliteApplyPath(dbArg, projectRoot, config) {
|
|
2142
2153
|
if (typeof dbArg === "string") {
|
|
2143
|
-
return (0,
|
|
2154
|
+
return (0, import_node_path10.resolve)(projectRoot, dbArg);
|
|
2144
2155
|
}
|
|
2145
2156
|
const sync = config?.dev?.sync;
|
|
2146
2157
|
if (typeof sync === "object" && sync !== null) {
|
|
2147
2158
|
if (sync.store === "sqlite") {
|
|
2148
|
-
return (0,
|
|
2159
|
+
return (0, import_node_path10.join)(projectRoot, "kora-sync.db");
|
|
2149
2160
|
}
|
|
2150
2161
|
if (typeof sync.store === "object" && sync.store !== null && sync.store.type === "sqlite") {
|
|
2151
2162
|
if (typeof sync.store.filename === "string" && sync.store.filename.length > 0) {
|
|
2152
|
-
return (0,
|
|
2163
|
+
return (0, import_node_path10.resolve)(projectRoot, sync.store.filename);
|
|
2153
2164
|
}
|
|
2154
|
-
return (0,
|
|
2165
|
+
return (0, import_node_path10.join)(projectRoot, "kora-sync.db");
|
|
2155
2166
|
}
|
|
2156
2167
|
}
|
|
2157
2168
|
return void 0;
|