@mintlify/scraping
Version:
Scrape documentation frameworks to Mintlify docs
32 lines • 1.35 kB
JavaScript
import * as fs from 'fs/promises';
import yaml from 'js-yaml';
import * as path from 'path';
import { fetchAsyncApi } from '../utils/network.js';
export const getAsyncApiDefinition = async (pathOrDocumentOrUrl) => {
if (typeof pathOrDocumentOrUrl === 'string') {
if (pathOrDocumentOrUrl.startsWith('http://')) {
// This is an invalid location either for a file or a URL
throw new Error('Only HTTPS URLs are supported. Please provide an HTTPS URL');
}
else {
try {
const url = new URL(pathOrDocumentOrUrl);
pathOrDocumentOrUrl = url;
}
catch {
const pathname = path.join(process.cwd(), pathOrDocumentOrUrl.toString());
const file = await fs.readFile(pathname, 'utf-8');
pathOrDocumentOrUrl = yaml.load(file);
}
}
}
const isUrl = pathOrDocumentOrUrl instanceof URL;
if (pathOrDocumentOrUrl instanceof URL) {
if (pathOrDocumentOrUrl.protocol !== 'https:') {
throw new Error('Only HTTPS URLs are supported. Please provide an HTTPS URL');
}
pathOrDocumentOrUrl = await fetchAsyncApi(pathOrDocumentOrUrl);
}
return { document: pathOrDocumentOrUrl, isUrl };
};
//# sourceMappingURL=getAsyncApiDefinition.js.map