lib/config.js
function resolveFile(baseDirs, addType, fileName, type, cb)
{
  // The label this file will have in the output
  // For hbs views, this is the name that it will be save as into the template array.
  var label = pathlib.basename(fileName);

  // Label can be overridden with entries of the form: "label:file-name-or-path"
  var idx = fileName.indexOf(':');
  if ( idx > 0 )
  {
    label = fileName.substr(0,idx);
    fileName = fileName.substr(idx+1);
  }

  // Construct a list of paths to check
  var paths = [];
  baseDirs.forEach(function(baseDir) {
    if ( addType )
      baseDir += '/'+type;

    // Search for exact filename
    paths.push(pathlib.resolve(baseDir,fileName));

    // And with the type as an extension
    paths.push(pathlib.resolve(baseDir,fileName+'.'+type));

    // Special case 'view' because it used to mean hbs
    if ( type == 'view' )
    {
      VIEW_TYPES.forEach(function(altType) {
        paths.push(pathlib.resolve(baseDir,fileName+'.'+altType));
      });
    }
  });

  // Async
  if ( cb )
  {
    async.detectSeries(paths, fs.exists, function(result) {
      if ( result )
        return cb(undefined, label+':'+result);
      else
        return cb(new Error(errStr));
    });
  }
  else
  {
    // Sync
    for ( i=0 ; i < paths.length ; i++ )
    {
      if ( fs.existsSync(paths[i]) )
      {
        return label+':'+paths[i];
      }
    }

    throw new Error('Unable to find source ' + type + ' file for ' + fileName + ' in ' + paths.join(', '));
  }
}
function resolveFile(baseDirs, addType, fileName, type, cb)
{
  // The label this file will have in the output
  // For hbs views, this is the name that it will be save as into the template array.
  var label = pathlib.basename(fileName);

  // Label can be overridden with entries of the form: "label:file-name-or-path"
  var idx = fileName.indexOf(':');
  if ( idx > 0 )
  {
    label = fileName.substr(0,idx);
    fileName = fileName.substr(idx+1);
  }

  // Construct a list of paths to check
  var paths = [];
  baseDirs.forEach(function(baseDir) {
    if ( addType )
      baseDir += '/'+type;

    // Search for exact filename
    paths.push(pathlib.resolve(baseDir,fileName));

    // And with the type as an extension
    paths.push(pathlib.resolve(baseDir,fileName+'.'+type));

    // Special case 'view' because it used to mean hbs
    if ( type == 'view' )
    {
      VIEW_TYPES.forEach(function(altType) {
        paths.push(pathlib.resolve(baseDir,fileName+'.'+altType));
      });
    }
  });

  // Async
  if ( cb )
  {
    async.detectSeries(paths, fs.exists, function(result) {
      if ( result )
        return cb(undefined, label+':'+result);
      else
        return cb(new Error(errStr));
    });
  }
  else
  {
    // Sync
    for ( i=0 ; i < paths.length ; i++ )
    {
      if ( fs.existsSync(paths[i]) )
      {
        return label+':'+paths[i];
      }
    }

    throw new Error('Unable to find source ' + type + ' file for ' + fileName + ' in ' + paths.join(', '));
  }
}
function resolveFile ( baseDirs , addType , fileName , type , cb ) { // The label this file will have in the output // For hbs views, this is the name that it will be save as into the template array. var label = pathlib . basename ( fileName ) ; // Label can be overridden with entries of the form: "label:file-name-or-path" var idx = fileName . indexOf ( ':' ) ; if ( idx > 0 ) { label = fileName . substr ( 0 , idx ) ; fileName = fileName . substr ( idx + 1 ) ; } // Construct a list of paths to check var paths = [ ] ; baseDirs . forEach ( function ( baseDir ) { if ( addType ) baseDir += '/' + type ; // Search for exact filename paths . push ( pathlib . resolve ( baseDir , fileName ) ) ; // And with the type as an extension paths . push ( pathlib . resolve ( baseDir , fileName + '.' + type ) ) ; // Special case 'view' because it used to mean hbs if ( type == 'view' ) { VIEW_TYPES . forEach ( function ( altType ) { paths . push ( pathlib . resolve ( baseDir , fileName + '.' + altType ) ) ; } ) ; } } ) ; // Async if ( cb ) { async . detectSeries ( paths , fs . exists , function ( result ) { if ( result ) return cb ( undefined , label + ':' + result ) ; else return cb ( new Error ( errStr ) ) ; } ) ; } else { // Sync for ( i = 0 ; i < paths . length ; i ++ ) { if ( fs . existsSync ( paths [ i ] ) ) { return label + ':' + paths [ i ] ; } } throw new Error ( 'Unable to find source ' + type + ' file for ' + fileName + ' in ' + paths . join ( ', ' ) ) ; } }
Resolve a file name into an absolute path Async if called with a cb, synchronous if not
Resolve a file name into an absolute path Async if called with a cb synchronous if not