UNPKG

@platform/react.ssr

Version:

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

33 lines (32 loc) 1.21 kB
import { bundler } from '../bundler'; import { Config } from '../config'; import { cli, fs, log } from './common'; export async function run(args = {}) { const { silent } = args; const config = await Config.create(); const bundlesDir = config.builder.bundles; const promptForVersion = async () => { const paths = await bundler.dir(bundlesDir).semver(); const versions = paths.map(path => fs.basename(path)).reverse(); const items = [...versions, '---']; const res = await cli.prompt.list({ message: 'bundle version', items }); return res; }; const version = args.prompt ? await promptForVersion() : args.version || fs.basename(await bundler.dir(bundlesDir).latest()); const { endpoint, accessKey, secret, bucket } = config.s3; const s3 = { endpoint, accessKey, secret }; const bucketKey = fs.join(config.s3.path.base, config.s3.path.bundles, version); const bundleDir = fs.resolve(fs.join(bundlesDir, version)); await bundler.push(s3).bundle({ bundleDir, bucket, bucketKey, silent, }); if (!args.silent) { log.info(); } return { version, bundleDir }; }