Skip to content

Commit

Permalink
chore: skip if file not found
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Oct 7, 2024
1 parent d729ad9 commit 30c5777
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions scripts/specs/snippets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fsp from 'fs/promises';

import { GENERATORS, capitalize, createClientName, toAbsolutePath } from '../common.js';
import { GENERATORS, capitalize, createClientName, exists, toAbsolutePath } from '../common.js';
import type { Language } from '../types.js';

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

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

if (!(await exists(ppath))) {
continue;
}

// find snippets for each operationId in the current gen.language + clientName combo
const snippetFileContent = await fsp.readFile(ppath, 'utf8');

const importMatch = snippetFileContent.match(/>IMPORT\n([\s\S]*?)\n.*IMPORT</);
if (importMatch) {
snippetSamples[gen.language].import = {
Expand Down

0 comments on commit 30c5777

Please sign in to comment.