server/boot/load-model.js
function loadConfigFromFS(app, apimanager, models, dir, uid, cb) {
  // clear out existing files from model structure
  models.forEach(
    function(model) {
      model.files = [];
    }
  );

  if (apimanager.host) {
    var files = [];
    logger.debug('loadConfigFromFS entry');
    try {
      if (dir !== '') {
        files = fs.readdirSync(dir);
      }
    } catch (e) {
      logger.error('Failed to read directory: ', dir);
      cb(e);
      return;
    }

    logger.debug('files: ', files);
    var jsonFile = new RegExp(/.*\.json$/);
    // correlate files with appropriate model
    files.forEach(
      function(file) {
        logger.debug('file match jsonFile: ', file.match(jsonFile));
        if (file.match(jsonFile)) {
          for (var i = 0; i < models.length; i++) {
            if (file.indexOf(models[i].prefix) > -1) {
              logger.debug('%s file: %s', models[i].name, file);
              models[i].files.push(file);
              break;
            }
          }
        }
      }
    );
    // populate data-store models with the file contents
    populateModelsWithAPImData(app, models, dir, uid, cb);
  } else {
    var YAMLfiles = [];
    logger.debug('dir: ', dir);

    //read the apic settings
    var cfg = readApicConfig(dir);

    //read the YAML files
    project.loadProject(dir).then(function(artifacts) {
      logger.debug('%j', artifacts);
      artifacts.forEach(
        function(artifact) {
          if (artifact.type === 'swagger') {
            YAMLfiles.push(artifact.filePath);
          }
        });

      // populate data-store models with the file contents
      populateModelsWithLocalData(app, YAMLfiles, cfg, dir, uid, cb);
    });
  }
}
function loadConfigFromFS(app, apimanager, models, dir, uid, cb) {
  // clear out existing files from model structure
  models.forEach(
    function(model) {
      model.files = [];
    }
  );

  if (apimanager.host) {
    var files = [];
    logger.debug('loadConfigFromFS entry');
    try {
      if (dir !== '') {
        files = fs.readdirSync(dir);
      }
    } catch (e) {
      logger.error('Failed to read directory: ', dir);
      cb(e);
      return;
    }

    logger.debug('files: ', files);
    var jsonFile = new RegExp(/.*\.json$/);
    // correlate files with appropriate model
    files.forEach(
      function(file) {
        logger.debug('file match jsonFile: ', file.match(jsonFile));
        if (file.match(jsonFile)) {
          for (var i = 0; i < models.length; i++) {
            if (file.indexOf(models[i].prefix) > -1) {
              logger.debug('%s file: %s', models[i].name, file);
              models[i].files.push(file);
              break;
            }
          }
        }
      }
    );
    // populate data-store models with the file contents
    populateModelsWithAPImData(app, models, dir, uid, cb);
  } else {
    var YAMLfiles = [];
    logger.debug('dir: ', dir);

    //read the apic settings
    var cfg = readApicConfig(dir);

    //read the YAML files
    project.loadProject(dir).then(function(artifacts) {
      logger.debug('%j', artifacts);
      artifacts.forEach(
        function(artifact) {
          if (artifact.type === 'swagger') {
            YAMLfiles.push(artifact.filePath);
          }
        });

      // populate data-store models with the file contents
      populateModelsWithLocalData(app, YAMLfiles, cfg, dir, uid, cb);
    });
  }
}
function loadConfigFromFS ( app , apimanager , models , dir , uid , cb ) { // clear out existing files from model structure models . forEach ( function ( model ) { model . files = [ ] ; } ) ; if ( apimanager . host ) { var files = [ ] ; logger . debug ( 'loadConfigFromFS entry' ) ; try { if ( dir !== '' ) { files = fs . readdirSync ( dir ) ; } } catch ( e ) { logger . error ( 'Failed to read directory: ' , dir ) ; cb ( e ) ; return ; } logger . debug ( 'files: ' , files ) ; var jsonFile = new RegExp ( / .*\.json$ / ) ; // correlate files with appropriate model files . forEach ( function ( file ) { logger . debug ( 'file match jsonFile: ' , file . match ( jsonFile ) ) ; if ( file . match ( jsonFile ) ) { for ( var i = 0 ; i < models . length ; i ++ ) { if ( file . indexOf ( models [ i ] . prefix ) > - 1 ) { logger . debug ( '%s file: %s' , models [ i ] . name , file ) ; models [ i ] . files . push ( file ) ; break ; } } } } ) ; // populate data-store models with the file contents populateModelsWithAPImData ( app , models , dir , uid , cb ) ; } else { var YAMLfiles = [ ] ; logger . debug ( 'dir: ' , dir ) ; //read the apic settings var cfg = readApicConfig ( dir ) ; //read the YAML files project . loadProject ( dir ) . then ( function ( artifacts ) { logger . debug ( '%j' , artifacts ) ; artifacts . forEach ( function ( artifact ) { if ( artifact . type === 'swagger' ) { YAMLfiles . push ( artifact . filePath ) ; } } ) ; // populate data-store models with the file contents populateModelsWithLocalData ( app , YAMLfiles , cfg , dir , uid , cb ) ; } ) ; } }
Loads persisted data from disk and populates models
@param {???} app - loopback application
@param {Array} models - instances of ModelType to populate with data
@param {string} dir - path to directory containing persisted data to load
@param {string} uid - snapshot identifier
@param {callback} cb - callback that handles error or successful completion
Loads persisted data from disk and populates models