@platform/react.ssr
Version:
An SSR (server-side-render) system for react apps bundled with ParcelJS and hosted on S3.
87 lines (86 loc) • 4.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var config_1 = require("../config");
var common_1 = require("./common");
function run(args) {
if (args === void 0) { args = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var config, _a, site, manifest, sites, domains, tasks;
var _this = this;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = args.config;
if (_a) return [3, 2];
return [4, config_1.Config.create()];
case 1:
_a = (_b.sent());
_b.label = 2;
case 2:
config = _a;
site = typeof args.site === 'string' ? args.site : args.site ? args.site.name : undefined;
manifest = args.manifest;
if (!!manifest) return [3, 4];
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];
}
});
}); })
.run({ concurrent: true })];
case 3:
_b.sent();
_b.label = 4;
case 4:
if (!manifest) {
common_1.log.error("The manifest could not be found.");
return [2, common_1.cli.exit(1)];
}
sites = manifest.sites.filter(function (item) { return (site ? item.name === site : true); });
domains = sites
.map(function (site) { return site.domain.filter(function (domain) { return !common_1.util.isDomainRegex(domain); }).map(function (domain) { return domain; }); })
.reduce(function (acc, next) { return acc.concat(next); }, [])
.map(function (domain) { return common_1.util.stripHttp(domain); })
.filter(function (domain) { return domain !== 'localhost'; })
.map(function (domain) { return "https://" + domain; });
tasks = common_1.cli.tasks();
domains.forEach(function (domain) {
var title = "" + domain;
tasks.task(title, function (e) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var url, res;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
url = domain + "/.manifest";
return [4, common_1.http.post(url)];
case 1:
res = _a.sent();
if (!res.ok) {
e.error(res.status + ": " + res.statusText);
}
return [2];
}
});
}); });
});
common_1.log.info();
common_1.log.info.cyan("Resetting manifest cache \uD83D\uDC4C");
common_1.log.info();
return [4, tasks.run({ concurrent: true })];
case 5:
_b.sent();
common_1.log.info();
return [2];
}
});
});
}
exports.run = run;