Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function getUrl(
filePath: string,
{ host, ...urlConfig }: GitInfo
) {
let getRaw = raw[host];
if (typeof getRaw !== 'function') {
throw new Error(`Could not parse files from ${host}`);
}
let url = getRaw(filePath, urlConfig);
let extName = path.extname(filePath);
if (!extName) {
return { fileType: '.js', url: `${url}.js` };
} else {
return { fileType: extName, url };
}
}
example,
extensions = [],
template,
}: {
examplePath: string,
pkgJSON?: Package | string | Promise,
gitInfo: GitInfo,
importReplacements?: Array,
dependencies?: Dependencies,
providedFiles?: Files,
example?: string | Promise,
name?: string,
extensions: string[],
template?: 'create-react-app' | 'create-react-app-typescript' | 'vue-cli',
}) {
let extension = path.extname(examplePath) || '.js';
let config = ensureExtensionAndTemplate(extension, extensions, template);
let pkg = await ensurePKGJSON(pkgJSON, importReplacements, gitInfo, config);
let { file, deps, internalImports } = await ensureExample(
example,
importReplacements,
pkg,
examplePath,
gitInfo,
config
);
let fileName = `example${extension}`;
let files = {
...templates[config.template],
async function getFile(gitInfo, filePath) {
const apiUrl = `${apiBase(gitInfo)}/${filePath}`;
const resp = await fetch(apiUrl);
if (path.extname(filePath) === '.json') {
return resp.json();
}
return resp.text();
}