UNPKG

@platform/react.ssr

Version:

A lightweight SSR (server-side-rendering) system for react apps bundled with ParcelJS and hosted on S3.

138 lines (137 loc) 6.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; var tslib_1 = require("tslib"); var config_1 = require("../config"); var push = require("./cmd.push"); var common_1 = require("./common"); function run(args) { return tslib_1.__awaiter(this, void 0, void 0, function () { var cli, config, manifest, versions, sites, current, version, s3, bundle, saveTo, _i, sites_1, site; var _this = this; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: cli = args.cli; return [4, config_1.Config.create()]; case 1: config = _a.sent(); versions = []; common_1.log.info(); return [4, cli .task('pull manifest', function (e) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, config.manifest.local.ensureLatest({ minimal: true })]; case 1: manifest = _a.sent(); return [2]; } }); }); }) .task('pull versions', function (e) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, config.s3.versions({ sort: 'DESC' })]; case 1: versions = _a.sent(); return [2]; } }); }); }) .run({ concurrent: true })]; case 2: _a.sent(); if (!manifest) { common_1.log.error('\nManifest could not be found.'); common_1.log.info.gray(config.manifest.s3.url); return [2, cli.exit(1)]; } common_1.log.info(); return [4, promptForSites({ cli: cli, manifest: manifest })]; case 3: sites = _a.sent(); if (sites.length === 0) { common_1.log.error("The site named '" + name + "' does not exist in the manifest."); return [2, cli.exit(1)]; } current = sites.map(function (_a) { var version = _a.version, name = _a.name; return ({ version: version, name: name }); }); return [4, promptForVersion({ cli: cli, current: current, versions: versions })]; case 4: version = _a.sent(); s3 = config.s3; bundle = common_1.fs.join(s3.path.bundles, version); saveTo = config.manifest.local.path; _i = 0, sites_1 = sites; _a.label = 5; case 5: if (!(_i < sites_1.length)) return [3, 8]; site = sites_1[_i]; return [4, manifest.change.site(site).bundle({ value: bundle, saveTo: saveTo })]; case 6: _a.sent(); _a.label = 7; case 7: _i++; return [3, 5]; case 8: return [4, push.manifest({ cli: cli, config: config, silent: false })]; case 9: _a.sent(); common_1.log.info(); return [2]; } }); }); } exports.run = run; function promptForSites(args) { return tslib_1.__awaiter(this, void 0, void 0, function () { var cli, manifest, sites, name, site; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: cli = args.cli, manifest = args.manifest; sites = manifest.sites.map(function (site) { return site.name || 'Unnamed'; }); sites = tslib_1.__spreadArrays(['all'], sites); return [4, cli.prompt.list({ message: 'site', items: sites })]; case 1: name = _a.sent(); if (name === 'all') { return [2, manifest.sites]; } else { site = manifest.site.byName(name); return [2, site ? [site] : []]; } return [2]; } }); }); } function promptForVersion(args) { return tslib_1.__awaiter(this, void 0, void 0, function () { var cli, versions; return tslib_1.__generator(this, function (_a) { cli = args.cli; versions = args.versions.map(function (value) { var matches = args.current.filter(function (item) { return item.version === value; }); var current = matches.length === 0 ? '' : matches.length === 1 ? matches[0].name : matches.map(function (m) { return m.name; }).join(','); return { name: value + " " + (matches.length > 0 ? "\uD83C\uDF3C " + current.toUpperCase() : ''), value: value, }; }); return [2, cli.prompt.list({ message: 'version', items: tslib_1.__spreadArrays(versions, ['---']), })]; }); }); }