From e16d37ff73d2352a9ed7285c5764d4221362d9c1 Mon Sep 17 00:00:00 2001
From: qmhc <40221744+qmhc@users.noreply.github.com>
Date: Mon, 16 Oct 2023 19:00:38 +0800
Subject: [PATCH] chore(dev): add playground route
---
.eslintignore | 2 ++
dev-server/.gitignore | 1 +
scripts/serve.ts | 28 +++++++++++++++++++++++++---
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/.eslintignore b/.eslintignore
index 287566609..18dd94af5 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -17,3 +17,5 @@ cache
common/icons/vue
common/icons/types
+
+dev-server/play.vue
diff --git a/dev-server/.gitignore b/dev-server/.gitignore
index 997b572e0..73790e056 100644
--- a/dev-server/.gitignore
+++ b/dev-server/.gitignore
@@ -1 +1,2 @@
/router.ts
+play.vue
diff --git a/scripts/serve.ts b/scripts/serve.ts
index 47c1942d8..ec247a142 100644
--- a/scripts/serve.ts
+++ b/scripts/serve.ts
@@ -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,
@@ -69,6 +67,11 @@ async function serveComponent() {
}`
})
.join(',\n')},
+ {
+ path: '/${demos.includes('play') ? '_' : ''}play',
+ name: 'playground',
+ component: () => import('../play.vue')
+ },
{
path: '/:catchAll(.*)',
redirect: '/'
@@ -87,6 +90,25 @@ async function serveComponent() {
'utf-8'
)
+ const playPath = resolve(devDir, 'play.vue')
+
+ if (!existsSync(playPath)) {
+ writeFileSync(
+ playPath,
+ await format(
+ `
+
+
+
+ `,
+ { ...prettierConfig, parser: 'vue' }
+ ),
+ 'utf-8'
+ )
+ }
+
await run('pnpm', ['serve'], {
cwd: devDir,
stdio: 'inherit',