import { readFileSync } from 'fs';
import { join } from 'path';

import { render as renderTemplate } from 'ejs';

import { ApplicationState } from '../common/entities';

const template = readFileSync(
  join(process.cwd(), '.compiled', 'dist', 'index.html'),
).toString();

export function render(state: ApplicationState, html: string) {
  return renderTemplate(
    template,
    { state: JSON.stringify(state), html },
    { delimiter: '$' },
  );
}
