You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
858 B
TypeScript

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