function codesandboxProjectCode()

in docs-sdk/docs-provider/src2/DemoContainer/codesandbox/createCodesandbox.ts [50:117]


function codesandboxProjectCode({
  mainCode,
  deps
}: {
  mainCode: string;
  deps: { [name: string]: string };
}): CSBFiles {
  const pkgJson = {
    name: "demo",
    main: "index.html",
    dependencies: {
      react: "latest",
      "react-dom": "latest",
      ...deps
    }
  };

  return {
    "tsconfig.json": JSON.stringify(
      {
        compilerOptions: {
          strict: true,
          module: "commonjs",
          jsx: "react",
          esModuleInterop: true,
          sourceMap: true,
          allowJs: true,
          lib: ["es6", "dom"],
          rootDir: "src",
          moduleResolution: "node"
        }
      },
      null,
      2
    ),
    "sandbox.config.json": JSON.stringify(
      {
        infiniteLoopProtection: true,
        hardReloadOnChange: false,
        template: "parcel"
      },
      null,
      2
    ),
    "package.json": JSON.stringify(pkgJson, null, 2),
    "index.html": `
<html>
  <head>
    <title>Demo</title>
    <meta charset="UTF-8" />
  </head>
  <body>
    <div id="app"></div>
    <script src="src/bootstrap.tsx"></script>
  </body>
</html>
  `.trim(),
    "src/main.tsx": mainCode,
    "src/bootstrap.tsx": `
import * as React from 'react'
import { render } from 'react-dom'
import App from './main'

const rootElement = document.getElementById('app')
render(<App />, rootElement)
    `
  };
}