/**
 * @function readAsset
 */

'use strict'

const fs = require('fs')
const path = require('path')

const assetDir = `${__dirname}/../../asset`

/** @lends readAsset */
function readAsset (name) {
  let filename = path.join(assetDir, name)
  let exists = fs.existsSync && fs.existsSync(filename)
  if (!exists) {
    return null
  }
  let cache = readAsset.cache[ filename ]
  if (cache) {
    return cache
  }
  let content = fs.readFileSync(filename).toString()
  readAsset.cache[ filename ] = content
  return content
}
readAsset.cache = {}

module.exports = readAsset
