/**
* React Static Boilerplate
* https://github.com/koistya/react-static-boilerplate
* Copyright (c) Konstantin Tarkus (@koistya) | MIT license
*/
import { join, dirname } from 'path';
import glob from 'glob';
import React from 'react';
import createTemplate from 'lodash/string/template';
import fs from './lib/fs';
const template = createTemplate(`
<%- title %>
<%= body %>
`);
export default async ({ pages }) => {
console.log('render');
const { route } = require('../build/app.node');
for (const page of pages) {
await route(page.path, async (component) => {
const data = {
title: '',
body: React.renderToString(component)
};
const file = join(__dirname, '../build', page.file.substr(0, page.file.lastIndexOf('.')) + '.html');
const html = template(data);
await fs.makeDir(dirname(file));
await fs.writeFile(file, html);
})
}
};