// @flow import fs from 'fs'; import path from 'path'; import { html } from 'common-tags'; import serialize from 'serialize-javascript'; // Match main.asdf123.js in production mode or bundle.js in dev mode const mainBundleRegex = /(main|bundle)\.(?:.*\.)?js$/; const bootstrapBundleRegex = /(bootstrap)\.(?:.*\.)?js$/; let bundles; try { bundles = fs.readdirSync( process.env.NODE_ENV === 'production' ? './build/static/js' : path.join(__dirname, '../../build/static/js') ); } catch (err) { console.error(err); throw new Error( 'It looks like you didn\'t run "yarn run dev:web" or "yarn run build:web" before starting hyperion. Please wait until either of them completes before starting hyperion.' ); } // Get the main bundle filename const mainBundle = bundles.find(bundle => mainBundleRegex.test(bundle)); const bootstrapBundle = bundles.find(bundle => bootstrapBundleRegex.test(bundle) ); if (!mainBundle || !bootstrapBundle) { throw new Error( 'It looks like you didn\'t run "yarn run dev:web" or "yarn run build:web" before starting hyperion. Please wait until either of them completes before starting hyperion.' ); } export const createScriptTag = ({ src }: { src: string }) => ``; export const getHeader = ({ metaTags, nonce, }: { metaTags: string, nonce: string, }) => { // prettier-ignore return html` ${metaTags}
`; }; export const getFooter = ({ state, data, bundles, nonce, }: { state: Object, data: Object, bundles: Array, nonce: string, }) => { return html`
${createScriptTag({ src: `/static/js/${bootstrapBundle}` })} ${bundles.map(src => createScriptTag({ src }))} ${createScriptTag({ src: `/static/js/${mainBundle}` })} `; };