MCPcopy Create free account
hub / github.com/hey-api/hey-api / generateOutput

Function generateOutput

packages/openapi-python/src/generate/output.ts:11–89  ·  view source on GitHub ↗
(context: Context)

Source from the content-addressed store, hash-verified

9import { generateClientBundle } from './client';
10
11export async function generateOutput(context: Context): Promise<{ fileCount: number }> {
12 const outputPath = path.resolve(context.config.output.path);
13
14 if (context.config.output.clean) {
15 if (
16 await fsPromises
17 .access(outputPath)
18 .then(() => true)
19 .catch(() => false)
20 ) {
21 await fsPromises.rm(outputPath, { force: true, recursive: true });
22 }
23 }
24
25 const config = getTypedConfig(context);
26
27 const client = getClientPlugin(config);
28 if ('bundle' in client.config && client.config.bundle && !config.dryRun) {
29 // not proud of this one
30 // @ts-expect-error
31 config._FRAGILE_CLIENT_BUNDLE_RENAMED = generateClientBundle({
32 header: config.output.header,
33 outputPath,
34 // @ts-expect-error
35 plugin: client,
36 project: context.gen,
37 });
38 }
39
40 for (const plugin of context.registerPlugins()) {
41 await plugin.run();
42 }
43
44 context.gen.plan();
45
46 const ctx = new IntentContext(context.spec);
47 for (const intent of context.intents) {
48 await intent.run(ctx);
49 }
50
51 let fileCount = 0;
52 const writes: Promise<void>[] = [];
53 for (const file of context.gen.render()) {
54 const filePath = path.resolve(outputPath, file.path);
55 const dir = path.dirname(filePath);
56 if (!context.config.dryRun) {
57 writes.push(
58 fsPromises
59 .mkdir(dir, { recursive: true })
60 .then(() => fsPromises.writeFile(filePath, file.content, { encoding: 'utf8' })),
61 );
62 }
63 fileCount++;
64 }
65 await Promise.all(writes);
66
67 const { source } = context.config.output;
68 if (source.enabled) {

Callers 1

createClientFunction · 0.90

Calls 13

getTypedConfigFunction · 0.90
getClientPluginFunction · 0.90
generateClientBundleFunction · 0.90
catchMethod · 0.80
accessMethod · 0.80
registerPluginsMethod · 0.80
pushMethod · 0.80
runMethod · 0.65
planMethod · 0.65
renderMethod · 0.65
allMethod · 0.65
resolveMethod · 0.45

Tested by

no test coverage detected