import { ensureEndingSlash } from '@vuepress/helper' import { getDirname, path } from 'vuepress/utils' import type { App } from 'vuepress' const __dirname = getDirname(import.meta.url) const CLIENT_FOLDER = ensureEndingSlash( path.resolve(__dirname, '../client'), ) export async function prepareClientConfigFile(app: App, { copyCode, twoslash, }: { copyCode: boolean, twoslash: boolean }): Promise { return await app.writeTemp( 'internal/plugin-shiki/client.js', `\ ${twoslash ? `import { enhanceTwoslash } from '${CLIENT_FOLDER}composables/twoslash.js'` : ''} ${copyCode ? `import { useCopyCode } from '${CLIENT_FOLDER}composables/copy-code.js'` : ''} import { useCollapsedLines } from '${CLIENT_FOLDER}composables/collapsed-lines.js' export default { ${twoslash ? `enhance({ app }) { enhanceTwoslash(app) },` : ''} ${copyCode ? `setup() { useCopyCode({ selector: __CC_SELECTOR__, duration: __CC_DURATION__, }) useCollapsedLines() },` : ''} } `, ) }