@platform/react.ssr
Version:
A lightweight SSR (server-side-rendering) system for react apps bundled with ParcelJS and hosted on S3.
54 lines (53 loc) • 1.82 kB
JavaScript
import { Config } from '../config';
import * as push from './cmd.push';
import { cli, fs, log } from './common';
export async function run() {
const config = await Config.create();
let manifest;
let versions = [];
log.info();
await cli
.tasks()
.task('pull manifest', async (e) => {
manifest = await config.manifest.local.ensureLatest({ minimal: true });
})
.task('pull versions', async (e) => {
versions = await config.s3.versions({ sort: 'DESC' });
})
.run({ concurrent: true });
if (!manifest) {
log.error('\nManifest could not be found.');
log.info.gray(config.manifest.s3.url);
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 });
await push.manifest({ config, silent: false });
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 ? '🌼' : ''}`,
value,
}));
return cli.prompt.list({
message: 'version',
items: [...versions, '---'],
});
}