import type { PostResourceTransformer } from '../types' import path from 'path' import { promises as fs } from 'fs' const transformer : PostResourceTransformer = { extension: "js", transform: async (value) => { const scriptPath = path.join(process.cwd(), 'scripts', value) const scriptContents = await fs.readFile(scriptPath) const scriptFileName = path.basename(value) const scriptDest = path.join(process.cwd(), '.next/static/scripts', value) const destDir = path.dirname(scriptDest) await fs.mkdir(destDir, { recursive: true }) await fs.writeFile(scriptDest, scriptContents) return { type: 'script', name: scriptFileName, path: path.join('/_next/static/scripts', value) } } } export default transformer