import fs from 'fs';
import { parse } from './parser';

export function extractIntl(files) {
  return new Promise((resolve, reject) => {
    if (!Array.isArray(files)) {
      files = [files];
    }

    const fileContents = files.map(readFile);

    fileContents[0].then(data => {
      return resolve(parse(data));
    }).catch(err => {
      return reject(err);
    });
  });
}

function readFile(filePath) {
  return new Promise((resolve, reject) => {
    fs.readFile(filePath, 'utf-8', (err, data) => {
      if (err) {
        return reject(err);
      }

      return resolve(data);
    });
  });
}

import fs from 'fs';
import { parse } from './parser';

export function extractIntl(files) {
  return new Promise((resolve, reject) => {
    if (!Array.isArray(files)) {
      files = [files];
    }

    return Promise.all(
      files.map(readFile)
    ).then(fileContents => {
      return resolve(
        fileContents
          .map(parse)
          .reduce((accumulator, messages) => Object.assign(accumulator, messages), {})
      );
    }).catch(err => {
      return reject(err);
    });
  });
}

function readFile(filePath) {
  return new Promise((resolve, reject) => {
    fs.readFile(filePath, 'utf-8', (err, data) => {
      if (err) {
        return reject(err);
      }

      return resolve(data);
    });
  });
}

Read from multiple files, not just the first one
Read from multiple files, not just the first one
