Kiriliuss/project-lvl2-s285

View on GitHub
src/index.js

Summary

Maintainability
A
0 mins
Test Coverage
import fs from 'fs';
import path from 'path';
import buildAst from './builderAst';
import getRender from './renderers';
import getParser from './parser';

const parse = (pathToFile) => {
  const file = fs.readFileSync(pathToFile, 'utf-8');
  const ext = path.extname(pathToFile).toLowerCase();
  return getParser(ext)(file);
};
export default (pathToFile1, pathToFile2, type) => {
  const file1Parsed = parse(pathToFile1);
  const file2Parsed = parse(pathToFile2);
  const ast = buildAst(file1Parsed, file2Parsed);
  return getRender(type)(ast);
};