@platform/react.ssr
Version:
An SSR (server-side-render) system for react apps bundled with ParcelJS and hosted on S3.
113 lines (112 loc) • 5.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var bundler_1 = require("../bundler");
var config_1 = require("../config");
var common_1 = require("./common");
var reset = require("./cmd.reset");
function run() {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var config, manifest, versions, site, version, s3, bundle, saveTo, bucket, source, target;
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 latest 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 version list', 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("Manifest could not be found.");
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();
bucket = s3.bucket;
source = config.manifest.local.path;
target = common_1.fs.join(s3.path.base, s3.path.manifest);
return [4, bundler_1.bundler.push(s3.config).manifest({ bucket: bucket, source: source, target: target, silent: false })];
case 6:
_a.sent();
return [4, reset.run({ config: config, manifest: manifest, site: site })];
case 7:
_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 ? '🌼 CURRENT' : ''),
value: value,
}); });
return [2, common_1.cli.prompt.list({
message: 'version',
items: versions.concat(['---']),
})];
});
});
}