Skip to content

Commit 30c5777

Browse files
committed
chore: skip if file not found
1 parent d729ad9 commit 30c5777

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

scripts/specs/snippets.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fsp from 'fs/promises';
22

3-
import { GENERATORS, capitalize, createClientName, toAbsolutePath } from '../common.js';
3+
import { GENERATORS, capitalize, createClientName, exists, toAbsolutePath } from '../common.js';
44
import type { Language } from '../types.js';
55

66
import type { CodeSamples, SnippetForMethod, SnippetSamples } from './types.js';
@@ -63,14 +63,17 @@ export async function transformSnippetsToCodeSamples(clientName: string): Promis
6363
continue;
6464
}
6565

66-
// find snippets for each operationId in the current gen.language + clientName combo
67-
const snippetFileContent = await fsp.readFile(
68-
toAbsolutePath(
69-
`snippets/${gen.language}/${gen.snippets.outputFolder}/${createClientName(clientName, gen.language)}${gen.snippets.extension}`,
70-
),
71-
'utf8',
66+
const ppath = toAbsolutePath(
67+
`snippets/${gen.language}/${gen.snippets.outputFolder}/${createClientName(clientName, gen.language)}${gen.snippets.extension}`,
7268
);
7369

70+
if (!(await exists(ppath))) {
71+
continue;
72+
}
73+
74+
// find snippets for each operationId in the current gen.language + clientName combo
75+
const snippetFileContent = await fsp.readFile(ppath, 'utf8');
76+
7477
const importMatch = snippetFileContent.match(/>IMPORT\n([\s\S]*?)\n.*IMPORT</);
7578
if (importMatch) {
7679
snippetSamples[gen.language].import = {

0 commit comments

Comments
 (0)