UNPKG

@platform/react.ssr

Version:

An SSR (server-side-render) system for react apps bundled with ParcelJS and hosted on S3.

44 lines (43 loc) 1.61 kB
import { Config } from '../config'; import { cli, http, log, util } from './common'; export async function run(args = {}) { const config = args.config || (await Config.create()); const site = typeof args.site === 'string' ? args.site : args.site ? args.site.name : undefined; let manifest = args.manifest; if (!manifest) { log.info(); await cli .tasks() .task('pull latest manifest', async (e) => { manifest = await config.manifest.local.ensureLatest({ minimal: true }); }) .run({ concurrent: true }); } if (!manifest) { log.error(`The manifest could not be found.`); return cli.exit(1); } const sites = manifest.sites.filter(item => (site ? item.name === site : true)); const domains = sites .map(site => site.domain.filter(domain => !util.isDomainRegex(domain)).map(domain => domain)) .reduce((acc, next) => [...acc, ...next], []) .map(domain => util.stripHttp(domain)) .filter(domain => domain !== 'localhost') .map(domain => `https://${domain}`); const tasks = cli.tasks(); domains.forEach(domain => { const title = `${domain}`; tasks.task(title, async (e) => { const url = `${domain}/.manifest`; const res = await http.post(url); if (!res.ok) { e.error(`${res.status}: ${res.statusText}`); } }); }); log.info(); log.info.cyan(`Resetting manifest cache 👌`); log.info(); await tasks.run({ concurrent: true }); log.info(); }