Skip to content

Commit

Permalink
chore(dev): add playground route
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Oct 16, 2023
1 parent fdea9d5 commit e16d37f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ cache

common/icons/vue
common/icons/types

dev-server/play.vue
1 change: 1 addition & 0 deletions dev-server/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/router.ts
play.vue
28 changes: 25 additions & 3 deletions scripts/serve.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { resolve } from 'node:path'
import { existsSync, readdirSync, statSync, writeFileSync } from 'node:fs'

import fs from 'fs-extra'
import minimist from 'minimist'
import { format } from 'prettier'
import { logger, prettierConfig, queryIdlePort, rootDir, run, specifyComponent } from './utils'

const { readdirSync, statSync, existsSync, writeFileSync } = fs

const args = minimist<{
s?: boolean,
sourcemap?: boolean,
Expand Down Expand Up @@ -69,6 +67,11 @@ async function serveComponent() {
}`
})
.join(',\n')},
{
path: '/${demos.includes('play') ? '_' : ''}play',
name: 'playground',
component: () => import('../play.vue')
},
{
path: '/:catchAll(.*)',
redirect: '/'
Expand All @@ -87,6 +90,25 @@ async function serveComponent() {
'utf-8'
)

const playPath = resolve(devDir, 'play.vue')

if (!existsSync(playPath)) {
writeFileSync(
playPath,
await format(
`<template>
<div></div>
</template>
<script setup lang="ts">
// write something or copy from playground
</script>`,
{ ...prettierConfig, parser: 'vue' }
),
'utf-8'
)
}

await run('pnpm', ['serve'], {
cwd: devDir,
stdio: 'inherit',
Expand Down

0 comments on commit e16d37f

Please sign in to comment.