Skip to content

Commit ce011e3

Browse files
authored
docs: fix snippets for helpers (#3529)
1 parent 4c59469 commit ce011e3

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

scripts/specs/snippets.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import fsp from 'fs/promises';
33
import { GENERATORS, capitalize, createClientName, toAbsolutePath } from '../common.js';
44
import type { Language } from '../types.js';
55

6-
import { waitForTask, waitForAppTask, waitForApiKey } from './helper-snippets.js';
6+
/* eslint import/namespace: ['error', { allowComputed: true }]*/
7+
import * as helperSnippets from './helper-snippets.js';
78
import type { CodeSamples, SnippetForMethod, SnippetSamples } from './types.js';
89

910
export function getCodeSampleLabel(language: Language): CodeSamples['label'] {
@@ -19,6 +20,19 @@ export function getCodeSampleLabel(language: Language): CodeSamples['label'] {
1920
}
2021
}
2122

23+
function getHelperSnippet(
24+
helperName: keyof typeof helperSnippets,
25+
language: string,
26+
): Record<string, string> | string {
27+
if (typeof helperSnippets[helperName][language] === 'string') {
28+
return {
29+
default: helperSnippets[helperName][language],
30+
};
31+
}
32+
33+
return helperSnippets[helperName][language];
34+
}
35+
2236
// Iterates over the snippet samples and sanitize the data to only keep the method part in order to use it in the guides.
2337
export function transformCodeSamplesToGuideMethods(snippetSamples: SnippetSamples): string {
2438
for (const [language, operationWithSample] of Object.entries(snippetSamples)) {
@@ -49,17 +63,9 @@ export function transformCodeSamplesToGuideMethods(snippetSamples: SnippetSample
4963
}
5064

5165
// add specific helper snippets to the current language
52-
snippetSamples[language].waitForAppTask = {
53-
default: waitForAppTask[language],
54-
};
55-
56-
snippetSamples[language].waitForApiKey = {
57-
default: waitForApiKey[language],
58-
};
59-
60-
snippetSamples[language].waitForTask = {
61-
default: waitForTask[language],
62-
};
66+
snippetSamples[language].waitForAppTask = getHelperSnippet('waitForAppTask', language);
67+
snippetSamples[language].waitForApiKey = getHelperSnippet('waitForApiKey', language);
68+
snippetSamples[language].waitForTask = getHelperSnippet('waitForTask', language);
6369
}
6470

6571
return JSON.stringify(snippetSamples, null, 2);

0 commit comments

Comments
 (0)