Skip to content

Commit 492d551

Browse files
committed
docs: add patch-pinceau script to fixed pnpm generate error
1 parent 5012a08 commit 492d551

File tree

7 files changed

+122
-18
lines changed

7 files changed

+122
-18
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"eslint": "^8.19.0",
2727
"pnpm": "^7.13.2",
2828
"sass": "^1.55.0",
29+
"ts-node": "^10.9.1",
2930
"typescript": "^4.7.4",
3031
"vite": "^3.2.2",
3132
"vue-tsc": "^1.0.9"

packages/docs/components/content/CodeBlockFile.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ const props = defineProps<{
99
filename?: string
1010
}>()
1111
12-
const { data } = await useFetch(`/api/file?path=${props.path}`)
13-
const content = prepareContent((data.value as any).content)
14-
15-
// console.log('modules → ', modules)
12+
const modules = import.meta.glob('./*.vue', { as: 'raw' })
1613
1714
function prepareContent(content: string) {
1815
return `\`\`\`${props.language || ''}${props.filename ? ` [${props.filename}]` : ''}\n${content}\n\`\`\``
1916
}
2017
18+
const module = modules[props.path]
19+
if (!module)
20+
console.error('Component Not Found.')
21+
22+
const content = prepareContent(await module() as any)
23+
2124
const shiki = await useShiki()
2225
2326
const { data: doc } = await useAsyncData(`playground-${content}`, async () => {

packages/docs/content/4.use-cases/1.playground.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ head.title: 'Playground | Examples'
88
::code-block{label="Preview" preview}
99
:playground
1010
::
11+
12+
::code-block{label="Playground.vue"}
13+
:code-block-file{path="./Playground.vue" language="vue"}
14+
::
1115
::

packages/docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"dev": "nuxt dev",
88
"generate": "nuxt generate",
99
"preview": "nuxt preview",
10-
"postinstall": "nuxt prepare"
10+
"postinstall": "nuxt prepare && pnpm patch-pinceau",
11+
"patch-pinceau": "ts-node --esm ./scripts/patchPinceau.ts"
1112
},
1213
"dependencies": {
1314
"@nuxt/ui": "^0.3.3",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import fs from 'fs'
2+
import path from 'path'
3+
4+
const cwd = path.resolve('./')
5+
const filePath = path.resolve('../../node_modules/pinceau/dist/nuxt.cjs')
6+
7+
const nuxtCjs = fs.readFileSync(filePath, 'utf-8').split('\n')
8+
9+
const target = 'const layerPaths = nuxt.options._layers.reduce('
10+
const result = ` if (layer?.cwd === '${cwd}') { return acc }`
11+
12+
const patched = nuxtCjs.findIndex(line => line.includes(result)) === -1
13+
14+
if (patched) {
15+
const line = nuxtCjs.findIndex(line => line.includes(target))
16+
17+
if (line !== -1)
18+
nuxtCjs.splice(line + 2, 0, result)
19+
20+
const newNuxtCjs = nuxtCjs.join('\n')
21+
22+
fs.writeFileSync(filePath, newNuxtCjs, { encoding: 'utf-8' })
23+
}

packages/docs/server/api/file.get.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)