zodvex 0.7.7-beta.2 → 0.7.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/cli/index.js +45 -13
- package/dist/cli/index.js.map +1 -1
- package/dist/public/cli/commands.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/public/cli/commands.ts +59 -17
package/dist/cli/index.js
CHANGED
|
@@ -2405,19 +2405,29 @@ ${dtsDeclarations.join("\n")}
|
|
|
2405
2405
|
async function generate(convexDir2, options) {
|
|
2406
2406
|
const resolved = resolveConvexDir(convexDir2);
|
|
2407
2407
|
const zodvexDir = path4.join(resolved, "_zodvex");
|
|
2408
|
-
writeStubApi(zodvexDir);
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
result
|
|
2416
|
-
result.
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2408
|
+
const restoreStubbedApi = writeStubApi(zodvexDir);
|
|
2409
|
+
let result;
|
|
2410
|
+
let schemaContent;
|
|
2411
|
+
let apiContent;
|
|
2412
|
+
let clientContent;
|
|
2413
|
+
let serverContent;
|
|
2414
|
+
try {
|
|
2415
|
+
result = await discoverModules(resolved);
|
|
2416
|
+
schemaContent = generateSchemaFile(result.models);
|
|
2417
|
+
apiContent = generateApiFile(
|
|
2418
|
+
result.functions,
|
|
2419
|
+
result.models,
|
|
2420
|
+
result.codecs,
|
|
2421
|
+
result.modelCodecs,
|
|
2422
|
+
result.functionCodecs,
|
|
2423
|
+
{ mini: options?.mini }
|
|
2424
|
+
);
|
|
2425
|
+
clientContent = generateClientFile({ mini: options?.mini });
|
|
2426
|
+
serverContent = generateServerFile();
|
|
2427
|
+
} catch (err) {
|
|
2428
|
+
restoreStubbedApi();
|
|
2429
|
+
throw err;
|
|
2430
|
+
}
|
|
2421
2431
|
fs3.mkdirSync(zodvexDir, { recursive: true });
|
|
2422
2432
|
writeIfChanged(path4.join(zodvexDir, "schema.js"), schemaContent.js);
|
|
2423
2433
|
writeIfChanged(path4.join(zodvexDir, "schema.d.ts"), schemaContent.dts);
|
|
@@ -2471,6 +2481,16 @@ function regenerate(resolved, options) {
|
|
|
2471
2481
|
});
|
|
2472
2482
|
}
|
|
2473
2483
|
function writeStubApi(zodvexDir) {
|
|
2484
|
+
const stubTargets = ["api.js", "api.d.ts"].map((name) => {
|
|
2485
|
+
const filePath = path4.join(zodvexDir, name);
|
|
2486
|
+
let original;
|
|
2487
|
+
try {
|
|
2488
|
+
original = fs3.readFileSync(filePath, "utf-8");
|
|
2489
|
+
} catch {
|
|
2490
|
+
original = null;
|
|
2491
|
+
}
|
|
2492
|
+
return { filePath, original };
|
|
2493
|
+
});
|
|
2474
2494
|
fs3.mkdirSync(zodvexDir, { recursive: true });
|
|
2475
2495
|
fs3.writeFileSync(
|
|
2476
2496
|
path4.join(zodvexDir, "api.js"),
|
|
@@ -2480,6 +2500,18 @@ function writeStubApi(zodvexDir) {
|
|
|
2480
2500
|
path4.join(zodvexDir, "api.d.ts"),
|
|
2481
2501
|
"// AUTO-GENERATED by zodvex \u2014 do not edit\n// Stub created for codegen bootstrap\n\nexport declare const zodvexRegistry: Record<string, any>\n"
|
|
2482
2502
|
);
|
|
2503
|
+
return () => {
|
|
2504
|
+
for (const { filePath, original } of stubTargets) {
|
|
2505
|
+
try {
|
|
2506
|
+
if (original !== null) {
|
|
2507
|
+
fs3.writeFileSync(filePath, original);
|
|
2508
|
+
} else {
|
|
2509
|
+
fs3.unlinkSync(filePath);
|
|
2510
|
+
}
|
|
2511
|
+
} catch {
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
};
|
|
2483
2515
|
}
|
|
2484
2516
|
function writeIfChanged(filePath, content) {
|
|
2485
2517
|
try {
|