44
55import type { SandpackFile } from '@codesandbox/sandpack-react/unstyled' ;
66
7+ /**
8+ * Ideally, we should update all markdown files and all the sandboxes
9+ * to use the same folder structure to include `src`. However, we can
10+ * do the same by prepending the root folder on this function.
11+ */
12+ const rootFolder = '/src/' ;
13+ export const AppJSPath = `/src/App.js` ;
14+ export const StylesCSSPath = `/src/styles.css` ;
15+ export const SUPPORTED_FILES = [ AppJSPath , StylesCSSPath ] ;
16+
717export const createFileMap = ( codeSnippets : any ) => {
818 return codeSnippets . reduce (
919 ( result : Record < string , SandpackFile > , codeSnippet : React . ReactElement ) => {
@@ -17,7 +27,7 @@ export const createFileMap = (codeSnippets: any) => {
1727
1828 if ( props . meta ) {
1929 const [ name , ...params ] = props . meta . split ( ' ' ) ;
20- filePath = '/' + name ;
30+ filePath = rootFolder + name ;
2131 if ( params . includes ( 'hidden' ) ) {
2232 fileHidden = true ;
2333 }
@@ -26,15 +36,16 @@ export const createFileMap = (codeSnippets: any) => {
2636 }
2737 } else {
2838 if ( props . className === 'language-js' ) {
29- filePath = '/App.js' ;
39+ filePath = AppJSPath ;
3040 } else if ( props . className === 'language-css' ) {
31- filePath = '/styles.css' ;
41+ filePath = StylesCSSPath ;
3242 } else {
3343 throw new Error (
3444 `Code block is missing a filename: ${ props . children } `
3545 ) ;
3646 }
3747 }
48+
3849 if ( result [ filePath ] ) {
3950 throw new Error (
4051 `File ${ filePath } was defined multiple times. Each file snippet should have a unique path name`
0 commit comments