import { getParameters } from 'codesandbox/lib/api/define'; import packageInfo from '../../../package.json'; const indexHtml = ` Ant Design Vue Demo
`; const appVue = ` `; const mainJs = `import { createApp } from 'vue'; import Antd from 'ant-design-vue'; import App from './App'; import 'ant-design-vue/dist/reset.css'; const app = createApp(App); app.use(Antd).mount('#app'); `; function getDeps(code: string) { return (code.match(/from '([^']+)';\n/g) || []) .map(v => v.slice(6, v.length - 3)) .reduce((prevV, dep) => { prevV[dep] = 'latest'; return prevV; }, {}); } type Meta = { title: string; }; // codeSandbox export function getCodeSandboxParams(code: string, meta: Meta): string { return getParameters({ files: { 'package.json': { content: JSON.stringify({ title: meta.title, dependencies: { ...getDeps(code), vue: 'next', 'ant-design-vue': packageInfo.version, }, devDependencies: { '@vue/cli-plugin-babel': '~4.5.0', typescript: '^4.0.5', }, browserslist: ['> 0.2%', 'not dead'], }), isBinary: false, }, 'index.html': { content: indexHtml, isBinary: false, }, 'src/demo.vue': { content: code, isBinary: false, }, 'src/App.vue': { content: appVue, isBinary: false, }, 'src/main.js': { content: mainJs, isBinary: false, }, }, }); }