import type { PostResourceTransformer } from '../types' import path from 'path' import { promises as fs } from 'fs' const transformer : PostResourceTransformer = { extension: "*", transform: async (value) => { try { const argPath = path.join(process.cwd(), 'scripts', value) const argContents = await fs.readFile(argPath) const argFileName = path.basename(value) const argDest = path.join(process.cwd(), '.next/static/scripts', value) const argDir = path.dirname(argDest) await fs.mkdir(argDir, { recursive: true }) await fs.writeFile(argDest, argContents) return { type: "resource", name: argFileName, path: path.join('/_next/static/scripts', value) } } catch { return { type: 'string', value } } } } export default transformer