var fs = require('fs')

function transform (file) {
  let extension = file.split('.').pop()
  let content = fs.readFileSync(file, 'utf-8')
  content = `import glsl from 'glslify'\n\nexport default glsl\`${content}\``
  fs.writeFileSync(file.replace(`.${extension}`, '.js'), content)
}

function readDir (dir) {
  let list = fs.readdirSync(dir)
  list.forEach(item => {
    let stats = fs.statSync(`${dir}/${item}`)
    if (stats.isFile() && (item.endsWith('.vs') || item.endsWith('.fs'))) {
      transform(`${dir}/${item}`)
    } else if (stats.isDirectory()) {
      readDir(`${dir}/${item}`)
    }
  })
}

readDir('./')