UNPKG

@platform/react.ssr

Version:

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

107 lines (106 loc) 4.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var config_1 = require("../config"); var push = require("./cmd.push"); var common_1 = require("./common"); function run() { return tslib_1.__awaiter(this, void 0, void 0, function () { var config, manifest, versions, site, version, s3, bundle, saveTo; var _this = this; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, config_1.Config.create()]; case 1: config = _a.sent(); versions = []; common_1.log.info(); return [4, common_1.cli .tasks() .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, common_1.cli.exit(1)]; } common_1.log.info(); return [4, promptForSite({ manifest: manifest })]; case 3: site = _a.sent(); if (!site) { common_1.log.error("The site named '" + name + "' does not exist in the manifest."); return [2, common_1.cli.exit(1)]; } return [4, promptForVersion({ current: site.version, versions: versions })]; case 4: version = _a.sent(); s3 = config.s3; bundle = common_1.fs.join(s3.path.bundles, version); saveTo = config.manifest.local.path; return [4, manifest.change.site(site).bundle({ value: bundle, saveTo: saveTo })]; case 5: _a.sent(); return [4, push.manifest({ config: config, silent: false })]; case 6: _a.sent(); common_1.log.info(); return [2]; } }); }); } exports.run = run; function promptForSite(args) { return tslib_1.__awaiter(this, void 0, void 0, function () { var manifest, sites, name; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: manifest = args.manifest; sites = manifest.sites.map(function (site) { return site.name || 'Unnamed'; }); return [4, common_1.cli.prompt.list({ message: 'site', items: sites })]; case 1: name = _a.sent(); return [2, manifest.site.byName(name)]; } }); }); } function promptForVersion(args) { return tslib_1.__awaiter(this, void 0, void 0, function () { var current, versions; return tslib_1.__generator(this, function (_a) { current = args.current; versions = args.versions.map(function (value) { return ({ name: value + " " + (value === current ? '🌼' : ''), value: value, }); }); return [2, common_1.cli.prompt.list({ message: 'version', items: versions.concat(['---']), })]; }); }); }