$process()

in base/processors/read-files.js [41:88]


    $process() {
      const fileReaders = this.fileReaders;
      const fileReaderMap = getFileReaderMap(fileReaders);
      const basePath = this.basePath;

      const sourcePromises = this.sourceFiles.map(sourceInfo => {

        sourceInfo = normalizeSourceInfo(basePath, sourceInfo);

        log.debug('Source Info:\n', sourceInfo);

        return getSourceFiles(sourceInfo).then(files => {

          const docsPromises = [];

          log.debug('Found ' + files.length + ' files:\n', files);

          files.forEach(file => {

            // Load up each file and extract documents using the appropriate fileReader
            const docsPromise = readFile(file).then(content => {

              // Choose a file reader for this file
              const fileReader = sourceInfo.fileReader ? fileReaderMap.get(sourceInfo.fileReader) : matchFileReader(fileReaders, file);

              log.debug('Reading File Content\nFile Path:', file, '\nFile Reader:', fileReader.name);

              const fileInfo = createFileInfo(file, content, sourceInfo, fileReader, basePath);

              const docs = fileReader.getDocs(fileInfo);

              // Attach the fileInfo object to each doc
              docs.forEach(doc => {
                doc.fileInfo = fileInfo;
              });

              return docs;
            });

            docsPromises.push(docsPromise);

          });
          return Promise.all(docsPromises).then(results => results.flat());
        });

      });
      return Promise.all(sourcePromises).then(results => results.flat());
    }