lib/AccessoryLoader.js
function loadDirectory(dir) {

  // exported accessory objects loaded from this dir
  var accessories = [];

  fs.readdirSync(dir).forEach(function(file) {

    // "Accessories" are modules that export a single accessory.
    if (file.split('_').pop() === 'accessory.js') {
      debug('Parsing accessory: %s', file);
      var loadedAccessory = require(path.join(dir, file)).accessory;
      accessories.push(loadedAccessory);
    }
    // "Accessory Factories" are modules that export an array of accessories.
    else if (file.split('_').pop() === 'accfactory.js') {
      debug('Parsing accessory factory: %s', file);

      // should return an array of objects { accessory: accessory-json }
      var loadedAccessories = require(path.join(dir, file));
      accessories = accessories.concat(loadedAccessories);
    }
  });

  // now we need to coerce all accessory objects into instances of Accessory (some or all of them may
  // be object-literal JSON-style accessories)
  return accessories.map(function(accessory) {
    if(accessory === null || accessory === undefined) { //check if accessory is not empty
      console.log("Invalid accessory!");
      return false;
    } else {
      return (accessory instanceof Accessory) ? accessory : parseAccessoryJSON(accessory);
    }
  }).filter(function(accessory) { return accessory ? true : false; });
}
function loadDirectory(dir) {

  // exported accessory objects loaded from this dir
  var accessories = [];

  fs.readdirSync(dir).forEach(function(file) {

    // "Accessories" are modules that export a single accessory.
    if (file.split('_').pop() === 'accessory.js') {
      debug('Parsing accessory: %s', file);
      var loadedAccessory = require(path.join(dir, file)).accessory;
      accessories.push(loadedAccessory);
    }
    // "Accessory Factories" are modules that export an array of accessories.
    else if (file.split('_').pop() === 'accfactory.js') {
      debug('Parsing accessory factory: %s', file);

      // should return an array of objects { accessory: accessory-json }
      var loadedAccessories = require(path.join(dir, file));
      accessories = accessories.concat(loadedAccessories);
    }
  });

  // now we need to coerce all accessory objects into instances of Accessory (some or all of them may
  // be object-literal JSON-style accessories)
  return accessories.map(function(accessory) {
    if(accessory === null || accessory === undefined) { //check if accessory is not empty
      console.log("Invalid accessory!");
      return false;
    } else {
      return (accessory instanceof Accessory) ? accessory : parseAccessoryJSON(accessory);
    }
  }).filter(function(accessory) { return accessory ? true : false; });
}
function loadDirectory ( dir ) { // exported accessory objects loaded from this dir var accessories = [ ] ; fs . readdirSync ( dir ) . forEach ( function ( file ) { // "Accessories" are modules that export a single accessory. if ( file . split ( '_' ) . pop ( ) === 'accessory.js' ) { debug ( 'Parsing accessory: %s' , file ) ; var loadedAccessory = require ( path . join ( dir , file ) ) . accessory ; accessories . push ( loadedAccessory ) ; } // "Accessory Factories" are modules that export an array of accessories. else if ( file . split ( '_' ) . pop ( ) === 'accfactory.js' ) { debug ( 'Parsing accessory factory: %s' , file ) ; // should return an array of objects { accessory: accessory-json } var loadedAccessories = require ( path . join ( dir , file ) ) ; accessories = accessories . concat ( loadedAccessories ) ; } } ) ; // now we need to coerce all accessory objects into instances of Accessory (some or all of them may // be object-literal JSON-style accessories) return accessories . map ( function ( accessory ) { if ( accessory === null || accessory === undefined ) { //check if accessory is not empty console . log ( "Invalid accessory!" ) ; return false ; } else { return ( accessory instanceof Accessory ) ? accessory : parseAccessoryJSON ( accessory ) ; } } ) . filter ( function ( accessory ) { return accessory ? true : false ; } ) ; }
Loads all accessories from the given folder. Handles object-literal-style accessories, "accessory factories",
and new-API style modules.
Loads all accessories from the given folder . Handles object - literal - style accessories accessory factories and new - API style modules .