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.
26 lines
770 B
TypeScript
26 lines
770 B
TypeScript
1 year ago
|
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
|