mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
22 lines
670 B
TypeScript
22 lines
670 B
TypeScript
import * as path from 'path';
|
|
|
|
import { exists, readFile } from './fileSystem';
|
|
|
|
/**
|
|
* Check if given file exists and try to read the content as string.
|
|
* @param input
|
|
*/
|
|
export async function readSpecFromDisk(input: string): Promise<string> {
|
|
const filePath = path.resolve(process.cwd(), input);
|
|
const fileExists = await exists(filePath);
|
|
if (fileExists) {
|
|
try {
|
|
const content = await readFile(filePath, 'utf8');
|
|
return content.toString();
|
|
} catch (e) {
|
|
throw new Error(`Could not read OpenApi spec: "${filePath}"`);
|
|
}
|
|
}
|
|
throw new Error(`Could not find OpenApi spec: "${filePath}"`);
|
|
}
|