SmartRW/project-lvl2-s329

View on GitHub
src/index.js

Summary

Maintainability
A
0 mins
Test Coverage
import fs from 'fs';
import path from 'path';
import getParser from './parsers';
import buildAST from './ast';
import render from './renderers';

const parse = (pathToFile) => {
  const fileExtension = path.extname(pathToFile);
  const fileContent = fs.readFileSync(pathToFile, 'utf-8');
  return getParser(fileExtension)(fileContent);
};

export default (pathToFirstFile, pathToSecondFile, type) => {
  const firstFile = parse(pathToFirstFile);
  const secondFile = parse(pathToSecondFile);
  const ast = buildAST(firstFile, secondFile);
  return render(ast, type);
};