UNPKG

@platform/react.ssr

Version:

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

58 lines (57 loc) 2.06 kB
import { bundler } from '../bundler'; import { Config } from '../config'; import { cli, log, fs } from './common'; import * as reset from './cmd.reset'; export async function run() { const config = await Config.create(); let manifest; let versions = []; log.info(); await cli .tasks() .task('pull latest manifest', async (e) => { manifest = await config.manifest.local.ensureLatest({ minimal: true }); }) .task('pull version list', async (e) => { versions = await config.s3.versions({ sort: 'DESC' }); }) .run({ concurrent: true }); if (!manifest) { log.error(`Manifest could not be found.`); return cli.exit(1); } log.info(); const site = await promptForSite({ manifest }); if (!site) { log.error(`The site named '${name}' does not exist in the manifest.`); return cli.exit(1); } const version = await promptForVersion({ current: site.version, versions }); const s3 = config.s3; const bundle = fs.join(s3.path.bundles, version); const saveTo = config.manifest.local.path; await manifest.change.site(site).bundle({ value: bundle, saveTo }); const bucket = s3.bucket; const source = config.manifest.local.path; const target = fs.join(s3.path.base, s3.path.manifest); await bundler.push(s3.config).manifest({ bucket, source, target, silent: false }); await reset.run({ config, manifest, site }); log.info(); } async function promptForSite(args) { const { manifest } = args; const sites = manifest.sites.map(site => site.name || 'Unnamed'); const name = await cli.prompt.list({ message: 'site', items: sites }); return manifest.site.byName(name); } async function promptForVersion(args) { const { current } = args; const versions = args.versions.map(value => ({ name: `${value} ${value === current ? '🌼 CURRENT' : ''}`, value, })); return cli.prompt.list({ message: 'version', items: [...versions, '---'], }); }