2021-06-05 05:18:20 +08:00
|
|
|
import { getParameters } from 'codesandbox/lib/api/define'
|
|
|
|
|
|
|
|
const indexHtml = `<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<title>Naive UI Demo</title>
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
padding: 24px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="app"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`
|
|
|
|
|
2021-06-05 06:05:49 +08:00
|
|
|
const appVue = `<template>
|
|
|
|
<n-loading-bar-provider>
|
|
|
|
<n-message-provider>
|
|
|
|
<n-notification-provider>
|
|
|
|
<n-dialog-provider>
|
|
|
|
<demo />
|
|
|
|
</n-dialog-provider>
|
|
|
|
</n-notification-provider>
|
|
|
|
</n-message-provider>
|
|
|
|
</n-loading-bar-provider>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import Demo from "./Demo.vue";
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
Demo,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>`
|
|
|
|
|
2021-06-05 05:18:20 +08:00
|
|
|
const mainJs = `import { createApp } from "vue";
|
|
|
|
import naive from "naive-ui";
|
|
|
|
import App from "./App.vue";
|
|
|
|
|
|
|
|
const app = createApp(App);
|
|
|
|
|
|
|
|
app.use(naive);
|
|
|
|
|
|
|
|
app.mount("#app");
|
|
|
|
`
|
|
|
|
|
2021-06-05 06:19:56 +08:00
|
|
|
function getDeps (code) {
|
|
|
|
return (code.match(/from '([^']+)'\n/g) || [])
|
|
|
|
.map((v) => v.slice(6, v.length - 2))
|
|
|
|
.reduce((prevV, dep) => {
|
|
|
|
prevV[dep] = 'latest'
|
|
|
|
return prevV
|
|
|
|
}, {})
|
|
|
|
}
|
|
|
|
|
2021-06-05 05:18:20 +08:00
|
|
|
export function getCodeSandboxParams (code) {
|
|
|
|
return getParameters({
|
|
|
|
files: {
|
|
|
|
'package.json': {
|
|
|
|
content: {
|
|
|
|
dependencies: {
|
2021-06-05 06:19:56 +08:00
|
|
|
...getDeps(code),
|
2021-06-05 05:18:20 +08:00
|
|
|
vue: 'next',
|
2021-06-16 10:43:16 +08:00
|
|
|
'vue-router': 'next',
|
2021-06-05 05:18:20 +08:00
|
|
|
'naive-ui': 'latest'
|
2021-06-05 06:05:49 +08:00
|
|
|
},
|
|
|
|
devDependencies: {
|
|
|
|
'@vue/cli-plugin-babel': '~4.5.0'
|
2021-06-05 05:18:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'index.html': {
|
|
|
|
content: indexHtml
|
|
|
|
},
|
2021-06-05 06:05:49 +08:00
|
|
|
'src/Demo.vue': {
|
2021-06-05 05:18:20 +08:00
|
|
|
content: code
|
|
|
|
},
|
2021-06-05 06:05:49 +08:00
|
|
|
'src/App.vue': {
|
|
|
|
content: appVue
|
|
|
|
},
|
2021-06-05 05:18:20 +08:00
|
|
|
'src/main.js': {
|
|
|
|
content: mainJs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|