@valaxyjs/devtools 0.0.1 → 0.18.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +13 -0
  2. package/build.config.ts +3 -0
  3. package/dist/client/assets/_plugin-vue_export-helper-PLawvS9c.js +11 -0
  4. package/dist/client/assets/about-ElTANHBg.js +12 -0
  5. package/dist/client/assets/categories-J8DcyOCk.js +12 -0
  6. package/dist/client/assets/index-Ic8qbUfo.js +4526 -0
  7. package/dist/client/assets/{index-UJyf60Kd.css → index-NKBWV0hh.css} +9 -1
  8. package/dist/client/assets/{index-vPMPXhW9.js → index-q944aN_L.js} +331 -646
  9. package/dist/client/assets/index-xfOC-KHy.css +61 -0
  10. package/dist/client/assets/tags--GcTVHIk.js +12 -0
  11. package/dist/client/index.html +3 -3
  12. package/dist/index.cjs +41 -5
  13. package/dist/index.d.cts +1 -1
  14. package/dist/index.d.mts +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.mjs +38 -5
  17. package/package.json +13 -2
  18. package/src/client/App.vue +4 -12
  19. package/src/client/components/PageFrontmatter.vue +66 -0
  20. package/src/client/components/PostPanel.vue +22 -0
  21. package/src/client/components/VDPostCategories.vue +26 -0
  22. package/src/client/components/VDPostList.vue +31 -0
  23. package/src/client/components/VDTag.vue +9 -0
  24. package/src/client/components.d.ts +51 -0
  25. package/src/client/composables/app.ts +10 -0
  26. package/src/client/index.html +1 -1
  27. package/src/client/main.ts +6 -3
  28. package/src/client/pages/about.vue +5 -0
  29. package/src/client/pages/categories.vue +5 -0
  30. package/src/client/pages/index.vue +29 -3
  31. package/src/client/pages/tags.vue +5 -0
  32. package/src/client/styles/index.css +8 -0
  33. package/src/client/typed-routes.d.ts +4 -0
  34. package/src/client/types/index.ts +3 -0
  35. package/src/client/utils/api.ts +18 -0
  36. package/src/client/utils/get.ts +19 -0
  37. package/src/client/utils/index.ts +4 -0
  38. package/src/client/utils/init.ts +27 -0
  39. package/src/client/vite.config.ts +12 -14
  40. package/src/node/api/index.ts +35 -0
  41. package/src/node/index.ts +22 -5
  42. package/uno.config.ts +0 -3
@@ -1,5 +1,31 @@
1
+ <script lang="ts" setup>
2
+ import { Pane, Splitpanes } from 'splitpanes'
3
+ import { onMounted } from 'vue'
4
+ import { isStaticMode } from '../utils'
5
+
6
+ onMounted(() => {
7
+ if (isStaticMode)
8
+ document.title = 'Valaxy DevTools (Production)'
9
+ })
10
+ </script>
11
+
1
12
  <template>
2
- <div>
3
- Index
4
- </div>
13
+ <main class="h-full" flex="~ col" text="gray-700 dark:gray-200">
14
+ <div class="w-full border-b shadow flex justify-end" dark="border-b-black">
15
+ <a href="https://valaxy.site" target="_blank" class="bg-gray-100 dark:bg-gray-900 inline-flex justify-center items-center w-8 h-8">
16
+ <div i-ri-book-line />
17
+ </a>
18
+ </div>
19
+
20
+ <div style="height: calc(100% - 32px)" overflow="auto">
21
+ <Splitpanes class="h-full">
22
+ <Pane>
23
+ <VDPostList />
24
+ </Pane>
25
+ <Pane>
26
+ <PostPanel />
27
+ </Pane>
28
+ </Splitpanes>
29
+ </div>
30
+ </main>
5
31
  </template>
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <div>
3
+ Tags
4
+ </div>
5
+ </template>
@@ -0,0 +1,8 @@
1
+ html,
2
+ body {
3
+ height: 100%;
4
+ }
5
+
6
+ .dark {
7
+ background-color: rgba(12, 16, 21);
8
+ }
@@ -39,6 +39,10 @@ import type {
39
39
 
40
40
  declare module 'vue-router/auto/routes' {
41
41
  export interface RouteNamedMap {
42
+ '/': RouteRecordInfo<'/', '/', Record<never, never>, Record<never, never>>,
43
+ '/about': RouteRecordInfo<'/about', '/about', Record<never, never>, Record<never, never>>,
44
+ '/categories': RouteRecordInfo<'/categories', '/categories', Record<never, never>, Record<never, never>>,
45
+ '/tags': RouteRecordInfo<'/tags', '/tags', Record<never, never>, Record<never, never>>,
42
46
  }
43
47
  }
44
48
 
@@ -0,0 +1,3 @@
1
+ export interface BlogWindow {
2
+ $frontmatter: any
3
+ }
@@ -0,0 +1,18 @@
1
+ // import from @vue/devtools-api not work
2
+ import { getAppWindow } from './get'
3
+
4
+ const target = getAppWindow()
5
+
6
+ export interface OpenInEditorOptions {
7
+ file?: string
8
+ line?: number
9
+ column?: number
10
+ }
11
+
12
+ export function openInEditor(options: OpenInEditorOptions = {}) {
13
+ const { file, line = 0, column = 0 } = options
14
+ if (file) {
15
+ const baseUrl = window.location.origin
16
+ target?.__VUE_INSPECTOR__.openInEditor(baseUrl, file, line, column)
17
+ }
18
+ }
@@ -0,0 +1,19 @@
1
+ export function getAppWindow() {
2
+ return window.parent.parent as unknown as {
3
+ __VUE_INSPECTOR__: {
4
+ openInEditor: (baseUrl: string, file: string, line: number, column: number) => void
5
+ }
6
+ }
7
+ }
8
+
9
+ /**
10
+ * window.parent.parent is the window object of the main app
11
+ */
12
+ export function getWindowProperty(property: string) {
13
+ return (window.parent.parent as any)[property]
14
+ }
15
+
16
+ export function getGlobalValaxyProperty(property: string) {
17
+ const $valaxy = (window.parent.parent as any).$valaxy
18
+ return $valaxy[property]
19
+ }
@@ -1 +1,5 @@
1
+ export * from './init'
2
+ export * from './api'
3
+ export * from './get'
4
+
1
5
  export const isStaticMode = document.body.getAttribute('data-valaxy-devtools-mode') === 'BUILD'
@@ -0,0 +1,27 @@
1
+ import { nextTick, onMounted } from 'vue'
2
+ import type { Router } from 'vue-router'
3
+ import { activePath, devtoolsRouter, frontmatter, pageData } from '../composables/app'
4
+ import { getWindowProperty } from './get'
5
+
6
+ export function initDevtoolsClient() {
7
+ const __VUE_DEVTOOLS_ROUTER__ = getWindowProperty('__VUE_DEVTOOLS_ROUTER__') as Router
8
+ devtoolsRouter.value = __VUE_DEVTOOLS_ROUTER__
9
+
10
+ devtoolsRouter.value.beforeEach((to, _from, next) => {
11
+ activePath.value = to.path
12
+ next()
13
+ })
14
+
15
+ // init $frontmatter and $pageData
16
+ onMounted(() => {
17
+ frontmatter.value = getWindowProperty('$frontmatter')
18
+ pageData.value = getWindowProperty('$pageData')
19
+ })
20
+
21
+ devtoolsRouter.value.afterEach(async () => {
22
+ await nextTick()
23
+ // get target post $frontmatter
24
+ frontmatter.value = getWindowProperty('$frontmatter')
25
+ pageData.value = getWindowProperty('$pageData')
26
+ })
27
+ }
@@ -1,9 +1,11 @@
1
1
  import { join, resolve } from 'node:path'
2
2
  import { defineConfig } from 'vite'
3
3
  import Vue from '@vitejs/plugin-vue'
4
- import Router from 'unplugin-vue-router/vite'
5
- import Components from 'unplugin-vue-components/vite'
4
+ import VueRouter from 'unplugin-vue-router/vite'
5
+ import VueComponents from 'unplugin-vue-components/vite'
6
6
  import Unocss from 'unocss/vite'
7
+ import { componentsDir } from '@advjs/gui/node'
8
+ import { unoConfig } from '../../../../uno.config'
7
9
 
8
10
  export default defineConfig({
9
11
  base: './',
@@ -48,22 +50,18 @@ export default defineConfig({
48
50
  },
49
51
  },
50
52
 
51
- Vue({
52
- script: {
53
- defineModel: true,
54
- },
55
- }),
56
-
57
- Router({
58
- routesFolder: ['pages'],
53
+ VueRouter({
54
+ routesFolder: join(__dirname, 'pages'),
59
55
  dts: join(__dirname, 'typed-routes.d.ts'),
60
56
  }),
61
-
62
- Components({
63
- dirs: ['components'],
57
+ Vue({
58
+ include: [/\.vue$/, /\.md$/],
59
+ }),
60
+ VueComponents({
61
+ dirs: ['components', componentsDir],
64
62
  dts: join(__dirname, 'components.d.ts'),
65
63
  }),
66
- Unocss(),
64
+ Unocss(unoConfig),
67
65
  ],
68
66
 
69
67
  optimizeDeps: {
@@ -0,0 +1,35 @@
1
+ import type { ResolvedConfig, ViteDevServer } from 'vite'
2
+ import bodyParser from 'body-parser'
3
+
4
+ import matter from 'gray-matter'
5
+ import fs from 'fs-extra'
6
+
7
+ const prefix = '/valaxy-devtools-api'
8
+
9
+ export function registerApi(server: ViteDevServer, _viteConfig: ResolvedConfig) {
10
+ const app = server.middlewares
11
+
12
+ app.use(bodyParser.json())
13
+
14
+ app.use(`${prefix}/frontmatter`, async (req, _res) => {
15
+ // update
16
+ if (req.method === 'POST') {
17
+ const { pageData, frontmatter: newFm } = await (req as any).body
18
+ // filePath
19
+ const path = pageData.path
20
+ if (fs.existsSync(path)) {
21
+ const rawMd = await fs.readFile(path, 'utf-8')
22
+ const matterFile = matter(rawMd)
23
+
24
+ // update frontmatter
25
+ matterFile.data = newFm
26
+ const newMd = matter.stringify(matterFile.content, matterFile.data)
27
+ await fs.writeFile(path, newMd)
28
+ }
29
+ }
30
+
31
+ // console.log('update', url, frontmatter)
32
+
33
+ // console.log('frontmatter', req.url, res)
34
+ })
35
+ }
package/src/node/index.ts CHANGED
@@ -1,22 +1,35 @@
1
1
  import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
2
2
  import c from 'picocolors'
3
3
  import sirv from 'sirv'
4
+ import { createProxyMiddleware } from 'http-proxy-middleware'
4
5
  import { DIR_CLIENT } from '../dir'
5
6
  import type { ValaxyDevtoolsOptions } from './types'
7
+ import { registerApi } from './api'
6
8
 
7
9
  const NAME = 'valaxy:devtools'
8
10
 
9
- export default function ValaxyDevtools(options: ValaxyDevtoolsOptions): Plugin {
11
+ // import.meta.env.VITE_DEV_VALAXY_DEVTOOLS = 'true'
12
+
13
+ export default function ValaxyDevtools(options: ValaxyDevtoolsOptions = {}): Plugin {
10
14
  let config: ResolvedConfig
11
15
 
12
16
  function configureServer(server: ViteDevServer) {
13
17
  const _print = server.printUrls
14
18
  const base = (options.base ?? server.config.base) || '/'
15
19
 
16
- server.middlewares.use(`${base}__valaxy_devtools__`, sirv(DIR_CLIENT, {
17
- single: true,
18
- dev: true,
19
- }))
20
+ const devtoolsUrl = `${base}__valaxy_devtools__/`
21
+ if (import.meta.env?.VITE_DEV_VALAXY_DEVTOOLS === 'true') {
22
+ server.middlewares.use(devtoolsUrl, createProxyMiddleware({
23
+ target: 'http://localhost:5001/#/',
24
+ changeOrigin: true,
25
+ }) as any)
26
+ }
27
+ else {
28
+ server.middlewares.use(devtoolsUrl, sirv(DIR_CLIENT, {
29
+ single: true,
30
+ dev: true,
31
+ }))
32
+ }
20
33
 
21
34
  server.printUrls = () => {
22
35
  let host = `${config.server.https ? 'https' : 'http'}://localhost:${config.server.port || '80'}`
@@ -39,11 +52,15 @@ export default function ValaxyDevtools(options: ValaxyDevtoolsOptions): Plugin {
39
52
  // eslint-disable-next-line no-console
40
53
  console.log(` ${c.green('➜')} ${c.bold('Inspect')}: ${colorUrl(`${host}${base}__inspect/`)}`)
41
54
  }
55
+
56
+ registerApi(server, config)
42
57
  }
43
58
 
44
59
  const plugin = <Plugin>{
45
60
  name: NAME,
46
61
 
62
+ enforce: 'pre',
63
+
47
64
  configResolved(_config) {
48
65
  config = _config
49
66
  },
package/uno.config.ts DELETED
@@ -1,3 +0,0 @@
1
- import unoConfig from '../../uno.config'
2
-
3
- export default unoConfig