@cushin/api-codegen 1.1.0 → 2.0.0
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.js +104 -201
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +141 -7
- package/dist/index.js +100 -53
- package/dist/index.js.map +1 -1
- package/package.json +14 -19
- package/README.md +0 -435
- package/dist/cli.d.ts +0 -1
- package/dist/config/index.d.ts +0 -84
- package/dist/config/index.js +0 -69
- package/dist/config/index.js.map +0 -1
- package/dist/config/schema.d.ts +0 -43
- package/dist/config/schema.js +0 -14
- package/dist/config/schema.js.map +0 -1
- package/dist/runtime/client.d.ts +0 -40
- package/dist/runtime/client.js +0 -260
- package/dist/runtime/client.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import ora from 'ora';
|
|
5
|
-
import { cosmiconfig } from 'cosmiconfig';
|
|
6
|
-
import path6 from 'path';
|
|
7
|
-
import { createJiti } from 'jiti';
|
|
8
|
-
import fs5 from 'fs/promises';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
2
|
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { setupCLIProgram, setupGenerateCommand, setupInitCommand, setupValidateCommand } from "@cushin/cli";
|
|
6
|
+
|
|
7
|
+
// src/config/index.ts
|
|
8
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
9
|
+
import path from "path";
|
|
11
10
|
var explorer = cosmiconfig("api-codegen", {
|
|
12
11
|
searchPlaces: [
|
|
13
12
|
"api-codegen.config.js",
|
|
@@ -26,9 +25,9 @@ async function loadConfig(configPath) {
|
|
|
26
25
|
return null;
|
|
27
26
|
}
|
|
28
27
|
const userConfig = result.config;
|
|
29
|
-
const rootDir =
|
|
30
|
-
const endpointsPath =
|
|
31
|
-
const outputDir =
|
|
28
|
+
const rootDir = path.dirname(result.filepath);
|
|
29
|
+
const endpointsPath = path.resolve(rootDir, userConfig.endpoints);
|
|
30
|
+
const outputDir = path.resolve(rootDir, userConfig.output);
|
|
32
31
|
const generateHooks = userConfig.generateHooks ?? true;
|
|
33
32
|
const generateServerActions = userConfig.generateServerActions ?? userConfig.provider === "nextjs";
|
|
34
33
|
const generateServerQueries = userConfig.generateServerQueries ?? userConfig.provider === "nextjs";
|
|
@@ -70,10 +69,17 @@ function validateConfig(config) {
|
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
|
|
72
|
+
// src/core/codegen.ts
|
|
73
|
+
import { createJiti } from "jiti";
|
|
74
|
+
|
|
75
|
+
// src/generators/hooks.ts
|
|
76
|
+
import fs from "fs/promises";
|
|
77
|
+
import path2 from "path";
|
|
78
|
+
|
|
73
79
|
// src/generators/base.ts
|
|
74
80
|
var BaseGenerator = class {
|
|
75
|
-
constructor(
|
|
76
|
-
this.context =
|
|
81
|
+
constructor(context2) {
|
|
82
|
+
this.context = context2;
|
|
77
83
|
}
|
|
78
84
|
isQueryEndpoint(endpoint) {
|
|
79
85
|
return endpoint.method === "GET";
|
|
@@ -174,15 +180,15 @@ var BaseGenerator = class {
|
|
|
174
180
|
var HooksGenerator = class extends BaseGenerator {
|
|
175
181
|
async generate() {
|
|
176
182
|
const content = this.generateContent();
|
|
177
|
-
const outputPath =
|
|
178
|
-
await
|
|
179
|
-
await
|
|
183
|
+
const outputPath = path2.join(this.context.config.outputDir, "hooks.ts");
|
|
184
|
+
await fs.mkdir(path2.dirname(outputPath), { recursive: true });
|
|
185
|
+
await fs.writeFile(outputPath, content, "utf-8");
|
|
180
186
|
}
|
|
181
187
|
generateContent() {
|
|
182
188
|
const useClientDirective = this.context.config.options?.useClientDirective ?? true;
|
|
183
|
-
const outputPath =
|
|
184
|
-
const endpointsPath =
|
|
185
|
-
const relativePath =
|
|
189
|
+
const outputPath = path2.join(this.context.config.outputDir, "types.ts");
|
|
190
|
+
const endpointsPath = path2.join(this.context.config.endpointsPath);
|
|
191
|
+
const relativePath = path2.relative(path2.dirname(outputPath), endpointsPath).replace(/\\/g, "/");
|
|
186
192
|
const content = `${useClientDirective ? "'use client';\n" : ""}
|
|
187
193
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
188
194
|
import { apiClient } from "./client";
|
|
@@ -308,12 +314,16 @@ export function ${hookName}(${params.join(",\n ")}) {
|
|
|
308
314
|
}`;
|
|
309
315
|
}
|
|
310
316
|
};
|
|
317
|
+
|
|
318
|
+
// src/generators/actions.ts
|
|
319
|
+
import fs2 from "fs/promises";
|
|
320
|
+
import path3 from "path";
|
|
311
321
|
var ServerActionsGenerator = class extends BaseGenerator {
|
|
312
322
|
async generate() {
|
|
313
323
|
const content = this.generateContent();
|
|
314
|
-
const outputPath =
|
|
315
|
-
await
|
|
316
|
-
await
|
|
324
|
+
const outputPath = path3.join(this.context.config.outputDir, "actions.ts");
|
|
325
|
+
await fs2.mkdir(path3.dirname(outputPath), { recursive: true });
|
|
326
|
+
await fs2.writeFile(outputPath, content, "utf-8");
|
|
317
327
|
}
|
|
318
328
|
generateContent() {
|
|
319
329
|
const imports = `'use server';
|
|
@@ -381,12 +391,16 @@ ${revalidateStatements}
|
|
|
381
391
|
}`;
|
|
382
392
|
}
|
|
383
393
|
};
|
|
394
|
+
|
|
395
|
+
// src/generators/queries.ts
|
|
396
|
+
import fs3 from "fs/promises";
|
|
397
|
+
import path4 from "path";
|
|
384
398
|
var ServerQueriesGenerator = class extends BaseGenerator {
|
|
385
399
|
async generate() {
|
|
386
400
|
const content = this.generateContent();
|
|
387
|
-
const outputPath =
|
|
388
|
-
await
|
|
389
|
-
await
|
|
401
|
+
const outputPath = path4.join(this.context.config.outputDir, "queries.ts");
|
|
402
|
+
await fs3.mkdir(path4.dirname(outputPath), { recursive: true });
|
|
403
|
+
await fs3.writeFile(outputPath, content, "utf-8");
|
|
390
404
|
}
|
|
391
405
|
generateContent() {
|
|
392
406
|
const imports = `import { cache } from 'react';
|
|
@@ -440,17 +454,21 @@ export const ${queryName} = cache(async (
|
|
|
440
454
|
});`;
|
|
441
455
|
}
|
|
442
456
|
};
|
|
457
|
+
|
|
458
|
+
// src/generators/types.ts
|
|
459
|
+
import fs4 from "fs/promises";
|
|
460
|
+
import path5 from "path";
|
|
443
461
|
var TypesGenerator = class extends BaseGenerator {
|
|
444
462
|
async generate() {
|
|
445
463
|
const content = this.generateContent();
|
|
446
|
-
const outputPath =
|
|
447
|
-
await
|
|
448
|
-
await
|
|
464
|
+
const outputPath = path5.join(this.context.config.outputDir, "types.ts");
|
|
465
|
+
await fs4.mkdir(path5.dirname(outputPath), { recursive: true });
|
|
466
|
+
await fs4.writeFile(outputPath, content, "utf-8");
|
|
449
467
|
}
|
|
450
468
|
generateContent() {
|
|
451
|
-
const outputPath =
|
|
452
|
-
const endpointsPath =
|
|
453
|
-
const relativePath =
|
|
469
|
+
const outputPath = path5.join(this.context.config.outputDir, "types.ts");
|
|
470
|
+
const endpointsPath = path5.join(this.context.config.endpointsPath);
|
|
471
|
+
const relativePath = path5.relative(path5.dirname(outputPath), endpointsPath).replace(/\\/g, "/");
|
|
454
472
|
return `// Auto-generated type definitions
|
|
455
473
|
// Do not edit this file manually
|
|
456
474
|
|
|
@@ -459,7 +477,7 @@ import { apiConfig } from '${relativePath}';
|
|
|
459
477
|
|
|
460
478
|
|
|
461
479
|
// Re-export endpoint configuration types
|
|
462
|
-
export type { APIConfig, APIEndpoint, HTTPMethod } from '
|
|
480
|
+
export type { APIConfig, APIEndpoint, HTTPMethod } from './schema';
|
|
463
481
|
|
|
464
482
|
/**
|
|
465
483
|
* Type helper to extract params schema from an endpoint
|
|
@@ -524,6 +542,10 @@ ${this.generateEndpointTypes()}
|
|
|
524
542
|
return types.join("\n");
|
|
525
543
|
}
|
|
526
544
|
};
|
|
545
|
+
|
|
546
|
+
// src/generators/client.ts
|
|
547
|
+
import fs5 from "fs/promises";
|
|
548
|
+
import path6 from "path";
|
|
527
549
|
var ClientGenerator = class extends BaseGenerator {
|
|
528
550
|
async generate() {
|
|
529
551
|
await this.generateClientFile();
|
|
@@ -552,8 +574,8 @@ var ClientGenerator = class extends BaseGenerator {
|
|
|
552
574
|
const endpointsPath = path6.join(this.context.config.endpointsPath);
|
|
553
575
|
const relativePath = path6.relative(path6.dirname(outputPath), endpointsPath).replace(/\\/g, "/");
|
|
554
576
|
return `${useClientDirective ? "'use client';\n" : ""}
|
|
555
|
-
import { createAPIClient } from '
|
|
556
|
-
import type { AuthCallbacks } from '
|
|
577
|
+
import { createAPIClient } from './core';
|
|
578
|
+
import type { AuthCallbacks } from './core';
|
|
557
579
|
import { apiConfig } from '${relativePath}';
|
|
558
580
|
import { z } from 'zod';
|
|
559
581
|
|
|
@@ -621,7 +643,7 @@ export type { AuthCallbacks };
|
|
|
621
643
|
`;
|
|
622
644
|
}
|
|
623
645
|
generateServerClientContent() {
|
|
624
|
-
return `import { createAPIClient } from '
|
|
646
|
+
return `import { createAPIClient } from './core';
|
|
625
647
|
import { apiConfig } from '../config/endpoints';
|
|
626
648
|
import type { APIEndpoints } from './types';
|
|
627
649
|
|
|
@@ -709,20 +731,24 @@ export const serverClient = createAPIClient(apiConfig) as APIClientMethods;
|
|
|
709
731
|
return methods.join("\n");
|
|
710
732
|
}
|
|
711
733
|
};
|
|
734
|
+
|
|
735
|
+
// src/generators/query-keys.ts
|
|
736
|
+
import fs6 from "fs/promises";
|
|
737
|
+
import path7 from "path";
|
|
712
738
|
var QueryKeysGenerator = class extends BaseGenerator {
|
|
713
739
|
async generate() {
|
|
714
740
|
const content = this.generateContent();
|
|
715
|
-
const outputPath =
|
|
741
|
+
const outputPath = path7.join(
|
|
716
742
|
this.context.config.outputDir,
|
|
717
743
|
"query-keys.ts"
|
|
718
744
|
);
|
|
719
|
-
await
|
|
720
|
-
await
|
|
745
|
+
await fs6.mkdir(path7.dirname(outputPath), { recursive: true });
|
|
746
|
+
await fs6.writeFile(outputPath, content, "utf-8");
|
|
721
747
|
}
|
|
722
748
|
generateContent() {
|
|
723
|
-
const outputPath =
|
|
724
|
-
const endpointsPath =
|
|
725
|
-
const relativePath =
|
|
749
|
+
const outputPath = path7.join(this.context.config.outputDir, "types.ts");
|
|
750
|
+
const endpointsPath = path7.join(this.context.config.endpointsPath);
|
|
751
|
+
const relativePath = path7.relative(path7.dirname(outputPath), endpointsPath).replace(/\\/g, "/");
|
|
726
752
|
const content = `// Auto-generated query keys
|
|
727
753
|
import { z } from 'zod';
|
|
728
754
|
import { apiConfig } from '${relativePath}';
|
|
@@ -772,20 +798,24 @@ ${resourceKeys.join("\n")}
|
|
|
772
798
|
return keys.join("\n");
|
|
773
799
|
}
|
|
774
800
|
};
|
|
801
|
+
|
|
802
|
+
// src/generators/query-options.ts
|
|
803
|
+
import fs7 from "fs/promises";
|
|
804
|
+
import path8 from "path";
|
|
775
805
|
var QueryOptionsGenerator = class extends BaseGenerator {
|
|
776
806
|
async generate() {
|
|
777
807
|
const content = this.generateContent();
|
|
778
|
-
const outputPath =
|
|
808
|
+
const outputPath = path8.join(
|
|
779
809
|
this.context.config.outputDir,
|
|
780
810
|
"query-options.ts"
|
|
781
811
|
);
|
|
782
|
-
await
|
|
783
|
-
await
|
|
812
|
+
await fs7.mkdir(path8.dirname(outputPath), { recursive: true });
|
|
813
|
+
await fs7.writeFile(outputPath, content, "utf-8");
|
|
784
814
|
}
|
|
785
815
|
generateContent() {
|
|
786
|
-
const outputPath =
|
|
787
|
-
const endpointsPath =
|
|
788
|
-
const relativePath =
|
|
816
|
+
const outputPath = path8.join(this.context.config.outputDir, "types.ts");
|
|
817
|
+
const endpointsPath = path8.join(this.context.config.endpointsPath);
|
|
818
|
+
const relativePath = path8.relative(path8.dirname(outputPath), endpointsPath).replace(/\\/g, "/");
|
|
789
819
|
const content = `// Auto-generated query options
|
|
790
820
|
import { queryOptions } from '@tanstack/react-query';
|
|
791
821
|
import { apiClient } from './client';
|
|
@@ -854,22 +884,26 @@ ${resourceOptions.join("\n")}
|
|
|
854
884
|
}
|
|
855
885
|
generateQueryOptionsExports() {
|
|
856
886
|
const groups = this.groupEndpointsByResource();
|
|
857
|
-
const exports
|
|
887
|
+
const exports = [];
|
|
858
888
|
Object.keys(groups).forEach((resource) => {
|
|
859
889
|
const hasQueries = groups[resource].some(
|
|
860
890
|
({ endpoint }) => endpoint.method === "GET"
|
|
861
891
|
);
|
|
862
|
-
if (hasQueries) exports
|
|
892
|
+
if (hasQueries) exports.push(` ${resource}: ${resource}QueryOptions,`);
|
|
863
893
|
});
|
|
864
|
-
return exports
|
|
894
|
+
return exports.join("\n");
|
|
865
895
|
}
|
|
866
896
|
};
|
|
897
|
+
|
|
898
|
+
// src/generators/prefetch.ts
|
|
899
|
+
import fs8 from "fs/promises";
|
|
900
|
+
import path9 from "path";
|
|
867
901
|
var PrefetchGenerator = class extends BaseGenerator {
|
|
868
902
|
async generate() {
|
|
869
903
|
const content = this.generateContent();
|
|
870
|
-
const outputPath =
|
|
871
|
-
await
|
|
872
|
-
await
|
|
904
|
+
const outputPath = path9.join(this.context.config.outputDir, "prefetchs.ts");
|
|
905
|
+
await fs8.mkdir(path9.dirname(outputPath), { recursive: true });
|
|
906
|
+
await fs8.writeFile(outputPath, content, "utf-8");
|
|
873
907
|
}
|
|
874
908
|
generateContent() {
|
|
875
909
|
const content = `// Auto-generated prefetch utilities
|
|
@@ -920,8 +954,8 @@ ${this.generatePrefetchFunctions()}
|
|
|
920
954
|
|
|
921
955
|
// src/generators/index.ts
|
|
922
956
|
var CodeGenerator = class {
|
|
923
|
-
constructor(
|
|
924
|
-
this.context =
|
|
957
|
+
constructor(context2) {
|
|
958
|
+
this.context = context2;
|
|
925
959
|
}
|
|
926
960
|
async generate() {
|
|
927
961
|
const generators = this.getGenerators();
|
|
@@ -952,6 +986,9 @@ var CodeGenerator = class {
|
|
|
952
986
|
return generators;
|
|
953
987
|
}
|
|
954
988
|
};
|
|
989
|
+
|
|
990
|
+
// src/core/codegen.ts
|
|
991
|
+
import { fileURLToPath } from "url";
|
|
955
992
|
var CodegenCore = class {
|
|
956
993
|
constructor(config) {
|
|
957
994
|
this.config = config;
|
|
@@ -985,153 +1022,19 @@ var CodegenCore = class {
|
|
|
985
1022
|
}
|
|
986
1023
|
}
|
|
987
1024
|
};
|
|
988
|
-
var program = new Command();
|
|
989
|
-
program.name("api-codegen").description("Generate type-safe API client code from endpoint definitions").version("1.0.0");
|
|
990
|
-
program.command("generate").alias("gen").description("Generate API client code from configuration").option("-c, --config <path>", "Path to configuration file").option("-w, --watch", "Watch for changes and regenerate").action(async (options) => {
|
|
991
|
-
const spinner = ora("Loading configuration...").start();
|
|
992
|
-
try {
|
|
993
|
-
const config = await loadConfig(options.config);
|
|
994
|
-
if (!config) {
|
|
995
|
-
spinner.fail(
|
|
996
|
-
chalk.red(
|
|
997
|
-
"No configuration file found. Please create an api-codegen.config.js file."
|
|
998
|
-
)
|
|
999
|
-
);
|
|
1000
|
-
process.exit(1);
|
|
1001
|
-
}
|
|
1002
|
-
spinner.text = "Validating configuration...";
|
|
1003
|
-
validateConfig(config);
|
|
1004
|
-
spinner.text = "Loading API endpoints...";
|
|
1005
|
-
const codegen = new CodegenCore(config);
|
|
1006
|
-
spinner.text = "Generating code...";
|
|
1007
|
-
await codegen.execute();
|
|
1008
|
-
spinner.succeed(
|
|
1009
|
-
chalk.green(
|
|
1010
|
-
`\u2728 Code generated successfully in ${chalk.cyan(config.outputDir)}`
|
|
1011
|
-
)
|
|
1012
|
-
);
|
|
1013
|
-
console.log(chalk.dim("\nGenerated files:"));
|
|
1014
|
-
const files = await fs5.readdir(config.outputDir);
|
|
1015
|
-
files.forEach((file) => {
|
|
1016
|
-
console.log(chalk.dim(` \u2022 ${file}`));
|
|
1017
|
-
});
|
|
1018
|
-
if (options.watch) {
|
|
1019
|
-
console.log(chalk.yellow("\n\u{1F440} Watching for changes..."));
|
|
1020
|
-
spinner.info(chalk.dim("Watch mode not yet implemented"));
|
|
1021
|
-
}
|
|
1022
|
-
} catch (error) {
|
|
1023
|
-
spinner.fail(chalk.red("Failed to generate code"));
|
|
1024
|
-
console.error(
|
|
1025
|
-
chalk.red("\n" + (error instanceof Error ? error.message : String(error)))
|
|
1026
|
-
);
|
|
1027
|
-
if (error instanceof Error && error.stack) {
|
|
1028
|
-
console.error(chalk.dim(error.stack));
|
|
1029
|
-
}
|
|
1030
|
-
process.exit(1);
|
|
1031
|
-
}
|
|
1032
|
-
});
|
|
1033
|
-
program.command("init").description("Initialize a new api-codegen configuration").option("-p, --provider <provider>", "Provider type (vite or nextjs)", "vite").action(async (options) => {
|
|
1034
|
-
const spinner = ora("Creating configuration file...").start();
|
|
1035
|
-
try {
|
|
1036
|
-
const configContent = generateConfigTemplate(options.provider);
|
|
1037
|
-
const configPath = path6.join(process.cwd(), "api-codegen.config.js");
|
|
1038
|
-
try {
|
|
1039
|
-
await fs5.access(configPath);
|
|
1040
|
-
spinner.warn(
|
|
1041
|
-
chalk.yellow(
|
|
1042
|
-
"Configuration file already exists at api-codegen.config.js"
|
|
1043
|
-
)
|
|
1044
|
-
);
|
|
1045
|
-
return;
|
|
1046
|
-
} catch {
|
|
1047
|
-
}
|
|
1048
|
-
await fs5.writeFile(configPath, configContent, "utf-8");
|
|
1049
|
-
spinner.succeed(
|
|
1050
|
-
chalk.green("\u2728 Configuration file created: api-codegen.config.js")
|
|
1051
|
-
);
|
|
1052
|
-
console.log(chalk.dim("\nNext steps:"));
|
|
1053
|
-
console.log(chalk.dim(" 1. Update the endpoints path in the config"));
|
|
1054
|
-
console.log(chalk.dim(" 2. Run: npx @cushin/api-codegen generate"));
|
|
1055
|
-
} catch (error) {
|
|
1056
|
-
spinner.fail(chalk.red("Failed to create configuration file"));
|
|
1057
|
-
console.error(
|
|
1058
|
-
chalk.red("\n" + (error instanceof Error ? error.message : String(error)))
|
|
1059
|
-
);
|
|
1060
|
-
process.exit(1);
|
|
1061
|
-
}
|
|
1062
|
-
});
|
|
1063
|
-
program.command("validate").description("Validate your API endpoints configuration").option("-c, --config <path>", "Path to configuration file").action(async (options) => {
|
|
1064
|
-
const spinner = ora("Loading configuration...").start();
|
|
1065
|
-
try {
|
|
1066
|
-
const config = await loadConfig(options.config);
|
|
1067
|
-
if (!config) {
|
|
1068
|
-
spinner.fail(chalk.red("No configuration file found"));
|
|
1069
|
-
process.exit(1);
|
|
1070
|
-
}
|
|
1071
|
-
spinner.text = "Validating configuration...";
|
|
1072
|
-
validateConfig(config);
|
|
1073
|
-
spinner.text = "Loading API endpoints...";
|
|
1074
|
-
new CodegenCore(config);
|
|
1075
|
-
const apiConfigModule = await import(pathToFileURL(config.endpointsPath).href);
|
|
1076
|
-
const apiConfig = apiConfigModule.apiConfig || apiConfigModule.default?.apiConfig || apiConfigModule.default;
|
|
1077
|
-
if (!apiConfig || !apiConfig.endpoints) {
|
|
1078
|
-
throw new Error("Invalid endpoints configuration");
|
|
1079
|
-
}
|
|
1080
|
-
const endpointCount = Object.keys(apiConfig.endpoints).length;
|
|
1081
|
-
spinner.succeed(
|
|
1082
|
-
chalk.green(
|
|
1083
|
-
`\u2728 Configuration is valid! Found ${endpointCount} endpoint${endpointCount === 1 ? "" : "s"}`
|
|
1084
|
-
)
|
|
1085
|
-
);
|
|
1086
|
-
console.log(chalk.dim("\nEndpoints:"));
|
|
1087
|
-
Object.entries(apiConfig.endpoints).forEach(([name, endpoint]) => {
|
|
1088
|
-
console.log(
|
|
1089
|
-
chalk.dim(
|
|
1090
|
-
` \u2022 ${chalk.cyan(name)}: ${endpoint.method} ${endpoint.path}`
|
|
1091
|
-
)
|
|
1092
|
-
);
|
|
1093
|
-
});
|
|
1094
|
-
} catch (error) {
|
|
1095
|
-
spinner.fail(chalk.red("Validation failed"));
|
|
1096
|
-
console.error(
|
|
1097
|
-
chalk.red("\n" + (error instanceof Error ? error.message : String(error)))
|
|
1098
|
-
);
|
|
1099
|
-
process.exit(1);
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
1102
|
-
function generateConfigTemplate(provider) {
|
|
1103
|
-
return `/** @type {import('@cushin/api-codegen').UserConfig} */
|
|
1104
|
-
export default {
|
|
1105
|
-
// Provider: 'vite' or 'nextjs'
|
|
1106
|
-
provider: '${provider}',
|
|
1107
|
-
|
|
1108
|
-
// Path to your API endpoints configuration
|
|
1109
|
-
endpoints: './lib/api/config/endpoints.ts',
|
|
1110
|
-
|
|
1111
|
-
// Output directory for generated files
|
|
1112
|
-
output: './lib/api/generated',
|
|
1113
|
-
|
|
1114
|
-
// Base URL for API requests (optional, can be set at runtime)
|
|
1115
|
-
baseUrl: process.env.VITE_API_URL || process.env.NEXT_PUBLIC_API_URL,
|
|
1116
1025
|
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
hookPrefix: 'use',
|
|
1127
|
-
actionSuffix: 'Action',
|
|
1128
|
-
},
|
|
1026
|
+
// src/cli.ts
|
|
1027
|
+
import path10 from "path";
|
|
1028
|
+
var program = new Command();
|
|
1029
|
+
setupCLIProgram(program);
|
|
1030
|
+
var context = {
|
|
1031
|
+
loadConfig,
|
|
1032
|
+
validateConfig,
|
|
1033
|
+
CodegenCore,
|
|
1034
|
+
pathToFileURL: (filePath) => new URL(`file://${path10.resolve(filePath)}`)
|
|
1129
1035
|
};
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
return new URL(`file://${path6.resolve(filePath)}`);
|
|
1134
|
-
}
|
|
1036
|
+
setupGenerateCommand(program, context);
|
|
1037
|
+
setupInitCommand(program);
|
|
1038
|
+
setupValidateCommand(program, context);
|
|
1135
1039
|
program.parse();
|
|
1136
|
-
//# sourceMappingURL=cli.js.map
|
|
1137
1040
|
//# sourceMappingURL=cli.js.map
|