function cacheFile(filename) {
  // First, convert the filename to something more digestible and use our cache
  // folder
  var cachePath = path.join(cacheDir, path.relative(rootDir, filename)).replace(/\.coffee$/, '.js');
  var content;

  // Try and stat the files for their last modified time
  try {
    var cacheTime = fs.statSync(cachePath).mtime;
    var sourceTime = fs.statSync(filename).mtime;
    if (cacheTime > sourceTime) {
      // We can return the cached version
      content = fs.readFileSync(cachePath, 'utf8');
    }
  } catch (err) {
    // If the cached file was not created yet, this will fail, and that is okay
  }

  // If we don't have the content, we need to compile ourselves
  if (!content) {
    // Read from disk and then compile
    var mapPath = path.resolve(cachePath.replace(/\.js$/, '.map'));
    var compiled = coffee.compile(fs.readFileSync(filename, 'utf8'), {
      filename: filename,
      sourceMap: true
    });
    content = compiled.js;

    // Since we don't know which version of CoffeeScript we have, make sure
    // we handle the older versions that return just the compiled version.
    if (content == null)
      content = compiled;

    try {
      // Try writing to cache
      mkpath.sync(path.dirname(cachePath));
      fs.writeFileSync(cachePath, content, 'utf8');
      if (mapPath)
        fs.writeFileSync(mapPath, compiled.v3SourceMap, 'utf8');
    } catch (err) {
      logCouldNotWriteCache()
    }
  }

  return content;
}
// Compile a file as you would with require and return the contents
Compile a file as you would with require and return the contents
Compile a file as you would with require and return the contents
function cacheFile(filename) {
  var cachePath = path.join(cacheDir, path.relative(rootDir, filename)).replace(/\.coffee$/, '.js');
  var content;
  try {
    var cacheTime = fs.statSync(cachePath).mtime;
    var sourceTime = fs.statSync(filename).mtime;
    if (cacheTime > sourceTime) {
      content = fs.readFileSync(cachePath, 'utf8');
    }
  } catch (err) {
  }
  if (!content) {
    var mapPath = path.resolve(cachePath.replace(/\.js$/, '.map'));
    var compiled = coffee.compile(fs.readFileSync(filename, 'utf8'), {
      filename: filename,
      sourceMap: true
    });
    content = compiled.js;
    if (content == null)
      content = compiled;
    try {
      mkpath.sync(path.dirname(cachePath));
      fs.writeFileSync(cachePath, content, 'utf8');
      if (mapPath)
        fs.writeFileSync(mapPath, compiled.v3SourceMap, 'utf8');
    } catch (err) {
      logCouldNotWriteCache()
    }
  }
  return content;
}
function cacheFile ( filename ) { var cachePath = path . join ( cacheDir , path . relative ( rootDir , filename ) ) . replace ( / \.coffee$ / , '.js' ) ; var content ; try { var cacheTime = fs . statSync ( cachePath ) . mtime ; var sourceTime = fs . statSync ( filename ) . mtime ; if ( cacheTime > sourceTime ) { content = fs . readFileSync ( cachePath , 'utf8' ) ; } } catch ( err ) { } if ( ! content ) { var mapPath = path . resolve ( cachePath . replace ( / \.js$ / , '.map' ) ) ; var compiled = coffee . compile ( fs . readFileSync ( filename , 'utf8' ) , { filename : filename , sourceMap : true } ) ; content = compiled . js ; if ( content == null ) content = compiled ; try { mkpath . sync ( path . dirname ( cachePath ) ) ; fs . writeFileSync ( cachePath , content , 'utf8' ) ; if ( mapPath ) fs . writeFileSync ( mapPath , compiled . v3SourceMap , 'utf8' ) ; } catch ( err ) { logCouldNotWriteCache ( ) } } return content ; }
Compile a file as you would with require and return the contents
Compile a file as you would with require and return the contents
// First, convert the filename to something more digestible and use our cache // folder // Try and stat the files for their last modified time // We can return the cached version // If the cached file was not created yet, this will fail, and that is okay // If we don't have the content, we need to compile ourselves // Read from disk and then compile // Since we don't know which version of CoffeeScript we have, make sure // we handle the older versions that return just the compiled version. // Try writing to cache