use new docs

This commit is contained in:
MapleLeaf
2022-01-02 22:02:10 -06:00
committed by Darius
parent 381f933fd1
commit ca520db701
70 changed files with 186 additions and 2964 deletions

View File

@@ -0,0 +1,40 @@
import { unlink, writeFile } from "node:fs/promises"
import type { Plugin } from "vite"
import { transformWithEsbuild } from "vite"
const prevalPattern = /\.preval\.(js|ts|jsx|tsx|mts|cts)$/
export function preval(): Plugin {
return {
name: "preval",
enforce: "pre",
async transform(code, filePath) {
if (!prevalPattern.test(filePath)) return
const tempFilePath = `${filePath}.preval.mjs`
try {
const transformResult = await transformWithEsbuild(code, filePath, {
target: "node16",
format: "esm",
})
await writeFile(tempFilePath, transformResult.code)
const runResult = await import(tempFilePath)
const serialized = Object.entries(runResult)
.map(([key, value]) => {
return key === "default"
? `export default ${JSON.stringify(value)}`
: `export const ${key} = ${JSON.stringify(value)}`
})
.join("\n")
return serialized + "\n"
} finally {
await unlink(tempFilePath).catch(console.warn)
}
},
}
}