@7nohe/openapi-react-query-codegen
Version:
OpenAPI React Query Codegen
22 lines (21 loc) • 1.05 kB
JavaScript
import { join } from "node:path";
import { Project } from "ts-morph";
import { buildGenerationContext, parseOperations } from "./parseOperations.mjs";
import { generateAllFiles } from "./tsmorph/index.mjs";
/**
* Create source files using ts-morph based generation.
*/
export const createSource = async ({ outputPath, client, version, pageParam, nextPageParam, initialPageParam, omitInitialPageParam, }) => {
// Initialize ts-morph project to read the generated OpenAPI client
const project = new Project({
skipAddingFilesFromTsConfig: true,
});
const sourceFiles = join(process.cwd(), outputPath);
project.addSourceFilesAtPaths(`${sourceFiles}/**/*`);
// Parse operations from the service file
const operations = await parseOperations(project, pageParam);
// Build generation context
const ctx = buildGenerationContext(project, client, pageParam, nextPageParam, initialPageParam, omitInitialPageParam, version);
// Generate all files using ts-morph
return generateAllFiles(operations, ctx);
};