/**
 * @function _readAsset
 */

'use strict'

import fs from 'fs'
import path from '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 = {}

export default _readAsset
