From 30c5777b943f381d43375f405435d46735b1245d Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 7 Oct 2024 13:15:17 +0200 Subject: [PATCH] chore: skip if file not found --- scripts/specs/snippets.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/specs/snippets.ts b/scripts/specs/snippets.ts index ee034a41d7..ea9f297ecf 100644 --- a/scripts/specs/snippets.ts +++ b/scripts/specs/snippets.ts @@ -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'; @@ -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