@valaxyjs/devtools 0.19.5 → 0.19.6
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.
- package/dist/client/assets/{about-DAq0mJYu.js → about-OznFGoV6.js} +1 -1
- package/dist/client/assets/{categories-tKEG33gR.js → categories-Dof0ZrYR.js} +1 -1
- package/dist/client/assets/index-BnannfxL.js +833 -0
- package/dist/client/assets/{index-DUxi88Gt.js → index-CPK49_y2.js} +335 -49
- package/dist/client/assets/{index-CIq_dmzy.css → index-DzN-2s1X.css} +1 -1
- package/dist/client/assets/migration-BvfMdnj6.js +122 -0
- package/dist/client/assets/{index-BaHoMyce.js → splitpanes.es-tsc-z8w6.js} +163 -942
- package/dist/client/assets/{tags-BakzoUlM.js → tags-BIEb0ZZ9.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/index.cjs +34 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +34 -0
- package/package.json +6 -4
- package/src/client/App.vue +9 -1
- package/src/client/components/VDHeader.vue +57 -0
- package/src/client/components.d.ts +48 -47
- package/src/client/main.ts +11 -1
- package/src/client/pages/index.vue +8 -18
- package/src/client/pages/migration.vue +73 -0
- package/src/client/shims.d.ts +12 -0
- package/src/client/typed-routes.d.ts +1 -0
- package/src/client/utils/get.ts +6 -0
- package/src/node/api/index.ts +49 -2
- package/src/node/types.ts +1 -0
package/src/node/api/index.ts
CHANGED
|
@@ -2,10 +2,38 @@ import type { ResolvedConfig, ViteDevServer } from 'vite'
|
|
|
2
2
|
import bodyParser from 'body-parser'
|
|
3
3
|
|
|
4
4
|
import matter from 'gray-matter'
|
|
5
|
+
import { JSON_SCHEMA } from 'js-yaml'
|
|
5
6
|
import fs from 'fs-extra'
|
|
6
7
|
|
|
7
8
|
const prefix = '/valaxy-devtools-api'
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* migration
|
|
12
|
+
* @param path
|
|
13
|
+
* @param frontmatter
|
|
14
|
+
*/
|
|
15
|
+
export async function migration(path: string, frontmatter: { [key: string]: string }) {
|
|
16
|
+
if (fs.existsSync(path)) {
|
|
17
|
+
const rawMd = await fs.readFile(path, 'utf-8')
|
|
18
|
+
const matterFile = matter(rawMd, { schema: JSON_SCHEMA } as any)
|
|
19
|
+
let mod = false
|
|
20
|
+
for (const key in frontmatter) {
|
|
21
|
+
if (key in matterFile.data) {
|
|
22
|
+
matterFile.data[frontmatter[key]] = matterFile.data[key]
|
|
23
|
+
delete matterFile.data[key]
|
|
24
|
+
mod = true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (mod) {
|
|
28
|
+
const newMd = matter.stringify(matterFile.content, matterFile.data)
|
|
29
|
+
await fs.writeFile(path, newMd)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// console.error(`post not exist:${path}`)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
9
37
|
export function registerApi(server: ViteDevServer, _viteConfig: ResolvedConfig) {
|
|
10
38
|
const app = server.middlewares
|
|
11
39
|
|
|
@@ -27,9 +55,28 @@ export function registerApi(server: ViteDevServer, _viteConfig: ResolvedConfig)
|
|
|
27
55
|
await fs.writeFile(path, newMd)
|
|
28
56
|
}
|
|
29
57
|
}
|
|
58
|
+
})
|
|
30
59
|
|
|
31
|
-
|
|
60
|
+
app.use(`${prefix}/migration`, async (req, _res) => {
|
|
61
|
+
// update
|
|
62
|
+
if (req.method === 'POST') {
|
|
63
|
+
const { pageData, frontmatter } = await (req as any).body
|
|
64
|
+
// filePath
|
|
65
|
+
const worker: Promise<void>[] = []
|
|
32
66
|
|
|
33
|
-
|
|
67
|
+
for (const item of pageData) {
|
|
68
|
+
const path = item
|
|
69
|
+
worker.push(migration(path, frontmatter))
|
|
70
|
+
}
|
|
71
|
+
// worker.push(migration(`${userRoot.root}/pages${item}.md`, frontmatter))
|
|
72
|
+
// for (const item of pageData)
|
|
73
|
+
// worker.push(migration(item, frontmatter))
|
|
74
|
+
|
|
75
|
+
Promise.all(worker).then(() => {
|
|
76
|
+
_res.end('ok')
|
|
77
|
+
}).catch((_) => {
|
|
78
|
+
_res.end('migration error')
|
|
79
|
+
})
|
|
80
|
+
}
|
|
34
81
|
})
|
|
35
82
|
}
|
package/src/node/types.ts
CHANGED