1export const SNACK_URL = 'https://snack.expo.dev'; 2// export const SNACK_URL = 'http://snack.expo.test'; 3 4type Config = { 5 baseURL: string; 6 templateId?: string; 7 code?: string | null; 8 files?: Record<string, string>; 9}; 10 11type File = { 12 type: 'CODE' | 'ASSET'; 13 contents?: string; 14 url?: string; 15}; 16 17export function getSnackFiles(config: Config) { 18 const { templateId, code, files, baseURL } = config; 19 20 const result: Record<string, File> = {}; 21 if (files) { 22 Object.keys(files).forEach(path => { 23 const url = files[path]; 24 const isCode = /\.(jsx?|tsx?|json|md)$/i.test(path); 25 if (isCode) { 26 result[path] = { 27 type: 'CODE', 28 url: url.match(/^https?:\/\//) ? url : `${baseURL}/${url}`, 29 }; 30 } else { 31 result[path] = { 32 type: 'ASSET', 33 contents: url, // Should be a snack-code-uploads S3 url 34 }; 35 } 36 }); 37 } 38 39 if (templateId) { 40 result['App.js'] = { type: 'CODE', url: `${baseURL}/${templateId}.js` }; 41 } else if (code) { 42 result['App.js'] = { type: 'CODE', contents: code }; 43 } 44 45 return result; 46} 47