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
986 B
TypeScript
34 lines
986 B
TypeScript
1 year ago
|
import { PostResourceTransformer } from "../types"
|
||
|
|
||
|
import path from 'path'
|
||
|
import { promises as fs } from 'fs'
|
||
|
import glslx from 'glslx'
|
||
|
|
||
|
const transformer : PostResourceTransformer = {
|
||
|
extension: "glsl",
|
||
|
transform: async (value) => {
|
||
|
const argPath = path.join(process.cwd(), 'scripts', value)
|
||
|
const argContents = await fs.readFile(argPath)
|
||
|
const argFileName = path.basename(value)
|
||
|
|
||
|
const {output: glslResult, log} = glslx.compile({name: argFileName, contents: argContents.toString('utf8')})
|
||
|
if (!glslResult) {
|
||
|
console.error(log)
|
||
|
throw new Error("Could not parse GLSL file")
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default transformer
|