Skip to content

Commit c6ca5f1

Browse files
committed
add missing files
1 parent 9d8a30d commit c6ca5f1

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/templates/exportSample.hbs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import client from 'github-connector';
2+
3+
export default async function main(args: {
4+
{{#each parameters}}
5+
{{{name}}}{{>isRequired}}: {{>type}}{{#if default}} = {{{default}}}{{/if}};
6+
{{/each}}
7+
}) {
8+
const res = await client.{{{camelCase serviceName}}}.{{name}}(args);
9+
10+
return res;
11+
}

src/utils/writeClientSamples.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { join, resolve } from 'path';
2+
3+
import type { Service } from '../client/interfaces/Service';
4+
import type { HttpClient } from '../HttpClient';
5+
import type { Indent } from '../Indent';
6+
import { mkdir, writeFile } from './fileSystem';
7+
import { formatCode as f } from './formatCode';
8+
import { formatIndentation as i } from './formatIndentation';
9+
import { isDefined } from './isDefined';
10+
import type { Templates } from './registerHandlebarTemplates';
11+
12+
/**
13+
* Generate Services using the Handlebar template and write to disk.
14+
* @param services Array of Services to write
15+
* @param templates The loaded handlebar templates
16+
* @param outputPath Directory to write the generated files to
17+
* @param httpClient The selected httpClient (fetch, xhr, node or axios)
18+
* @param useUnionTypes Use union types instead of enums
19+
* @param useOptions Use options or arguments functions
20+
* @param indent Indentation options (4, 2 or tab)
21+
* @param postfix Service name postfix
22+
* @param clientName Custom client class name
23+
*/
24+
export const writeClientSamples = async (
25+
services: Service[],
26+
templates: Templates,
27+
outputPath: string,
28+
httpClient: HttpClient,
29+
useUnionTypes: boolean,
30+
useOptions: boolean,
31+
indent: Indent,
32+
postfix: string,
33+
clientName?: string
34+
): Promise<void> => {
35+
for (const service of services) {
36+
await mkdir(join(outputPath, service.name));
37+
for (const operation of service.operations) {
38+
const file = resolve(outputPath, service.name, `${operation.name}${postfix}.ts`);
39+
const templateResult = templates.exports.sample({
40+
...operation,
41+
serviceName: service.name,
42+
httpClient,
43+
useUnionTypes,
44+
useOptions,
45+
postfix,
46+
exportClient: isDefined(clientName),
47+
});
48+
await writeFile(file, i(f(templateResult), indent));
49+
}
50+
}
51+
};

0 commit comments

Comments
 (0)